From f25e4350ef0031d761f5a4767e4a2d24a6ba8f89 Mon Sep 17 00:00:00 2001 From: aszlig Date: Thu, 2 Jun 2016 18:20:47 +0200 Subject: [PATCH] aqbanking: Add an updater script The promised updater, which feeds sources.nix and should help updating all the aqbanking libraries at the same time. I was very reluctant to write the updater entirely in Nix as I've done a while ago for Chromium, because this would involve ugly hacks to do so. That's why I've done a more conservative approach here, only using nix-instantiate to get the contents of the current sources.nix. Signed-off-by: aszlig Cc: @cillianderoiste, @urkud --- .../libraries/aqbanking/sources.nix | 1 + .../development/libraries/aqbanking/update.sh | 92 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100755 pkgs/development/libraries/aqbanking/update.sh diff --git a/pkgs/development/libraries/aqbanking/sources.nix b/pkgs/development/libraries/aqbanking/sources.nix index ae49abb44de3..f53d9a9e26f1 100644 --- a/pkgs/development/libraries/aqbanking/sources.nix +++ b/pkgs/development/libraries/aqbanking/sources.nix @@ -1,3 +1,4 @@ +# This file is autogenerated from update.sh in the same directory. { gwenhywfar.version = "4.15.3"; gwenhywfar.sha256 = "0fp67s932x66xfljb26zbrn8ambbc5y5c3hllr6l284nr63qf3ka"; diff --git a/pkgs/development/libraries/aqbanking/update.sh b/pkgs/development/libraries/aqbanking/update.sh new file mode 100755 index 000000000000..2ba0192cbb64 --- /dev/null +++ b/pkgs/development/libraries/aqbanking/update.sh @@ -0,0 +1,92 @@ +#!/bin/sh -e +basedir="$(cd "$(dirname "$0")" && pwd)" + +getCurrentVersions() { + [ -e "$basedir/sources.nix" ] || return 0 + (cd "$basedir" && nix-instantiate --eval --strict -E ' + toString ((import ../../../../lib).mapAttrsToList + (name: info: "${name}:${info.version}!${info.sha256}!${info.releaseId}") + (import ./sources.nix)) + ' | tr -d '"') +} + +currentVersions="$(getCurrentVersions)" + +getLastestVersion() { + local baseurl="http://www.aquamaniac.de" + local pkglist="sites/download/packages.php?package=$1&showall=1" + local url="$baseurl/$pkglist" + local reVersion='[0-9]+(\.[0-9]+)+' # Only release versions, no betas! + local reHref='href=".*release=([0-9]+).*dummy=[^0-9]*('"$reVersion"')\.tar' + local reFull='s/^.*.*\<'"$reHref"'.*/\2!\1/p' + curl -s "$url" | sed -nre "$reFull" | sort -V -k 1,1 | tail -n1 +} + +getEntry() { + local name="$1" + for entry in $currentVersions; do + if [ "${entry%%:*}" = "$name" ]; then + echo "${entry#*:}" + return 0 + fi + done + return 1 +} + +prefetchNew() { + local name="$1" + local version="$2" + local package="$3" + local releaseId="$4" + + local url="http://www.aquamaniac.de/sites/download/download.php" + local qstring="package=$package&release=$releaseId&file=01"; + + nix-prefetch-url --name "$name-$version.tar.gz" "$url?$qstring" +} + +processPackage() { + local name="$1" + local package="$2" + + local latest="$(getLastestVersion "$package")" + local current="$(getEntry "$name")" + local currentTail="${current#*!}" + + local currentVersion="${current%%!*}" + local currentSha256="${currentTail%%!*}" + local currentReleaseId="${current##*!}" + + local latestVersion="${latest%%!*}" + local latestReleaseId="${latest##*!}" + + if [ "$latestVersion" = "$currentVersion" -a \ + "$latestReleaseId" = "$currentReleaseId" ]; then + echo " $name.version = \"$currentVersion\";" + echo " $name.sha256 = \"$currentSha256\";" + echo " $name.releaseId = \"$currentReleaseId\";" + return 0 + fi + + local latestSha256="$( + prefetchNew "$name" "$latestVersion" "$package" "$latestReleaseId" + )" + + echo " $name.version = \"$latestVersion\";" + echo " $name.sha256 = \"$latestSha256\";" + echo " $name.releaseId = \"$latestReleaseId\";" + return 0 +} + +generateNewSources() { + echo "# This file is autogenerated from update.sh in the same directory." + echo "{" + for package in gwenhywfar:01 libchipcard:02 aqbanking:03; do + processPackage "${package%%:*}" "${package##*:}" + done + echo "}" +} + +if newSources="$(generateNewSources)"; then + echo "$newSources" > "$basedir/sources.nix" +fi