X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=mount-latest-subvol;h=d7be613c763d122d0259b5a434ca4a161f599627;hb=0310db0c0589445a132e77f0b7a8fbb5e1ae3082;hp=e4c4d6b0a652b992f6feb7483cecd394bbf1040c;hpb=d46190aff6f5dc65bd39524e3937dc5765895b42;p=distro-setup diff --git a/mount-latest-subvol b/mount-latest-subvol index e4c4d6b..d7be613 100644 --- a/mount-latest-subvol +++ b/mount-latest-subvol @@ -73,26 +73,72 @@ mnt() { e mount $dir fi } +fstab() { + while read -r start mpoint end; do + l="$start $mpoint $end" + # kill off any lines that duplicate the mount point. + sed --follow-symlinks -ri "\%$l%b;\%^\s*\S+\s+$mpoint\s%d" /etc/fstab + tu /etc/fstab <<<"$l" + done +} +kill-dir() { + found_pids=false + sig=${1:-TERM} + if pids=$(timeout 4 lsof -t $dir); then + found_pids=true + timeout 4 lsof -w $dir + 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 + found_pids=true + fuser -$sig -mvk $dir + fi + if $found_pids; then + sleep .5 + return 0 + fi + return 1 +} + +force=false +if [[ $1 == -f ]]; then + force=true +fi ret=0 ##### begin setup fstab for subvols we care about ###### first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab) -tu /etc/fstab <