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
98 # get version from package files
99 # set $version variable
100 version_from_files() {
101 local pkg=$1 url fn dt d
105 # take output filename (anything after last slash)
107 # skip inexistent files
108 test -e "$fn" || continue
111 if [ "$(echo $d | tr -d -)" -gt "$(echo $dt | tr -d -)" ]; then
118 version=$(echo "$dt" | tr -d -)
121 version=$(echo "$dt" | tr - .)
127 APPDIR=$(d=$0; [ -L "$d" ] && d=$(readlink -f "$d"); dirname "$d")
131 pkgs='GeoIP-db-City GeoIP-db-Country GeoIP-db-IPASNum xtables-geoip'
132 for pkg in ${*:-$pkgs}; do
140 urls=$(get_urls $specfile)
142 version_from_files $pkg $urls
143 oldvers=$(awk '/^Version:[ ]+/{print $NF}' $specfile)
144 if [ "$oldvers" != "$version" ]; then
145 update_version $specfile $version
147 commit_vcs $specfile $version
153 # report each package git status
154 for pkg in ${*:-$pkgs}; do
158 git status --porcelain
159 git status | grep ahead || :
161 test -n "$out" && echo "$pkg: $out"