about summary refs log tree commit diff
path: root/pkgs/tools/graphics/netpbm
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2020-02-24 22:21:27 +0100
committerJan Tojnar <jtojnar@gmail.com>2020-03-01 15:13:02 +0100
commitb19ce7cfe90d984e0d230b967fbbb80a112a204f (patch)
treeafe0543e0596d6bf497b3d6e4aa49ca66887557c /pkgs/tools/graphics/netpbm
parent7948e6785b4aa6a1289645575816e423d85f6aea (diff)
netpbm: add updateScript
Diffstat (limited to 'pkgs/tools/graphics/netpbm')
-rw-r--r--pkgs/tools/graphics/netpbm/default.nix2
-rwxr-xr-xpkgs/tools/graphics/netpbm/update.sh40
2 files changed, 42 insertions, 0 deletions
diff --git a/pkgs/tools/graphics/netpbm/default.nix b/pkgs/tools/graphics/netpbm/default.nix
index b67e71c0fdf02..903c6336bcdab 100644
--- a/pkgs/tools/graphics/netpbm/default.nix
+++ b/pkgs/tools/graphics/netpbm/default.nix
@@ -61,6 +61,8 @@ stdenv.mkDerivation {
     done
   '';
 
+  passthru.updateScript = ./update.sh;
+
   meta = {
     homepage = http://netpbm.sourceforge.net/;
     description = "Toolkit for manipulation of graphic images";
diff --git a/pkgs/tools/graphics/netpbm/update.sh b/pkgs/tools/graphics/netpbm/update.sh
new file mode 100755
index 0000000000000..670e872e951d2
--- /dev/null
+++ b/pkgs/tools/graphics/netpbm/update.sh
@@ -0,0 +1,40 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -p bash -p subversion -p common-updater-scripts -i bash
+
+die() {
+    echo "error: $1" >&2
+    exit 1
+}
+
+attr=netpbm
+svnRoot=https://svn.code.sf.net/p/netpbm/code/advanced
+
+oldRev=$(nix-instantiate --eval -E "with import ./. {}; $attr.src.rev" | tr -d '"')
+if [[ -z "$oldRev" ]]; then
+    die "Could not extract old revision."
+fi
+
+latestRev=$(svn info --show-item "last-changed-revision" "$svnRoot")
+if [[ -z "$latestRev" ]]; then
+    die "Could not find out last changed revision."
+fi
+
+versionInfo=$(svn cat -r "$latestRev" "$svnRoot/version.mk")
+if [[ -z "$versionInfo" ]]; then
+    die "Could not get version info."
+fi
+
+nixFile=$(nix-instantiate --eval --strict -A "$attr.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/')
+if [[ ! -f "$nixFile" ]]; then
+    die "Could not evaluate '$attr.meta.position' to locate the .nix file!"
+fi
+
+# h remembers if we found the pattern; on the last line, if a pattern was previously found, we exit with 1
+# https://stackoverflow.com/a/12145797/160386
+sed -i "$nixFile" -re '/(\brev\b\s*=\s*)"'"$oldRev"'"/{ s||\1"'"$latestRev"'"|; h }; ${x; /./{x; q1}; x}' && die "Unable to update revision."
+
+majorRelease=$(grep --perl-regex --only-matching 'NETPBM_MAJOR_RELEASE = \K.+' <<< "$versionInfo")
+minorRelease=$(grep --perl-regex --only-matching 'NETPBM_MINOR_RELEASE = \K.+' <<< "$versionInfo")
+pointRelease=$(grep --perl-regex --only-matching 'NETPBM_POINT_RELEASE = \K.+' <<< "$versionInfo")
+
+update-source-version "$attr" "$majorRelease.$minorRelease.$pointRelease"