#!/bin/sh
umask 022
# See how we are called
case "$1" in
  start|load)
    if /bin/grep -q -w cpm /etc/group; then
      /bin/chgrp -R cpm /var/lib/cpm/{raw,fullrate,mediumterm,longterm,transient,manual}
    fi
    /bin/chmod -R a-st+rX,gu+w,o-w /var/lib/cpm/{raw,fullrate,mediumterm,longterm,transient,manual}
    /bin/rm -f /var/lib/cpm/*/*.cdt.temp
    /usr/bin/CSserver > /var/log/cpm/CSserver.log 2> /var/log/cpm/CSserver.err &
    ;;
  stop|unload)
    killall -9 CSserver CSserverd CSserver.bin CSserverd.bin
    ;;
  restart|reload)
    killall -9 CSserver CSserverd CSserver.bin CSserverd.bin
    /bin/rm -f /var/lib/cpm/*/*.cdt.temp
    /usr/bin/CSserver > /var/log/cpm/CSserver.log 2> /var/log/cpm/CSserver.err &
    ;;
  debug)
    killall -9 CSserver CSserverd CSserver.bin CSserverd.bin
    /bin/rm -f /var/lib/cpm/*/*.cdt.temp
    /usr/bin/CSserverd > /var/log/cpm/CSserver.log 2> /var/log/cpm/CSserver.err &
    ;;
  *)
    echo "Usage: $0 {start|load|stop|unload|restart|reload|debug}"
    exit 1
esac
exit 0
