2021-05-27 11:02:13 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
. /etc/archbox.conf
|
|
|
|
|
|
|
|
# Text colors/formatting
|
|
|
|
red="\033[38;5;1"
|
|
|
|
green="\033[38;5;2"
|
|
|
|
bold="\033[1m"
|
|
|
|
reset="\033[m"
|
|
|
|
|
|
|
|
err(){
|
|
|
|
printf "${red}${bold}%s${reset}\n" "==> $*" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
msg(){
|
|
|
|
printf "${green}${bold}%s${reset}\n" "==> $*" 1>&2
|
|
|
|
}
|
|
|
|
|
|
|
|
rbind(){
|
2021-05-28 08:17:42 +00:00
|
|
|
if [ "$(mount | grep "${CHROOT}"${1} >/dev/null 2>&1)" ]; then
|
2021-05-27 11:02:13 +00:00
|
|
|
msg "${CHROOT}${1} already mounted."
|
|
|
|
else
|
|
|
|
mount -R $1 "${CHROOT}"${1}
|
|
|
|
msg "${CHROOT}${1} mounted!"
|
|
|
|
fi
|
2021-05-28 08:17:42 +00:00
|
|
|
if [ "$2" = "make-rslave" ]; then
|
2021-05-27 11:02:13 +00:00
|
|
|
mount --make-rslave ${CHROOT}${1}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
rbind_diff() {
|
2021-05-28 08:17:42 +00:00
|
|
|
if [ "$(mount | grep "${CHROOT}"${2})" ]; then
|
2021-05-27 11:02:13 +00:00
|
|
|
msg "$CHROOT$2 already mounted."
|
|
|
|
else
|
|
|
|
mount -R $1 "${CHROOT}"${2}
|
|
|
|
msg "${CHROOT}${2} mounted!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
bindproc() {
|
2021-05-28 08:17:42 +00:00
|
|
|
if [ "$(mount | grep "${CHROOT}"/proc)" ]; then
|
2021-05-27 11:02:13 +00:00
|
|
|
msg "${CHROOT}/proc already mounted."
|
|
|
|
else
|
|
|
|
mount -t proc /proc "${CHROOT}"/proc
|
2021-05-28 08:17:42 +00:00
|
|
|
msg "${CHROOT}/proc mounted!"
|
2021-05-27 11:02:13 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
rmbind() {
|
|
|
|
umount_args=-R
|
2021-05-28 08:17:42 +00:00
|
|
|
[ "$LAZY_UMOUNT" = "yes" ] && umount_args=-Rl
|
|
|
|
if [ "$(mount | grep "${CHROOT}"${1})" ]; then
|
2021-05-27 11:02:13 +00:00
|
|
|
umount $umount_args "${CHROOT}"${1}
|
|
|
|
msg "${CHROOT}${1} unmounted!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
start)
|
|
|
|
bindproc
|
|
|
|
rbind /tmp
|
|
|
|
rbind /sys make-rslave
|
|
|
|
rbind /dev make-rslave
|
2021-05-28 08:17:42 +00:00
|
|
|
[ "$MOUNT_RUN" = "yes" ] && rbind /run
|
|
|
|
if [ "$MOUNT_MOD" = "yes" ]; then
|
2021-05-27 11:02:13 +00:00
|
|
|
rbind "$(readlink -f /lib/modules)"
|
|
|
|
rbind /boot
|
|
|
|
fi
|
|
|
|
[ -d /var/lib/dbus ] && rbind /var/lib/dbus
|
|
|
|
for i in $SHARED_FOLDER; do
|
|
|
|
if [ $i = *:* ]; then
|
|
|
|
source=$(printf "%s" "$i" | sed 's/:.*//')
|
|
|
|
target=$(printf "%s" "$i" | sed 's/.*://')
|
|
|
|
mkdir -p "${CHROOT}"${target}
|
|
|
|
rbind_diff $source $target;
|
|
|
|
else
|
|
|
|
rbind $i;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
msg "Starting services"
|
|
|
|
for j in $SERVICES; do
|
|
|
|
if [ $j = *:* ]; then
|
|
|
|
delay=$(printf "%s" "$j" | sed 's/.*://')
|
|
|
|
service=$(printf "%s" "$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
|
|
|
|
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
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
rmbind /proc
|
|
|
|
rmbind /tmp
|
|
|
|
rmbind /sys
|
|
|
|
rmbind /dev
|
|
|
|
[ $MOUNT_RUN = "yes" ] && rmbind /run
|
|
|
|
if [ $MOUNT_MOD = "yes" ]; then
|
|
|
|
rmbind $(readlink -f /lib/modules)
|
|
|
|
rmbind /boot
|
|
|
|
fi
|
|
|
|
rmbind /var/lib/dbus
|
|
|
|
for i in $SHARED_FOLDER; do
|
|
|
|
if [ $i = *:* ]; then
|
|
|
|
target=$(printf "%s" "$i" | sed 's/.*://')
|
|
|
|
rmbind $target;
|
|
|
|
else
|
|
|
|
rmbind $i;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|