root-enter: upgrade to 11

This commit is contained in:
ptrcnull 2024-04-09 20:55:01 +02:00
parent cff1ac9b2a
commit a40921c801
2 changed files with 42 additions and 12 deletions

View file

@ -1,7 +1,7 @@
# 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=10 pkgver=11
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"
@ -16,5 +16,5 @@ package() {
} }
sha512sums=" sha512sums="
f573f95bf93486f3417e0adfebdabc3a50f8dd7dd16489f3367fc32c93e187ea41daa19b86a17d73a913ddcfb10d1f8cd5b32b1bb376f6ff152e1ae8d2f7e18f enter 8f5c61d316624ec599f71c0b4e17a62b3c950fef1895a8a86b978a454b721b56de4049f588005113387647c9850ad879f303b2b3036f65007df364aebe8f00c3 enter
" "

View file

@ -1,6 +1,9 @@
#!/bin/sh #!/bin/sh
set -eu set -eu
USERNAME="${USERNAME:-$(id -u -n)}"
UNSHARE_CMD="${UNSHARE_CMD:-unshare}"
# make sure we're root # make sure we're root
if [ "$(id -u)" != 0 ]; then if [ "$(id -u)" != 0 ]; then
sucmd="su -c" sucmd="su -c"
@ -10,19 +13,28 @@ if [ "$(id -u)" != 0 ]; then
sucmd="sudo" sucmd="sudo"
fi fi
exec $sucmd env HOME="$HOME" USERNAME="$(id -u -n)" "$0" "$@" exec $sucmd \
env \
HOME="$HOME" \
USERNAME="$USERNAME" \
UNSHARE_CMD="$UNSHARE_CMD" \
WAYLAND_DISPLAY="$WAYLAND_DISPLAY" \
DISPLAY="$DISPLAY" \
XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" \
DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS" \
"$0" "$@"
fi fi
# and make sure we're in a separate mount namespace # and make sure we're in a separate mount namespace
if [ "$(readlink /proc/$$/ns/mnt | cut -d: -f2)" = "$(readlink /proc/1/ns/mnt | cut -d: -f2)" ]; then if [ "$(readlink /proc/$$/ns/mnt | cut -d: -f2)" = "$(readlink /proc/1/ns/mnt | cut -d: -f2)" ]; then
exec unshare -m "$0" "$@" exec $UNSHARE_CMD --keep-caps -m "$0" "$@"
fi fi
bindpoints="/etc/resolv.conf" bindpoints="/etc/resolv.conf"
command="" command=""
user="$USERNAME" user="$USERNAME"
while getopts "be:u:c:" opt; do while getopts "bde:u:c:" opt; do
case $opt in case $opt in
'b') bindpoints=" 'b') bindpoints="
$bindpoints $bindpoints
@ -31,6 +43,11 @@ while getopts "be:u:c:" opt; do
$HOME/packages $HOME/packages
$HOME/.abuild $HOME/.abuild
" ;; " ;;
'd') bindpoints="
$bindpoints
$XDG_RUNTIME_DIR
/tmp
" ;;
'e') bindpoints="$bindpoints $OPTARG" ;; 'e') bindpoints="$bindpoints $OPTARG" ;;
'u') user="$OPTARG" ;; 'u') user="$OPTARG" ;;
'c') command="$OPTARG" ;; 'c') command="$OPTARG" ;;
@ -47,11 +64,14 @@ if [ ! -d "$dest" ]; then
exit 1 exit 1
fi fi
if [ ! -x "$dest"/bin/sh ]; then if ! [ -x "$dest"/bin/sh -o -L "$dest"/bin/sh ]; then
echo "$dest does not contain executable /bin/sh" echo "$dest does not contain executable /bin/sh"
exit 1 exit 1
fi fi
# do stupid path fixup
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:$PATH"
mount -t proc proc "$dest"/proc mount -t proc proc "$dest"/proc
mount -t sysfs sysfs "$dest"/sys mount -t sysfs sysfs "$dest"/sys
mount -t tmpfs tmpfs "$dest"/tmp mount -t tmpfs tmpfs "$dest"/tmp
@ -61,16 +81,23 @@ if grep -q devtmpfs /proc/filesystems; then
else else
mount -t tmpfs tmpfs "$dest"/dev mount -t tmpfs tmpfs "$dest"/dev
if [ -x "$dest"/sbin/mdev ]; then if [ -x "$dest"/sbin/mdev -o -L "$dest"/sbin/mdev ]; then
echo "devtmpfs not supported - running 'mdev -s' instead" echo "devtmpfs not supported - running 'mdev -s' instead"
chroot "$dest" /sbin/mdev -s chroot "$dest" /sbin/mdev -sv
else else
echo "devtmpfs not supported - devices need to be created manually" echo "devtmpfs not supported - devices need to be created manually"
fi fi
fi fi
mkdir -p "$dest"/dev/pts "$dest"/dev/shm
mount -t devpts devpts "$dest"/dev/pts mount -t devpts devpts "$dest"/dev/pts
mount -t tmpfs tmpfs "$dest"/dev/shm mount -t tmpfs tmpfs "$dest"/dev/shm
# workaround for shitty android-based stuff
if ! [ -f /etc/resolv.conf ]; then
# remove /etc/resolv.conf from bindpoints
bindpoints="${bindpoints#/etc/resolv.conf}"
fi
for bindpoint in $bindpoints; do for bindpoint in $bindpoints; do
if [ -f "$bindpoint" ]; then if [ -f "$bindpoint" ]; then
touch "$dest"/"$bindpoint" touch "$dest"/"$bindpoint"
@ -78,7 +105,7 @@ for bindpoint in $bindpoints; do
mkdir -p "$dest"/"$bindpoint" mkdir -p "$dest"/"$bindpoint"
fi fi
mount --bind "$bindpoint" "$dest"/"$bindpoint" mount -o bind "$bindpoint" "$dest"/"$bindpoint"
done done
# if running on chromeos, fixup symlink exec # if running on chromeos, fixup symlink exec
@ -96,10 +123,13 @@ if [ -e "/run/chrome" ]; then
fi fi
fi fi
mount -o bind "$dest" /mnt
pivot_root /mnt /mnt/mnt
if [ "$command" ]; then if [ "$command" ]; then
exec chroot "$dest" su $user -c "$command" exec su $user -c "$command"
elif [ "$#" -gt 0 ]; then elif [ "$#" -gt 0 ]; then
exec chroot "$dest" su $user -c "$*" exec su $user -c "$*"
else else
exec chroot "$dest" login -f $user exec login -p -f $user
fi fi