xastir/scripts/get-NWSdata.in
Tom Russo ffaa6014e4 Make get-NWSdata exit with non-zero error code on failed download
NWS changed their files right after we updated get-NWSdata to get the
3 March versions, and delayed implementation until 16 April.

I had previously set up get-NWSdata to exit with a non-zero exit code
if any dbfawk files were out of date, but I failed to make it do so if
any files failed to download.

Had I done so back in commit ee337c07, the automated github testing we
do on every commit would have pointed out the problem to us long ago.
Instead, it was silently "passing" the get-NWSdata test precisely
because it was failing to download any files and wasn't causing an
error exit.

Now, if either download of a file fails *or* dbfawks are out of date,
the script will exit with exit code 1, and it will exit with exit
code 0 only if all downloads succeeded and all dbfawks work.   It will
report at the end which downloads failed and which dbfawks are out of
date.

Had this code been in place earlier, we would have known that NWS
pulled the rug out from under us the day it happened instead of 4
months later and after having inconvenienced users.

C.f. #390
2026-07-13 17:22:34 -06:00

146 lines
4.6 KiB
Bash
Executable file

#!/bin/sh
#
# Script to retrieve NWS data files.
#
# Run this from the INSTALLED location of the script, i.e.
# /usr/local/share/xastir/scripts
# or /usr/share/xastir/scripts
#
#
# Originally written 2006/03/07 by Steven, WM5Z, and Curt, WE7U.
#
# Copyright (C) 2000-2026 The Xastir Group
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# See README.MAPS for a bit more information on the program.
#
#
# NOTE: Run this script as root.
#
# MAINTAINERS: Go here to find out what the latest versions are:
# <http://www.nws.noaa.gov/geodata/>
# <http://www.weather.gov/gis/AWIPSShapefiles>
# Please only have ONE of each variable listed here! Note that the "Valid
# Date" listed on the NWS web pages is the date at which the Shapefile
# should START to be used. Don't just blindly put the newest filename
# here if that start-date hasn't arrived yet!
#
FILE1="w_16ap26" # GREEN: NWSM Library: County Warning Area Boundaries
FILE2="z_16ap26" # GREEN: NWSM Library: Public Forecast Zone Boundaries
FILE3="mz16ap26" # GREEN: NWSM Library: Coastal and Offshore Marine Zones
FILE4="oz16ap26" # GREEN: NWSM Library: Coastal and Offshore Marine Zones
FILE5="hz17fe26" # GREEN: NWSM Library: Coastal and Offshore Marine Zones
FILE6="fz16ap26" # GREEN: NWSM Library: Fire Weather Zone Boundaries
FILE7="c_16ap26" # RED: Counties, States, Provinces: U.S. Counties
prefix=@prefix@
cd ${prefix}/share/xastir/Counties || exit 1
# Remove any old zip files hanging around in this directory
#
rm -f *.zip 2>&1 >/dev/null
exitcode=0
badfetch=""
# Fetch new copies, unzip into place, delete archive.
#
#
DIR=WSOM
for d in $FILE1 $FILE2 $FILE3 $FILE4 $FILE5 $FILE6; do
if [ -e $d.shp ]; then
echo "Already have $d shapefile, skipping..."
else
# Remove possible older copies
cut=`echo $d|cut -c1-2 -`
rm -f $cut*.shx $cut*.shp $cut*.dbf $cut*.prj $cut*.zip 2>&1 >/dev/null
wget https://www.weather.gov/source/gis/Shapefiles/$DIR/$d.zip
if [ $? -ne 0 ]
then
exitcode=1
badfetch="$d.zip $badfetch"
else
unzip $d.zip
rm -f *.zip
fi
fi
done
DIR=County
for d in $FILE7; do
if [ -e $d.shp ]; then
echo "Already have $d shapefile, skipping..."
else
# Remove possible older copies
cut=`echo $d|cut -c1-2 -`
rm -f $cut*.shx $cut*.shp $cut*.dbf $cut*.prj $cut*.zip 2>&1 >/dev/null
wget https://www.weather.gov/source/gis/Shapefiles/$DIR/$d.zip
unzip $d.zip
rm -f *.zip
fi
done
####################
# After download/install of map files above, run commands such as these:
#
# cd /usr/local/share/xastir; testdbfawk -D config -d Counties/mz11au16.dbf 2>&1 | head -5
# cd /usr/local/share/xastir; testdbfawk -D config -d Counties/w_11au16.dbf 2>&1 | head -5
#
# to determine whether there's dbfawk support for each of the NWS files. NWS
# changes the signature on their files often so we need to create a new
# dbfawk for each in xastir/config, test it, then add it into the
# Makefile.am file there and commit, then do another "make install" to put
# the dbfawk's into place.
# Fixed the issue where there's an 'a' or 'b' after the filename root. NWS likes
# to do that, but have non-a/b files extracted from the zip, which made the below
# tests fail.
####################
#
baddbfawk=""
for d in $FILE1 $FILE2 $FILE3 $FILE4 $FILE5 $FILE6 $FILE7; do
e=`echo $d | sed -e's/\(.*[0-9]\)[a-f]$/\1/'`
if [ -e $e.dbf ]; then
echo
echo $e.dbf
# Run in a separate shell so we don't mess up the current directory for the -e test above
result=`cd ${prefix}/share/xastir; ${prefix}/bin/testdbfawk -D config -d Counties/$e.dbf 2>&1 | head -3 | tail -1`
echo $result
if [ "$result" = "No matching dbfawk signature found" ]; then
echo "Fix dbfawk for $e!"
baddbfawk="$e $baddbfawk"
exitcode=1
fi
fi
done
echo
if [ $exitcode -eq 1 ] ; then
echo "Out-of-date dbfawks: $baddbfawk ."
echo "Failed downloads: $badfetch ."
fi
exit $exitcode