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