#!/bin/bash # a simple fm tuner frontend script # Pete Nesbitt, Dec 2006. # REQUIRES: # fmtools utility available at http://www.stanford.edu/~blp/fmtools/ # -my version is 0.99.1 but it shouldn't matter # EDIT THIS array to match you cable fm guilde. # (could be expanded to self build from fmscan someday) # Use a '+' to separate frequency from name, replace spaces with '_' STATION_LIST[0]="93.7+JR_Country" STATION_LIST[1]="94.5+The_Beat" STATION_LIST[2]="95.3+Z95" STATION_LIST[3]="96.1+Fairchild_Radio" STATION_LIST[4]="96.9+CKKS" STATION_LIST[5]="97.7+CBC_French" STATION_LIST[6]="99.3+CFOX" STATION_LIST[7]="99.7+CKKQ_Victoria" STATION_LIST[8]="100.5+KISM_Bellingham" STATION_LIST[9]="101.1+CFMI" STATION_LIST[10]="102.7+CFRO" STATION_LIST[11]="103.5+QMFM" STATION_LIST[12]="105.7+CBC_English" DEF_CHOICE="8" # temp files STN_TMP="/tmp/stations.tmp" FREQ_TMP="/tmp/frequencies.tmp" # 'fm' utility FM="/usr/local/bin/fm" # volume in percent # intensity (0-65535) VOL_PER="40" FM_VOLUME="`echo 65635/100*${VOL_PER}|bc`" ############ ##Functions: # show stations show_station_names() { count=1 echo echo "Available FM Stations:" for STATION in `echo ${STATION_LIST[@]}`; do # stations by number printf "%10s %-18s %-s\n" "${count})" "`echo ${STATION} |cut -d'+' -f2|sed -e s/_/" "/g`" "(`echo ${STATION} |cut -d'+' -f1`)" # stations by name let count=count+1 done echo } # select station select_station() { printf " Please enter a number (or 'q' to quit): [${DEF_CHOICE}]: " read CHOICE if [ "${CHOICE}" = "" ]; then CHOICE="${DEF_CHOICE}";fi if [ "${CHOICE}" = "q" ] || [ "${CHOICE}" = "Q" ]; then echo "exited by user";exit 0;fi #adjust for start from 0 let CHOICE=CHOICE-1 SELECTED="`echo ${STATION_LIST[${CHOICE}]}|cut -d'+' -f1`" } # play what is picked play_selected() { $FM on &> /dev/null # volume not supported by my card # $FM +$FM_VOLUME &> /dev/null $FM -q $1 &> /dev/null } ##### ##### start of script ############ clear ## first clean up any old runs: rm -f $FREQ_TMP $STN_TMP &> /dev/null show_station_names select_station play_selected $SELECTED echo echo "Playing `echo ${STATION_LIST[${CHOICE}]} |awk -F+ '{print $2"\t"$1}'|sed -e s/_/" "/g`" echo echo "Enter 'fm off' to turn off radio" echo #eof