lots of fixes
[distro-setup] / myunison
index fa79b4af9e8abc680ff7cc065410d66b89111c36..506e9c6237cc0857ed662678efc2f6fc8f0f7696 100755 (executable)
--- a/myunison
+++ b/myunison
@@ -1,18 +1,38 @@
-#!/bin/bash -l
+#!/bin/bash -lx
 
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
+# note, we could have done machine specific subvols,
+# but there were so few files, it just didn't seem
+# necessary to have an rw copy on those machines
+# which did not have the whole p subvol.
+
 gen_args=()
-do_snapshot=true
-while [[ $1 == -* ]]; do
+do_snapshot=false
+batch=false
+while [[ $1 ]]; do
     case $1 in
-        -n) do_snapshot=false; shift ;;
+        -ob) gen_args+=(--ours -b); batch=true; shift ;;
+        -b) gen_args+=(-b); batch=true; shift ;;
+        -n) do_snapshot=true; shift ;;
+        -h|--help)
+            echo "$0: help is head of $BASH_SOURCE:"
+            head -n 30 "$BASH_SOURCE"
+            exit 0
+            ;;
         --) shift; break ;;
         -*) gen_args+=($1) ; shift ;;
+        *) host=$1; shift ;;
     esac
 done
+if [[ ! $host ]]; then
+    host=$1
+fi
 
+if [[ $host == demohost ]]; then
+    do_snapshot=false
+fi
 
 # arch and debian don't play nice with unison.
 # "connection lost" on unison-gtk, with bignum errs in term,
@@ -23,28 +43,47 @@ done
 # However, I got a gtk error running the ui version.
 # todo: I should test pushing my unison version instead
 # of pulling it.
+echo "$0: running: gen ${gen_args[@]}"
 /p/c/subdir_files/.unison/gen ${gen_args[@]}
-if [[ ! $1 ]]; then
+if [[ ! $host ]]; then
     echo "$0: error: expected argument for hostname"
     exit 1
 fi
 
-host=$1
 
 # todo: this doesn't deal with if the host is running arch too
 
-# note, without bash, it prints some crap about tty
-# on an uncustomized jessie install.
-scp /usr/bin/unison root@$host:/usr/local/bin
+# debian uses this path, and has gtk version linked as /usr/bin/unison,
+# but I'd rather not push the gtk version
+push_path=/usr/bin/unison-latest-stable
+if [[ ! -e $push_path ]]; then
+    push_path=/usr/bin/unison
+fi
+# note, i'd prefer to use /usr/local/bin, but it's not in arch's default
+# path for root.
+rsync -L /usr/bin/unison-latest-stable root@$host:/usr/bin/unison
 
 if $do_snapshot; then
     unison-snapshot
-    ssh root@$host unison-snapshot
+    if ! ssh root@$host "! type unison-snapshot || unison-snapshot"; then
+        if [[ ! ${gen_args[@]} ]]; then
+            # gen_args are all about syncing with new systems where
+            # we could expect the remote snapshot to not be available yet.
+            echo "$0: error: failed remote unison-snapshot"
+            exit 1
+        fi
+    fi
+fi
+
+if $batch; then
+    # todo, figure out what the cli version is called in non-debian distros
+    f=unison-latest-stable
+else
+    f=unison-gtk
+    type -t $f &>/dev/null || f=unison-gtk2 # for arch
 fi
 
-f=unison-gtk
-type -t $f &>/dev/null || f=unison-gtk2 # for arch
-if s $f "$@"; then
+if s $f  "$host"; then
     if [[ $host == frodo ]]; then
         # only send data to the machine i do full backups to
         p=/p/c/machine_specific/$HOSTNAME/.unison/