dot_testing/builds/utils/establish-annex-link

117 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
printf "This tool is for establishing sshfs links to transfer git-annex repo contents.\n"
printf "server or client?\n"
printf 'EITHER OF `s` or `c`\n'
read -p "?> "
case "$REPLY" in
s)
printf "[] ensure that port 22 is unfiltered\n"
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
printf "[] starting sshd\n"
sudo systemctl start sshd
WIRELESS_INTERFACE=$(
nmcli --get-values GENERAL.DEVICE,GENERAL.TYPE device show |
sed '/^wifi/!{h;d;};x' |
head -n1)
IP_OF_INTERFACE=$(
ip address show dev $WIRELESS_INTERFACE |
grep 'inet ' |
awk -F' ' '{print $2}' |
awk -F'/' '{print $1}')
printf "[] instruct client to connect to %s\n" "$IP_OF_INTERFACE"
printf "[] waiting to stop sshd\n"
read
sudo systemctl stop sshd
printf "[] sshd stopped, but port 22 still open\n"
;;
c)
printf "What IP to connect to?\n"
printf "ENSURE THAT the IP is accessable on the current VLAN\n"
printf 'ONE OF `ipv4 address`'
read -p "?> " ADDRESS
INFORMED_GUESS=$(ssh usr@$ADDRESS hostname)
if [ -z "$INFORMED_GUESS" ]; then
printf "What hostname?\n"
mkdir -p ~/annex-remotes
ls ~/annex-remotes
read -p "?> " REMOTE_HOST
else
REMOTE_HOST=$INFORMED_GUESS
printf "[] using hostname %s\n" "$INFORMED_GUESS"
fi
printf "[] mounting fs via sshfs\n"
mkdir -p ~/annex-remotes/$REMOTE_HOST
fusermount3 -qu ~/annex-remotes/$REMOTE_HOST
sshfs usr@$ADDRESS:/home/usr/annex ~/annex-remotes/$REMOTE_HOST
printf "[] mounted fs\n"
# check if the fuse mount worked
df_output=$(df -h | grep -c '/home/usr/annex')
if [ "$df_output" -eq 0 ]; then
printf "It seems the sshfs mount didn't work. Exiting.\n"
exit 1
fi
# check if we need to make a copy of the annex on the new device
if [ ! -d ~/annex-remotes/$REMOTE_HOST/.git ]; then
printf "Should I do that with the current computer's git-annex store?\n\n"
printf '`y`) initialize with the local store\n'
printf '`n`) no, just mount the sshfs\n'
read -p '?> '
case $REPLY in
y)
cd ~/annex-remotes/$REMOTE_HOST
printf "[] cloning the local git-annex store\n"
git clone -v ~/annex
shopt -s dotglob # include dotfiles and dotdirs in wildcard
mv ./annex/* . # move everything up a dir
if find "annex" -maxdepth 1 -type f -o -type d -empty; then # if annex is empty...
printf "[] removing spurious ./annex directory\n"
rm -r ./annex # ...remove it
fi
git annex init "$REMOTE_HOST"
cd ~/annex
git remote add $REMOTE_HOST ~/annex-remotes/$REMOTE_HOST
;;
esac # it's okay that the `n` and `*` cases fall-through
fi
printf "[] waiting to stop sshfs\n"
read
fusermount3 -u ~/annex-remotes/$REMOTE_HOST
printf "[] unmounted sshfs\n"
;;
*)
printf "unknown\n"
;;
esac