From f86c15f484b5099fc5034d21745634658db8534d Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Mon, 8 Jan 2024 14:01:27 +0000 Subject: [PATCH 1/4] rar: add update script --- pkgs/tools/archivers/rar/update.sh | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 pkgs/tools/archivers/rar/update.sh diff --git a/pkgs/tools/archivers/rar/update.sh b/pkgs/tools/archivers/rar/update.sh new file mode 100755 index 000000000000..8d5bb647d287 --- /dev/null +++ b/pkgs/tools/archivers/rar/update.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl gnused jq + +set -euo pipefail + +DIRNAME=$(dirname "$0") +readonly DIRNAME +readonly NIXPKGS_ROOT="../../../.." +readonly NIX_FLAGS=(--extra-experimental-features 'nix-command flakes') + +updateHash() +{ + local -r version="${1//./}" + local -r arch="$2" + local -r os="$3" + local -r nix_arch="$4" + + url="https://www.rarlab.com/rar/rar$os-$arch-$version.tar.gz" + hash=$(nix store prefetch-file --json "$url" | jq -r .hash) + currentHash=$(cd "$DIRNAME" && nix "${NIX_FLAGS[@]}" eval --raw "$NIXPKGS_ROOT#legacyPackages.$nix_arch.rar.src.outputHash") + + sed -i "s|$currentHash|$hash|g" "$DIRNAME/default.nix" +} + +updateVersion() +{ + local -r version="$1" + sed -i "s|version = \"[0-9.]*\";|version = \"$version\";|g" "$DIRNAME/default.nix" +} + +# TODO: get latest version +readonly latestVersion="${1:-}" + +if [[ -z "$latestVersion" ]]; then + echo "usage: $0 " + exit 1 +fi + +currentVersion=$(cd "$DIRNAME" && nix "${NIX_FLAGS[@]}" eval --raw "$NIXPKGS_ROOT#legacyPackages.x86_64-linux.rar.version") +readonly currentVersion + +if [[ "$currentVersion" == "$latestVersion" ]]; then + echo "rar is up-to-date: ${currentVersion}" + exit 0 +fi + +updateHash "$latestVersion" x32 linux i686-linux +updateHash "$latestVersion" x64 linux x86_64-linux +updateHash "$latestVersion" arm macos aarch64-darwin +updateHash "$latestVersion" x64 macos x86_64-darwin + +updateVersion "$latestVersion" From c25a85bea5a459c12d1bfaaeaa13efcdd5b3a823 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Mon, 8 Jan 2024 14:07:57 +0000 Subject: [PATCH 2/4] rar: 6.21 -> 6.24 --- pkgs/tools/archivers/rar/default.nix | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pkgs/tools/archivers/rar/default.nix b/pkgs/tools/archivers/rar/default.nix index a1c22835752b..f3d68879fecd 100644 --- a/pkgs/tools/archivers/rar/default.nix +++ b/pkgs/tools/archivers/rar/default.nix @@ -1,26 +1,30 @@ -{ lib, stdenv, fetchurl, autoPatchelfHook, installShellFiles }: +{ lib +, stdenv +, fetchurl +, autoPatchelfHook +, installShellFiles +}: let - version = "6.21"; + version = "6.24"; downloadVersion = lib.replaceStrings [ "." ] [ "" ] version; - # Use `nix store prefetch-file ` to generate the hashes for the other systems - # TODO: create update script + # Use `./update.sh ` to generate the below srcUrl = { i686-linux = { url = "https://www.rarlab.com/rar/rarlinux-x32-${downloadVersion}.tar.gz"; - hash = "sha256-mDeRmLTjF0ZLv4JoLrgI8YBFFulBSKfOPb6hrxDZIkU="; + hash = "sha256-aacgJH0iJLRNEaZuVyzl/FxZgSnW3dIZFUfaqt0l88M="; }; x86_64-linux = { url = "https://www.rarlab.com/rar/rarlinux-x64-${downloadVersion}.tar.gz"; - hash = "sha256-3fr5aVkh/r6OfBEcZULJSZp5ydakJOLRPlgzMdlwGTM="; + hash = "sha256-iOIqjoQSXJR2N7vyjHRuM4oKYyedgPn51zc2A4ddses="; }; aarch64-darwin = { url = "https://www.rarlab.com/rar/rarmacos-arm-${downloadVersion}.tar.gz"; - hash = "sha256-OR9HBlRteTzuyQ06tyXTSrFTBHFwmZ41kUfvgflogT4="; + hash = "sha256-2r4zWDT7Xw/CNvA7oNEsGfrXJDzFa5gNthIB/5TYR5U="; }; x86_64-darwin = { url = "https://www.rarlab.com/rar/rarmacos-x64-${downloadVersion}.tar.gz"; - hash = "sha256-UN3gmEuIpCXwmw3/l+KdarAYLy1DxGoPAOB2bfJTGbw="; + hash = "sha256-4vENPNfMpQstsm9+8+glHPK9fAlDmnHWbCHW+HUwSX4="; }; }.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}"); manSrc = fetchurl { @@ -29,7 +33,7 @@ let hash = "sha256-93cSr9oAsi+xHUtMsUvICyHJe66vAImS2tLie7nt8Uw="; }; in -stdenv.mkDerivation rec { +stdenv.mkDerivation { pname = "rar"; inherit version; @@ -60,9 +64,10 @@ stdenv.mkDerivation rec { meta = with lib; { description = "Utility for RAR archives"; homepage = "https://www.rarlab.com/"; - sourceProvenance = with sourceTypes; [ binaryNativeCode ]; license = licenses.unfree; + mainProgram = "rar"; maintainers = with maintainers; [ thiagokokada ]; platforms = with platforms; linux ++ darwin; + sourceProvenance = with sourceTypes; [ binaryNativeCode ]; }; } From b2d0d556f1d97a932c65496cd15002a8463904ac Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Mon, 8 Jan 2024 15:57:48 +0000 Subject: [PATCH 3/4] rar: make update script get the latest version --- pkgs/tools/archivers/rar/default.nix | 4 ++- pkgs/tools/archivers/rar/update.sh | 48 +++++++++++++++++++++------- 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 ` 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 " - 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 From ce262e428718bbb65c7df5561eb20c3c2d9e0403 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Mon, 8 Jan 2024 19:27:17 +0000 Subject: [PATCH 4/4] rar: allow evaluation in all platforms --- pkgs/tools/archivers/rar/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/tools/archivers/rar/default.nix b/pkgs/tools/archivers/rar/default.nix index 8faa605b96d1..168316813f76 100644 --- a/pkgs/tools/archivers/rar/default.nix +++ b/pkgs/tools/archivers/rar/default.nix @@ -9,7 +9,7 @@ let version = "6.24"; downloadVersion = lib.replaceStrings [ "." ] [ "" ] version; # Use `./update.sh` to generate the entries below - srcUrl = { + srcs = { i686-linux = { url = "https://www.rarlab.com/rar/rarlinux-x32-${downloadVersion}.tar.gz"; hash = "sha256-aacgJH0iJLRNEaZuVyzl/FxZgSnW3dIZFUfaqt0l88M="; @@ -26,7 +26,7 @@ let url = "https://www.rarlab.com/rar/rarmacos-x64-${downloadVersion}.tar.gz"; hash = "sha256-4vENPNfMpQstsm9+8+glHPK9fAlDmnHWbCHW+HUwSX4="; }; - }.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}"); + }; manSrc = fetchurl { url = "https://aur.archlinux.org/cgit/aur.git/plain/rar.1?h=rar&id=8e39a12e88d8a3b168c496c44c18d443c876dd10"; name = "rar.1"; @@ -37,7 +37,7 @@ stdenv.mkDerivation { pname = "rar"; inherit version; - src = fetchurl srcUrl; + src = fetchurl (srcs.${stdenv.hostPlatform.system}); dontBuild = true; @@ -69,7 +69,7 @@ stdenv.mkDerivation { license = licenses.unfree; mainProgram = "rar"; maintainers = with maintainers; [ thiagokokada ]; - platforms = with platforms; linux ++ darwin; + platforms = lib.attrNames srcs; sourceProvenance = with sourceTypes; [ binaryNativeCode ]; }; }