From 0c9d346602bdec50d7891d4e79d383cd7ab714bf Mon Sep 17 00:00:00 2001 From: tea Date: Sun, 16 Jun 2024 16:00:01 +0200 Subject: [PATCH] add gentoo package testing script --- .local/bin/chroot_testing | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 .local/bin/chroot_testing diff --git a/.local/bin/chroot_testing b/.local/bin/chroot_testing new file mode 100755 index 0000000..c05c87c --- /dev/null +++ b/.local/bin/chroot_testing @@ -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