#! /bin/sh
# /etc/init.d/vboxgetty: start and stop vboxgetty
#
# Written by Christian Schwarz <schwarz@debian.org>.
#

# Please specify a free ISDN tty here:
TTY=ttyI5
# And fill in your local calling number here:
MSN=123456789
# User name that wants to use vboxgetty
USER=wily
# Set run_vbox to 1 to start vboxgetty at boot up or 0 to disable it.
run_vbox=0

# --end-of-configuration-part--

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/vboxgetty
NAME=vboxgetty

test -f $DAEMON || exit 0

case "$1" in
  start)
    if [ $run_vbox = 1 ]
    then
      # Rotate log files, if necessary.
      if [ "`find /var/log/isdn -name vbox.$TTY -ctime 1`"x = ""x ]; then
        # vbox' log file is older than 1 day, so rotate all logs.
        cd /var/log/isdn
        savelog -g adm -m 640 -u root -c 4 vbox.$TTY >/dev/null
      fi
      echo -n "Starting voice vbox: vboxgetty"
      /usr/sbin/vboxgetty -d/dev/$TTY -i"ATZ&E$MSN" -u$USER &
      echo "."
    fi
    ;;
  stop)
    if [ $run_vbox = 1 ]
    then
      echo -n "Stopping voice vbox: vboxgetty"
      start-stop-daemon --stop --verbose --pidfile /var/run/vbox-pid.$TTY --exec $DAEMON
      echo "."
    fi
    ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start|stop}"
    exit 1
    ;;
esac

exit 0
