#!/bin/sh
	# Copyright 2001, 2002 Adrian Lester.
	#
	#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
	#####################################################################
#!/bin/sh
#Script to control presets etc. for radio card.
#Usage: fmcontrol [station] [volume]
#You might want to edit the next few lines.
	#This sets the path to the station config file FROM INSIDE your home directory.
	#Obviously if multiple users are using this script this must be the same for each.
STATIONFILE=.radiostations
	#This is the default volume if .fmrc is not found:
DEFAULTVOLME=60000
	#This is the path to the fm binary:
FMPATH=/usr/bin/fm

#Unless you want to fiddle with the script you shouldn't need to change
#anything under here.

#*********************************************************************

cd $()

#Set the default volume.
if [ -e .fmrc ]
	then
	VOLUME=$( grep -e "^VOL" .fmrc | cut -f 2 -d ' ' )
else
	VOLUME=$DEFAULTVOLUME
fi	

OK=1
STATION=$1
while [ $OK != 0 ]
	do
	if [ $STATION ]
		then
		FREQUENCY=$( grep "^$STATION" $STATIONFILE | cut -f 2 )
		if [ $FREQUENCY ]
			then
			VOLCHANGE=0
			VOLCHANGE=$( grep "^$STATION" $STATIONFILE | cut -f 3 )
			OK=0
		else
			echo Invalid station or error in config file.
			echo Available Stations are:
                	cut -f 1 $STATIONFILE
                	echo Please enter a station name:
                	read STATION
		fi
	else
		echo No station specified.
		echo Available Stations are:
		cut -f 1 $STATIONFILE
		echo Please enter a station name:
		read STATION
	fi
done

if [ $2 ]
	then
	VOLUME=$2
else 
	VOLUME=$(($VOLUME + $VOLCHANGE))
fi

$FMPATH $FREQUENCY $VOLUME
