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