54 lines
1.3 KiB
Plaintext
54 lines
1.3 KiB
Plaintext
|
#!/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
|
||
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
_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
|