Last active
September 29, 2020 00:32
-
-
Save pleasemarkdarkly/82d8730e69a501694d7c3a15233b29c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# https://gist.github.com/82d8730e69a501694d7c3a15233b29c9 / https://gist.githubusercontent.com/pleasemarkdarkly/82d8730e69a501694d7c3a15233b29c9/raw/5a39090a55c5b552a787e1d9140960432514c3b5/chroot-start-stop-status | |
edit_chroot_start_stop_status () { | |
echo gist-paste -u 82d8730e69a501694d7c3a15233b29c9 | |
nano ./chroot-start-stop-status | |
gist-paste chroot-start-stop-status -u 82d8730e69a501694d7c3a15233b29c9 | |
echo $0_ | |
} | |
# Package | |
HOSTNAME="Blackbox8000" | |
PACKAGE="debian-chroot" | |
DNAME="Debian Chroot" | |
# Others | |
INSTALL_DIR="/usr/local/${PACKAGE}" | |
PATH="${INSTALL_DIR}/bin:${PATH}" | |
CHROOTTARGET=`realpath ${INSTALL_DIR}/var/chroottarget` | |
start_daemon () | |
{ | |
echo "chroot start_daemon() start-stop-status" | |
# Mount if install is finished | |
if [ -f ${INSTALL_DIR}/var/installed ]; then | |
# Make sure we don't mount twice | |
echo "mounting relevant system directories" | |
grep -q "${CHROOTTARGET}/proc " /proc/mounts || mount -vt proc proc ${CHROOTTARGET}/proc | |
grep -q "${CHROOTTARGET}/sys " /proc/mounts || mount -vt sysfs sys ${CHROOTTARGET}/sys | |
grep -q "${CHROOTTARGET}/dev " /proc/mounts || mount -vo bind /dev ${CHROOTTARGET}/dev | |
grep -q "${CHROOTTARGET}/dev/pts " /proc/mounts || mount -vo bind /dev/pts ${CHROOTTARGET}/dev/pts | |
grep -q "${CHROOTTARGET}/run " /proc/mounts || mount -vo bind /run ${CHROOTTARGET}/run | |
grep -q "${CHROOTTARGET}/home " /proc/mounts || mount -vo bind /volume1/systems/synology_918+/mounts/homes ${CHROOTTARGET}/home | |
grep -q "${CHROOTTARGET}/root " /proc/mounts || mount -vo bind /volume1/systems/synology_918+/mounts/debian-chroot.root ${CHROOTTARGET}/root | |
[ ! -d ${CHROOTTARGET}/volume1 ] && mkdir -p ${CHROOTTARGET}/volume1 | |
grep -q "${CHROOTTARGET}/volume1 " /volume1 || mount -o bind /volume1 ${CHROOTTARGET}/volume1 | |
[ ! -d ${CHROOTTARGET}/volumeUSB1 ] && mkdir -p ${CHROOTTARGET}/volumeUSB1 | |
grep -q "${CHROOTTARGET}/volumeUSB1 " /volumeUSB1 || mount -o bind /volumeUSB1 ${CHROOTTARGET}/volumeUSB1 | |
[ ! -d ${CHROOTTARGET}/volumeUSB2 ] && mkdir -p ${CHROOTTARGET}/volumeUSB2 | |
grep -q "${CHROOTTARGET}/volumeUSB2 " /volumeUSB2 || mount -o bind /volumeUSB2 ${CHROOTTARGET}/volumeUSB2 | |
# Start all services | |
${INSTALL_DIR}/app/start.py | |
fi | |
} | |
stop_daemon () | |
{ | |
# Stop running services | |
${INSTALL_DIR}/app/stop.py | |
# Unmount | |
umount ${CHROOTTARGET}/dev/pts | |
umount ${CHROOTTARGET}/dev | |
umount ${CHROOTTARGET}/sys | |
umount ${CHROOTTARGET}/proc | |
umount ${CHROOTTARGET}/run | |
umount ${CHROOTTARGET}/home | |
umount ${CHROOTTARGET}/root | |
umount ${CHROOTTARGET}/volume1 | |
`grep -q "${CHROOTTARGET}/volumeUSB1 " /proc/mounts` && umount ${CHROOTTARGET}/volumeUSB1 | |
`grep -q "${CHROOTTARGET}/volumeUSB2 " /proc/mounts` && umount ${CHROOTTARGET}/volumeUSB2 | |
} | |
daemon_status () | |
{ | |
`grep -q "${CHROOTTARGET}/proc " /proc/mounts` && \ | |
`grep -q "${CHROOTTARGET}/sys " /proc/mounts` && \ | |
`grep -q "${CHROOTTARGET}/dev " /proc/mounts` && \ | |
`grep -q "${CHROOTTARGET}/dev/pts " /proc/mounts` && \ | |
`grep -q "${CHROOTTARGET}/run " /proc/mounts` | |
# `grep -q "${CHROOTTARGET}/home " /proc/mounts` && \ | |
# `grep -q "${CHROOTTARGET}/root " /proc/mounts` && \ | |
# `grep -q "${CHROOTTARGET}/volume1 " /proc/mounts` && \ | |
# `grep -q "${CHROOTTARGET}/volumeUSB1 " /proc/mounts` && \ | |
# `grep -q "${CHROOTTARGET}/volumeUSB2 " /proc/mounts` | |
} | |
case $1 in | |
start) | |
if daemon_status; then | |
echo ${DNAME} is already running | |
exit 0 | |
else | |
echo Starting ${DNAME} ... | |
start_daemon | |
exit $? | |
fi | |
;; | |
stop) | |
if daemon_status; then | |
echo Stopping ${DNAME} ... | |
stop_daemon | |
exit 0 | |
else | |
echo ${DNAME} is not running | |
exit 0 | |
fi | |
;; | |
status) | |
if daemon_status; then | |
echo ${DNAME} is running | |
exit 0 | |
else | |
echo ${DNAME} is not running | |
exit 1 | |
fi | |
;; | |
chroot) | |
chroot ${CHROOTTARGET} /usr/bin/zsh | |
;; | |
*) | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment