#! /bin/sh

### BEGIN INIT INFO
# Provides:          debathena-cluster-cups-config
# Required-Start:    cups $remote_fs
# Required-Stop:     cups $remote_fs
# Should-Start:      $local_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Cluster CUPS configuration
# Description:       Ensure cluster printers exist
### END INIT INFO

. /lib/lsb/init-functions

case "$1" in
  start)
    if [ -f /var/lib/debathena-cluster-cups-config-reconfigure_required ]; then
      log_action_msg "Adding cluster printers"
      nologin=0
      if [ ! -f /var/run/athena-nologin ]; then
	touch /var/run/athena-nologin
	nologin=1
      fi
      if /usr/share/debathena-cluster-cups-config/configure-athena-printers add; then
	rm -f /var/lib/debathena-cluster-cups-config-reconfigure_required
	log_end_msg 0
      else
	log_end_msg 1
      fi
      [ $nologin -eq 1 ] && rm /var/run/athena-nologin
    fi
    ;;
  stop|restart|reload|force-reload|status)
    exit 0
    ;;
  *)
    log_action_msg "Usage: /etc/init.d/debathena-cluster-cups-config {start}"
    exit 1
    ;;
esac
exit 0
