root-enter: upgrade to 7

This commit is contained in:
ptrcnull 2022-07-19 05:31:00 +02:00
parent db660a39c9
commit 2555cc55b0
2 changed files with 79 additions and 42 deletions

View file

@ -1,13 +1,15 @@
# Contributor: Patrycja Rosa <alpine@ptrcnull.me> # Contributor: Patrycja Rosa <alpine@ptrcnull.me>
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me> # Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=root-enter pkgname=root-enter
pkgver=6 pkgver=7
pkgrel=0 pkgrel=0
pkgdesc="enter chroot with mounts" pkgdesc="enter chroot with mounts"
url="https://git.ddd.rip/ptrcnull/ptrcports" url="https://git.ddd.rip/ptrcnull/ptrcports"
arch="noarch" arch="noarch"
license="BSD-2-Clause" license="BSD-2-Clause"
depends="execline"
source="enter" source="enter"
builddir="$srcdir"
options="!check" options="!check"
package() { package() {
@ -15,5 +17,5 @@ package() {
} }
sha512sums=" sha512sums="
6e458ca9f00ce8a804bb1ff07e639a682546d3cb4e963f7fbad262625e0af74db7b94d11c2ad2fd16f7d229f4d936a80bd334216c0f1cafde4b3c650a34bf3ae enter 695da33b6a8eeca6e77e7afb6ea36f14b66d53afbb5408911905fbfaf93ef6e54f12819ef0af267919707f9e3c867f63fb905092c6909dd5fc68805e20849f2f enter
" "

View file

@ -1,48 +1,83 @@
#!/bin/sh #!/bin/execlineb
set -e elgetopt "be:u:c:"
[ "$(id -u)" = 0 ] || DOAS="${DOAS:-doas}" multisubstitute {
[ "$unshared" = 1 ] || exec $DOAS env unshared=1 unshare -m $0 "$@" importas -D "0" build ELGETOPT_b
importas -D "" extra_mounts ELGETOPT_e
importas -D "" user_arg ELGETOPT_u
importas -D "" command_arg ELGETOPT_c
importas -D "" dest 1
importas -i USER USER
importas -i HOME HOME
}
bindpoints="/etc/resolv.conf" shift
user="patrycja" elgetpositionals
command="ash -l" emptyenv -oP
while getopts "be:u:c:" opt; do backtick -D "ash -l" command {
case $opt in ifelse { test -n $command_arg } {
'b') bindpoints=" echo $command_arg
$bindpoints }
/home/patrycja/aports
/home/patrycja/packages
/home/patrycja/.abuild
" ;;
'e') bindpoints="$bindpoints $OPTARG" ;;
'u') user=$OPTARG ;;
'c') command=$OPTARG ;;
*) echo "unknown $opt" ;;
esac
done
shift $(( $OPTIND - 1 ))
if [ ! -d "$1" ]; then ifelse { test $# -gt 0 } {
echo "no such directory: $1" echo $@
}
echo ash -l
}
importas -ui command command
# TODO: add -s to that when not using `su` later
backtick -D "" -E user { ifelse { test -n $user_arg } { echo $user_arg } echo $USER }
backtick -D "" -E build_mounts {
if { test $build = 1 }
echo "
${HOME}/aports
${HOME}/packages
${HOME}/.abuild
"
}
define -s -C bindpoints "/etc/resolv.conf ${build_mounts} ${extra_mounts}"
ifelse -n { test -d $dest } {
foreground { echo "no such file or directory: $dest" }
exit 1 exit 1
fi }
mount -t devtmpfs devtmpfs $1/dev ifelse -n { test -x ${dest}/bin/sh } {
mount -t tmpfs shm $1/dev/shm foreground { echo "$dest does not contain executable /bin/sh" }
mount -t devpts devpts $1/dev/pts exit 1
mount -t sysfs sysfs $1/sys }
mount -t proc proc $1/proc
mount -t tmpfs tmpfs $1/tmp
for point in $bindpoints; do
if [ -f $point ]; then
touch $1$point
else
mkdir -p $1$point
fi
mount --bind $point $1$point
done
chroot $1 /bin/sh -c "su $user -c '$command'" backtick -E uid { id -u }
backtick -E -D "exec" sucmd { if { test $uid != 0 } echo doas }
$sucmd
unshare -m
foreground { mount -t devtmpfs devtmpfs ${dest}/dev }
foreground { mount -t tmpfs shm ${dest}/dev/shm }
foreground { mount -t devpts devpts ${dest}/dev/pts }
foreground { mount -t sysfs sysfs ${dest}/sys }
foreground { mount -t proc proc ${dest}/proc }
foreground { mount -t tmpfs tmpfs ${dest}/tmp }
foreground {
forx -E point { $bindpoints }
# ensure $point exists in destination
ifthenelse { test -f $point } {
touch ${dest}${point}
} {
mkdir -p ${dest}${point}
}
mount --bind $point ${dest}${point}
}
chroot ${dest}
su - $user -c "$command"