biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / tools / archivers / rar / update.sh
blobf81562727f29d70255f910138bfba3803dc5a8dd
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl gawk gnused pup jq
4 set -euo pipefail
6 DIRNAME=$(dirname "$0")
7 readonly DIRNAME
8 readonly NIXPKGS_ROOT="../../../.."
9 readonly NIX_FLAGS=(--extra-experimental-features 'nix-command flakes')
11 # awk is used for parsing the RARLAB website to get the newest version
12 readonly AWK_FIELD_SEPARATOR='[-.]'
13 # shellcheck disable=SC2016
14 readonly AWK_COMMAND='
15 # We will get the following output from pup:
16 # /rar/rarlinux-x64-700b3.tar.gz
17 # /rar/rarmacos-x64-700b3.tar.gz
18 # /rar/rarlinux-x64-624.tar.gz
19 # /rar/rarbsd-x64-624.tar.gz
20 # /rar/rarmacos-x64-624.tar.gz
22 # Ignore anything that is flagged as beta (e.g.: `/rar/rarlinux-x64-700b3.tar.gz`)
23 !/[0-9]+b[0-9]*.tar.gz$/ {
24 # /rar/rarlinux-x64-624.tar.gz -> 624
25 val = $3
26 # Only get the value if it is bigger than the current one
27 if (val > max) max = val
29 END {
30 # 624 -> 6.24
31 printf "%.2f\n", max/100
35 updateHash() {
36 local -r version="${1//./}"
37 local -r arch="$2"
38 local -r os="$3"
39 local -r nix_arch="$4"
41 url="https://www.rarlab.com/rar/rar$os-$arch-$version.tar.gz"
42 hash=$(nix store prefetch-file --json "$url" | jq -r .hash)
43 currentHash=$(cd "$DIRNAME" && nix "${NIX_FLAGS[@]}" eval --raw "$NIXPKGS_ROOT#legacyPackages.$nix_arch.rar.src.outputHash")
45 sed -i "s|$currentHash|$hash|g" "$DIRNAME/default.nix"
48 updateVersion() {
49 local -r version="$1"
50 sed -i "s|version = \"[0-9.]*\";|version = \"$version\";|g" "$DIRNAME/default.nix"
53 latestVersion="${1:-}"
54 if [[ -z "$latestVersion" ]]; then
55 latestVersion=$(
56 curl --silent --location --fail https://www.rarlab.com/download.htm | \
57 pup 'a[href*=".tar.gz"] attr{href}' | \
58 awk -F"$AWK_FIELD_SEPARATOR" "$AWK_COMMAND"
61 readonly latestVersion
62 echo "Latest version: $latestVersion"
64 currentVersion=$(cd "$DIRNAME" && nix "${NIX_FLAGS[@]}" eval --raw "$NIXPKGS_ROOT#legacyPackages.x86_64-linux.rar.version")
65 readonly currentVersion
66 echo "Current version: $currentVersion"
68 if [[ "$currentVersion" == "$latestVersion" ]]; then
69 echo "rar is up-to-date"
70 exit 0
73 updateHash "$latestVersion" x32 linux i686-linux
74 updateHash "$latestVersion" x64 linux x86_64-linux
75 updateHash "$latestVersion" arm macos aarch64-darwin
76 updateHash "$latestVersion" x64 macos x86_64-darwin
78 updateVersion "$latestVersion"