X-Git-Url: http://git.pld-linux.org/?a=blobdiff_plain;ds=sidebyside;f=update-geoip.sh;h=b58932e356319a920c6eb242fcfc4857bfdbca2c;hb=6c0815a;hp=1642aa54a7112fcb6521902d4b09cde0245966cf;hpb=98b7acb3d4ed803ca31ca48e73dcb29408bc8318;p=packages%2Frpm-build-tools.git diff --git a/update-geoip.sh b/update-geoip.sh index 1642aa5..b58932e 100755 --- a/update-geoip.sh +++ b/update-geoip.sh @@ -30,6 +30,11 @@ while [ $# -gt 0 ]; do esac done +die() { + echo >&2 "$0: ERROR: $*" + exit 1 +} + # get file DATE in GMT timezone filedate() { local file="$1" @@ -82,6 +87,7 @@ update_version() { s/^\(Release:[ \t]\+\)[.0-9]\+\$/\11/ " $specfile + rm *.zip *.gz *.xz # update md5 out=$(md5 -p1 $specfile 2>&1) || echo "$out" @@ -124,6 +130,29 @@ version_from_files() { esac } +version_from_attachment() { + local url fn dt d t + t=$(mktemp) + + for url in "$@"; do + # remove querystring to receive proper headers + url=${url%\?*} + curl -Is "$url" -o "$t" + fn=$(awk 'BEGIN {FS=": "}/^[Cc]ontent-[Dd]isposition/{sub(/.*filename=/, "", $2); print $2}' "$t") + fn=${fn#GeoLite2-Country-CSV_} + d=$(echo "$fn" | sed -e 's/[^0-9-]//g') + + if [ "$d" -gt "$dt" ]; then + dt=$d + fi + done + + test -n "$dt" || die "Failed to find date from $*" + + rm -f $t + version=$dt +} + dir=$(dirname "$0") APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d") PATH=$APPDIR:$PATH @@ -139,8 +168,13 @@ for pkg in ${*:-$pkgs}; do specfile=*.spec urls=$(get_urls $specfile) - update_urls $urls - version_from_files $pkg $urls + if [ "$pkg" = "xtables-geoip" ]; then + version_from_attachment $urls + else + update_urls $urls + version_from_files $pkg $urls + fi + oldvers=$(awk '/^Version:[ ]+/{print $NF}' $specfile) if [ "$oldvers" != "$version" ]; then update_version $specfile $version