diff options
author | Alyssa Ross <hi@alyssa.is> | 2024-01-20 12:31:50 +0100 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2024-01-20 12:32:25 +0100 |
commit | b7baf40e099b4215181fe7b0c63083b12ef2c7fb (patch) | |
tree | a6efabd31d05b6d0a36624729e80377bbbfb0149 /nixpkgs/pkgs/tools/archivers/rar/update.sh | |
parent | 710028664e26e85cb831a869b3da9f6993902255 (diff) | |
parent | 0799f514b1cd74878174939df79ac60ca5036673 (diff) | |
download | nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar.gz nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar.bz2 nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar.lz nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar.xz nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.tar.zst nixlib-b7baf40e099b4215181fe7b0c63083b12ef2c7fb.zip |
Merge branch 'nixos-unstable-small' of https://github.com/NixOS/nixpkgs
Conflicts: nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix
Diffstat (limited to 'nixpkgs/pkgs/tools/archivers/rar/update.sh')
-rwxr-xr-x | nixpkgs/pkgs/tools/archivers/rar/update.sh | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/tools/archivers/rar/update.sh b/nixpkgs/pkgs/tools/archivers/rar/update.sh new file mode 100755 index 000000000000..f81562727f29 --- /dev/null +++ b/nixpkgs/pkgs/tools/archivers/rar/update.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl gawk gnused pup jq + +set -euo pipefail + +DIRNAME=$(dirname "$0") +readonly DIRNAME +readonly NIXPKGS_ROOT="../../../.." +readonly NIX_FLAGS=(--extra-experimental-features 'nix-command flakes') + +# 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" + 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" +} + +latestVersion="${1:-}" +if [[ -z "$latestVersion" ]]; then + 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" + 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" |