Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- PATH=/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin
- # Folder with Chrooted Debian
- CHROOT_DIR=/tmp/mnt/sda1/optware-ng.arm/debian
- # Some folder/folders outside of sandbox,
- # will be mounted to /mnt, /mnt2... folders inside Debian
- # Uncommented next 1-3 lines starting with "EXT_DIR" if you need
- # to mount a folder or more inside chrooted debian
- # EXT_DIR=/tmp/mnt/sda1/Media/
- # EXT_DIR2=/tmp/mnt/sda1/Media2/
- # EXT_DIR3=/jffs/
- CHROOT_SERVICES_LIST=/opt/etc/chroot-services.list
- if [ ! -e "$CHROOT_SERVICES_LIST" ]; then
- echo "Please, define Debian services to start in
- $CHROOT_SERVICES_LIST first!"
- echo "One service per line. Hint: this is a script names from
- Debian's /etc/init.d/"
- exit 1
- fi
- MountedDirCount="$(mount | grep $CHROOT_DIR | wc -l)"
- start() {
- if [ $MountedDirCount -gt 0 ]; then
- echo "Chroot'ed services seems to be already started,
- exiting..."
- exit 1
- fi
- echo "Starting chroot'ed Debian services..."
- for dir in dev proc sys; do
- mount -o bind /$dir $CHROOT_DIR/$dir
- done
- [ -z "$EXT_DIR" ] || mount -o bind $EXT_DIR $CHROOT_DIR/mnt
- [ -z "$EXT_DIR2" ] || mkdir -p $CHROOT_DIR/mnt2 && mount -o bind $EXT_DIR2 $CHROOT_DIR/mnt2
- [ -z "$EXT_DIR3" ] || mkdir -p $CHROOT_DIR/jffs && mount -o bind $EXT_DIR3 $CHROOT_DIR/jffs
- for item in $(cat $CHROOT_SERVICES_LIST); do
- chroot $CHROOT_DIR /etc/init.d/$item start
- done
- }
- stop() {
- if [ $MountedDirCount -eq 0 ]; then
- echo "Chroot'ed services seems to be already stopped,
- exiting..."
- exit 1
- fi
- echo "Stopping chroot'ed Debian services..."
- for item in $(cat $CHROOT_SERVICES_LIST); do
- chroot $CHROOT_DIR /etc/init.d/$item stop
- sleep 2
- done
- mount | grep $CHROOT_DIR | awk '{print $3}' | xargs umount -l
- }
- restart() {
- if [ $MountedDirCount -eq 0 ]; then
- echo "Chroot'ed services seems to be already stopped"
- start
- else
- # echo "Stopping chroot'ed Debian services..."
- for item in $(cat $CHROOT_SERVICES_LIST); do
- chroot $CHROOT_DIR /etc/init.d/$item stop
- sleep 2
- done
- mount | grep $CHROOT_DIR | awk '{print $3}' | xargs umount -l
- echo "Restarting chroot'ed Debian services..."
- for dir in dev proc sys; do
- mount -o bind /$dir $CHROOT_DIR/$dir
- done
- [ -z "$EXT_DIR" ] || mount -o bind $EXT_DIR $CHROOT_DIR/mnt
- [ -z "$EXT_DIR2" ] || mkdir -p $CHROOT_DIR/mnt2 && mount -o bind $EXT_DIR2 $CHROOT_DIR/mnt2
- [ -z "$EXT_DIR3" ] || mkdir -p $CHROOT_DIR/jffs && mount -o bind $EXT_DIR3 $CHROOT_DIR/jffs
- for item in $(cat $CHROOT_SERVICES_LIST); do
- chroot $CHROOT_DIR /etc/init.d/$item start
- done
- fi
- }
- enter() {
- [ -z "$EXT_DIR" ] || mount -o bind $EXT_DIR $CHROOT_DIR/mnt
- mount -o bind /dev/ /opt/debian/dev/
- mount -o bind /dev/pts /opt/debian/dev/pts
- mount -o bind /proc/ /opt/debian/proc/
- mount -o bind /sys/ /opt/debian/sys/
- chroot /opt/debian /bin/bash
- }
- status() {
- if [ $MountedDirCount -gt 0 ]; then
- echo "Chroot'ed services running..."
- else
- echo "Chroot'ed services not running!"
- fi
- }
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- restart
- ;;
- enter)
- enter
- ;;
- status) status
- ;;
- *)
- echo "Usage: (start|stop|restart|enter|status)"
- exit 1
- ;;
- esac
- echo Done.
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement