1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl gawk gnused pup jq
6 DIRNAME
=$
(dirname "$0")
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
26 # Only get the value if it is bigger than the current one
27 if (val > max) max = val
31 printf "%.2f\n", max/100
36 local -r version
="${1//./}"
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"
50 sed -i "s|version = \"[0-9.]*\";|version = \"$version\";|g" "$DIRNAME/default.nix"
53 latestVersion
="${1:-}"
54 if [[ -z "$latestVersion" ]]; then
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"
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"