X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=mount-latest-subvol;h=96210c4424907040ae4f284bf88ae330158d977d;hb=90bd397922e7240c41377e7404f79f190bfbc9d8;hp=215b07f8faf0f73ef227005ae693b17f626caf9d;hpb=af37f71b1c4e1dfa9ebe9a270f4b839cd742cad5;p=distro-setup diff --git a/mount-latest-subvol b/mount-latest-subvol index 215b07f..96210c4 100644 --- a/mount-latest-subvol +++ b/mount-latest-subvol @@ -14,9 +14,11 @@ # limitations under the License. # usage: mount-latest-subvol +# +# Note, at source location, intentionally not executable, run and read +# install-my-scripts. -# TODO, check our current directory, make sure we arent going to kill ourselves - +cd / [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" errcatch() { @@ -83,6 +85,17 @@ fstab() { tu /etc/fstab <<<"$l" done } +pid-check() { + for p in ${pids}; do + for m in ${my_pids[@]}; do + if (( p == m )); then + echo "$0: error: pids to kill includes our pid or a parent. ps output:" >&2 + ps -f -p $p + exit 1 + fi + done + done +} kill-dir() { for sig; do echo kill-dir $sig @@ -90,11 +103,13 @@ kill-dir() { if pids=$(timeout 4 lsof -t $dir); then found_pids=true timeout 4 lsof -w $dir + pid-check kill -$sig $pids fi # fuser will find open sockets that lsof won't, for example from gpg-agent. # note: -v shows kernel processes, which then doesn't return true when we want - if timeout 4 fuser -m $dir &>/dev/null; then + if pids=$(timeout 4 fuser -m $dir 2>/dev/null); then + pid-check found_pids=true fuser -$sig -mvk $dir fi @@ -114,9 +129,25 @@ fi ret=0 ##### begin setup fstab for subvols we care about ###### -first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab) +root_dev=$(awk '$2 == "/" {print $1}' /etc/mtab) + + +if cryptsetup status $root_dev &>/dev/null; then + crypt_dev=$root_dev +else # if we are in a recovery boot, find the next best crypt device + noauto=,noauto + for dev in $(dmsetup ls --target crypt | awk '{print $1}'); do + dev=/dev/mapper/$dev + if awk '{print $1}' /etc/mtab | grep -Fx $dev &>/dev/null; then + crypt_dev=$dev + break + fi + done +fi + + fstab </dev/null; then @@ -182,6 +227,7 @@ for vol in q a o i; do continue fi + # populated by check-subvol-stale fresh_snap=$(