#!/bin/sh
upsdb=/local/ups/db
state=$1
case $state in
  'start')
     start=$upsdb/.upsfiles/startup/ups_startup
     (while [ ! -f $start ]; do sleep 5; done; $start) > /tmp/ups.out 2>&1 &
     ;;
  'stop')
     $upsdb/.upsfiles/shutdown/ups_shutdown
     ;;
  'config')
     case $0 in
     /*) initd=$0;;
     *)  initd=`pwd`/$0;;
     esac
     sfile=`echo $initd | sed -e 's;init.d/;rc3.d/S99;'`
     kfile=`echo $initd | sed -e 's;init.d/;rc0.d/K01;'`
     ln -s $initd $sfile
     ln -s $initd $kfile
     sfile=`echo $initd | sed -e 's;init.d/;rc5.d/S99;'`
     kfile=`echo $initd | sed -e 's;init.d/;rc6.d/K01;'`
     ln -s $initd $sfile
     ln -s $initd $kfile
     ;;
  *)
     echo "usage: $0 {start|stop|config}"
     ;;
esac
