From a3fabcc7cd8bda5f912229fff24dd0385903d192 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Fri, 20 Nov 2020 15:53:16 -0800 Subject: [PATCH] set up sshfs module and mounting with startup for 238/645/3115 --- .gitignore | 3 + .../function/ssh-mounts/00-ssh-mount-238 | 1 - .../function/ssh-mounts/238 | 2 +- .../function/ssh-mounts/238-lights | 0 .../function/ssh-mounts/hacking | 0 .../function/ssh-mounts/lights | 0 {238 => 238.kebler.net}/startup/238-mounts.sh | 8 ++- 238/logs/238-mount.log | 28 -------- .../function/ssh-mounts/00-mount-3115.sh | 21 ++++++ 3115.kebler.net/function/ssh-mounts/3115 | 72 +++++++++++++++++++ 3115.kebler.net/startup/3115-mounts.sh | 19 +++++ .../function/ssh-mounts/00-mount-645.sh | 29 ++++++++ .../function/ssh-mounts}/645 | 10 +-- .../function/ssh-mounts}/645-lights | 12 ++-- .../function/ssh-mounts}/backup-645-lights | 2 - 645.kebler.net/startup/645-mounts.sh | 19 +++++ 645/misc/mount-645.sh | 33 --------- all/env/{ssh.env => ssh-agent-socket.env} | 0 all/modules/sshfs/sshfs.sh | 8 ++- all/startup/ssh-agent-socket | 2 + 20 files changed, 188 insertions(+), 81 deletions(-) create mode 100644 .gitignore rename {238 => 238.kebler.net}/function/ssh-mounts/00-ssh-mount-238 (97%) rename {238 => 238.kebler.net}/function/ssh-mounts/238 (96%) rename {238 => 238.kebler.net}/function/ssh-mounts/238-lights (100%) rename {238 => 238.kebler.net}/function/ssh-mounts/hacking (100%) rename {238 => 238.kebler.net}/function/ssh-mounts/lights (100%) rename {238 => 238.kebler.net}/startup/238-mounts.sh (57%) delete mode 100644 238/logs/238-mount.log create mode 100644 3115.kebler.net/function/ssh-mounts/00-mount-3115.sh create mode 100644 3115.kebler.net/function/ssh-mounts/3115 create mode 100644 3115.kebler.net/startup/3115-mounts.sh create mode 100755 645.kebler.net/function/ssh-mounts/00-mount-645.sh rename {645/function/mounts => 645.kebler.net/function/ssh-mounts}/645 (83%) rename {645/function/mounts => 645.kebler.net/function/ssh-mounts}/645-lights (82%) rename {645/function/mounts => 645.kebler.net/function/ssh-mounts}/backup-645-lights (99%) create mode 100755 645.kebler.net/startup/645-mounts.sh delete mode 100755 645/misc/mount-645.sh rename all/env/{ssh.env => ssh-agent-socket.env} (100%) create mode 100644 all/startup/ssh-agent-socket diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86be436 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/645.kebler.net/logs/ +/238.kebler.net/logs/ +*.log diff --git a/238/function/ssh-mounts/00-ssh-mount-238 b/238.kebler.net/function/ssh-mounts/00-ssh-mount-238 similarity index 97% rename from 238/function/ssh-mounts/00-ssh-mount-238 rename to 238.kebler.net/function/ssh-mounts/00-ssh-mount-238 index c5338c9..308be2e 100755 --- a/238/function/ssh-mounts/00-ssh-mount-238 +++ b/238.kebler.net/function/ssh-mounts/00-ssh-mount-238 @@ -16,7 +16,6 @@ mnt238relays mnt238switches } -#!/bin/bash function ssh-unmount-238 () { echo mounting folders locally from 238 network hosts umnt238gate diff --git a/238/function/ssh-mounts/238 b/238.kebler.net/function/ssh-mounts/238 similarity index 96% rename from 238/function/ssh-mounts/238 rename to 238.kebler.net/function/ssh-mounts/238 index e0c2f31..a06c8eb 100644 --- a/238/function/ssh-mounts/238 +++ b/238.kebler.net/function/ssh-mounts/238 @@ -67,7 +67,7 @@ usmount /mnt/238/water/home } function mnt238hass(){ -smount root@hassio.238.kebler.net:/ /mnt/238/hass -p 22 +smount root@hassio.238.kebler.net:/ /mnt/238/hass -p 22 -o allow_other } function umnt238hass(){ diff --git a/238/function/ssh-mounts/238-lights b/238.kebler.net/function/ssh-mounts/238-lights similarity index 100% rename from 238/function/ssh-mounts/238-lights rename to 238.kebler.net/function/ssh-mounts/238-lights diff --git a/238/function/ssh-mounts/hacking b/238.kebler.net/function/ssh-mounts/hacking similarity index 100% rename from 238/function/ssh-mounts/hacking rename to 238.kebler.net/function/ssh-mounts/hacking diff --git a/238/function/ssh-mounts/lights b/238.kebler.net/function/ssh-mounts/lights similarity index 100% rename from 238/function/ssh-mounts/lights rename to 238.kebler.net/function/ssh-mounts/lights diff --git a/238/startup/238-mounts.sh b/238.kebler.net/startup/238-mounts.sh similarity index 57% rename from 238/startup/238-mounts.sh rename to 238.kebler.net/startup/238-mounts.sh index 0b74c5c..3c7c43e 100755 --- a/238/startup/238-mounts.sh +++ b/238.kebler.net/startup/238-mounts.sh @@ -6,10 +6,14 @@ llog "sourcing: $f" source "$f" done # declare -F | grep 238 +delay=60 mkdir -p $dir/logs touch $dir/logs/238-mount.log -( sleep 60 ; +notify-send "mounting 238 network directories in $delay secs" +( sleep $delay ; echo $(date) > $dir/logs/238-mount.log; -llog "after delay 238 network mounting" +llog "after $delay sec delay 238 network is mounting" +notify-send "mounting 238 network directories in /mnt/238" ssh-mount-238 2>&1 | tee -a $dir/logs/238-mount.log +notify-send "done mounting 238 network directories" ) & diff --git a/238/logs/238-mount.log b/238/logs/238-mount.log deleted file mode 100644 index 3dfdb46..0000000 --- a/238/logs/238-mount.log +++ /dev/null @@ -1,28 +0,0 @@ -Fri Nov 13 09:45:13 PST 2020 -mounting folders locally from 238 network hosts -remote sysadmin@gateway.238.kebler.net:/home/sysadmin already mounted at /mnt/238/gate/sysadmin, aborting mount -remote sysadmin@gateway.238.kebler.net:/opt already mounted at /mnt/238/gate/opt, aborting mount -remote root@gateway.238.kebler.net:/ already mounted at /mnt/238/gate/root, aborting mount -remote root@gateway.238.kebler.net:/etc already mounted at /mnt/238/gate/etc, aborting mount -remote sysadmin@nas.238.kebler.net:/opt already mounted at /mnt/238/nas/opt, aborting mount -remote sysadmin@nas.238.kebler.net:/mnt/data already mounted at /mnt/238/nas/data, aborting mount -remote sysadmin@nas.238.kebler.net:/mnt/datamirror already mounted at /mnt/238/nas/datamirror, aborting mount -remote sysadmin@nas.kebler.net:/home/sysadmin already mounted at /mnt/238/nas/sysadmin, aborting mount -remote root@nas.238.kebler.net:/ already mounted at /mnt/238/nas/root, aborting mount -remote root@hassio.238.kebler.net:/ already mounted at /mnt/238/hass, aborting mount -remote sysadmin@trantor.kebler.net:/home/sysadmin already mounted at /mnt/238/trantor/sysadmin, aborting mount -remote sysadmin@trantor.kebler.net:/opt already mounted at /mnt/238/trantor/opt, aborting mount -remote sysadmin@trantor.kebler.net:/mnt/data already mounted at /mnt/238/trantor/data, aborting mount -remote root@trantor.kebler.net:/ already mounted at /mnt/238/trantor/root, aborting mount -remote sysadmin@water.kebler.net:/home/sysadmin already mounted at /mnt/238/water/home, aborting mount -remote sysadmin@water.kebler.net:/opt already mounted at /mnt/238/water/opt, aborting mount -remote root@water.kebler.net:/ already mounted at /mnt/238/water/root, aborting mount -host lights.238.kebler.net not reachable, aborting mount -host lights.238.kebler.net not reachable, aborting mount -host lights.238.kebler.net not reachable, aborting mount -host lights.238.kebler.net not reachable, aborting mount -host lights.238.kebler.net not reachable, aborting mount -host lights.238.kebler.net not reachable, aborting mount -host lights.238.kebler.net not reachable, aborting mount -host lights.238.kebler.net not reachable, aborting mount -host lights.238.kebler.net not reachable, aborting mount diff --git a/3115.kebler.net/function/ssh-mounts/00-mount-3115.sh b/3115.kebler.net/function/ssh-mounts/00-mount-3115.sh new file mode 100644 index 0000000..0a79c07 --- /dev/null +++ b/3115.kebler.net/function/ssh-mounts/00-mount-3115.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +module_load sshfs +module_load net-utils +module_load filesystem + +function ssh-mount-3115 () { +echo ======== ...mounting 3115 devices via vpn ======== +mnt3115gate +mnt3115nas +mnt3115hass +mntfrodo +} + +function ssh-unmount-3115 () { +echo ======== ...mounting 3115 devices via vpn ======== +umnt3115gate +umnt3115nas +umnt3115hass +umntfrodo +} diff --git a/3115.kebler.net/function/ssh-mounts/3115 b/3115.kebler.net/function/ssh-mounts/3115 new file mode 100644 index 0000000..ed78f52 --- /dev/null +++ b/3115.kebler.net/function/ssh-mounts/3115 @@ -0,0 +1,72 @@ +#!/bin/bash +# vpn tunnel must be operation with dns resolution at 3115 dns server + + +function mnt3115nas(){ +smount sysadmin@nas.3115.kebler.net:/opt /mnt/3115/nas/opt -p 22 +smount sysadmin@nas.3115.kebler.net:/mnt/data /mnt/3115/nas/data -p 22 +smount sysadmin@nas.3115.kebler.net:/mnt/backup /mnt/3115/nas/backup -p 22 +smount sysadmin@nas.3115.kebler.net:/home/sysadmin /mnt/3115/nas/sysadmin -p 22 +smount root@nas.3115.kebler.net:/ /mnt/3115/nas/root -p 22 +} + +function umnt3115nas(){ +usmount /mnt/3115/nas/opt +usmount /mnt/3115/nas/data +usmount /mnt/3115/nas/backup +usmount /mnt/3115/nas/sysadmin +usmount /mnt/3115/nas/root +} + +function mnt3115gate(){ +smount root@grouter.3115.kebler.net:/ /mnt/3115/gate -p 22 +} + +function umnt3115gate(){ +usmount /mnt/3115/gate +} + + +function mntfrodo(){ +smount sysadmin@frodo.kebler.net:/opt /mnt/3115/frodo/opt -p 22 +smount sysadmin@frodo.kebler.net:/home/sysadmin /mnt/3115/frodo/sysadmin -p 22 +smount sysadmin@frodo.kebler.net:/mnt/data /mnt/3115/frodo/data -p 22 +smount root@frodo.kebler.net:/ /mnt/3115/frodo/root -p 22 +} + +function umntfrodo(){ +usmount /mnt/3115/frodo/opt +usmount /mnt/3115/frodo/sysadmin +usmount /mnt/3115/frodo/data +usmount /mnt/3115/frodo/root +} + +function mnt3115hass(){ +smount root@hassio.3115.kebler.net:/ /mnt/3115/hass -p 22 +} + +function umnt3115hass(){ +usmount /mnt/3115/hass +} + +# via NAT at WAN interface (mostly to support old gateway) + +function mnt3115gatew(){ +smount sysadmin@3115.kebler.net:/opt /mnt/3115/wgate/opt -p 22 +smount sysadmin@3115.kebler.net:/home/sysadmin /mnt/3115/wgate/sysadmin -p 22 +smount root@3115.kebler.net:/ /mnt/3115/wgate/root -p 22 +} + +function umnt3115gatew(){ +usmount /mnt/3115/wgate/opt +usmount /mnt/3115/wgate/sysadmin +usmount /mnt/3115/wgate/root +} + +function mnt3115nasw(){ +smount sysadmin@3115.kebler.net:/opt /mnt/3115/nas/opt -p 322 +smount sysadmin@3115.kebler.net:/mnt/data /mnt/3115/nas/data -p 322 +smount sysadmin@3115.kebler.net:/mnt/backup /mnt/3115/nas/backup -p 322 +smount sysadmin@3115.kebler.net:/home/sysadmin /mnt/3115/nas/sysadmin -p 322 +smount root@3115.kebler.net:/ /mnt/3115/nas/root -p 322 +} diff --git a/3115.kebler.net/startup/3115-mounts.sh b/3115.kebler.net/startup/3115-mounts.sh new file mode 100644 index 0000000..24bb0cb --- /dev/null +++ b/3115.kebler.net/startup/3115-mounts.sh @@ -0,0 +1,19 @@ +#!/bin/bash +llog "startup for 3115 mounts" +dir=$(dirname "$(dirname -- "${BASH_SOURCE[0]}")") +for f in $dir/function/ssh-mounts/*; do +llog "sourcing: $f" +source "$f" +done +# declare -F | grep 238 +delay=60 +mkdir -p $dir/logs +touch $dir/logs/3115-mount.log +notify-send "mounting 3115 network directories in $delay secs" +( sleep $delay ; +echo $(date) > $dir/logs/3115-mount.log; +llog "after $delay sec delay 3115 network is mounting" +notify-send "mounting 3115 network directories in /mnt/3115" +ssh-mount-3115 2>&1 | tee -a $dir/logs/3115-mount.log +notify-send "done mounting 3115 network directories" +) & diff --git a/645.kebler.net/function/ssh-mounts/00-mount-645.sh b/645.kebler.net/function/ssh-mounts/00-mount-645.sh new file mode 100755 index 0000000..bb9bbfb --- /dev/null +++ b/645.kebler.net/function/ssh-mounts/00-mount-645.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +module_load sshfs +module_load net-utils +module_load filesystem + +function ssh-mount-645 () { +echo ======== ...mounting 645 devices via vpn ======== +mnt645gate +mnt645nas +mnt645hass +mntnadal +mnt645lights +mnt645relays +mnt645switches +mnt645lightsbu +} + +function ssh-unmount-645 () { +echo ======== ...mounting 645 devices via vpn ======== +umnt645gate +umnt645nas +umnt645hass +umntnadal +umnt645lights +umnt645relays +umnt645switches +umnt645lightsbu +} diff --git a/645/function/mounts/645 b/645.kebler.net/function/ssh-mounts/645 similarity index 83% rename from 645/function/mounts/645 rename to 645.kebler.net/function/ssh-mounts/645 index b690d5f..a4866c6 100644 --- a/645/function/mounts/645 +++ b/645.kebler.net/function/ssh-mounts/645 @@ -19,7 +19,7 @@ usmount /mnt/645/nas/root } function mnt645gate(){ -smount root@grouter.645.kebler.net:/ /mnt/645/gate -p 22 +smount root@router.645.kebler.net:/ /mnt/645/gate -p 22 } function umnt645gate(){ @@ -28,10 +28,10 @@ usmount /mnt/645/gate function mntnadal(){ -smount sysadmin@nadal.kebler.net:/opt /mnt/645/nadal/opt -p 22 -smount sysadmin@nadal.kebler.net:/home/sysadmin /mnt/645/nadal/sysadmin -p 22 -smount sysadmin@nadal.kebler.net:/mnt/data /mnt/645/nadal/data -p 22 -smount root@nadal.kebler.net:/ /mnt/645/nadal/root -p 22 +smount sysadmin@nadal.645.kebler.net:/opt /mnt/645/nadal/opt -p 22 +smount sysadmin@nadal.645.kebler.net:/home/sysadmin /mnt/645/nadal/sysadmin -p 22 +smount sysadmin@nadal.645.kebler.net:/mnt/data /mnt/645/nadal/data -p 22 +smount root@nadal.645.kebler.net:/ /mnt/645/nadal/root -p 22 } function umntnadal(){ diff --git a/645/function/mounts/645-lights b/645.kebler.net/function/ssh-mounts/645-lights similarity index 82% rename from 645/function/mounts/645-lights rename to 645.kebler.net/function/ssh-mounts/645-lights index 86bbca4..4acb238 100644 --- a/645/function/mounts/645-lights +++ b/645.kebler.net/function/ssh-mounts/645-lights @@ -1,9 +1,9 @@ #!/bin/bash -function mntw645lights(){ -smount sysadmin@testvpn.kebler.net:/home/sysadmin /mnt/645/lights/controller/sysadmin -p 322 -smount sysadmin@testvpn.kebler.net:/opt /mnt/645/lights/controller/opt -p 322 -smount root@testvpn.kebler.net:/ /mnt/645/lights/controller/root -p 322 -} +# function mntw645lights(){ +# smount sysadmin@testvpn.kebler.net:/home/sysadmin /mnt/645/lights/controller/sysadmin -p 322 +# smount sysadmin@testvpn.kebler.net:/opt /mnt/645/lights/controller/opt -p 322 +# smount root@testvpn.kebler.net:/ /mnt/645/lights/controller/root -p 322 +# } function mnt645lights(){ smount sysadmin@controller.lights.645.kebler.net:/home/sysadmin /mnt/645/lights/controller/sysadmin -p 22 @@ -39,7 +39,7 @@ smount root@controller.lights.645.kebler.net:/ /mnt/645/lights/switches/root -p } -function umntswitches(){ +function umnt645switches(){ usmount /mnt/645/lights/switches/opt usmount /mnt/645/lights/switches/root usmount /mnt/645/lights/switches/sysadmin diff --git a/645/function/mounts/backup-645-lights b/645.kebler.net/function/ssh-mounts/backup-645-lights similarity index 99% rename from 645/function/mounts/backup-645-lights rename to 645.kebler.net/function/ssh-mounts/backup-645-lights index c20f64b..4358768 100644 --- a/645/function/mounts/backup-645-lights +++ b/645.kebler.net/function/ssh-mounts/backup-645-lights @@ -10,5 +10,3 @@ usmount /mnt/645/lights/backup/opt usmount /mnt/645/lights/backup/root usmount /mnt/645/lights/backup/sysadmin } - - diff --git a/645.kebler.net/startup/645-mounts.sh b/645.kebler.net/startup/645-mounts.sh new file mode 100755 index 0000000..f3e26dd --- /dev/null +++ b/645.kebler.net/startup/645-mounts.sh @@ -0,0 +1,19 @@ +#!/bin/bash +llog "startup for 645 mounts" +dir=$(dirname "$(dirname -- "${BASH_SOURCE[0]}")") +for f in $dir/function/ssh-mounts/*; do +llog "sourcing: $f" +source "$f" +done +# declare -F | grep 238 +delay=60 +mkdir -p $dir/logs +touch $dir/logs/645-mount.log +notify-send "mounting 645 network directories in $delay secs" +( sleep $delay ; +echo $(date) > $dir/logs/645-mount.log; +llog "after $delay sec delay 645 network is mounting" +notify-send "mounting 645 network directories in /mnt/645" +ssh-mount-645 2>&1 | tee -a $dir/logs/645-mount.log +notify-send "done mounting 645 network directories" +) & diff --git a/645/misc/mount-645.sh b/645/misc/mount-645.sh deleted file mode 100755 index c30eb90..0000000 --- a/645/misc/mount-645.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# debug logging use -v for verbose i.e. logging -if [ "$1" = '-v' ]; then - # if not in live terminal session then log to file instead - tty -s; - if [ "0" != "$?" ]; then - SCRIPT_PATH=$(readlink -f "$0") - SCRIPT_DIR=$(dirname $SCRIPT_PATH) - SCRIPT_NAME=$(basename ${SCRIPT_PATH%.*}) - mkdir -p $SCRIPT_DIR/logs - # log is the /logs subdirectory of original script directory - LOG_PATH="$SCRIPT_DIR/logs/$SCRIPT_NAME.log" - exec 1> $LOG_PATH 2>&1 - fi -else - # silence stdout - exec 1> /dev/null -fi - -echo $(date) -echo setting ssh-agent socket -export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket" -echo source mounting functions -echo ======== ...mounting 645 devices via vpn ======== -mnt645gate -mnt645nas -mnt645hass -mntnadal -mnt645lights -mnt645relays -mnt645switches -mnt645lightsbu diff --git a/all/env/ssh.env b/all/env/ssh-agent-socket.env similarity index 100% rename from all/env/ssh.env rename to all/env/ssh-agent-socket.env diff --git a/all/modules/sshfs/sshfs.sh b/all/modules/sshfs/sshfs.sh index 691bf70..eef2ba5 100755 --- a/all/modules/sshfs/sshfs.sh +++ b/all/modules/sshfs/sshfs.sh @@ -1,5 +1,7 @@ #!/bin/bash # depends on sshfs fuse for ssh +module_load filesystem + function smount(){ local HOST HOST=$(sed 's/.*@\(.*\):.*/\1/' <<< "$1") @@ -7,13 +9,13 @@ HOST=$(sed 's/.*@\(.*\):.*/\1/' <<< "$1") if [[ $(mounted $2) ]]; then echo "remote $1 already mounted at $2, aborting mount" else - echo "mounting $1 at $2 via ssh" - sshfs $1 $2 $3 $4 -o default_permissions + echo "mounting via ssh $*" + sshfs "$@" -o default_permissions fi } function usmount(){ -if [[ $(mountpoint $1 | grep not) ]]; then +if [[ $(mounted $1) ]]; then echo "unmounting remote file system at $1" fusermount -u $1 else diff --git a/all/startup/ssh-agent-socket b/all/startup/ssh-agent-socket new file mode 100644 index 0000000..0a433e5 --- /dev/null +++ b/all/startup/ssh-agent-socket @@ -0,0 +1,2 @@ +source "$BASH_SHELL_NETWORK/all/env/ssh-agent-socket.env" +llog "ssh socket set to: $(env | grep SSH_AUTH_SOCK)"