better option for new system
[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 gen_args=()
7 do_snapshot=true
8 while [[ $1 ]]; do
9 case $1 in
10 -n) do_snapshot=false; shift ;;
11 --) shift; break ;;
12 -*) gen_args+=($1) ; shift ;;
13 *) host=$1; shift ;;
14 esac
15 done
16
17
18 # arch and debian don't play nice with unison.
19 # "connection lost" on unison-gtk, with bignum errs in term,
20 # and simply freezing on cli, all means compiled under
21 # different ocaml versions.
22 # I had the great realization that unison is a self contained
23 # binary with no special runtime dependencies.
24 # However, I got a gtk error running the ui version.
25 # todo: I should test pushing my unison version instead
26 # of pulling it.
27 /p/c/subdir_files/.unison/gen ${gen_args[@]}
28 if [[ ! $host ]]; then
29 echo "$0: error: expected argument for hostname"
30 exit 1
31 fi
32
33
34 # todo: this doesn't deal with if the host is running arch too
35
36 # note, without bash, it prints some crap about tty
37 # on an uncustomized jessie install.
38 scp /usr/bin/unison root@$host:/usr/local/bin
39
40 echo "$0: egen args ${gen_args[@]}"
41 if $do_snapshot; then
42 unison-snapshot
43 if ! ssh root@$host unison-snapshot; then
44 if [[ ! ${gen_args[@]} ]]; then
45 # gen_args are all about syncing with new systems where
46 # we could expect the remote snapshot to not be available yet.
47 echo "$0: error: failed remote unison-snapshot"
48 exit 1
49 fi
50 fi
51 fi
52
53 f=unison-gtk
54 type -t $f &>/dev/null || f=unison-gtk2 # for arch
55 if s $f "$host"; then
56 if [[ $host == frodo ]]; then
57 # only send data to the machine i do full backups to
58 p=/p/c/machine_specific/$HOSTNAME/.unison/
59 s rsync -rlptgohi $p root@$host:$p
60 fi
61 p=/p/c/machine_specific/$host/.unison/
62 s rsync -rlptgohvi root@$host:$p $p
63 fi