diff options
author | adamw <adamw@FreeBSD.org> | 2014-08-12 04:16:28 +0800 |
---|---|---|
committer | adamw <adamw@FreeBSD.org> | 2014-08-12 04:16:28 +0800 |
commit | e048186a19f57e89c1d725936a5ce4ac72ebde61 (patch) | |
tree | 1c7ef3fa469187c1036897ee4987e4833eaa4585 /net/GeoIP | |
parent | dc091ae1f998329b111f01c0e51e8a7877cad677 (diff) | |
download | freebsd-ports-gnome-e048186a19f57e89c1d725936a5ce4ac72ebde61.tar.gz freebsd-ports-gnome-e048186a19f57e89c1d725936a5ce4ac72ebde61.tar.zst freebsd-ports-gnome-e048186a19f57e89c1d725936a5ce4ac72ebde61.zip |
Ensure that DATADIR exists before attempting to fetch the data files
into it. Also, make the script more robust and ask fewer questions in
adverse conditions.
PORTREVISION bump.
PR: 192597
Submitted by: mandree
Diffstat (limited to 'net/GeoIP')
-rw-r--r-- | net/GeoIP/Makefile | 2 | ||||
-rw-r--r-- | net/GeoIP/files/geoipupdate.sh.in | 50 |
2 files changed, 26 insertions, 26 deletions
diff --git a/net/GeoIP/Makefile b/net/GeoIP/Makefile index 263ea519d7c1..9fdfe2e960c6 100644 --- a/net/GeoIP/Makefile +++ b/net/GeoIP/Makefile @@ -3,7 +3,7 @@ PORTNAME= GeoIP PORTVERSION= 1.6.0 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= net geography MASTER_SITES= http://geolite.maxmind.com/download/geoip/api/c/ diff --git a/net/GeoIP/files/geoipupdate.sh.in b/net/GeoIP/files/geoipupdate.sh.in index 73625467f8a2..b80f292527cc 100644 --- a/net/GeoIP/files/geoipupdate.sh.in +++ b/net/GeoIP/files/geoipupdate.sh.in @@ -1,31 +1,31 @@ #!/bin/sh +set -eu echo Fetching GeoIP.dat and GeoIPv6.dat... -TEMPFILE=`mktemp %%DATADIR%%/GeoIP.dat-XXXXXX` -if fetch -o - http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz | gunzip >> $TEMPFILE ; then - chmod 644 $TEMPFILE - if ! mv $TEMPFILE %%DATADIR%%/GeoIP.dat ; then - rm $TEMPFILE - echo Unable to overwrite %%DATADIR%%/GeoIP.dat - exit 2 +# arguments: +# $1 URL +# $2 output file name +_fetch() { + url="$1" + out="$2" + TEMPFILE="$(mktemp "%%DATADIR%%"/GeoIP.dat-XXXXXX)" + trap 'rc=$? ; set +e ; rm -f "'"$TEMPFILE"'" ; exit $rc' 0 + if fetch -o - "$url" | gunzip >> "$TEMPFILE" ; then + chmod 444 "$TEMPFILE" + if ! mv -f "$TEMPFILE" "%%DATADIR%%"/"$2" ; then + echo "Unable to replace %%DATADIR%%/$2" + return 2 + fi + else + echo "$2 download failed" + return 1 fi -else - rm $TEMPFILE - echo GeoIP.dat download failed - exit 1 -fi + rm -f "$TEMPFILE" + trap - 0 + return 0 +} -TEMPFILE=`mktemp %%DATADIR%%/GeoIPv6.dat-XXXXXX` -if fetch -o - http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz | gunzip >> $TEMPFILE ; then - chmod 644 $TEMPFILE - if ! mv $TEMPFILE %%DATADIR%%/GeoIPv6.dat ; then - rm $TEMPFILE - echo Unable to overwrite %%DATADIR%%/GeoIPv6.dat - exit 2 - fi -else - rm $TEMPFILE - echo GeoIPv6.dat download failed - exit 1 -fi +_fetch "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz" GeoIP.dat + +_fetch "http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz" GeoIPv6.dat |