remove kinsis / unused input settings
[distro-setup] / switch-primary-host
1 #!/bin/bash
2
3 source /a/bin/errhandle/errcatch-function
4 source /a/bin/errhandle/bash-trace-function
5 errcatch
6
7 cd /
8
9 old=$1
10 new=$HOSTNAME
11
12 if [[ ! $old ]]; then
13 echo "$0: error: no \$1 given, should be old host"
14 exit 1
15 fi
16
17 if ! timeout -s 9 2 ssh $old : ; then
18 echo "$0: error: can't ssh to $old"
19 fi
20
21 for p in emacs firefox pidgin; do
22 ssh $old killall $p ||:
23 done
24
25 # note: duplicated in check-subvol-stale
26 last_a=$(
27 vol=a
28 for s in /mnt/root/btrbk/$vol.*; do
29 f=${s##*/}
30 unix_time=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s)
31 printf "%s\n" $unix_time
32 done | sort -r | head -n 1
33 )
34
35 if [[ $last_a != [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] ]]; then
36 echo "$0: error: last_a bad value: $last_a"
37 exit 1
38 fi
39
40 # if last_a is recent enough, skip doing btrbk
41 if (( last_a < $(date +%s) - 60*60 )); then
42 if ! ssh $old btrbk-run -pvt $new; then
43 echo "$0: error: failed btrbk-run"
44 exit 1
45 fi
46 fi
47
48 switch-mail-host $old $new