#!/bin/bash
### BEGIN INIT INFO
# Provides: sandbox
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Set up namespace for sandbox
# description: sandbox, xguest and other apps that want to use pam_namespace \
#              require this script be run at boot.  This service script does \
#              not actually run any service but sets up: \
#              / to be shared by any app that starts a separate namespace
#              If you do not use sandbox, xguest or pam_namespace you can turn \
#              this service off.\
#
### END INIT INFO
# sandbox:        Set up / mountpoint to be shared, /var/tmp, /tmp, /home/sandbox unshared

# Get lsb functions
. /lib/lsb/init-functions
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

if [ -f /etc/default/sandbox ]; then
  . /etc/default/sandbox
fi

if [ "$RUN" = "NO" ]; then
  echo "Sandbox disabled, edit /etc/default/sandbox to enable it"
  exit 0
fi

LOCKFILE=/var/lock/sandbox

base=${0##*/}

start() {
	echo -n "Starting sandbox"

	[ -f "$LOCKFILE" ] && return 0

	touch $LOCKFILE
	mount --make-rshared / || return $? 
	return 0
}

stop() {
	echo -n "Stopping sandbox"

	[ -f "$LOCKFILE" ] || return 1
}

status() {
	if [ -f "$LOCKFILE" ]; then 
	    echo "$base is running"
	else
	    echo "$base is stopped"
	fi
	exit 0
}

case "$1" in
    restart)
	start
	;;

    force-reload)
	start
	;;

    start)
	start
	echo
	;;

    stop)
	stop
	echo
	;;

    status)
	status
	;;

    *)
	echo $"Usage: $0 {start|stop|status|restart}"
	exit 3
	;;
esac
