#!/bin/sh
# /etc/init.d/dphys-admin - boot time trigger automatic updates
# authors dsbg and franklin, last modification 2006.11.24
# copyright ETH Zuerich Physics Departement
#   use under either modified/non-advertising BSD or GPL license

# this init.d script is intended to be run from rc2.d
#   must run after S20oidentd, else no identd answers, package server blocks us
#     preferably after basic system functions are working, such as S23ntp
#   and sensibly before lots more stuff, which wastes time if this reboots
#   so we run it as rc2.d/S24dphys-admin

PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH

# what we are
NAME=dphys-admin

case "$1" in

  start)
    echo "Starting ${NAME} automatic updates ..."

    # installing/updating dphys-admin Package on an Debian system
    #   will re-run this init.d script from Debians postinst script
    #     this will produce recursive apt-get and dpkg calls
    #   this wail fail to lock /var/lib/dpkg/lock, and give an error mail
    #     this confuses our site monitoring, so prevent this
    if fuser /var/lib/dpkg/lock > /dev/null 2> /dev/null ; then
      echo INFO: dphys-admin init.d preventing recursive call while update
      exit 0
    fi

    # in case system was switched off for a while, run an upgrade
    # this will produce output, so no -n in above echo
    dphys-admin init

    echo "done."
    ;;

  stop)
    echo "'Stopping' ${NAME} automatic updates (does nothing)."
    ;;

  restart|reload|force-reload)
    echo "No daemon to (force-)re[start|load] in ${NAME}"
    ;;

  *)
    echo "Usage: $0 {start}"

    exit 1
    ;;

esac

exit 0

