#!/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