bash-bear rename and a few improvements
[distro-setup] / prof-backup
1 #!/bin/bash
2
3 # We setup kd as a server which runs profanity, because profanity
4 # contains important state which it does not save to disk: the most
5 # recent read message in each chat room and for private messages.
6 # To do this, uses data directories in /d/p.
7
8 # However, if we need to take kd down for maintenance, we can run
9 # profanity on HOST2 with data directory in /p. To do this, stop
10 # profanity, run prof-backup, and then systemctl start profanity from
11 # HOST2, and then run prof. To connect from other machines, run prof
12 # HOST2_SSH_NAME. To have the profanity service stopped and started with
13 # switch-mail-host, do touch /p/profanity-here. To do the reverse,
14 #
15 # systemctl stop profanity
16 # rsync /p/profanity{,-config} kdwg.b8.nz:/d/p
17 # ssh root@kdwg.b8.nz systemctl --now enable profanity
18
19 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
20 source /a/bin/bash-bear-trap/bash-bear
21
22 source /a/bin/bash_unpublished/source-state
23 if [[ ! $HOSTNAME ]]; then
24 HOSTNAME=$(cat /etc/hostname)
25 fi
26 if [[ $HOSTNAME != "$HOST2" ]]; then
27 exit 0
28 fi
29
30 case $HOSTNAME in
31 kd)
32 if systemctl --quiet is-active profanity; then
33 rsync /d/p/profanity{,-config} /p
34 fi
35 ;;
36 *)
37 if ssh iank@b8.nz systemctl --user --quiet is-active profanity; then
38 rsync -a b8.nz:/d/p/profanity{,-config} /p
39 fi
40 ;;
41 esac