#!/bin/sh
### BEGIN INIT INFO
# Provides:          dezign start
# Required-Start:    $local_fs $network $named $time $syslog
# Required-Stop:     $local_fs $network $named $time $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Description:       dezign start script
### END INIT INFO

RUNAS=root

start() {
  g-ether-load.sh
  g-ether-start-service.sh
  
  if [ -f /home/root/init/first_boot ]; then
    if [ ! -f /tmp/init_running ]; then
      echo "first boot"
      chmod 755 /home/root/init/init_sys_first_time.sh
      rm -f /home/root/init/first_boot
      /home/root/init/init_sys_first_time.sh
    fi
  fi
  
  /home/root/de/dezign/dezign.wdt &
  
  if [ -f /mnt/dezign/work/bin/plugins.sh ]; then
    echo "start plugin worker" >&2
    sh /mnt/dezign/work/bin/plugins.sh &
  fi
}

stop() {
    echo "stop"
}

uninstall() {
  echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
  local SURE
  read SURE
  if [ "$SURE" = "yes" ]; then
    stop
    rm -f "$PIDFILE"
    echo "Notice: log file was not removed: $LOGFILE" >&2
    update-rc.d -f $NAME remove
    rm -fv "$0"
  else
    echo "Abort!"
  fi
}

status() {
    echo "status"
}


case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status
    ;;
  uninstall)
    uninstall
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|uninstall}"
esac