2024-06-16 16:00:01 +02:00
|
|
|
#!/bin/zsh
|
|
|
|
# chroot into an environment for gentoo package testing
|
|
|
|
# no argument: modify template
|
|
|
|
# first argument: suffix of the test subvolume
|
|
|
|
|
|
|
|
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
|
|
|
|
|
|
|
|
local chroot_dir="/mnt/testing"
|
|
|
|
|
|
|
|
if [[ "$(id -u)" != 0 ]]; then
|
|
|
|
print -Pu2 "%B%F{red}you have to be root%f%b"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -v 1 ]]; then
|
|
|
|
chroot_dir="${chroot_dir}_${1}"
|
|
|
|
if [[ ! -d ${chroot_dir} ]]; then
|
|
|
|
btrfs subvolume snapshot /mnt/testing "${chroot_dir}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
cp --dereference /etc/resolv.conf ${chroot_dir}/etc/
|
|
|
|
|
|
|
|
mount --types proc /proc ${chroot_dir}/proc
|
|
|
|
mount --rbind /sys ${chroot_dir}/sys
|
|
|
|
mount --rbind /dev ${chroot_dir}/dev
|
|
|
|
mount --rbind /run ${chroot_dir}/run
|
|
|
|
|
|
|
|
mount -o bind,ro ~tea/src/gentoo ${chroot_dir}/var/db/repos/gentoo
|
|
|
|
mount -o bind,ro ~tea/src/guru ${chroot_dir}/var/db/repos/guru
|
2024-06-19 18:57:26 +02:00
|
|
|
mount -o bind,ro ~tea/src/tastytea-overlay ${chroot_dir}/var/db/repos/tastytea
|
2024-06-16 16:00:01 +02:00
|
|
|
|
|
|
|
chroot ${chroot_dir} /bin/bash -l
|
|
|
|
|
|
|
|
function _try_umount() {
|
|
|
|
local dir=${1}
|
|
|
|
|
|
|
|
setopt NO_ERR_RETURN
|
|
|
|
umount --recursive ${dir} || umount --lazy ${dir}
|
|
|
|
setopt ERR_RETURN
|
|
|
|
}
|
|
|
|
|
2024-06-19 18:57:26 +02:00
|
|
|
_try_umount ${chroot_dir}/var/db/repos/tastytea
|
2024-06-16 16:00:01 +02:00
|
|
|
_try_umount ${chroot_dir}/var/db/repos/guru
|
|
|
|
_try_umount ${chroot_dir}/var/db/repos/gentoo
|
|
|
|
|
|
|
|
_try_umount ${chroot_dir}/run
|
|
|
|
_try_umount ${chroot_dir}/dev
|
|
|
|
_try_umount ${chroot_dir}/sys
|
|
|
|
_try_umount ${chroot_dir}/proc
|
|
|
|
|
|
|
|
if [[ -v 1 ]]; then
|
|
|
|
print -Pu2 "%F{blue}delete snapshot with%f" \
|
|
|
|
"%F{magenta}btrfs subvolume delete ${chroot_dir}%f"
|
|
|
|
fi
|