conf_only=false
dry_run=false # mostly for testing
+resume_arg=
-temp=$(getopt -l help hcnt: "$@") || usage 1
+temp=$(getopt -l help hcnrt: "$@") || usage 1
eval set -- "$temp"
while true; do
case $1 in
-c) conf_only=true; shift ;;
-n) dry_run=true; dry_run_arg=-n; shift ;;
+ -r) resume_arg=-r; shift ;;
-t) IFS=, targets=($2); shift 2 ;;
-h|--help) usage ;;
--) shift; break ;;
# a subvol on current host is not fresh.
# umount first to ensure we don't have any errors
# todo: do some kill fuser stuff to make umount more reliable
-# todo: run this on a systemd timer on $primary, once per hour.
+# todo: run this on a systemd timer on $primary, once per hour,
+# and if primary is, change that timer over to primary, and make
+# sure we mount the latest
# todo: setup lock so that if this is already running, we exit out, so
# that manual runs don't interfere with cronjobs.
fi
if $dry_run; then
- btrbk -n run
+ btrbk -n $resume_arg run
else
- btrbk -q run
+ btrbk -q $resume_arg run
fi
# if we have /p, rsync to targets without /p
if ! $dry_run; then
for tg in ${targets[@]}; do
scp $script_dir/{mount-latest-subvol,check-subvol-stale} \
- root@tg:/usr/local/bin
+ root@$tg:/usr/local/bin
ssh root@$tg bash <<'EOF'
set -e
chmod +x /usr/local/bin/{mount-latest-subvol,check-subvol-stale}
done
dir=/nocow
-l=$(sed -rn "s#^(\s*\S+\s+)/q(\s.*)(subvol=q)#\1$dir\2subvol=nocow#p" /etc/fstab)
-if [[ $l ]] && ! mountpoint $dir; then
+if ! mountpoint $dir; then
+ subvol=/mnt/root/nocow
+ if [[ ! -e nocow ]]; then
+ btrfs subvolume create $subvol
+ chown root:1000 $subvol
+ chattr +C $subvol
+ fi
+
+ first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab)
tu /etc/fstab <<EOF
-$l
+$first_root_crypt /nocow btrfs noatime,subvol=nocow 0 0
EOF
s mkdir -p $dir
s chown ian:ian $dir
# I haven't gotten around to getting a non-debian exim
# setup.
mail-setup exim4
-else
- mail-setup postfix
+ else
+ mail-setup postfix
fi
-if isubuntu; then
- # disable crash report annoying crap
- s dd of=/etc/default/apport <<<'enabled=0'
-fi
+ if isubuntu; then
+ # disable crash report annoying crap
+ s dd of=/etc/default/apport <<<'enabled=0'
+ fi
# fai sets this an old way that doesn't work for stretch.
# no harm in setting it universally here.
case $distro in
arch) pi syncthing ;;
ubuntu|debian)
- # google led me here:
- # https://apt.syncthing.net/
- curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
- s="deb http://apt.syncthing.net/ syncthing release"
- if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != $s ]]; then
- echo "$s" | s dd of=/etc/apt/sources.list.d/syncthing.list
- p update
+ # testing has relatively up to date packages
+ if ! isdebian-testing; then
+ # based on error when doing apt-get update:
+ # E: The method driver /usr/lib/apt/methods/https could not be found.
+ pi apt-transport-https
+ # google led me here:
+ # https://apt.syncthing.net/
+ curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
+ s="deb http://apt.syncthing.net/ syncthing release"
+ if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != $s ]]; then
+ echo "$s" | s dd of=/etc/apt/sources.list.d/syncthing.list
+ p update
+ fi
fi
pi syncthing
;;
e $forward > ~/.forward
e $forward | s tee /root/.forward
-# linode image has a root alias. completely useless, remove it.
-sudo sed -i '/^root:/d' /etc/aliases
-
-s newaliases
-
# offlineimap uses this too, it is much easier to use one location than to
# condition it's config and postfix's config
fi
fi
+# linode image has a root alias. completely useless, remove it.
+sudo sed -i '/^root:/d' /etc/aliases
+
+s newaliases
+
+
# based on http://www.postfix.org/qmgr.8.html and my notes in gnus
dir=/nocow/$type
sdir=/var/spool/$type
}
errcatch
-
+tu() {
+ while read -r line; do
+ file="$1"
+ grep -xFq "$line" "$file" || tee -a "$file"<<<"$line"
+ done
+}
e() { printf "%s\n" "$*"; "$@"; }
+mnt() {
+ dir=$1
+ if ! mountpoint $dir >/dev/null; then
+ mkdir -p $dir
+ e mount $dir
+ fi
+}
ret=0
fi
-mkdir -p /q /p /i
-
for vol in q p; do
d=/$vol
if ! awk '{print $2}' /etc/fstab | grep -xF $d &>/dev/null; then
new_roots=()
for r in ${roots[@]}; do
# /q/a /a none bind 0 0
- new_roots+=($(sed -rn "s#^$r/\S+\s+(\S+)\s+none\s+bind\s.*#\1#" /etc/fstab))
+ new_roots+=($(sed -rn "s#^$r/\S+\s+(\S+)\s+none\s+bind\s.*#\1#p" /etc/fstab))
done
(( ${#new_roots} )) || break
binds+=(${new_roots[@]})
if e check-subvol-stale $d; then
for b in ${binds[@]}; do
- mount $b
+ mnt $b
done
continue
fi
if ! $umount_ret; then
for dir in ${unmounted[@]}; do
- mount $dir
+ mnt $dir
done
ret=1
continue
# things otherwise didn't get mounted very strangely.
e btrfs sub snapshot btrbk/$last_snap $vol
for dir in $d ${binds[@]}; do
- e mount $dir
+ e mnt $dir
done
done
exit $ret