fix mistake from recent commit
[distro-setup] / myunison
1 #!/bin/bash -lx
2
3 set -eE -o pipefail
4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
5
6 # note, we could have done machine specific subvols,
7 # but there were so few files, it just didn't seem
8 # necessary to have an rw copy on those machines
9 # which did not have the whole p subvol.
10
11 gen_args=()
12 do_snapshot=false
13 batch=false
14 while [[ $1 ]]; do
15 case $1 in
16 -ob) gen_args+=(--ours -b); batch=true; shift ;;
17 -b) gen_args+=(-b); batch=true; shift ;;
18 -n) do_snapshot=true; shift ;;
19 -h|--help)
20 echo "$0: help is head of $BASH_SOURCE:"
21 head -n 30 "$BASH_SOURCE"
22 exit 0
23 ;;
24 --) shift; break ;;
25 -*) gen_args+=($1) ; shift ;;
26 *) host=$1; shift ;;
27 esac
28 done
29 if [[ ! $host ]]; then
30 host=$1
31 fi
32
33 if [[ $host == demohost ]]; then
34 do_snapshot=false
35 fi
36
37 # arch and debian don't play nice with unison.
38 # "connection lost" on unison-gtk, with bignum errs in term,
39 # and simply freezing on cli, all means compiled under
40 # different ocaml versions.
41 # I had the great realization that unison is a self contained
42 # binary with no special runtime dependencies.
43 # However, I got a gtk error running the ui version.
44 # todo: I should test pushing my unison version instead
45 # of pulling it.
46 echo "$0: running: gen ${gen_args[@]}"
47 /p/c/subdir_files/.unison/gen ${gen_args[@]}
48 if [[ ! $host ]]; then
49 echo "$0: error: expected argument for hostname"
50 exit 1
51 fi
52
53
54 # todo: this doesn't deal with if the host is running arch too
55
56 # debian uses this path, and has gtk version linked as /usr/bin/unison,
57 # but I'd rather not push the gtk version
58 push_path=/usr/bin/unison-latest-stable
59 if [[ ! -e $push_path ]]; then
60 push_path=/usr/bin/unison
61 fi
62 # note, i'd prefer to use /usr/local/bin, but it's not in arch's default
63 # path for root.
64 rsync -L /usr/bin/unison-latest-stable root@$host:/usr/bin/unison
65
66 if $do_snapshot; then
67 unison-snapshot
68 if ! ssh root@$host "! type unison-snapshot || unison-snapshot"; then
69 if [[ ! ${gen_args[@]} ]]; then
70 # gen_args are all about syncing with new systems where
71 # we could expect the remote snapshot to not be available yet.
72 echo "$0: error: failed remote unison-snapshot"
73 exit 1
74 fi
75 fi
76 fi
77
78 if $batch; then
79 # todo, figure out what the cli version is called in non-debian distros
80 f=unison-latest-stable
81 else
82 f=unison-gtk
83 type -t $f &>/dev/null || f=unison-gtk2 # for arch
84 fi
85
86 if s $f "$host"; then
87 if [[ $host == frodo ]]; then
88 # only send data to the machine i do full backups to
89 p=/p/c/machine_specific/$HOSTNAME/.unison/
90 s rsync -rlptgohi $p root@$host:$p
91 fi
92 p=/p/c/machine_specific/$host/.unison/
93 s rsync -rlptgohvi root@$host:$p $p
94 fi