#!/bin/sh

# alaram_clock: run a big alarm at a pre-determained time
#
# Installation: copy that file to a place in your PATH
#
# Usage: alarm_clock params_for_at
#  e.g: 
#    alaram_clock 7:00
#    alaram_clock 7:00 am
#    alaram_clock now + 30 minutes
#    
# at(1) has a pretty comprehensive syntax for defining the time to run 
# the task.
#
#  This script is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This package is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should find a copy of the GNU General Public License at 
#  http://tzafrir.org.il/GPL . if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#  02111-1307, USA.

DISPLAY=${DISPLAY:-:0}
export DISPLAY

# adjust this to your screen:
XTERM_GEOM=160x50+30+20 

case "$1" in
loop)
  # Used internally: print a nagging message in a loop
  # aumix is used to adjust volume. I currently use snd-oss-mixer .
  aumix -v 90
  while true
  do 
    echo -e "\a`date +%H:%M:%S`: RING RING RING"
    sleep 1
  done 
  ;;
ring)
  # Used internally: the alarm terminal
  xterm +vb -fg yellow -bg red -class alarm -geom $XTERM_GEOM -title Alarm \
    -e $0 loop
  ;;
*)
  set -e
  prog=$0
  if [ "$DISPLAY" = '' ]; then
    echo >&2 "$0: DISPLAY not set. Aborting!"
  fi
  echo env DISPLAY=$DISPLAY $prog ring| at "$@" 
  echo "Muting audio"
  aumix -v 0
  ;;
esac
