archbox/archboxinit.bash

73 lines
2.1 KiB
Bash
Raw Normal View History

2020-12-28 05:22:53 +00:00
#!/usr/bin/env bash
2020-10-27 06:12:14 +00:00
source /etc/archbox.conf
2021-01-04 04:38:20 +00:00
msg(){
echo "$(tput bold)$(tput setaf 2)==> $@ $(tput sgr0)"
}
rbind() {
[[ $(mount | grep $CHROOT$1) ]] && msg "$CHROOT$1 already mounted." \
|| (mount -R $1 $CHROOT$1 && msg "$CHROOT$1 mounted!")
[[ $2 = "make-rslave" ]] && mount --make-rslave $CHROOT$1
}
bindproc() {
2021-01-11 07:03:14 +00:00
[[ $(mount | grep $CHROOT/proc) ]] && msg "$CHROOT/proc already mounted." \
2021-01-04 04:38:20 +00:00
|| (mount -t proc /proc $CHROOT/proc && msg "$CHROOT/proc mounted!")
}
rmbind() {
umount_args=-R
[[ $LAZY_UMOUNT = "yes" ]] && umount_args=-Rl
[[ $(mount | grep $CHROOT$1) ]] && umount $umount_args $CHROOT$1 \
&& msg "$CHROOT$1 unmounted!"
}
2020-11-11 13:02:05 +00:00
case $1 in
2020-12-31 16:16:31 +00:00
start)
2021-01-04 04:38:20 +00:00
bindproc
rbind /tmp
rbind /sys make-rslave
rbind /dev make-rslave
[[ $MOUNT_RUN = "yes" ]] && rbind /run
[[ $MOUNT_MOD = "yes" ]] && rbind $(readlink -f /lib/modules) && rbind /boot
2021-01-04 04:38:20 +00:00
[[ -d /var/lib/dbus ]] && rbind /var/lib/dbus
2021-01-12 15:45:10 +00:00
for i in ${SHARED_FOLDER[@]}; do
mkdir -p $CHROOT/$i
rbind $i
done
2021-01-12 17:09:27 +00:00
msg "Starting services"
2021-01-12 15:45:10 +00:00
for j in ${SERVICES[@]}; do
2021-01-12 17:09:27 +00:00
if [[ $j = *:* ]]; then
delay=$(echo $j | sed 's/.*://')
service=$(echo $j | sed 's/:.*//')
chroot $CHROOT /bin/su -c "/usr/local/bin/archboxctl exec $service" > /dev/null 2>&1 &
sleep $delay
else
chroot $CHROOT /bin/su -c "/usr/local/bin/archboxctl exec $j" > /dev/null 2>&1 &
fi
2021-01-11 07:00:43 +00:00
done
if [[ -e /etc/archbox.rc ]]; then
cp /etc/archbox.rc /tmp/archbox.rc
chmod +x /tmp/archbox.rc
chroot $CHROOT /bin/su -c '/tmp/archbox.rc' > /tmp/archbox.rc.log 2>&1
rm /tmp/archbox.rc
fi
2020-12-31 16:16:31 +00:00
exit 0
;;
stop)
2021-01-04 04:38:20 +00:00
rmbind /proc
rmbind /tmp
rmbind /sys
rmbind /dev
[[ $MOUNT_RUN = "yes" ]] && rmbind /run
[[ $MOUNT_MOD = "yes" ]] && rmbind $(readlink -f /lib/modules) && rmbind /boot
2021-01-04 04:38:20 +00:00
rmbind /var/lib/dbus
2021-01-12 15:45:10 +00:00
for i in ${SHARED_FOLDER[@]}; do
rmbind $i
done
2020-12-31 16:16:31 +00:00
exit 0
;;
2020-11-11 13:02:05 +00:00
esac