3 [[ $EUID == 0 ]] ||
exec sudo
-E "$BASH_SOURCE" "$@"
6 set -E; shopt -s extdebug
11 echo "${BASH_SOURCE[1]}:${BASH_LINENO[0]}:in \`$BASH_COMMAND' returned $err"
13 echo "$0: exiting with code $err"
20 local -i argc_index
=0 arg frame i start
=${1:-1} max_indent
=8 indent
23 if [[ $
(shopt -p extdebug
) == *-s* ]]; then
27 for ((frame
=0; frame
< ${#FUNCNAME[@]}-1; frame
++)); do
28 argc
=${BASH_ARGC[frame]}
30 ((frame
< start
)) && continue
31 if (( ${#BASH_SOURCE[@]} > 1 )); then
32 source="${BASH_SOURCE[frame+1]}:${BASH_LINENO[frame]}:"
34 indent
=$
((frame-start
+1))
35 indent
=$
((indent
< max_indent ? indent
: max_indent
))
36 printf "%${indent}s↳%sin \`%s" '' "$source" "${FUNCNAME[frame]}"
38 for ((i
=argc_index-1
; i
>= argc_index-argc
; i--
)); do
39 printf " %s" "${BASH_ARGV[i]}"
48 while read -r line
; do
50 grep -xFq "$line" "$file" ||
tee -a "$file"<<<"$line"
53 e
() { printf "%s\n" "$*"; "$@"; }
56 if ! mountpoint
$dir >/dev
/null
; then
64 first_root_crypt
=$
(awk '$2 == "/" {print $1}' /etc
/mtab
)
66 $first_root_crypt /q btrfs noatime,subvol=q 0 0
72 $first_root_crypt /p btrfs noatime,subvol=p 0 0
76 if [[ $HOSTNAME == treetowl
]]; then
77 # partitioned it with fai partitioner outside of fai,
78 # because it\'s worth it to have 1% space reserved for boot and
79 # swap partitions in case I ever want to boot off those drives.
81 # . /a/bin/fai/fai-wrapper
82 # eval-fai-classfile /a/bin/fai/fai/config/class/51-multi-boot
83 # fai-setclass ROTATIONAL
84 # export LUKS_DIR=/q/root/luks/
85 # # because the partition nums existed already
86 # fai-setclass REPARTITION
87 # /a/bin/fai/fai/config/hooks/partition.DEFAULT
89 # just the first in the btrfs raid
90 dev
=ata-TOSHIBA_MD04ACA500_84REK6NTFS9A-part1
92 /dev/mapper/crypt_dev_$dev /i btrfs noatime,subvol=i 0 0
94 tu
/etc
/crypttab
<<EOF
95 crypt_dev_$dev /dev/disk/by-id/$dev /q/root/luks/host-treetowl discard,luks
100 /q/i /i none bind 0 0
107 if ! awk '{print $2}' /etc
/fstab |
grep -xF $d &>/dev
/null
; then
116 for r
in ${roots[@]}; do
117 # /q/a /a none bind 0 0
118 new_roots
+=($
(sed -rn "s#^$r/\S+\s+(\S+)\s+none\s+bind\s.*#\1#p" /etc
/fstab
))
120 (( ${#new_roots} )) ||
break
121 binds
+=(${new_roots[@]})
122 roots
=( ${new_roots[@]} )
125 if e check-subvol-stale
$d; then
126 for b
in ${binds[@]}; do
132 last_snap
=$
(</nocow
/btrfs-stale
/$vol)
133 if [[ ! $last_snap ]]; then
134 echo "$0: error. empty last_snap var"
141 for dir
in $
(echo $d ${binds[*]}\ |
tac -s\
); do
142 if mountpoint
$dir; then
143 if e umount
-R $dir; then
147 echo "$0: failed to umount $dir"
153 if ! $umount_ret; then
154 for dir
in ${unmounted[@]}; do
162 if [[ -e $vol ]]; then
165 # Note, we make a few assumptions in this script, like
166 # $d was not a different subvol id than $vol, and
167 # things otherwise didn't get mounted very strangely.
168 e btrfs sub snapshot btrbk
/$last_snap $vol
169 for dir
in $d ${binds[@]}; do