Browse Source

change indent tabs -> spaces

master
mxmehl 5 years ago
parent
commit
43b176b79a
  1. 184
      mnt-sftp.sh

184
mnt-sftp.sh

@ -36,7 +36,7 @@ source config.cfg
# Add SSH key to local keyring if not already happened
function sshadd {
ssh-add -l >/dev/null || ssh-add
ssh-add -l >/dev/null || ssh-add
}
for ((i = 0; i < ${#PRESSH[*]}; i++))
@ -55,114 +55,114 @@ SSHLIST=$(grep -E "Host\s[[:alnum:]]" $SSHCONFIG | awk -F' ' '{ print $2 }')
# 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" \
"<manual input>" $SSHLIST ${PRESSHLIST[*]}); 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 }')
## Recognize if the input was entered manually, by .ssh/config or by the predefined SSH list in config.cfg
ISPRE=$(echo ${PRESSHLIST[@]} | grep -q "$SSH" ; echo $?)
if [ "$SSH" == "<manual input>" ]; then
MAN="1"
SSHUSER=$(zenity --entry --text "SSH user" --title "Enter SSH user")
SSHHOST=$(zenity --entry --text "SSH host" --title "Enter SSH host")
SSHPORT=$(zenity --entry --text "SSH port (default 22)" --title "Enter SSH port")
SSHPASS=$(zenity --entry --hide-text --text "SSH password" --title "Enter SSH password")
SSHPATH=$(zenity --entry --text "Desired root directory on server (default /)" --title "Enter SSH root directory")
if [ "$SSHPORT" == "" ]; then
SSHPORT=22
fi
if [ "$SSHPATH" == "" ]; then
SSHPATH="/"
fi
SSH="m-$SSHUSER-$RANDOM"
elif [ "$ISPRE" == "0" ]; then
MAN="1"
# Detect which predefined host was chosen and set variables accordingly
for ((i = 0; i < ${#PRESSHLIST[*]}; i++))
do
if [ "$(echo ${PRESSHLIST[$i]} | grep -q "$SSH" ; echo $?)" == "0" ]; then
SSHUSER=${PREUSER[$i]}
SSHHOST=${PREHOST[$i]}
SSHPORT=${PREPORT[$i]}
SSHPASS=${PREPASS[$i]}
SSHPATH=${PREPATH[$i]}
fi
done
SSH="p-$SSHUSER-$RANDOM"
else
MAN="0"
fi
# Make a local directory if not available
if [ ! -e "$LOCALMOUNTDIR"/"$SSH" ]; then
mkdir -p "$LOCALMOUNTDIR"/"$SSH"
fi
# Command to mount actually
if [ "$MAN" = "0" ]; then
sshfs -C "$SSH": "$LOCALMOUNTDIR"/"$SSH"/ -o follow_symlinks &
else
echo "$SSHPASS" | sshfs -C -o password_stdin -p "$SSHPORT" "$SSHUSER"@"$SSHHOST":"$SSHPATH" "$LOCALMOUNTDIR"/"$SSH"/ -o follow_symlinks &
fi
quitquestion # one more ssh server or quit?
if ! SSH=$(zenity --list \
--height=400 \
--text="Please choose. Cancel to unmount drives." \
--title="Choose SSH server" \
--column "Available SSH servers" \
"<manual input>" $SSHLIST ${PRESSHLIST[*]}); 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 }')
## Recognize if the input was entered manually, by .ssh/config or by the predefined SSH list in config.cfg
ISPRE=$(echo ${PRESSHLIST[@]} | grep -q "$SSH" ; echo $?)
if [ "$SSH" == "<manual input>" ]; then
MAN="1"
SSHUSER=$(zenity --entry --text "SSH user" --title "Enter SSH user")
SSHHOST=$(zenity --entry --text "SSH host" --title "Enter SSH host")
SSHPORT=$(zenity --entry --text "SSH port (default 22)" --title "Enter SSH port")
SSHPASS=$(zenity --entry --hide-text --text "SSH password" --title "Enter SSH password")
SSHPATH=$(zenity --entry --text "Desired root directory on server (default /)" --title "Enter SSH root directory")
if [ "$SSHPORT" == "" ]; then
SSHPORT=22
fi
if [ "$SSHPATH" == "" ]; then
SSHPATH="/"
fi
SSH="m-$SSHUSER-$RANDOM"
elif [ "$ISPRE" == "0" ]; then
MAN="1"
# Detect which predefined host was chosen and set variables accordingly
for ((i = 0; i < ${#PRESSHLIST[*]}; i++))
do
if [ "$(echo ${PRESSHLIST[$i]} | grep -q "$SSH" ; echo $?)" == "0" ]; then
SSHUSER=${PREUSER[$i]}
SSHHOST=${PREHOST[$i]}
SSHPORT=${PREPORT[$i]}
SSHPASS=${PREPASS[$i]}
SSHPATH=${PREPATH[$i]}
fi
done
SSH="p-$SSHUSER-$RANDOM"
else
MAN="0"
fi
# Make a local directory if not available
if [ ! -e "$LOCALMOUNTDIR"/"$SSH" ]; then
mkdir -p "$LOCALMOUNTDIR"/"$SSH"
fi
# Command to mount actually
if [ "$MAN" = "0" ]; then
sshfs -C "$SSH": "$LOCALMOUNTDIR"/"$SSH"/ -o follow_symlinks &
else
echo "$SSHPASS" | sshfs -C -o password_stdin -p "$SSHPORT" "$SSHUSER"@"$SSHHOST":"$SSHPATH" "$LOCALMOUNTDIR"/"$SSH"/ -o follow_symlinks &
fi
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
zenity --question --text="Unmount all configured\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 FILE in "$LOCALMOUNTDIR"/*;
do
if [ "$(cat /etc/mtab | grep -q "$FILE"; echo $?)" == "0" ]; then
fusermount -u "$FILE"
echo "$FILE unmounted."
fi
done
# Remove all empty directories which have been created by the manual/predefined mount process (m-XYZ-$RANDOM)
find "$LOCALMOUNTDIR"/ -maxdepth 1 -type d -empty -regextype sed -regex ".*/[pm]-.\+\?-[0-9]\{2,6\}" -delete
exit 0
for FILE in "$LOCALMOUNTDIR"/*;
do
if [ "$(cat /etc/mtab | grep -q "$FILE"; echo $?)" == "0" ]; then
fusermount -u "$FILE"
echo "$FILE unmounted."
fi
done
# Remove all empty directories which have been created by the manual/predefined mount process (m-XYZ-$RANDOM)
find "$LOCALMOUNTDIR"/ -maxdepth 1 -type d -empty -regextype sed -regex ".*/[pm]-.\+\?-[0-9]\{2,6\}" -delete
exit 0
}
# Should another SSHFS storage be mounted?
function quitquestion {
zenity --question \
--text="Mount another SSHFS storage?"
if [ "$?" = "1" ]; then
exit 0
fi
zenity --question \
--text="Mount another SSHFS storage?"
if [ "$?" = "1" ]; then
exit 0
fi
}
sshadd # sshadd function
sshadd # sshadd function
# Loop for endless mounts until stopped by unmount or unmountquestion
while :
do
mount # mount function
mount # mount function
done

Loading…
Cancel
Save