bunch of updates and fixes
authorIan Kelling <ian@iankelling.org>
Sun, 17 Jul 2016 23:51:45 +0000 (16:51 -0700)
committerIan Kelling <ian@iankelling.org>
Sun, 17 Jul 2016 23:51:45 +0000 (16:51 -0700)
myunison
unison-snapshot

index 68ec7d4ff72d3a7556e240e6272af3ff3bc7d2f0..8e3c8b3eceac9352c5867affd32a69810cd8e1b5 100755 (executable)
--- a/myunison
+++ b/myunison
@@ -1,19 +1,30 @@
-#!/bin/bash -lx
+#!/bin/bash -l
 
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+set -x
 
 gen_args=()
 do_snapshot=true
+batch=false
 while [[ $1 ]]; do
     case $1 in
+        -ob) gen_args+=(--ours -b); batch=true; shift ;;
+        -b) gen_args+=(-b); batch=true; shift ;;
         -n) do_snapshot=false; 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
 
 # arch and debian don't play nice with unison.
 # "connection lost" on unison-gtk, with bignum errs in term,
@@ -24,6 +35,7 @@ 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 [[ ! $host ]]; then
     echo "$0: error: expected argument for hostname"
@@ -33,14 +45,19 @@ fi
 
 # 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.
+scp /usr/bin/unison-latest-stable root@$host:/usr/bin/unison
 
-echo "$0: egen args ${gen_args[@]}"
 if $do_snapshot; then
     unison-snapshot
-    if ! ssh root@$host unison-snapshot; then
+    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.
@@ -50,14 +67,20 @@ if $do_snapshot; then
     fi
 fi
 
-f=unison-gtk
-type -t $f &>/dev/null || f=unison-gtk2 # for arch
+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
+
 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/
+        p=/q/p/c/machine_specific/$HOSTNAME/.unison/
         s rsync -rlptgohi $p root@$host:$p
     fi
-    p=/p/c/machine_specific/$host/.unison/
+    p=/q/p/c/machine_specific/$host/.unison/
     s rsync -rlptgohvi root@$host:$p $p
 fi
index aa2a63b4520db30112eb3e8fc24a5db07557193c..154eed0702fe0c5930816bbe0d156e38e29545f4 100755 (executable)
@@ -1,24 +1,25 @@
 #!/bin/bash -l
-
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
-base=unison-$(date "+%Y:%m:%d")
-for mountp in /mnt/root /mnt/iroot; do
+sv() { echo "$@"; "$@"; }
+
+date=unison-$(date "+%Y:%m:%d")
+for mountp in /mnt/root/q /mnt/iroot/i; do
     [[ -e $mountp ]] || continue
-    full_base=$mountp/$base
-    existing=( $full_base-* )
-    if [[ -e ${existing[0]} ]]; then
-        snapshot=$full_base-$(( ${#existing[@]} + 1 ))
+    date_path=${mountp%/*}/$date
+    todays=( $date_path-* )
+    IFS=$'\n' todays=($(sort -Vr <<<"${todays[*]}")); unset IFS
+    if [[ -e ${todays[0]} ]]; then
+        snapshot=$date_path-$(( ${todays[0]##*-} + 1 ))
     else
-        snapshot=$full_base-1
+        snapshot=$date_path-1
     fi
-    s btrfs subvolume snapshot -r $mountp $snapshot
-    existing=( $mountp/unison-* )
+    sv s btrfs subvolume snapshot -r $mountp $snapshot
+    existing=( ${mountp%/*}/unison-* )
+    IFS=$'\n' existing=($(sort -Vr <<<"${existing[*]}")); unset IFS
     # keep 10 unison snapshots around
     if (( ${#existing[@]} > 10 )); then
-        IFS=$'\n' existing=($(sort -Vr <<<"${existing[*]}"))
-        unset IFS
-        s btrfs subvolume delete ${existing[@]:10}
+        sv s btrfs subvolume delete ${existing[@]:10}
     fi
 done