archbox/archboxinit.bash

59 lines
1.6 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 /lib/modules && rbind /boot
[[ -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
for j in ${SERVICES[@]}; do
chroot $CHROOT /bin/su -c "/usr/local/bin/archboxctl exec $j" > /dev/null 2>&1
2021-01-11 07:00:43 +00:00
done
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 /lib/modules && rmbind /boot
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