add gentoo package testing script
This commit is contained in:
parent
9431f1a454
commit
0c9d346602
53
.local/bin/chroot_testing
Executable file
53
.local/bin/chroot_testing
Executable file
@ -0,0 +1,53 @@
|
||||
#!/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
|
Loading…
x
Reference in New Issue
Block a user