about summary refs log tree commit diff
path: root/pkgs/tools
diff options
context:
space:
mode:
authorThiago Kenji Okada <thiagokokada@gmail.com>2024-01-08 15:57:48 +0000
committerThiago Kenji Okada <thiagokokada@gmail.com>2024-01-08 16:43:32 +0000
commitb2d0d556f1d97a932c65496cd15002a8463904ac (patch)
tree81920d0d113bae58837243d80c072ccdd90dafe4 /pkgs/tools
parentc25a85bea5a459c12d1bfaaeaa13efcdd5b3a823 (diff)
downloadnixlib-b2d0d556f1d97a932c65496cd15002a8463904ac.tar
nixlib-b2d0d556f1d97a932c65496cd15002a8463904ac.tar.gz
nixlib-b2d0d556f1d97a932c65496cd15002a8463904ac.tar.bz2
nixlib-b2d0d556f1d97a932c65496cd15002a8463904ac.tar.lz
nixlib-b2d0d556f1d97a932c65496cd15002a8463904ac.tar.xz
nixlib-b2d0d556f1d97a932c65496cd15002a8463904ac.tar.zst
nixlib-b2d0d556f1d97a932c65496cd15002a8463904ac.zip
rar: make update script get the latest version
Diffstat (limited to 'pkgs/tools')
-rw-r--r--pkgs/tools/archivers/rar/default.nix4
-rwxr-xr-xpkgs/tools/archivers/rar/update.sh48
2 files changed, 40 insertions, 12 deletions
diff --git a/pkgs/tools/archivers/rar/default.nix b/pkgs/tools/archivers/rar/default.nix
index f3d68879fecd..8faa605b96d1 100644
--- a/pkgs/tools/archivers/rar/default.nix
+++ b/pkgs/tools/archivers/rar/default.nix
@@ -8,7 +8,7 @@
 let
   version = "6.24";
   downloadVersion = lib.replaceStrings [ "." ] [ "" ] version;
-  # Use `./update.sh <version>` to generate the below
+  # Use `./update.sh` to generate the entries below
   srcUrl = {
     i686-linux = {
       url = "https://www.rarlab.com/rar/rarlinux-x32-${downloadVersion}.tar.gz";
@@ -61,6 +61,8 @@ stdenv.mkDerivation {
     installManPage ${manSrc}
   '';
 
+  passthru.updateScript = ./update.sh;
+
   meta = with lib; {
     description = "Utility for RAR archives";
     homepage = "https://www.rarlab.com/";
diff --git a/pkgs/tools/archivers/rar/update.sh b/pkgs/tools/archivers/rar/update.sh
index 8d5bb647d287..f81562727f29 100755
--- a/pkgs/tools/archivers/rar/update.sh
+++ b/pkgs/tools/archivers/rar/update.sh
@@ -1,5 +1,5 @@
 #!/usr/bin/env nix-shell
-#!nix-shell -i bash -p curl gnused jq
+#!nix-shell -i bash -p curl gawk gnused pup jq
 
 set -euo pipefail
 
@@ -8,8 +8,31 @@ readonly DIRNAME
 readonly NIXPKGS_ROOT="../../../.."
 readonly NIX_FLAGS=(--extra-experimental-features 'nix-command flakes')
 
-updateHash()
-{
+# awk is used for parsing the RARLAB website to get the newest version
+readonly AWK_FIELD_SEPARATOR='[-.]'
+# shellcheck disable=SC2016
+readonly AWK_COMMAND='
+# We will get the following output from pup:
+# /rar/rarlinux-x64-700b3.tar.gz
+# /rar/rarmacos-x64-700b3.tar.gz
+# /rar/rarlinux-x64-624.tar.gz
+# /rar/rarbsd-x64-624.tar.gz
+# /rar/rarmacos-x64-624.tar.gz
+
+# Ignore anything that is flagged as beta (e.g.: `/rar/rarlinux-x64-700b3.tar.gz`)
+!/[0-9]+b[0-9]*.tar.gz$/ {
+    # /rar/rarlinux-x64-624.tar.gz -> 624
+    val = $3
+    # Only get the value if it is bigger than the current one
+    if (val > max) max = val
+}
+END {
+    # 624 -> 6.24
+    printf "%.2f\n", max/100
+}
+'
+
+updateHash() {
     local -r version="${1//./}"
     local -r arch="$2"
     local -r os="$3"
@@ -22,25 +45,28 @@ updateHash()
     sed -i "s|$currentHash|$hash|g" "$DIRNAME/default.nix"
 }
 
-updateVersion()
-{
+updateVersion() {
     local -r version="$1"
     sed -i "s|version = \"[0-9.]*\";|version = \"$version\";|g" "$DIRNAME/default.nix"
 }
 
-# TODO: get latest version
-readonly latestVersion="${1:-}"
-
+latestVersion="${1:-}"
 if [[ -z "$latestVersion" ]]; then
-    echo "usage: $0 <version to update>"
-    exit 1
+    latestVersion=$(
+        curl --silent --location --fail https://www.rarlab.com/download.htm | \
+            pup 'a[href*=".tar.gz"] attr{href}' | \
+            awk -F"$AWK_FIELD_SEPARATOR" "$AWK_COMMAND"
+    )
 fi
+readonly latestVersion
+echo "Latest version: $latestVersion"
 
 currentVersion=$(cd "$DIRNAME" && nix "${NIX_FLAGS[@]}" eval --raw "$NIXPKGS_ROOT#legacyPackages.x86_64-linux.rar.version")
 readonly currentVersion
+echo "Current version: $currentVersion"
 
 if [[ "$currentVersion" == "$latestVersion" ]]; then
-    echo "rar is up-to-date: ${currentVersion}"
+    echo "rar is up-to-date"
     exit 0
 fi