added manual ssh input; improved fusermount strategy

This commit is contained in:
2015-03-23 17:55:58 +03:00
parent 3afb52d2bd
commit 80aae45cf7

View File

@@ -18,7 +18,7 @@ function mount {
--text="Please choose. Cancel to unmount drives." \
--title="Choose SSH server" \
--column "Preconfigured SSH servers" \
${PRESSH[*]}); then
"<manual input>" ${PRESSH[*]}); then
unmountquestion # If you press cancel, it should ask you to unmount all drives
fi
@@ -26,13 +26,34 @@ function mount {
# This command cuts of everything after |
SSH=$(echo $SSH | awk -F\| '{ print $1 }')
if [ "$SSH" == "<manual input>" ]; then
MAN=1
SSHUSER=$(zenity --entry --text "SSH user" --title "Enter SSH user")
SSHPASS=$(zenity --entry --hide-text --text "SSH password" --title "Enter SSH password")
SSHHOST=$(zenity --entry --text "SSH host" --title "Enter SSH host")
SSHPORT=$(zenity --entry --text "SSH port (default 22)" --title "Enter SSH port")
SSHPATH=$(zenity --entry --text "Desired root directory (default /)" --title "Enter SSH root directory")
if [ "$SSHPORT" == "" ]; then
SSHPORT=22
fi
if [ "$SSHPATH" == "" ]; then
SSHPATH="/"
fi
SSH="$SSHUSER-$RANDOM"
fi
# 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 &
if [ $MAN = 0 ]; then
sshfs "$SSH": "$LOCALMOUNTDIR"/"$SSH"/ -o follow_symlinks &
else
echo "$SSHPASS" | sshfs -o password_stdin -p "$SSHPORT" "$SSHUSER"@"$SSHHOST":"$SSHPATH" "$LOCALMOUNTDIR"/"$SSH"/ -o follow_symlinks &
fi
quitquestion # one more ssh server or quit?
@@ -50,11 +71,20 @@ function unmountquestion {
# Procedure to unmount all preconfigured SSHFS drives and exit program afterwards
function unmount {
for ((i = 0; i < ${#PRESSH[*]}; i++))
#for ((i = 0; i < ${#PRESSH[*]}; i++))
#do
#fusermount -u "$LOCALMOUNTDIR"/"${PRESSH[$i]}"
#echo ""${PRESSH[$i]}" unmounted."
#done
for FILE in "$LOCALMOUNTDIR"/*;
do
fusermount -u "$LOCALMOUNTDIR"/"${PRESSH[$i]}"
echo ""${PRESSH[$i]}" unmounted."
if [ "$(cat /etc/mtab | grep -q "$FILE"; echo $?)" == "0" ]; then
fusermount -u "$FILE"
echo "$FILE unmounted."
fi
done
exit 0
}