# Function for sshfs front end menu function f-sshfs () { explain () { clear ; fig-col figlet sshfs info-col ; echo cat << EOSSHFS Briefly, "ssh" is a protocol that allows secure encrypted access to other machines that have an "ssh daemon" (server) installed. To use ssh you must have an account on the remote "host" (server machine). You need your user name on that machine, and usually a password, unless ssh has been configured to allow "keypairs" for login. "Sshfs" is a clever system that allows you to access filesystems remotely via ssh, yet have the contents appear in a "mountpoint" directory on your local machine. INX uses $HOME/sshfs as the directory to contain mountpoints, and creates directories in it according to the IP number or hostname of the "remote host". You can choose which program to use for browsing the "share" (for example, the music player MOC, the file manager Midnight Commander, and so on). You can connect/mount or disconnect/unmount shares. On "unmounting", the mountpoint directory is removed by the INX "menu method" until you reconnect, to avoid confusion. Be aware that unmounting will fail if the directory is in use! EOSSHFS echo ; echo ; fig-col echo "Hit any key to continue..." read -s -n 1 clear ; fig-col ; echo echo "If you prefer, you can do this from the command line, of course." echo ; head-col echo "The commands for do-it-yourself are on these lines:" echo ; info-col echo "Make a directory (preferably in $HOME) to act as a mountpoint:" echo ; yellow ; bold echo "mkdir -p /path/to/mountpoint" echo ; info-col echo "To mount:" bold ; yellow ; echo echo "sshfs username@remote.host:/optional/path /path/to/mountpoint" echo ; info-col echo "To unmount:" echo ; bold ; yellow echo "fusermount -u /path/to/mountpoint" echo ; info-col echo echo "\"mountpoint\" can of course be any directory you create that is readable and writable." echo echo "You can, obviously, also use ssh in the usual manner for shell access, but sshfs gives you local access to files as if you had them on your machine - with some lag, naturally, if accessing over slow links. On a local network, the lag is rarely noticeable." echo echo "For shell access only, as opposed to sshfs, the stock command is:" echo ; yellow ; bold echo "ssh remote-username@IP-or-host" echo ; echo ; fig-col echo "Hit any key to return to the sshfs access menu." read -s -n 1 f-sshfs } options () { # Just opens a few possibilities at the selected mount point clear fig-col figlet options echo ; head-col echo "Choose an access method for $SSHOST:" info-col echo echo "1: Midnight Commander (mc)." echo "2: Vifm. " echo "3: The MOC music player." echo "4: Give me a command prompt at the mount point." echo head-col echo "x: Just give me a prompt." echo ; fig-col echo "Any other key to return to the access menu." f-ttynum read -s -n 1 ACCESS case $ACCESS in 1) echo f-sup echo mc $HOME/sshfs/$SSHOST options ;; 2) echo f-sup echo vifm $HOME/sshfs/$SSHOST options ;; 3) echo f-sup echo mocp $HOME/sshfs/$SSHOST options ;; 4) cd $HOME/sshfs/$SSHOST clear echo echo "This is a subshell - exit when you have finished, and you will return to the options menu." unbold ; white ; echo /bin/bash && cd options ;; x) clear f-prompt ;; *) f-sshfs ;; esac } connect () { clear fig-col figlet mount share echo head-col echo "Please enter the address or IP number of the server. (e.g. bleep.org , 10.1.1.2 )" echo ; white read SSHOST echo ; head-col echo "Enter your user name on the remote server (e.g. bill, linus)" echo ; white read SSHNAME echo ; head-col echo "Enter the remote directory path to access ( leave blank for your remote home directory)" echo ; white read DIRPATH echo ; head-col echo "Your $DIRPATH directory on $SSHNAME@$SSHOST will be mounted at $HOME/sshfs/$SSHOST" white echo ; info-col echo "If this is your first connection to $SSHOST, you will be asked to confirm." head-col ; echo echo "Hit < n > to abort: or any other key to connect." read -s -n 1 CONNECT case $CONNECT in n) white f-sshfs ;; *) echo f-sup # Make the mountpoint if ! [ -d $HOME/sshfs/$SSHOST ] ; then mkdir -p $HOME/sshfs/$SSHOST fi # If we can't connect port 22, forget it... 'nc -w 2 -z $SSHOST 22' checks... # Adding port options just means asking more questions... if ! nc -w 2 -z $SSHOST 22 ; then echo echo "\"$SSHOST\" doesn't seem to be listening (at least on the standard ssh port [22])" echo "Either try again later, or use command-line sshfs to specify the port." echo "Hit any key to return to the sshfs menu." read -s -n 1 rm -rf $HOME/sshfs/"$SSHOST" f-sshfs fi echo if ! sshfs "$SSHNAME"@"$SSHOST":"$DIRPATH" "$HOME"/sshfs/"$SSHOST" then echo echo "There seems to be a problem... try again." sleep 3 #Could be in use if grep $SSHOST /etc/mtab > /dev/null 2>&1 ; then echo echo "$SSHOST appears to be mounted already." sleep 3 f-sshfs else rm -rf $HOME/sshfs/"$SSHOST" f-sshfs fi else options fi ;; esac } browse () { clear bold ; fig-col ; echo figlet browse remote files echo head-col echo "Browse your remote file systems (sshfs)" mountcheck head-col ; echo echo "Choose by number - any non-number key to return to the access menu." info-col ; echo COUNT=1 for dir in $(ls -d $HOME/sshfs/*) do printf $COUNT ; printf ': ' ; printf "$(basename $dir)" ; echo echo $(basename $dir) > /tmp/access"$COUNT" COUNT=$((( $COUNT + 1 ))) done echo f-ttynum read -s -n 1 SERVER case $SERVER in [1-9]) SSHOST=$(cat /tmp/access"$SERVER") rm -f /tmp/access* options ;; *) f-sshfs ;; esac } mountcheck () { if grep sshfs /etc/mtab > /dev/null 2>&1 ; then echo ; fig-col echo "According to /etc/mtab, you have the following mounted with sshfs." echo ; bold ; green ; bred ; grep sshfs /etc/mtab | cut -d' ' -f1 bblack else echo ; head-col echo "You don't have any mounted remote filesystems now, according to /etc/mtab." echo echo "Hit any key to return to the access menu." white read -s -n 1 f-sshfs fi } unmount () { white ; clear bold ; fig-col ; echo figlet unmount shares mountcheck echo ; head-col echo "Choose the remote filesystem to unmount and disconnect." echo ; info-col COUNT=1 for dir in $(ls -d $HOME/sshfs/*) do printf $COUNT ; printf ': ' ; printf "$(basename $dir)" ; echo echo $(basename $dir) > /tmp/access"$COUNT" COUNT=$((( $COUNT + 1 ))) done echo ; head-col echo "Choose by number - any non-number key to return to the access menu." echo f-ttynum read -s -n 1 UNMOUNT case $UNMOUNT in [1-9]) echo ; head-col echo "Unmounting $(cat /tmp/access"$UNMOUNT")" fusermount -u $HOME/sshfs/$(cat /tmp/access"$UNMOUNT") echo sleep 2 rmdir $HOME/sshfs/$(cat /tmp/access"$UNMOUNT") rm -f /tmp/access* unmount ;; *) f-sshfs ;; esac } clear bold ; fig-col ; echo figlet Secure Access echo head-col echo "This menu enables access via the ssh file system." echo ; info-col echo "1: Connect to an ssh server filesystem (sshfs)" echo "2: Browse connected remote filesystems" echo "3: Disconnect/Unmount remote filesystems" echo "4: Explain ssh and sshfs." echo head-col echo "m: INX main menu" echo "w: Net and Web menu" echo "f: Flip colours" echo "x: Give me a command prompt" if grep sshfs /etc/mtab > /dev/null 2>&1 ; then info-col ; echo echo "Currently mounted sshfs directories:" bold ; echo ; fig-col grep sshfs /etc/mtab | cut -d" " -f2 white fi f-ttynum read -s -n 1 SSHFS case $SSHFS in 1) connect ;; 2) browse ;; 3) unmount ;; 4) explain ;; m) f-menu ;; w) f-net ;; f) export CALL=sharinx f-switch ;; x) clear f-prompt ;; *) echo echo "I didn't understand that request - please try again." sleep 2 f-sshfs ;; esac }