# Update GeoIP packages to new version provided by MaxMind.
#
# Author: Elan Ruusamäe <glen@pld-linux.org>
+#
+# Changelog:
# 2012-07-04 Created initial version
# 2014-03-04 Rewritten to be smarter when checking for updates avoiding full download if no changes.
# 2014-06-06 Fix finding new versions if multiple previous archives were present
+# 2015-08-25 Add auto commit support
set -e
update=false
status=false
+commit=true
while [ $# -gt 0 ]; do
case "$1" in
update|-u|-update|--update)
esac
done
+die() {
+ echo >&2 "$0: ERROR: $*"
+ exit 1
+}
+
# get file DATE in GMT timezone
filedate() {
local file="$1"
s/^\(Release:[ \t]\+\)[.0-9]\+\$/\11/
" $specfile
+ rm *.zip *.gz *.xz
# update md5
out=$(md5 -p1 $specfile 2>&1) || echo "$out"
out=$(builder -bb $specfile 2>&1) || echo "$out"
}
+commit_vcs() {
+ local specfile="$1" version="$2"
+
+ git commit -m "updated to $version" $specfile
+ git push || echo push failed
+}
+
# get version from package files
# set $version variable
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
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
+ if $commit; then
+ commit_vcs $specfile $version
+ fi
fi
cd ..
done
for pkg in ${*:-$pkgs}; do
pkg=${pkg%.spec}
cd $pkg
+ out=$(
git status --porcelain
+ git status | grep ahead || :
+ )
+ test -n "$out" && echo "$pkg: $out"
cd ..
done