Bring DBUS_SESSION_BUS_ADDRESS variable to chroot

This commit is contained in:
lemniskett 2020-10-29 10:56:55 +07:00
parent 28a4025ee5
commit 0d061f1e4f
2 changed files with 13 additions and 6 deletions

View File

@ -14,9 +14,13 @@ asroot(){
[[ $EUID -ne 0 ]] && err "Run this as root!" [[ $EUID -ne 0 ]] && err "Run this as root!"
} }
storedbus(){
echo $DBUS_SESSION_ADDRESS > /tmp/archbox_dbus_session_address
}
help_text(){ help_text(){
cat << EOF cat << EOF
USAGE $0 <arguments> USAGE: $0 <arguments>
OPTIONS: OPTIONS:
--create LINK Creates a chroot enviroment. --create LINK Creates a chroot enviroment.
@ -74,8 +78,9 @@ case $1 in
chroot $CHROOT /bin/bash -c "sh /chroot_setup" chroot $CHROOT /bin/bash -c "sh /chroot_setup"
;; ;;
--enter) --enter)
copyresolv storedbus
$PRIV /usr/local/share/archbox/bin/archbox --enter copyresolv
$PRIV /usr/local/share/archbox/bin/archbox enter
;; ;;
--help) --help)
help_text help_text
@ -87,8 +92,9 @@ case $1 in
err "Unknown option: $1" err "Unknown option: $1"
;; ;;
*) *)
storedbus
copyresolv copyresolv
COMMAND=$(echo $@ | tr ' ' '\ ') COMMAND=$(echo $@ | tr ' ' '\ ')
$PRIV /usr/local/share/archbox/bin/archbox $COMMAND $PRIV /usr/local/share/archbox/bin/archbox $COMMAND
;; ;;
esac esac

View File

@ -2,6 +2,7 @@
source /etc/archbox.conf source /etc/archbox.conf
DBUS_ADDRESS="$(cat /tmp/archbox_dbus_session_address)"
COMMAND=$(echo $@ | tr ' ' '\ ') COMMAND=$(echo $@ | tr ' ' '\ ')
[[ $1 = "--enter" ]] && chroot $CHROOT /bin/su $USER \ [[ $1 = "enter" ]] && chroot $CHROOT /sbin/env DBUS_SESSION_BUS_ADDRESS=$DBUS_ADDRESS /bin/su $USER \
|| chroot $CHROOT /bin/su -c "$COMMAND" $USER || chroot $CHROOT /bin/su -c "env $DBUS_ADDRESS $COMMAND" $USER