From 87a825d85f909b8f19008e0fff24abaf5dfb9767 Mon Sep 17 00:00:00 2001 From: ptrcnull Date: Tue, 26 Apr 2022 01:10:13 +0200 Subject: [PATCH] root-enter: new aport --- root-enter/APKBUILD | 19 +++++++++++++++++++ root-enter/enter | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 root-enter/APKBUILD create mode 100755 root-enter/enter diff --git a/root-enter/APKBUILD b/root-enter/APKBUILD new file mode 100644 index 0000000..a3dff86 --- /dev/null +++ b/root-enter/APKBUILD @@ -0,0 +1,19 @@ +# Contributor: Patrycja Rosa +# Maintainer: Patrycja Rosa +pkgname=root-enter +pkgver=1.0.0 +pkgrel=0 +pkgdesc="enter chroot with mounts" +url="https://git.ddd.rip/ptrcnull/ptrcports" +arch="noarch" +license="BSD-2-Clause" +source="enter" +options="!check" + +package() { + install -Dm755 enter "$pkgdir"/usr/bin/enter +} + +sha512sums=" +f64c60c1937f4ac6145b3fc00dc9dce8205328009e60219282e8cba5837aff63674d4b3bef2fb751323e21720ab9ff251356817b0c2734ef2ebe315162e6caf8 enter +" diff --git a/root-enter/enter b/root-enter/enter new file mode 100755 index 0000000..d82fec8 --- /dev/null +++ b/root-enter/enter @@ -0,0 +1,41 @@ +#!/bin/sh + +set -e + +[ "$unshared" = 1 ] || exec doas env unshared=1 unshare -m $0 $@ + +bindpoints="/etc/resolv.conf" +user="patrycja" +command="ash -l" + +while getopts "be:u:s:" opt; do + case $opt in + 'b') bindpoints=" + $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 )) + +mount -t devtmpfs devtmpfs $1/dev +mount -t tmpfs shm $1/dev/shm +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'"