rename err to bash-bear
[distro-setup] / mount-latest-subvol
index 3844e7279e488d33d8f479820650a9c4c2bb895a..13cfc3d159967ad8bff254093081dbe66933962a 100644 (file)
@@ -18,7 +18,7 @@ readonly this_file
 cd /
 [[ $EUID == 0 ]] || exec sudo -E "$this_file" "$@"
 
-source /usr/local/lib/err
+source /usr/local/lib/bash-bear
 
 usage() {
   cat <<EOF
@@ -38,7 +38,7 @@ EOF
   exit $1
 }
 
-
+pre="mount-latest-subvol:${SSH_CLIENT:+ $HOSTNAME:}"
 
 tu() {
   while read -r line; do
@@ -48,17 +48,17 @@ tu() {
 }
 d() {
   if $verbose; then
-    printf "%s\n" "$*"
+    printf "$pre %s\n" "$*"
   fi
 }
 m() {
   if $verbose; then
-    printf "%s\n" "$*"
+    printf "$pre %s\n" "$*"
   fi
   "$@"
 }
 x() {
-  printf "%s\n" "$*"
+  printf "$pre %s\n" "$*"
   "$@"
 }
 
@@ -271,6 +271,7 @@ EOF
   fi
   fstab <<EOF
 /o/m  /m  none  bind$mopts  0 0
+/o/debbugs  /debbugs  none  bind$mopts  0 0
 EOF
 fi
 
@@ -317,6 +318,7 @@ for vol in ${all_vols[@]}; do
   ##### end building up list of bind mounts  ######
 
 
+
   # if latest is already mounted, make sure binds are mounted and move on
   m check-subvol-stale $d
   # populated by check-subvol-stale if stale
@@ -335,6 +337,28 @@ for vol in ${all_vols[@]}; do
     continue
   fi
 
+
+  ##### begin checking for loopback mounts ####
+  found_loop=false
+  for l in $(losetup -ln|awk '{print $6}'); do
+    for dir in $d ${binds[@]}; do
+      if [[ $l == $dir* ]]; then
+        echo "$0: found loopback mount $l. giving up on unmounting $dir"
+        ret=1
+        found_loop=true
+        break
+      fi
+    done
+    if $found_loop; then
+      break
+    fi
+  done
+  if $found_loop; then
+    continue
+  fi
+  ##### end end checking loopback mounts ####
+
+
   ## not using arbtt at the moment
   # if [[ $vol == q ]]; then
   #   ## allow to fail, user might not be logged in
@@ -477,7 +501,7 @@ for dir in /mnt/r7/amy/{root/root,boot/boot}_ubuntubionic /mnt/{root2/root,boot2
   rm -f /nocow/btrfs-stale/$vol
 done
 
-if (( $ret )); then
+if (( ret >= 1 )); then
   echo "$0: exit status $ret. see error above"
 fi
 exit $ret