cd /
[[ $EUID == 0 ]] || exec sudo -E "$script" "$@"
+source /usr/local/lib/err
usage() {
cat <<EOF
}
-errcatch() {
- set -E; shopt -s extdebug
- _err-trap() {
- err=$?
- exec >&2
- set +x
- echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}:in \`$BASH_COMMAND' returned $err"
- bash-trace 2
- echo "$0: exiting with code $err"
- exit $err
- }
- trap _err-trap ERR
- set -o pipefail
-}
-bash-trace() {
- local -i argc_index=0 frame i start=${1:-1} max_indent=8 indent
- local source
- local extdebug=false
- if [[ $(shopt -p extdebug) == *-s* ]]; then
- extdebug=true
- fi
-
- for ((frame=0; frame < ${#FUNCNAME[@]}-1; frame++)); do
- argc=${BASH_ARGC[frame]}
- argc_index+=$argc
- ((frame < start)) && continue
- if (( ${#BASH_SOURCE[@]} > 1 )); then
- source="${BASH_SOURCE[frame+1]}:${BASH_LINENO[frame]}:"
- fi
- indent=$((frame-start+1))
- indent=$((indent < max_indent ? indent : max_indent))
- printf "%${indent}s↳%sin \`%s" '' "$source" "${FUNCNAME[frame]}"
- if $extdebug; then
- for ((i=argc_index-1; i >= argc_index-argc; i--)); do
- printf " %s" "${BASH_ARGV[i]}"
- done
- fi
- echo \'
- done
-}
-errcatch
-
tu() {
while read -r line; do
file="$1"
# you can remove this if you do not have options which can have args with spaces or empty.
-verbose=false
+verbose=true
force=false
temp=$(getopt -l help,force,verbose hfv "$@") || usage 1
eval set -- "$temp"
if m umount -R $dir; then
unmounted+=($dir)
else
- if ! kill-dir TERM TERM TERM INT INT HUP HUP; then
+ if ! kill-dir TERM TERM TERM INT INT HUP HUP TERM TERM TERM INT INT HUP HUP; then
if $force; then kill-dir KILL; fi
fi
fi
done
+ # if we unmounted some but not all, restore them and move on
if ! $umount_ret; then
for dir in ${unmounted[@]}; do
mnt $dir
continue
fi
+ #### begin dealing with leaf vols ####
# todo: decipher /mnt/root, like we do in check-subvol-stale
cd /mnt/root
if [[ -e $vol ]]; then
if [[ $bsub ]]; then
tmp=$(mktemp)
# in testing, same subvol is 136 bytes. allow some overhead
- btrfs send --no-data -p $bsub $leaf | head -c 1000 > $tmp
+ btrfs send --no-data -p $bsub $leaf | head -c 1000 > $tmp || [[ $? == 141 ]]
if (( $(stat -c%s $tmp) < 1000)); then
# example output for an empty diff:
# Found a valid Btrfs stream header, version 1
done
## end expire leaf vols ##
fi
+ #### end dealing with leaf vols ####
+
# Note, we make a few assumptions in this script, like
# $d was not a different subvol id than $vol, and
# things otherwise didn't get mounted very strangely.
done
stale_dir=/nocow/btrfs-stale
rm -f $stale_dir/$d
+
done
### disabled