2 # Update GeoIP packages to new version provided by MaxMind.
4 # Author: Elan Ruusamäe <glen@pld-linux.org>
7 # 2012-07-04 Created initial version
8 # 2014-03-04 Rewritten to be smarter when checking for updates avoiding full download if no changes.
9 # 2014-06-06 Fix finding new versions if multiple previous archives were present
10 # 2015-08-25 Add auto commit support
17 while [ $# -gt 0 ]; do
19 update|-u|-update|--update)
23 status|-s|-status|--status)
33 # get file DATE in GMT timezone
36 TZ=GMT stat -c '%y' "$file" | awk '{print $1}'
39 # get package, no sources
42 out=$(builder -g -ns $pkg 2>&1) || echo "$out"
46 local specfile=$1 t url
49 builder -su $specfile 2>/dev/null > $t
63 local specfile=$1 url fn z
66 # take output filename (anything after last slash)
68 # remove querystring for mtime match to work
70 test -e "$fn" && z= || unset z
71 curl ${z+-z "$fn"} -o "$fn" "$url" -R -s
75 # set version to $version in $specfile and build the package
77 local specfile="$1" version="$2" out
81 s/^\(Version:[ \t]\+\)[.0-9]\+\$/\1$version/
82 s/^\(Release:[ \t]\+\)[.0-9]\+\$/\11/
86 out=$(md5 -p1 $specfile 2>&1) || echo "$out"
89 out=$(builder -bb $specfile 2>&1) || echo "$out"
93 local specfile="$1" version="$2"
95 git commit -m "updated to $version" $specfile
96 git push || echo push failed
99 # get version from package files
100 # set $version variable
101 version_from_files() {
102 local pkg=$1 url fn dt d
106 # take output filename (anything after last slash)
108 # skip inexistent files
109 test -e "$fn" || continue
112 if [ "$(echo $d | tr -d -)" -gt "$(echo $dt | tr -d -)" ]; then
119 version=$(echo "$dt" | tr -d -)
122 version=$(echo "$dt" | tr - .)
128 APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
132 pkgs='GeoIP-db-City GeoIP-db-Country GeoIP-db-IPASNum xtables-geoip'
133 for pkg in ${*:-$pkgs}; do
141 urls=$(get_urls $specfile)
143 version_from_files $pkg $urls
144 oldvers=$(awk '/^Version:[ ]+/{print $NF}' $specfile)
145 if [ "$oldvers" != "$version" ]; then
146 update_version $specfile $version
148 commit_vcs $specfile $version
154 # report each package git status
155 for pkg in ${*:-$pkgs}; do
159 git status --porcelain
160 git status | grep ahead || :
162 test -n "$out" && echo "$pkg: $out"