From 399d717bc433cbcaab8f813e7571d6329c64ec82 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Sat, 6 Mar 2021 12:28:09 +0700 Subject: [PATCH 1/7] Add copyresolv to uth. --- archbox.bash | 8 ++------ copyresolv.bash | 4 ---- archboxcommand.bash => exec.bash | 0 install.sh | 2 +- uth.bash | 8 ++++++++ 5 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 copyresolv.bash rename archboxcommand.bash => exec.bash (100%) create mode 100644 uth.bash diff --git a/archbox.bash b/archbox.bash index 20bc920..6c5046f 100644 --- a/archbox.bash +++ b/archbox.bash @@ -6,10 +6,6 @@ checkdep(){ hash $1 2>/dev/null || err "Install $1!" } -copyresolv(){ - $PRIV $PREFIX/share/archbox/bin/copyresolv -} - asroot(){ [[ $EUID -ne 0 ]] && err "Run this as root!" } @@ -94,7 +90,7 @@ case $1 in ;; -e|--enter) storeenv - copyresolv + $PRIV $PREFIX/share/archbox/bin/uth copyresolv $PRIV $PREFIX/share/archbox/bin/archbox enter exit $? ;; @@ -129,7 +125,7 @@ case $1 in ;; *) storeenv - copyresolv + $PRIV $PREFIX/share/archbox/bin/uth copyresolv $PRIV $PREFIX/share/archbox/bin/archbox $@ exit $? ;; diff --git a/copyresolv.bash b/copyresolv.bash deleted file mode 100644 index 2806988..0000000 --- a/copyresolv.bash +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -source /etc/archbox.conf -cp /etc/resolv.conf $CHROOT/etc/resolv.conf diff --git a/archboxcommand.bash b/exec.bash similarity index 100% rename from archboxcommand.bash rename to exec.bash diff --git a/install.sh b/install.sh index 813bdf8..7953757 100755 --- a/install.sh +++ b/install.sh @@ -6,11 +6,11 @@ mkdir -p $PREFIX/share/archbox/bin install -v -D -m 755 ./archbox.bash $PREFIX/bin/archbox install -v -D -m 755 ./archbox-desktop.bash $PREFIX/bin/archbox-desktop [[ ! -e /etc/archbox.conf ]] && install -v -D -m 755 ./archbox.conf /etc/archbox.conf -install -v -D -m 755 ./copyresolv.bash $PREFIX/share/archbox/bin/copyresolv install -v -D -m 755 ./archboxcommand.bash $PREFIX/share/archbox/bin/archbox install -v -D -m 755 ./remount_run.bash $PREFIX/share/archbox/bin/remount_run install -v -D -m 755 ./chroot_setup.bash $PREFIX/share/archbox/chroot_setup.bash install -v -D -m 755 ./archboxinit.bash $PREFIX/share/archbox/bin/archboxinit +install -v -D -m 755 ./uth.bash $PREFIX/share/archbox/bin/uth grep 'PREFIX=' /etc/archbox.conf >/dev/null 2>&1 || cat << EOF >> /etc/archbox.conf diff --git a/uth.bash b/uth.bash new file mode 100644 index 0000000..76d4588 --- /dev/null +++ b/uth.bash @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +source /etc/archbox.conf + +case $1 in + copyresolv) + cp /etc/resolv.conf $CHROOT/etc/resolv.conf + ;; +esac \ No newline at end of file From 5a7b37a14bb8d7c972451ddf15e18749eb3e18f3 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Sat, 6 Mar 2021 12:39:59 +0700 Subject: [PATCH 2/7] Add remount_run to uth. --- archbox.bash | 4 ++-- exp/startx-killxdg.bash | 2 +- install.sh | 1 - remount_run.bash | 24 ------------------------ uth.bash | 19 +++++++++++++++++++ 5 files changed, 22 insertions(+), 28 deletions(-) delete mode 100644 remount_run.bash diff --git a/archbox.bash b/archbox.bash index 6c5046f..e1de6d7 100644 --- a/archbox.bash +++ b/archbox.bash @@ -104,12 +104,12 @@ case $1 in ;; --remount-run) storeenv - $PRIV $PREFIX/share/archbox/bin/remount_run + $PRIV $PREFIX/share/archbox/bin/uth remountrun exit $? ;; --mount-runtime-only) storeenv - $PRIV $PREFIX/share/archbox/bin/remount_run runtimeonly + $PRIV $PREFIX/share/archbox/bin/uth runtimeonly exit $? ;; -h|--help) diff --git a/exp/startx-killxdg.bash b/exp/startx-killxdg.bash index fc5f8d1..8ec6443 100755 --- a/exp/startx-killxdg.bash +++ b/exp/startx-killxdg.bash @@ -3,4 +3,4 @@ source /etc/archbox.conf startx -$PRIV $PREFIX/share/archbox/bin/remount_run killxdg +$PRIV $PREFIX/share/archbox/bin/uth killxdg diff --git a/install.sh b/install.sh index 7953757..3130677 100755 --- a/install.sh +++ b/install.sh @@ -7,7 +7,6 @@ install -v -D -m 755 ./archbox.bash $PREFIX/bin/archbox install -v -D -m 755 ./archbox-desktop.bash $PREFIX/bin/archbox-desktop [[ ! -e /etc/archbox.conf ]] && install -v -D -m 755 ./archbox.conf /etc/archbox.conf install -v -D -m 755 ./archboxcommand.bash $PREFIX/share/archbox/bin/archbox -install -v -D -m 755 ./remount_run.bash $PREFIX/share/archbox/bin/remount_run install -v -D -m 755 ./chroot_setup.bash $PREFIX/share/archbox/chroot_setup.bash install -v -D -m 755 ./archboxinit.bash $PREFIX/share/archbox/bin/archboxinit install -v -D -m 755 ./uth.bash $PREFIX/share/archbox/bin/uth diff --git a/remount_run.bash b/remount_run.bash deleted file mode 100644 index 0bd8d1c..0000000 --- a/remount_run.bash +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -source /etc/archbox.conf -source /tmp/archbox_env - -case $1 in - killxdg) - umount -l $CHROOT/run - fuser -km $XDG_RUNTIME_DIR - exit $? - ;; - runtimeonly) - mkdir -p $CHROOT$XDG_RUNTIME_DIR - umount -Rl $CHROOT$XDG_RUNTIME_DIR 2>/dev/null - mount | grep $CHROOT$XDG_RUNTIME_DIR || \ - mount --rbind $XDG_RUNTIME_DIR $CHROOT$XDG_RUNTIME_DIR - exit $? - ;; - *) - umount -l $CHROOT/run - mount --rbind /run $CHROOT/run - exit $? - ;; -esac diff --git a/uth.bash b/uth.bash index 76d4588..5bf8ab1 100644 --- a/uth.bash +++ b/uth.bash @@ -1,8 +1,27 @@ #!/usr/bin/env bash + source /etc/archbox.conf +source /tmp/archbox_env case $1 in copyresolv) cp /etc/resolv.conf $CHROOT/etc/resolv.conf ;; + killxdg) + umount -l $CHROOT/run + fuser -km $XDG_RUNTIME_DIR + exit $? + ;; + runtimeonly) + mkdir -p $CHROOT$XDG_RUNTIME_DIR + umount -Rl $CHROOT$XDG_RUNTIME_DIR 2>/dev/null + mount | grep $CHROOT$XDG_RUNTIME_DIR || \ + mount --rbind $XDG_RUNTIME_DIR $CHROOT$XDG_RUNTIME_DIR + exit $? + ;; + remountrun) + umount -l $CHROOT/run 2>/dev/null + mount --rbind /run $CHROOT/run + exit $? + ;; esac \ No newline at end of file From 774b97537dd941c3dc3ca152cfde0ad326ddd0f2 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Sat, 6 Mar 2021 12:44:16 +0700 Subject: [PATCH 3/7] Rename archboxinit --- archboxinit.bash => init.bash | 0 install.sh | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename archboxinit.bash => init.bash (100%) diff --git a/archboxinit.bash b/init.bash similarity index 100% rename from archboxinit.bash rename to init.bash diff --git a/install.sh b/install.sh index 3130677..6111184 100755 --- a/install.sh +++ b/install.sh @@ -8,7 +8,7 @@ install -v -D -m 755 ./archbox-desktop.bash $PREFIX/bin/archbox-desktop [[ ! -e /etc/archbox.conf ]] && install -v -D -m 755 ./archbox.conf /etc/archbox.conf install -v -D -m 755 ./archboxcommand.bash $PREFIX/share/archbox/bin/archbox install -v -D -m 755 ./chroot_setup.bash $PREFIX/share/archbox/chroot_setup.bash -install -v -D -m 755 ./archboxinit.bash $PREFIX/share/archbox/bin/archboxinit +install -v -D -m 755 ./init.bash $PREFIX/share/archbox/bin/init install -v -D -m 755 ./uth.bash $PREFIX/share/archbox/bin/uth grep 'PREFIX=' /etc/archbox.conf >/dev/null 2>&1 || cat << EOF >> /etc/archbox.conf From 7fcc8d2ad0f6d97c2ad6478c724512b4ed3a7838 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Sat, 6 Mar 2021 12:51:01 +0700 Subject: [PATCH 4/7] Separate enter and exec command and some changes. --- archbox.bash | 10 +++++----- enter.bash | 13 +++++++++++++ exec.bash | 3 +-- install.sh | 3 ++- 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 enter.bash diff --git a/archbox.bash b/archbox.bash index e1de6d7..14d8ba3 100644 --- a/archbox.bash +++ b/archbox.bash @@ -82,7 +82,7 @@ case $1 in checkdep sed sed -i 's/CheckSpace/#CheckSpace/g' $CHROOT/etc/pacman.conf msg "Mounting necessary filesystems..." - $PREFIX/share/archbox/bin/archboxinit start + $PREFIX/share/archbox/bin/init start cp $PREFIX/share/archbox/chroot_setup.bash $CHROOT/chroot_setup echo $USER > /tmp/archbox_user chroot $CHROOT /bin/bash -c "/chroot_setup" @@ -91,16 +91,16 @@ case $1 in -e|--enter) storeenv $PRIV $PREFIX/share/archbox/bin/uth copyresolv - $PRIV $PREFIX/share/archbox/bin/archbox enter + $PRIV $PREFIX/share/archbox/bin/enter exit $? ;; -m|--mount) storeenv - $PRIV $PREFIX/share/archbox/bin/archboxinit start + $PRIV $PREFIX/share/archbox/bin/init start ;; -u|--umount) storeenv - $PRIV $PREFIX/share/archbox/bin/archboxinit stop + $PRIV $PREFIX/share/archbox/bin/init stop ;; --remount-run) storeenv @@ -126,7 +126,7 @@ case $1 in *) storeenv $PRIV $PREFIX/share/archbox/bin/uth copyresolv - $PRIV $PREFIX/share/archbox/bin/archbox $@ + $PRIV $PREFIX/share/archbox/bin/exec $@ exit $? ;; esac diff --git a/enter.bash b/enter.bash new file mode 100644 index 0000000..22abf6d --- /dev/null +++ b/enter.bash @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +source /etc/archbox.conf +source /tmp/archbox_env + +REQ_ENV="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS " +REQ_ENV+="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR " +[[ ! -z $DISPLAY ]] && REQ_ENV+="DISPLAY=$DISPLAY " +[[ ! -z $WAYLAND_DISPLAY ]] && REQ_ENV+="WAYLAND_DISPLAY=$WAYLAND_DISPLAY " + +ENV="$REQ_ENV $ENV_VAR" +COMMAND="$@" +chroot $CHROOT /sbin/env $ENV /bin/su $USER \ No newline at end of file diff --git a/exec.bash b/exec.bash index b7828ad..02a6941 100644 --- a/exec.bash +++ b/exec.bash @@ -10,5 +10,4 @@ REQ_ENV+="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR " ENV="$REQ_ENV $ENV_VAR" COMMAND="$@" -[[ $1 = "enter" ]] && (chroot $CHROOT /sbin/env $ENV /bin/su $USER; exit 0) \ - || chroot $CHROOT /bin/su -c "env $ENV $COMMAND" $USER +chroot $CHROOT /bin/su -c "env $ENV $COMMAND" $USER \ No newline at end of file diff --git a/install.sh b/install.sh index 6111184..f4a0d17 100755 --- a/install.sh +++ b/install.sh @@ -6,7 +6,8 @@ mkdir -p $PREFIX/share/archbox/bin install -v -D -m 755 ./archbox.bash $PREFIX/bin/archbox install -v -D -m 755 ./archbox-desktop.bash $PREFIX/bin/archbox-desktop [[ ! -e /etc/archbox.conf ]] && install -v -D -m 755 ./archbox.conf /etc/archbox.conf -install -v -D -m 755 ./archboxcommand.bash $PREFIX/share/archbox/bin/archbox +install -v -D -m 755 ./exec.bash $PREFIX/share/archbox/bin/exec +install -v -D -m 755 ./enter.bash $PREFIX/share/archbox/bin/enter install -v -D -m 755 ./chroot_setup.bash $PREFIX/share/archbox/chroot_setup.bash install -v -D -m 755 ./init.bash $PREFIX/share/archbox/bin/init install -v -D -m 755 ./uth.bash $PREFIX/share/archbox/bin/uth From 715fc2259a81e9f562db4b39a22ba933b4d9c012 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Sat, 6 Mar 2021 13:09:14 +0700 Subject: [PATCH 5/7] Make variables only accessible to user. --- archbox.bash | 4 ++-- archbox.conf | 2 +- enter.bash | 2 +- exec.bash | 2 +- uth.bash | 4 ++++ 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/archbox.bash b/archbox.bash index 14d8ba3..f93a899 100644 --- a/archbox.bash +++ b/archbox.bash @@ -12,7 +12,7 @@ asroot(){ storeenv() { echo "# This will be sourced when entering Archbox" > /tmp/archbox_env - chmod 777 /tmp/archbox_env >/dev/null 2>&1 + $PRIV $PREFIX/share/archbox/bin/uth chownvar $USER [[ ! -z $WAYLAND_DISPLAY ]] && echo "WAYLAND_DISPLAY=$WAYLAND_DISPLAY" >> /tmp/archbox_env if [[ ! -z $DISPLAY ]]; then hash xhost >/dev/null 2>&1 && xhost +local: > /dev/null @@ -84,7 +84,7 @@ case $1 in msg "Mounting necessary filesystems..." $PREFIX/share/archbox/bin/init start cp $PREFIX/share/archbox/chroot_setup.bash $CHROOT/chroot_setup - echo $USER > /tmp/archbox_user + echo $ARCHBOX_USER > /tmp/archbox_user chroot $CHROOT /bin/bash -c "/chroot_setup" exit $? ;; diff --git a/archbox.conf b/archbox.conf index 3021eb5..f95761d 100644 --- a/archbox.conf +++ b/archbox.conf @@ -1,4 +1,4 @@ -USER="lemniskett" +ARCHBOX_USER="lemniskett" PRIV="sudo" INSTALL_PATH="/var/archlinux" CHROOT="$INSTALL_PATH/root.x86_64" diff --git a/enter.bash b/enter.bash index 22abf6d..76d04c5 100644 --- a/enter.bash +++ b/enter.bash @@ -10,4 +10,4 @@ REQ_ENV+="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR " ENV="$REQ_ENV $ENV_VAR" COMMAND="$@" -chroot $CHROOT /sbin/env $ENV /bin/su $USER \ No newline at end of file +chroot $CHROOT /sbin/env $ENV /bin/su $ARCHBOX_USER \ No newline at end of file diff --git a/exec.bash b/exec.bash index 02a6941..d182fbd 100644 --- a/exec.bash +++ b/exec.bash @@ -10,4 +10,4 @@ REQ_ENV+="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR " ENV="$REQ_ENV $ENV_VAR" COMMAND="$@" -chroot $CHROOT /bin/su -c "env $ENV $COMMAND" $USER \ No newline at end of file +chroot $CHROOT /bin/su -c "env $ENV $COMMAND" $ARCHBOX_USER \ No newline at end of file diff --git a/uth.bash b/uth.bash index 5bf8ab1..c6a5fa5 100644 --- a/uth.bash +++ b/uth.bash @@ -24,4 +24,8 @@ case $1 in mount --rbind /run $CHROOT/run exit $? ;; + chownvar) + chown $2:$2 /tmp/archbox_env + chmod 700 /tmp/archbox_env + ;; esac \ No newline at end of file From 79e443c23708d32e3335a8715aaf0089c35b3182 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Sat, 6 Mar 2021 13:21:08 +0700 Subject: [PATCH 6/7] Update README. --- README.md | 21 ++++++++++++++------- archbox.bash | 4 ---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fa24d9b..83193c8 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Description=Archbox init PartOf=multi-user.target [Service] -ExecStart=/usr/local/bin/archbox --mount +ExecStart=/usr/local/share/archbox/bin/init start Type=oneshot User=root @@ -38,7 +38,10 @@ WantedBy=multi-user.target ``` Thanks to [@SamsiFPV](https://github.com/SamsiFPV) -If you don't use systemd, either create your own init service, or create a @reboot cronjob. +If you don't use systemd, either create your own init service, or create a @reboot cronjob : +``` +@reboot /usr/local/share/archbox/bin/init start +``` ### Removing chroot environment **IMPORTANT**, Make sure you've unmounted everything in chroot environment, it's better to remove the init script and reboot to unmount everything. if you can't reboot for some reason, do : ``` @@ -70,14 +73,18 @@ archbox sudo pacman -Syu You may want to add these rules if you want to use Archbox without password (assuming the install prefix is ```/usr/local``` and you're in group ```wheel```) : #### Sudo ``` -%wheel ALL=(root) NOPASSWD: /usr/local/share/archbox/bin/archbox,/usr/local/share/archbox/bin/copyresolv,/usr/local/share/archbox/bin/remount_run,/usr/local/share/archbox/bin/archboxinit +%wheel ALL=(root) NOPASSWD: +/usr/local/share/archbox/bin/enter, +/usr/local/share/archbox/bin/exec, +/usr/local/share/archbox/bin/uth, +/usr/local/share/archbox/bin/init ``` #### Doas ``` -permit nopass :wheel as root cmd /usr/local/share/archbox/bin/archbox -permit nopass :wheel as root cmd /usr/local/share/archbox/bin/copyresolv -permit nopass :wheel as root cmd /usr/local/share/archbox/bin/remount_run -permit nopass :wheel as root cmd /usr/local/share/archbox/bin/archboxinit +permit nopass :wheel as root cmd /usr/local/share/archbox/bin/enter +permit nopass :wheel as root cmd /usr/local/share/archbox/bin/exec +permit nopass :wheel as root cmd /usr/local/share/archbox/bin/uth +permit nopass :wheel as root cmd /usr/local/share/archbox/bin/init ``` ### Misc #### Systemd services diff --git a/archbox.bash b/archbox.bash index f93a899..1b1ac63 100644 --- a/archbox.bash +++ b/archbox.bash @@ -95,20 +95,16 @@ case $1 in exit $? ;; -m|--mount) - storeenv $PRIV $PREFIX/share/archbox/bin/init start ;; -u|--umount) - storeenv $PRIV $PREFIX/share/archbox/bin/init stop ;; --remount-run) - storeenv $PRIV $PREFIX/share/archbox/bin/uth remountrun exit $? ;; --mount-runtime-only) - storeenv $PRIV $PREFIX/share/archbox/bin/uth runtimeonly exit $? ;; From 97d06627d4882375fd8b5fd0ca5c08b6b90f7e12 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Sat, 6 Mar 2021 13:24:01 +0700 Subject: [PATCH 7/7] Update README. --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 83193c8..e8add76 100644 --- a/README.md +++ b/README.md @@ -73,11 +73,7 @@ archbox sudo pacman -Syu You may want to add these rules if you want to use Archbox without password (assuming the install prefix is ```/usr/local``` and you're in group ```wheel```) : #### Sudo ``` -%wheel ALL=(root) NOPASSWD: -/usr/local/share/archbox/bin/enter, -/usr/local/share/archbox/bin/exec, -/usr/local/share/archbox/bin/uth, -/usr/local/share/archbox/bin/init +%wheel ALL=(root) NOPASSWD: /usr/local/shre/archbox/bin/enter,/usr/local/share/archbox/bin/exec,/usr/local/share/archbox/bin/uth,/usr/local/share/archbox/bin/init ``` #### Doas ```