#!/bin/sh

set -e

. "$SETUP_DATA_DIR/common-data"
. "$SETUP_DATA_DIR/common-functions"

if [ -f "$CHROOT_SCRIPT_CONFIG" ]; then
    . "$CHROOT_SCRIPT_CONFIG"
elif [ "$STATUS" = "ok" ]; then
    fatal "script-config file '$CHROOT_SCRIPT_CONFIG' does not exist"
fi

if [ $STAGE = "setup-start" ]; then
    info "Adding messagebus to access list for session ${SESSION_ID}"
    sed -i "/^root-users/s/$/,messagebus/" /var/lib/schroot/session/"${SESSION_ID}"
fi

if [ $STAGE = "setup-stop" ]; then
    info "Inhibiting dbus-daemon-launch-helper during chroot shutdown"
    touch /var/run/debathena-inhibit-dbus-helper
fi

