#!/bin/bash # Author: Kevin P. Inscoe . # File: setrootwx.sh # Date of creation: May 1, 1996. # Warranty: None expressed or implied. # License: The Open Software License. V1.1 http://www.opensource.org/licenses/osl.php # # OSI Certified Open Source Software. http://www.opensource.org/licenses/ # # Requirements: # # GNU bash 2.0 (tested on 2.05b) - http://www.gnu.org/software/bash/bash.html # Lynx - http://lynx.isc.org/ # XV - http://www.trilon.com/xv/xv.html # And X-11 compatible running desktop # # The purpose of this program is: # # Displays a list of on-line images (usually weather radar screens) to a rooted # X Windows display. I run this on one of my test web servers and since I did not # the graphics display for anything meaningful and I like to monitor the weather (wx) # I wrote this script. It original started life as a way to put the local TV radar screen # on my Sun CDE desktop. The URI included in this script encompass my view of # Central Florida (Orlando). Of course change to suit your part of the world. The # original script used netpbm and xsetroot. Later the Linux version used xloadimage. # There are several ways to do it however I now run this as a kiosk unattended. No # longer as a desktop. # # Notes: # # You must first set the control panel in CDE to "no background" # if using this script on Solaris. Takes various radar screens for # Central Florida and updates the background. I run this as cron # every 20 minutes during daytime hours. # # For a complete listing of radar sites you can consult: # # http://www.kevininscoe.com/wx/ # http://iwin.nws.noaa.gov/ # # Updates: # # April 2, 2003 # # Recently this script has been moved to my Redhat 8 desktop but should still # work on a Solaris desktop. It previously worked under Solaris 8 # # October 14, 2004 - Version 2.0 (complete re-write) # # Changed the format to a sequential display rather than a random display. Also added # logic for seasonal displays as individual months. # # Globals DISPLAY=localhost:0; export DISPLAY lynx_bogus_text="HTML document text" STATUS=/home/kinscoe/tmp/setrootwxstatus.tmp PNGTMP=/home/kinscoe/tmp/setrootwxdesktop.png DESKTOP=/home/kinscoe/tmp/setrootwxdesktop.gif ### OS specific paths ### # Gentoo #XDISP="/usr/bin/xloadimage -onroot -full" # Redhat 8 # The XV that comes with Redhat 8 is broken. Use xloadimage. XDISP="/usr/X11R6/bin/xloadimage -onroot -full" #XDISP="/usr/X11R6/bin/xloadimage -onroot -full -fit" #XDISP="/usr/X11R6/bin/xv -quit -root -rmode 5 -maxpect -max +viewonly" FL=/usr/bin/file #LYNX=/usr/bin/lynx # Nagios hack LYNX=/usr/bin/lynx HEAD=/usr/bin/head EXPR=/usr/bin/expr BC=/usr/bin/bc PRINTF=/usr/bin/printf # Solaris 8 #XDISP="/usr/local/bin/XV -quit -root -rmode 5 -maxpect -max +viewonly" #LYNX=/usr/local/bin/lynx #HEAD=/bin/head #EXPR=/bin/expr # All CUT=/bin/cut DT=/bin/date ECHO=/bin/echo AWK=/bin/awk SED=/bin/sed RM=/bin/rm CONV=/usr/local/bin/convert BC=/usr/bin/bc # Uncomment this if you want to watch a hurricane (or some other image) full time #HURR="http://www.nhc.noaa.gov/storm_graphics/AT01/refresh/AL0107W+gif/145632W.gif" ##### Functions have to be first in bash (yeah I know annoying) #### function season { cmonth=`$DT "+%m" | $SED -e 's/0//g'` currmonth=`$PRINTF "obase=16\n%s\nquit\n" $cmonth | tail -1 | $BC` lastcode=`$ECHO $last | $CUT -c4` if [ "$lastcode" = "[" ]; then if [ "${URISA[$currmonth]}" ]; then next="URISA[$currmonth]" GFX=${URISA[$currmonth]} else next="URI[1]" GFX=${URI[1]} fi; else # Ok we are in the middle of processing seasons # cycle through A-E for this month if they exist GFX=${URI[1]} # default seacode=`$ECHO $last | $CUT -c5` next="URI[1]" case "$seacode" in "A" ) if [ "${URISB[$currmonth]}" ]; then next="URISB[$currmonth]" GFX=${URISB[$currmonth]} fi; ;; "B" ) if [ "${URISC[$currmonth]}" ]; then next="URISC[$currmonth]" GFX=${URISC[$currmonth]} fi; ;; "C" ) if [ "${URISD[$currmonth]}" ]; then next="URISD[$currmonth]" GFX=${URISD[$currmonth]} fi; ;; "D" ) if [ "${URISE[$currmonth]}" ]; then next="URISE[$currmonth]" GFX=${URISE[$currmonth]} fi; ;; "E" ) next="URI[1]" GFX=${URI[1]} ;; esac fi; $ECHO "$next" > $STATUS $ECHO "last=$last, new=$next" } function nagios () { NAGIOS="http://nagios.edu.regn.net/nagios/cgi-bin/statusmap.cgi?host=all&createimage&canvas_x=0&canvas_y=0&canvas_width=953&canvas_height=857&max_width=0&max_height=0&layout=5&layermode=exclude" $LYNX -auth=guest:watchit -source "$NAGIOS" > $PNGTMP # $LYNX -auth=guest:watchit -dump -source "$NAGIOS" > $PNGTMP } #### Main #### # Define our display URI's in order in the URI array # # Notes on this @ http://www.tldp.org/LDP/abs/html/arrays.html # Note that the numbers MUST be sequential from 1 or gaps will # be ignored by the logic # URI[1]="http://radar.wunderground.com/data/nids/MLB19_0.gif" URI[2]="http://www.jeppesen.com/download/weather/ussatra00.gif" URI[3]="http://image.weather.com/images/maps/travel/trvlthun_600x405.jpg" URI[4]="http://sec.noaa.gov/rt_plots/dregion.gif" URI[5]="http://weather.cod.edu/nexrad/brefs/MLB/MLB.BREF1.gif" URI[6]="http://www.sec.noaa.gov/rt_plots/Xray.gif" URI[7]="http://www.goes.noaa.gov/GIFS/ECI6.JPG" URI[8]="http://www.uni.edu/storm/wximages/images/frnts_stnplt.gif" URI[9]="http://www.nws.noaa.gov/mdl/radar/SE_probsvr.gif" URI[10]="http://www.nws.noaa.gov/mdl/radar/SE_categ.gif" URI[11]="http://www.uni.edu/storm/wximages/images/usfronts.gif" URI[12]="http://www.spc.noaa.gov/products/md/validmd.gif" URI[13]="http://images.ibsys.com/orl/images/weather/auto/fdot040_320x240.jpg" URI[14]="http://weather.unisys.com/radar/rad_us.gif" URI[15]="http://twister.sbs.ohio-state.edu/severe/kinx.gif" URI[16]="http://image.weather.com/images/maps/travel/trvlthun_600x405.jpg" URI[17]="http://www.cpc.ncep.noaa.gov/products/predictions/threats/threats.gif" URI[18]="http://www.hpc.ncep.noaa.gov/noaa/noaa.gif" URI[19]="http://images.ibsys.com/orl/images/weather/auto/fdot056_320x240.jpg" URI[20]="http://www.sec.noaa.gov/rt_plots/Kp.gif" URI[21]="http://www.intellicast.com/WeatherImg/SatelliteLoop/hiatlsat_None_anim.gif" URI[22]="http://earthquake.usgs.gov/eqcenter/recenteqsus/index.gif" URI[23]="http://www.internettrafficreport.com/gifs/tr_map_namerica.gif" URI[24]="http://www.ssd.noaa.gov/PS/FIRE/DATA/RT/FL/ALB/20.jpg" URI[25]="http://www.spacew.com/www/fof2.gif" URI[26]="http://images.ibsys.com/orlpn/images/weather/auto/suntrustcam2_640x480.jpg?1073517643685" URI[27]="http://www.flamedia.com/light2.jpg" URI[28]="http://sec.noaa.gov/rt_plots/dregion_q1.gif" # Hurricane seasonal stuff below - I saw less value in doing these # so I commented them out - 12-26-2007 #URI[29]="http://www.nhc.noaa.gov/tafb_latest/ATSA_latest.gif" #URI[30]="http://www.nhc.noaa.gov/tafb_latest/GULF_latest.gif" #URI[31]="http://www.nhc.noaa.gov/tafb_latest/TSA_latest.gif" #URI[32]="http://www.nhc.noaa.gov/tafb_latest/WATL_latest.gif" # # Now define seasonal URI's # # The array number is the number of the month. The "S" after URI denotes seasonal. # Use A-E in sequence after the the "S" to denote the order you want. Gaps in the # sequence like the array numbers above will cause a reset back to URI[1] again. # # August and Sept. cause a Octal conversion error - remember to use Octal notation # (10 and 11) # dangera="http://www.nhc.noaa.gov/tafb_latest/danger_atl_latest.gif" dangerb="http://cimss.ssec.wisc.edu/tropic/real-time/wavetrak/winds/wavetrkAv.gif" dangerc="http://www.nhc.noaa.gov/gtwo/two_atl.gif" dangerd="http://www.nhc.noaa.gov/tafb_latest/danger_atl_latest.gif" # May URISA[5]=$dangera URISB[5]=$dangerb URISB[5]=$dangerc URISB[5]=$dangerd # June URISA[6]=$dangera URISB[6]=$dangerb URISB[6]=$dangerc URISB[6]=$dangerd # July URISA[7]=$dangera URISB[7]=$dangerb URISB[7]=$dangerc URISB[7]=$dangerd # August URISA[10]=$dangera URISB[10]=$dangerb URISB[10]=$dangerc URISB[10]=$dangerd # September URISA[11]=$dangera URISB[11]=$dangerb URISB[11]=$dangerc URISB[11]=$dangerd # October URISA[12]=$dangera URISB[12]=$dangerb URISB[12]=$dangerc URISB[12]=$dangerd # November URISB[13]=$dangera URISA[13]=$dangerb URISA[13]=$dangerc URISA[13]=$dangerd # # Grab the last status file # if [ -s $STATUS ]; then last=`$HEAD -n 1 $STATUS` scheme=`$ECHO $last | $AWK -F[ '{ print $1 }'` num=`$ECHO $last | $AWK -F[ '{ print $2 }' | $AWK -F] '{ print $1 }'` # What is the last URL we provided? if [ "$scheme" = "URI" ]; then newnum=`$EXPR $num + 1` if [ "${URI[$newnum]}" ]; then GFX=${URI[$newnum]} $ECHO "URI[$newnum]" > $STATUS $ECHO "last=$last, new=URI[$newnum]" else season fi; else season fi; else $ECHO "URI[1]" > $STATUS GFX=${URI[1]} $ECHO "First run" fi; # # Display the image making sure it's not a 404 or blank # good_image_dump=0 until [ $good_image_dump = 1 ]; do $RM -f $DESKTOP # Are we in hurricane mode? If HURR variable exists and is not null # then use that otherwise use the URL we were given... XFX=${HURR:-$GFX} $ECHO "Pulling URI $XFX..." $LYNX -source $XFX > $PNGTMP $CONV -verbose $PNGTMP -resize 70% $DESKTOP # Check that we received output from our dump if [ -s $DESKTOP ]; then # Is it a supportable graphics type that imagemagick can work with? type=`$FL $DESKTOP | $AWK -F: '{ print $2 }' | $SED -e 's/^ *\(.*\) *$/\1/'` $ECHO "Image type=$type" if [ "$type" != "$lynx_bogus_text" ]; then $XDISP $DESKTOP good_image_dump=1 else # No it wasn't so move on to next in list... $ECHO "Unsupported or bogus graphics image from site, going to next in list..." fi; else # we didn't so perhaps the site is down or that URL is bogus so move # on to the next URL in the list... $ECHO "Empty data from website or bad URL, going to next in list..." fi; done