various fixes
authorIan Kelling <ian@iankelling.org>
Fri, 18 Nov 2016 14:43:32 +0000 (06:43 -0800)
committerIan Kelling <ian@iankelling.org>
Fri, 18 Nov 2016 14:43:32 +0000 (06:43 -0800)
btrbk-run
distro-begin
distro-end
mail-setup
mount-latest-subvol

index 05589d1c8626391454b9e0cf261e4196d4e52a1e..c59faf99c9eecb0e976a532bd6e2ef00225c59f7 100755 (executable)
--- a/btrbk-run
+++ b/btrbk-run
@@ -18,13 +18,15 @@ script_dir=$(dirname $(readlink "$BASH_SOURCE"))
 
 conf_only=false
 dry_run=false # mostly for testing
+resume_arg=
 
-temp=$(getopt -l help hcnt: "$@") || usage 1
+temp=$(getopt -l help hcnrt: "$@") || usage 1
 eval set -- "$temp"
 while true; do
     case $1 in
         -c) conf_only=true; shift ;;
         -n) dry_run=true; dry_run_arg=-n; shift ;;
+        -r) resume_arg=-r; shift ;;
         -t) IFS=, targets=($2); shift 2 ;;
         -h|--help) usage ;;
         --) shift; break ;;
@@ -81,7 +83,9 @@ fi
 # a subvol on current host is not fresh.
 # umount first to ensure we don't have any errors
 # todo: do some kill fuser stuff to make umount more reliable
-# todo: run this on a systemd timer on $primary, once per hour.
+# todo: run this on a systemd timer on $primary, once per hour,
+# and if primary is, change that timer over to primary, and make
+# sure we mount the latest
 # todo: setup lock so that if this is already running, we exit out, so
 # that manual runs don't interfere with cronjobs.
 
@@ -129,9 +133,9 @@ if $conf_only; then
 fi
 
 if $dry_run; then
-    btrbk -n run
+    btrbk -n $resume_arg run
 else
-    btrbk -q run
+    btrbk -q $resume_arg run
 fi
 
 # if we have /p, rsync to targets without /p
@@ -153,7 +157,7 @@ fi
 if ! $dry_run; then
     for tg in ${targets[@]}; do
         scp $script_dir/{mount-latest-subvol,check-subvol-stale} \
-            root@tg:/usr/local/bin
+            root@$tg:/usr/local/bin
         ssh root@$tg bash <<'EOF'
 set -e
 chmod +x /usr/local/bin/{mount-latest-subvol,check-subvol-stale}
index 5297da810986af9fe2484dbc71b409f4ff0fc6ae..bf298d58e1fa741762ed8584c65aa782d4dd5a97 100755 (executable)
@@ -577,10 +577,17 @@ for dir in /{i,w,k}; do
 done
 
 dir=/nocow
-l=$(sed -rn "s#^(\s*\S+\s+)/q(\s.*)(subvol=q)#\1$dir\2subvol=nocow#p" /etc/fstab)
-if [[ $l ]] && ! mountpoint $dir; then
+if ! mountpoint $dir; then
+    subvol=/mnt/root/nocow
+    if [[ ! -e nocow ]]; then
+        btrfs subvolume create $subvol
+        chown root:1000 $subvol
+        chattr +C $subvol
+    fi
+
+    first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab)
     tu /etc/fstab <<EOF
-$l
+$first_root_crypt  /nocow  btrfs  noatime,subvol=nocow  0 0
 EOF
     s mkdir -p $dir
     s chown ian:ian $dir
@@ -678,14 +685,14 @@ if isdeb; then
     # I haven't gotten around to getting a non-debian exim
     # setup.
     mail-setup exim4
-else
-    mail-setup postfix
+   else
+       mail-setup postfix
 fi
 
-if isubuntu; then
-    # disable crash report annoying crap
-    s dd of=/etc/default/apport <<<'enabled=0'
-fi
+   if isubuntu; then
+       # disable crash report annoying crap
+       s dd of=/etc/default/apport <<<'enabled=0'
+   fi
 
 # fai sets this an old way that doesn't work for stretch.
 # no harm in setting it universally here.
index 38bd60b7d2a5c10ef95f8ac272d24f4e68e9e4be..f12d57515672f0de4020fb8a1b840b21fd26c983 100755 (executable)
@@ -261,13 +261,19 @@ fi
 case $distro in
     arch) pi syncthing ;;
     ubuntu|debian)
-        # google led me here:
-        # https://apt.syncthing.net/
-        curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
-        s="deb http://apt.syncthing.net/ syncthing release"
-        if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != $s ]]; then
-            echo "$s" | s dd of=/etc/apt/sources.list.d/syncthing.list
-            p update
+        # testing has relatively up to date packages
+        if ! isdebian-testing; then
+            # based on error when doing apt-get update:
+            # E: The method driver /usr/lib/apt/methods/https could not be found.
+            pi apt-transport-https
+            # google led me here:
+            # https://apt.syncthing.net/
+            curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
+            s="deb http://apt.syncthing.net/ syncthing release"
+            if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != $s ]]; then
+                echo "$s" | s dd of=/etc/apt/sources.list.d/syncthing.list
+                p update
+            fi
         fi
         pi syncthing
         ;;
index 819aa8d0623cd48420bd7dfac345f88b046a794c..f7dd6b4a01c33455dbcbddd47ea4859e17aa6afe 100755 (executable)
@@ -74,11 +74,6 @@ smarthost="$host::587" # exim
 e $forward > ~/.forward
 e $forward | s tee /root/.forward
 
-# linode image has a root alias. completely useless, remove it.
-sudo sed -i '/^root:/d' /etc/aliases
-
-s newaliases
-
 
 # offlineimap uses this too, it is much easier to use one location than to
 # condition it's config and postfix's config
@@ -180,6 +175,12 @@ EOF
     fi
 fi
 
+# linode image has a root alias. completely useless, remove it.
+sudo sed -i '/^root:/d' /etc/aliases
+
+s newaliases
+
+
 # based on http://www.postfix.org/qmgr.8.html and my notes in gnus
 dir=/nocow/$type
 sdir=/var/spool/$type
index 6a714d1a791ff8a67d4901f9654b5a049f93ccfd..f62f1f45612d274f1bf8196e9971973d10bba356 100644 (file)
@@ -44,8 +44,20 @@ bash-trace() {
 }
 errcatch
 
-
+tu() {
+    while read -r line; do
+        file="$1"
+        grep -xFq "$line" "$file" || tee -a "$file"<<<"$line"
+    done
+}
 e() { printf "%s\n" "$*"; "$@"; }
+mnt() {
+    dir=$1
+    if ! mountpoint $dir >/dev/null; then
+        mkdir -p $dir
+        e mount $dir
+    fi
+}
 
 ret=0
 
@@ -90,8 +102,6 @@ EOF
 
 fi
 
-mkdir -p /q /p /i
-
 for vol in q p; do
     d=/$vol
     if ! awk '{print $2}' /etc/fstab | grep -xF $d &>/dev/null; then
@@ -105,7 +115,7 @@ for vol in q p; do
         new_roots=()
         for r in ${roots[@]}; do
             # /q/a  /a  none  bind  0 0
-            new_roots+=($(sed -rn "s#^$r/\S+\s+(\S+)\s+none\s+bind\s.*#\1#" /etc/fstab))
+            new_roots+=($(sed -rn "s#^$r/\S+\s+(\S+)\s+none\s+bind\s.*#\1#p" /etc/fstab))
         done
         (( ${#new_roots} )) || break
         binds+=(${new_roots[@]})
@@ -114,7 +124,7 @@ for vol in q p; do
 
     if e check-subvol-stale $d; then
         for b in ${binds[@]}; do
-            mount $b
+            mnt $b
         done
         continue
     fi
@@ -142,7 +152,7 @@ for vol in q p; do
 
     if ! $umount_ret; then
         for dir in ${unmounted[@]}; do
-            mount $dir
+            mnt $dir
         done
         ret=1
         continue
@@ -157,7 +167,7 @@ for vol in q p; do
     # things otherwise didn't get mounted very strangely.
     e btrfs sub snapshot btrbk/$last_snap $vol
     for dir in $d ${binds[@]}; do
-        e mount $dir
+        e mnt $dir
     done
 done
 exit $ret