root-enter: upgrade to 11
This commit is contained in:
parent
cff1ac9b2a
commit
a40921c801
2 changed files with 42 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
|||
# Contributor: Patrycja Rosa <alpine@ptrcnull.me>
|
||||
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
|
||||
pkgname=root-enter
|
||||
pkgver=10
|
||||
pkgver=11
|
||||
pkgrel=0
|
||||
pkgdesc="enter chroot with mounts"
|
||||
url="https://git.ddd.rip/ptrcnull/ptrcports"
|
||||
|
@ -16,5 +16,5 @@ package() {
|
|||
}
|
||||
|
||||
sha512sums="
|
||||
f573f95bf93486f3417e0adfebdabc3a50f8dd7dd16489f3367fc32c93e187ea41daa19b86a17d73a913ddcfb10d1f8cd5b32b1bb376f6ff152e1ae8d2f7e18f enter
|
||||
8f5c61d316624ec599f71c0b4e17a62b3c950fef1895a8a86b978a454b721b56de4049f588005113387647c9850ad879f303b2b3036f65007df364aebe8f00c3 enter
|
||||
"
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
USERNAME="${USERNAME:-$(id -u -n)}"
|
||||
UNSHARE_CMD="${UNSHARE_CMD:-unshare}"
|
||||
|
||||
# make sure we're root
|
||||
if [ "$(id -u)" != 0 ]; then
|
||||
sucmd="su -c"
|
||||
|
@ -10,19 +13,28 @@ if [ "$(id -u)" != 0 ]; then
|
|||
sucmd="sudo"
|
||||
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
|
||||
|
||||
# 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
|
||||
exec unshare -m "$0" "$@"
|
||||
exec $UNSHARE_CMD --keep-caps -m "$0" "$@"
|
||||
fi
|
||||
|
||||
bindpoints="/etc/resolv.conf"
|
||||
command=""
|
||||
user="$USERNAME"
|
||||
|
||||
while getopts "be:u:c:" opt; do
|
||||
while getopts "bde:u:c:" opt; do
|
||||
case $opt in
|
||||
'b') bindpoints="
|
||||
$bindpoints
|
||||
|
@ -31,6 +43,11 @@ while getopts "be:u:c:" opt; do
|
|||
$HOME/packages
|
||||
$HOME/.abuild
|
||||
" ;;
|
||||
'd') bindpoints="
|
||||
$bindpoints
|
||||
$XDG_RUNTIME_DIR
|
||||
/tmp
|
||||
" ;;
|
||||
'e') bindpoints="$bindpoints $OPTARG" ;;
|
||||
'u') user="$OPTARG" ;;
|
||||
'c') command="$OPTARG" ;;
|
||||
|
@ -47,11 +64,14 @@ if [ ! -d "$dest" ]; then
|
|||
exit 1
|
||||
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"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# do stupid path fixup
|
||||
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:$PATH"
|
||||
|
||||
mount -t proc proc "$dest"/proc
|
||||
mount -t sysfs sysfs "$dest"/sys
|
||||
mount -t tmpfs tmpfs "$dest"/tmp
|
||||
|
@ -61,16 +81,23 @@ if grep -q devtmpfs /proc/filesystems; then
|
|||
else
|
||||
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"
|
||||
chroot "$dest" /sbin/mdev -s
|
||||
chroot "$dest" /sbin/mdev -sv
|
||||
else
|
||||
echo "devtmpfs not supported - devices need to be created manually"
|
||||
fi
|
||||
fi
|
||||
mkdir -p "$dest"/dev/pts "$dest"/dev/shm
|
||||
mount -t devpts devpts "$dest"/dev/pts
|
||||
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
|
||||
if [ -f "$bindpoint" ]; then
|
||||
touch "$dest"/"$bindpoint"
|
||||
|
@ -78,7 +105,7 @@ for bindpoint in $bindpoints; do
|
|||
mkdir -p "$dest"/"$bindpoint"
|
||||
fi
|
||||
|
||||
mount --bind "$bindpoint" "$dest"/"$bindpoint"
|
||||
mount -o bind "$bindpoint" "$dest"/"$bindpoint"
|
||||
done
|
||||
|
||||
# if running on chromeos, fixup symlink exec
|
||||
|
@ -96,10 +123,13 @@ if [ -e "/run/chrome" ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
mount -o bind "$dest" /mnt
|
||||
pivot_root /mnt /mnt/mnt
|
||||
|
||||
if [ "$command" ]; then
|
||||
exec chroot "$dest" su $user -c "$command"
|
||||
exec su $user -c "$command"
|
||||
elif [ "$#" -gt 0 ]; then
|
||||
exec chroot "$dest" su $user -c "$*"
|
||||
exec su $user -c "$*"
|
||||
else
|
||||
exec chroot "$dest" login -f $user
|
||||
exec login -p -f $user
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue