commit
8ef030add5
7 changed files with 344 additions and 0 deletions
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
# Local directory where the remote storages should be mounted to |
||||
LOCALMOUNTDIR=/home/user/remote |
||||
|
||||
## mnt-sftp.sh |
||||
# Preconfigured HOSTs in ~/.ssh/config can be used |
||||
PRESSH[0]=server1 |
||||
PRESSH[1]=user@server2.tld |
||||
PRESSH[2]=root@12.34.56.78 |
||||
|
||||
|
||||
## mnt-share.sh |
||||
NASIP='192.168.178.255' |
||||
NASDIR='Share' |
||||
NASUSER='user' |
||||
NASPASS='password' |
||||
|
||||
|
||||
## mnt-share2.sh |
||||
SHAREPATH[0]='0:192.168.178.255/Share' |
||||
SHAREUSER[0]='user' |
||||
SHAREPASS[0]='password' |
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
#!/bin/bash |
||||
# Variablen: PART NASIP DEST NAME |
||||
# Erforderlich: pcmanfm smbfs/cifs-utils |
||||
|
||||
cd "$(dirname "$(readlink -f "$0")")" |
||||
# Test if config.cfg exists and set needed variables |
||||
if [ ! -e config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi |
||||
source config.cfg |
||||
|
||||
## FUNKTIONEN |
||||
|
||||
# Überprüft, ob Root-Rechte am Start sind |
||||
function rootcheck { |
||||
if [ $EUID -ne 0 ]; then |
||||
echo "Dieses Script benötigt Root-Rechte. Rechte erlangen mit \"su\" oder \"sudo -i\"." |
||||
exit 1 |
||||
fi |
||||
} |
||||
|
||||
# Möglichkeit, Variablen zu ändern |
||||
function varcheck { |
||||
echo "Folgende Parameter sind vorgegeben:" |
||||
echo "Adresse des Zielortes: $NASPATH" |
||||
echo "User für Zielort, falls nötig (sonst leer): $NASUSER" |
||||
echo "Passwort für Zielort, falls nötig (sonst leer): $NASPASS" |
||||
read -p "Sollen diese so übernommen werden? [y/n]: " YN |
||||
if [ "$YN" = "y" ]; then |
||||
echo "Daten wurden akzeptiert. Fahre fort..." |
||||
elif [ "$YN" = "n" ]; then |
||||
echo "Nun gewünschte Daten für Zielort eingeben:" |
||||
read -p "Adresse des Zielortes: " NASPATH |
||||
read -p "User für Zielort, falls nötig (sonst leer): " NASUSER |
||||
read -p "Passwort für Zielort, falls nötig (sonst leer): " NASPASS |
||||
echo "Daten wurden übernommen. Fahre fort..." |
||||
else |
||||
echo "Ungültige Eingabe. Script wird beendet." |
||||
exit 1 |
||||
fi |
||||
unset YN |
||||
} |
||||
|
||||
# Mounte Zielverzeichnis |
||||
function nasmount { |
||||
if ! ([ "$NASUSER" = "" ] && [ "$NASPASS" = "" ]); then |
||||
OPT="-o user=$NASUSER,password=$NASPASS" |
||||
fi |
||||
|
||||
if [ ! -e /mnt/nas ]; then |
||||
mkdir -p /mnt/nas |
||||
fi |
||||
|
||||
mount -t cifs //$NASPATH /mnt/nas $OPT |
||||
} |
||||
|
||||
# Fragt Namen des Kunden ab und erstellt Verzeichnis wenn nötig |
||||
function destcheck { |
||||
read -p "Name des Kunden: " NAME |
||||
if [ ! -e /mnt/nas/$NAME ]; then |
||||
mkdir /mnt/nas/$NAME |
||||
fi |
||||
} |
||||
|
||||
# Frage zu sichernde Partition ab |
||||
function partmount { |
||||
fdisk -l |
||||
YN="y" |
||||
while [ "$YN" = "y" ]; do |
||||
read -p "Welche NTFS-Partition soll gemountet werden? [z.B /dev/sda1]: " PART |
||||
if [ ! -e $PART ]; then |
||||
echo "Partition nicht vorhanden, bitte zu mountende Partition auswählen!" |
||||
else |
||||
if [ ! -e /mnt$PART ]; then |
||||
mkdir -p /mnt$PART |
||||
fi |
||||
mount -t ntfs-3g $PART /mnt$PART -o force |
||||
pcmanfm /mnt$PART /mnt/nas/$KUNDE & |
||||
fi |
||||
read -p "Noch eine Partition mounten? y für Ja, beliebige Taste zum Abbrechen: " YN |
||||
done |
||||
unset YN |
||||
} |
||||
|
||||
|
||||
## START DES PROGRAMMS |
||||
rootcheck |
||||
|
||||
if [ "$1" = "unmount" ]; then |
||||
umount /mnt/nas /mnt/dev/* |
||||
echo "/mnt/nas und /mnt/dev/* wurden ausgehängt. Beende." |
||||
exit 1 |
||||
fi |
||||
|
||||
varcheck |
||||
nasmount |
||||
destcheck |
||||
partmount |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
1. Datei von NAS auf lokal herunterladen |
||||
2. RM auf Datei, Eigenschaften, Berechtigungen, Datei als Programm ausführen |
||||
3. Im Dateimanager zu lokaler Datei navigieren und F4 drücken --> Terminal an dieser Stelle wird geöffnet |
||||
4. "su" eingeben für Root-Rechte |
||||
5. ./mountscript.sh --> Anweisungen folgen |
||||
|
||||
Zum Unmounten aller Partitionen + NAS: |
||||
./mountscript.sh unmount |
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash |
||||
|
||||
cd "$(dirname "$(readlink -f "$0")")" |
||||
# Test if config.cfg exists and set needed variables |
||||
if [ ! -e config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi |
||||
source config.cfg |
||||
|
||||
|
||||
# Add SSH key to local keyring if not already happened |
||||
function sshadd { |
||||
ssh-add -l >/dev/null || ssh-add |
||||
} |
||||
|
||||
# Choose preconfigured HOST to mount |
||||
function mount { |
||||
if ! SSH=$(zenity --list \ |
||||
--height=400 \ |
||||
--text="Please choose. Cancel to unmount drives." \ |
||||
--title="Choose SSH server" \ |
||||
--column "Preconfigured SSH servers" \ |
||||
${PRESSH[*]}); then |
||||
unmountquestion # If you press cancel, it should ask you to unmount all drives |
||||
fi |
||||
|
||||
# If you double click on an entry, it gives 'server1|server1' as result instead of 'server1' |
||||
# This command cuts of everything after | |
||||
SSH=$(echo $SSH | awk -F\| '{ print $1 }') |
||||
|
||||
# Make a local directory if not available |
||||
if [ ! -e "$LOCALMOUNTDIR"/"$SSH" ]; then |
||||
mkdir -p "$LOCALMOUNTDIR"/"$SSH" |
||||
fi |
||||
|
||||
# Command to mount actually |
||||
sshfs "$SSH": "$LOCALMOUNTDIR"/"$SSH"/ -o follow_symlinks & |
||||
|
||||
quitquestion # one more ssh server or quit? |
||||
|
||||
} |
||||
|
||||
# Ask if all preconfigured SSHFS drives should be unmounted |
||||
function unmountquestion { |
||||
zenity --question --text="Unmount all preconfigured\nSSHFS drives now?" |
||||
if [ "$?" = "0" ]; then |
||||
unmount # unmount function |
||||
else |
||||
exit 0 |
||||
fi |
||||
} |
||||
|
||||
# Procedure to unmount all preconfigured SSHFS drives and exit program afterwards |
||||
function unmount { |
||||
for ((i = 0; i < ${#PRESSH[*]}; i++)) |
||||
do |
||||
fusermount -u "$LOCALMOUNTDIR"/"${PRESSH[$i]}" |
||||
echo ""${PRESSH[$i]}" unmounted." |
||||
done |
||||
exit 0 |
||||
} |
||||
|
||||
# Should another SSHFS storage be mounted? |
||||
function quitquestion { |
||||
zenity --question \ |
||||
--text="Mount another SSHFS storage?" |
||||
if [ "$?" = "1" ]; then |
||||
exit 0 |
||||
fi |
||||
} |
||||
|
||||
sshadd # sshadd function |
||||
|
||||
# Loop for endless mounts until stopped by unmount or unmountquestion |
||||
while : |
||||
do |
||||
mount # mount function |
||||
done |
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash |
||||
# Variablen: PART NASIP DEST NAME |
||||
# Erforderlich: pcmanfm smbfs/cifs-utils |
||||
|
||||
cd "$(dirname "$(readlink -f "$0")")" |
||||
# Test if config.cfg exists and set needed variables |
||||
if [ ! -e config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi |
||||
source config.cfg |
||||
|
||||
## FUNKTIONEN |
||||
|
||||
# Überprüft, ob Root-Rechte am Start sind |
||||
function rootcheck { |
||||
if [ $EUID -ne 0 ]; then |
||||
echo "Dieses Script benötigt Root-Rechte. Rechte erlangen mit \"su\" oder \"sudo -i\"." |
||||
exit 1 |
||||
fi |
||||
} |
||||
|
||||
# Möglichkeit, Variablen zu ändern |
||||
function varcheck { |
||||
echo "Folgende Parameter sind vorgegeben:" |
||||
echo "Adresse des Zielortes: $NASDIR auf $NASIP" |
||||
echo "User für Zielort, falls nötig (sonst leer): $NASUSER" |
||||
echo "Passwort für Zielort, falls nötig (sonst leer): $NASPASS" |
||||
read -p "Sollen diese so übernommen werden? [y/n]: " YN |
||||
if [ "$YN" = "y" ]; then |
||||
echo "Daten wurden akzeptiert. Fahre fort..." |
||||
elif [ "$YN" = "n" ]; then |
||||
echo "Nun gewünschte Daten für Zielort eingeben:" |
||||
read -p "Adresse des Zielortes: " NASPATH |
||||
read -p "User für Zielort, falls nötig (sonst leer): " NASUSER |
||||
read -p "Passwort für Zielort, falls nötig (sonst leer): " NASPASS |
||||
echo "Daten wurden übernommen. Fahre fort..." |
||||
else |
||||
echo "Ungültige Eingabe. Script wird beendet." |
||||
exit 1 |
||||
fi |
||||
unset YN |
||||
} |
||||
|
||||
# Mounte Zielverzeichnis |
||||
function nasmount { |
||||
if ! ([ "$NASUSER" = "" ] && [ "$NASPASS" = "" ]); then |
||||
OPT="-o user=$NASUSER,password=$NASPASS" |
||||
fi |
||||
|
||||
if [ ! -e $LOCALMOUNTDIR/$NASDIR ]; then |
||||
mkdir -p $LOCALMOUNTDIR/$NASDIR |
||||
fi |
||||
|
||||
mount -t cifs //$NASIP/$NASDIR $LOCALMOUNTDIR/$NASDIR $OPT |
||||
} |
||||
|
||||
|
||||
## START DES PROGRAMMS |
||||
#rootcheck |
||||
|
||||
if [ "$1" = "unmount" ]; then |
||||
umount /mnt/nas /mnt/dev/* |
||||
echo "/mnt/nas und /mnt/dev/* wurden ausgehängt. Beende." |
||||
exit 1 |
||||
fi |
||||
|
||||
varcheck |
||||
nasmount |
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash |
||||
|
||||
## VARIABLES TO BE CHANGED |
||||
|
||||
cd "$(dirname "$(readlink -f "$0")")" |
||||
# Test if config.cfg exists and set needed variables |
||||
if [ ! -e config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi |
||||
source config.cfg |
||||
|
||||
# Choose preconfigured SHARE to mount |
||||
function mount { |
||||
if ! SHARE=$(zenity --list \ |
||||
--height=300 \ |
||||
--text="Please choose. Cancel to unmount shares." \ |
||||
--title="Choose Network Share" \ |
||||
--column "Preconfigured Network Shares" \ |
||||
${SHAREPATH[*]}); then |
||||
unmountquestion # If you press cancel, it should ask you to unmount all drives |
||||
fi |
||||
|
||||
# If you double click on an entry, it gives 'server1|server1' as result instead of 'server1' |
||||
# This command cuts of everything after | |
||||
NUM=$(echo $SHARE | awk -F: '{ print $1 }') # Which Array? |
||||
SHARE=$(echo $SHARE | awk -F\| '{ print $1 }' | awk -F: '{ print $2 }') |
||||
SHAREDIR=$(echo $SHARE | awk -F/ '{ print $2 }') # Directory to use |
||||
|
||||
# Make a local directory if not available |
||||
if [ ! -e "$LOCALMOUNTDIR"/"$SHAREDIR" ]; then |
||||
mkdir -p "$LOCALMOUNTDIR"/"$SHAREDIR" |
||||
fi |
||||
|
||||
# Command to mount actually |
||||
OPT="-o user="${SHAREUSER[$NUM]}",password="${SHAREPASS[$NUM]}"" |
||||
echo "mount -t cifs //$SHARE $LOCALMOUNTDIR/$SHAREDIR $OPT" |
||||
|
||||
quitquestion # one more share or quit? |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
# Ask if all preconfigured shares should be unmounted |
||||
function unmountquestion { |
||||
zenity --question --text="Unmount all preconfigured\nnetwork shares now?" |
||||
if [ "$?" = "0" ]; then |
||||
unmount # unmount function |
||||
else |
||||
exit 0 |
||||
fi |
||||
} |
||||
|
||||
# Procedure to unmount all preconfigured shares and exit program afterwards |
||||
function unmount { |
||||
for ((i = 0; i < ${#SHAREPATH[*]}; i++)) |
||||
do |
||||
SHAREDIR=$(echo "${SHAREPATH[$i]}" | awk -F/ '{ print $2 }') |
||||
unmount "$LOCALMOUNTDIR"/$SHAREDIR |
||||
echo ""${SHAREPATH[$i]}" unmounted." |
||||
done |
||||
exit 0 |
||||
} |
||||
|
||||
# Should another network share storage be mounted? |
||||
function quitquestion { |
||||
zenity --question \ |
||||
--text="Mount another network share storage?" |
||||
if [ "$?" = "1" ]; then |
||||
exit 0 |
||||
fi |
||||
} |
||||
|
||||
# Loop for endless mounts until stopped by unmount or unmountquestion |
||||
while : |
||||
do |
||||
mount # mount function |
||||
done |
Loading…
Reference in new issue