diff --git a/README.md b/README.md index fa24d9b..e8add76 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,14 @@ 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/shre/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 20bc920..1b1ac63 100644 --- a/archbox.bash +++ b/archbox.bash @@ -6,17 +6,13 @@ 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!" } 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 @@ -86,34 +82,30 @@ 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 + echo $ARCHBOX_USER > /tmp/archbox_user chroot $CHROOT /bin/bash -c "/chroot_setup" exit $? ;; -e|--enter) storeenv - copyresolv - $PRIV $PREFIX/share/archbox/bin/archbox enter + $PRIV $PREFIX/share/archbox/bin/uth copyresolv + $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 - $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) @@ -129,8 +121,8 @@ case $1 in ;; *) storeenv - copyresolv - $PRIV $PREFIX/share/archbox/bin/archbox $@ + $PRIV $PREFIX/share/archbox/bin/uth copyresolv + $PRIV $PREFIX/share/archbox/bin/exec $@ exit $? ;; esac 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/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/enter.bash similarity index 71% rename from archboxcommand.bash rename to enter.bash index b7828ad..76d04c5 100644 --- a/archboxcommand.bash +++ b/enter.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 /sbin/env $ENV /bin/su $ARCHBOX_USER \ No newline at end of file diff --git a/exec.bash b/exec.bash new file mode 100644 index 0000000..d182fbd --- /dev/null +++ b/exec.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 /bin/su -c "env $ENV $COMMAND" $ARCHBOX_USER \ No newline at end of file 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/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 813bdf8..f4a0d17 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 ./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 ./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 diff --git a/remount_run.bash b/uth.bash similarity index 61% rename from remount_run.bash rename to uth.bash index 0bd8d1c..c6a5fa5 100644 --- a/remount_run.bash +++ b/uth.bash @@ -3,22 +3,29 @@ source /etc/archbox.conf source /tmp/archbox_env -case $1 in +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 $? - ;; - *) - umount -l $CHROOT/run + ;; + remountrun) + umount -l $CHROOT/run 2>/dev/null mount --rbind /run $CHROOT/run exit $? - ;; -esac + ;; + chownvar) + chown $2:$2 /tmp/archbox_env + chmod 700 /tmp/archbox_env + ;; +esac \ No newline at end of file