From 11eac495325d3419785b2229c47a98fb74cd3cbc Mon Sep 17 00:00:00 2001 From: lemniskett Date: Thu, 29 Oct 2020 13:07:50 +0700 Subject: [PATCH] Provide a way to bring custom enviroment variables to chroot. --- archbox.conf | 6 +++++- archboxcommand.bash | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/archbox.conf b/archbox.conf index cb3ee23..5e77f64 100644 --- a/archbox.conf +++ b/archbox.conf @@ -1,4 +1,8 @@ USER=lemniskett PRIV="sudo" INSTALL_PATH="/var/archlinux" -CHROOT="$INSTALL_PATH/root.x86_64" \ No newline at end of file +CHROOT="$INSTALL_PATH/root.x86_64" + +# Put your desired enviroment variable here, for example +# ENV_VAR="HOME=/var/home/lemniskett" +ENV_VAR="" diff --git a/archboxcommand.bash b/archboxcommand.bash index 9652bea..50a0cf9 100755 --- a/archboxcommand.bash +++ b/archboxcommand.bash @@ -2,8 +2,10 @@ source /etc/archbox.conf -DBUS_ADDRESS_ENV="$(cat /tmp/archbox_dbus_session_address)" -XDG_RUNTIME_ENV="$(cat /tmp/archbox_xdg_runtime_dir)" +REQ_ENV="DBUS_SESSION_BUS_ADDRESS=$(cat /tmp/archbox_dbus_session_address) XDG_RUNTIME_DIR=$(cat /tmp/archbox_xdg_runtime_dir)" + +ENV="$REQ_ENV $ENV_VAR" + COMMAND=$(echo $@ | tr ' ' '\ ') -[[ $1 = "enter" ]] && chroot $CHROOT /sbin/env DBUS_SESSION_BUS_ADDRESS=$DBUS_ADDRESS_ENV XDG_RUNTIME_DIR=$XDG_RUNTIME_ENV /bin/su $USER \ - || chroot $CHROOT /bin/su -c "env DBUS_SESSION_BUS_ADDRESS=$DBUS_ADDRESS XDG_RUNTIME_DIR=$XDG_RUNTIME_ENV $COMMAND" $USER +[[ $1 = "enter" ]] && chroot $CHROOT /sbin/env $ENV /bin/su $USER \ + || chroot $CHROOT /bin/su -c "env $ENV $COMMAND" $USER