#! /bin/sh

# mixer-reset.sh - Version 2.0
# Uses an audio mixer to initialize the volume of your audio
# peripherals, and the main volume is set regarding the current time
# Put this in your crontab !
#
# Copyright (c) 2000 Raphaël HALIMI <raph@captainblood.org>
#
# This program 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 program 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 have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA

VERSION="2.0"

FORMAT=`date | grep "  "`

if [ -z "$FORMAT" ] ; then
   HEURE=`date | cut -d " " -f 4 | cut -d ":" -f 1`
else
   HEURE=`date | cut -d " " -f 5 | cut -d ":" -f 1`
fi

# Some variables to make configuration easier - it is HIGHLY recommended to
# change these to suit your system... Or simply install aumix :-)

MIXER=aumix
MAIN_VOLUME_OPTION='-v'
MIXER_OPTIONS='-b90 -t70 -s90 -w90 -p90 -l90 -m60 -c90 -x90 -i90 -o0'


case "$1" in
     reset)
           $MIXER $MIXER_OPTIONS
	   ;;
     update)
           case "$HEURE" in
	        07)
		  MAIN_VOLUME=+10
		  ;;
		09)
		  MAIN_VOLUME=+15
		  ;;
		20)
		  MAIN_VOLUME=-5
		  ;;
		22)
		  MAIN_VOLUME=-10
		  ;;
		00)
		  MAIN_VOLUME=-10
		  ;;
		*)
		  MAIN_VOLUME=+0
		  ;;
	   esac
	   $MIXER $MAIN_VOLUME_OPTION$MAIN_VOLUME
	   ;;
      all)
           $MIXER $MIXER_OPTIONS
           case "$HEURE" in
	        07)
		  MAIN_VOLUME=+10
		  ;;
		09)
		  MAIN_VOLUME=+15
		  ;;
		20)
		  MAIN_VOLUME=-5
		  ;;
		22)
		  MAIN_VOLUME=-10
		  ;;
		00)
		  MAIN_VOLUME=-10
		  ;;
		*)
		  MAIN_VOLUME=+0
		  ;;
	   esac
	   $MIXER $MAIN_VOLUME_OPTION$MAIN_VOLUME
	   ;;
      *)
           echo "Mixer Reset v$VERSION - By Raphaël HALIMI <raph@captainblood.org>"
	   echo -e "Usage: mixer-reset.sh {reset|update|all}\n"
	   echo "reset - set everything but the main volume to the values specified"
	   echo "        in the script."
	   echo "update - increase or decrease the main volume according to the current time."
	   echo "all - the two actions above."
	   exit 1
	   ;;
esac
