-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathnetmount-sshfs
More file actions
executable file
·37 lines (31 loc) · 1.21 KB
/
netmount-sshfs
File metadata and controls
executable file
·37 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env sh
# author: gotbletu
# desc: toggle mount/unmount sshfs
# depend: sshfs fuse2 openssh coreutils grep util-linux
# demo: https://youtu.be/nB31zZR2qy8
# example: mkdir -vp /tmp/zinohd && sshfs root@192.168.1.120:/media/data /tmp/zinohd
# echo "mypass" | sshfs root@192.168.1.120:/media/data /tmp/zinohd -o password_stdin
# unmount: fusermount -u /full/path/mountpoint
#------Login-----------
host_nickname=mancave
host_server=username@192.168.1.120
host_password="abcdefg"
host_dir=/
mount_point="$XDG_RUNTIME_DIR/sshfs/${host_nickname}_${host_server}"
#----------------------
color_off='\e[0m'
red='\e[0;31m'
green='\e[0;32m'
if [ -d "$mount_point" ]; then
fusermount -u "$mount_point"
rmdir "$mount_point"
host_server=$(mount | grep -i "$host_server" | cut -d':' -f1)
else
mkdir -p "$mount_point"
# auto login
echo "$host_password" | sshfs "$host_server":"$host_dir" "$mount_point" -o password_stdin
# prompt for password
# sshfs "$host_server":"$host_dir" "$mount_point"
host_server=$(mount | grep -i "$host_server" | cut -d':' -f1)
fi
[ -z "$host_server" ] && printf "%b\n" "unmounted${red} $mount_point ${color_off}" || printf "%b\n" "mounted at${green} $mount_point ${color_off}"