lots: shellcheck, streaming stuff, fixes
[distro-setup] / schrootupdate
1 #!/bin/bash
2
3 set -eE -o pipefail
4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
5
6 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
7
8 # used to have more than one, leaving commented in case we do
9 #for n in bullseye; do
10 n=bullseye
11 if [[ -e /etc/schroot/chroot.d/$n.conf ]]; then
12 cd /
13 schroot -c $n -- apt-get -y update
14 schroot -c $n -- apt-get -y dist-upgrade --purge --auto-remove
15 fi
16 #done
17
18 # if we haven't upgraded yet
19 if [[ ! -d /mnt/boot/debianbullseye_bootstrap ]]; then
20 exit 0
21 fi
22
23 dev=$(awk '$2 == "/mnt/boot" {print $1}' /etc/mtab)
24 if [[ ! $dev ]]; then
25 exit 0
26 fi
27 mkdir -p /mnt/tmptimer
28 if ! mountpoint /mnt/tmptimer &>/dev/null; then
29 mount -o subvol=debianbullseye_bootstrap $dev /mnt/tmptimer
30 fi
31 cd /mnt/tmptimer
32 for d in dev proc sys dev/pts; do
33 [[ -d $d ]]
34 if ! mountpoint $d &>/dev/null; then
35 mount -o bind /$d $d
36 fi
37 done
38 chroot . apt-get -y update
39 chroot . apt-get -y dist-upgrade --purge --auto-remove
40
41 for d in dev/pts dev proc sys; do
42 if mountpoint $d &>/dev/null; then
43 umount $d
44 fi
45 done
46 cd /
47 umount /mnt/tmptimer