[packages/rpm-build-tools] update-geoip.sh: rewrite for dynamic urls; use smarter fetch (curl with timestamp check)
glen
glen at pld-linux.org
Tue Mar 4 22:40:30 CET 2014
commit b10dfc6fd83e9dc815becebee560816cd497f666
Author: Elan Ruusamäe <glen at delfi.ee>
Date: Tue Mar 4 23:36:12 2014 +0200
update-geoip.sh: rewrite for dynamic urls; use smarter fetch (curl with timestamp check)
update-geoip.sh | 112 +++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 87 insertions(+), 25 deletions(-)
---
diff --git a/update-geoip.sh b/update-geoip.sh
index 7140fb7..84b33d2 100755
--- a/update-geoip.sh
+++ b/update-geoip.sh
@@ -1,4 +1,10 @@
#!/bin/sh
+# Update GeoIP packages to new version provided by MaxMind.
+#
+# Author: Elan Ruusamäe <glen at pld-linux.org>
+# 2012-07-04 Created initial version
+# 2014-03-04 Rewritten to be smarter when checking for updates avoiding full download if no changes.
+
set -e
update=false
@@ -19,53 +25,109 @@ while [ $# -gt 0 ]; do
esac
done
-dir=$(dirname "$0");
-cd "$dir"
+# get file DATE in GMT timezone
+filedate() {
+ local file="$1"
+ TZ=GMT stat -c '%y' "$file" | awk '{print $1}'
+}
-pkgs='GeoIP-db-City GeoIP-db-Country GeoIP-db-IPASNum xtables-geoip'
-for pkg in ${*:-$pkgs}; do
- $status && continue
+# get package, no sources
+get_package() {
+ local pkg=$1 out
+ out=$(builder -g -ns $pkg 2>&1) || echo "$out"
+}
- out=$(./builder -g -ns $pkg 2>&1) || echo "$out"
- cd $pkg
+update_urls() {
+ local specfile=$1 t fn z
+ # update urls
+ t=$(mktemp)
+ builder -su $specfile > $t 2>/dev/null
+ while read url; do
+ fn=${url##*/}
+ test -e "$fn" && z= || unset z
+ curl ${z+-z "$fn"} -o "$fn" "$url" -R -s
+ done < $t
+ rm -f $t
+}
- $update && rm -vf *.gz *.zip *.xz
+# set version to $version in $specfile and build the package
+update_version() {
+ local specfile="$1" version="$2" out
- specfile=*.spec
+ # update version
+ sed -i -e "
+ s/^\(Version:[ \t]\+\)[.0-9]\+\$/\1$version/
+ s/^\(Release:[ \t]\+\)[.0-9]\+\$/\11/
+ " $specfile
+
+ # update md5
+ out=$(md5 -p1 $specfile 2>&1) || echo "$out"
- out=$(../md5 -p1 $specfile 2>&1) || echo "$out"
+ # build it
+ out=$(builder -bb $specfile 2>&1) || echo "$out"
+}
- version=$(awk '/^Version:[ ]+/{print $NF}' $specfile)
+# get version from package files
+# set $version variable
+version_from_files() {
+ local pkg=$1 dt4 dt6
case "$pkg" in
xtables-geoip)
- dt4=$(TZ=GMT stat -c '%y' *.zip | awk '{print $1}' | tr -d -)
- dt6=$(TZ=GMT stat -c '%y' *.gz | awk '{print $1}' | tr -d -)
+ dt4=$(filedate *.zip | tr -d -)
+ dt6=$(filedate *.gz | tr -d -)
if [ "$dt4" -gt "$dt6" ]; then
- dt=$dt4
+ version=$dt4
else
- dt=$dt6
+ version=$dt6
fi
;;
GeoIP-db-City)
- dt=$(TZ=GMT stat -c %y *.xz | awk '{print $1}' | tr - .)
+ dt4=$(filedate GeoLiteCity-*.dat.xz | tr - .)
+ dt6=$(filedate GeoLiteCityv6-*.dat.gz | tr - .)
+ if [ "$(echo $dt4 | tr -d .)" -gt "$(echo $dt6 | tr -d .)" ]; then
+ version=$dt4
+ else
+ version=$dt6
+ fi
+ ;;
+ GeoIP-db-Country)
+ dt4=$(filedate GeoIP-*.dat.gz | tr - .)
+ dt6=$(filedate GeoIPv6-*.dat.gz | tr - .)
+ if [ "$(echo $dt4 | tr -d .)" -gt "$(echo $dt6 | tr -d .)" ]; then
+ version=$dt4
+ else
+ version=$dt6
+ fi
;;
*)
- dt=$(TZ=GMT stat -c %y *.gz | awk '{print $1}' | tr - .)
+ version=$(filedate *.gz | tr - .)
;;
esac
+}
- if [ "$version" != "$dt" ]; then
- version=$dt
- sed -i -e "
- s/^\(Version:[ \t]\+\)[.0-9]\+\$/\1$version/
- s/^\(Release:[ \t]\+\)[.0-9]\+\$/\11/
- " $specfile
- fi
+dir=$(dirname "$0")
+APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
+PATH=$APPDIR:$PATH
+cd "$dir"
- out=$(../builder -bb *.spec 2>&1) || echo "$out"
+pkgs='GeoIP-db-City GeoIP-db-Country GeoIP-db-IPASNum xtables-geoip'
+for pkg in ${*:-$pkgs}; do
+ $status && continue
+
+ get_package $pkg
+ cd $pkg
+ specfile=*.spec
+
+ update_urls $specfile
+ version_from_files $pkg
+ oldvers=$(awk '/^Version:[ ]+/{print $NF}' $specfile)
+ if [ "$oldvers" != "$version" ]; then
+ update_version $specfile $version
+ fi
cd ..
done
+# report each package git status
for pkg in ${*:-$pkgs}; do
cd $pkg
git status --porcelain
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/rpm-build-tools.git/commitdiff/b10dfc6fd83e9dc815becebee560816cd497f666
More information about the pld-cvs-commit
mailing list