#! /bin/sh
# /etc/init.d/0install
#
# chkconfig: 345 90 10
# description: Downloads resources under /uri/0install
#
# Written by Thomas Leonard, tal197 at users.sourceforge.net.
#
# chkconfig: 345 17 70

test -x "/usr/sbin/zero-install" || exit 0

# Source function library.
. /etc/init.d/functions

case "$1" in
  start)
    [ -f /var/lock/subsys/zero-install ] && exit 0
    if [ ! -L /uri/0install/.lazyfs-cache ]; then
	action "Mounting zero-install filesystem" mount -t lazyfs0d1d26 -o/var/cache/zero-inst lazyfs /uri/0install
    fi
    echo -n "Starting zero-install daemon"
    daemon --user "zeroinst" "/usr/sbin/zero-install" && echo_success || echo_failure
    echo
    touch /var/lock/subsys/zero-install
    ;;
  stop)
    PID_FILE=/uri/0install/.lazyfs-cache/.0inst-pid
    if [ -f $PID_FILE ]; then
      action "Stopping zero-install daemon" kill -INT "`cat $PID_FILE`"
    fi
    if grep -q /uri/0install /proc/mounts; then
	action "UnMounting zero-install filesystem" umount /uri/0install
    fi
    rm -f /var/lock/subsys/zero-install
    ;;
  status) status zero-install;;
  restart|reload)
      $0 stop
      $0 start
      ;;
  *)
    ACTIONS="{start|stop|restart|reload|status}"
    echo "Usage: $0 $ACTIONS" >&2
    exit 1
    ;;
esac
