rar: make update script get the latest version
This commit is contained in:
parent
c25a85bea5
commit
b2d0d556f1
2 changed files with 40 additions and 12 deletions
|
@ -8,7 +8,7 @@
|
||||||
let
|
let
|
||||||
version = "6.24";
|
version = "6.24";
|
||||||
downloadVersion = lib.replaceStrings [ "." ] [ "" ] version;
|
downloadVersion = lib.replaceStrings [ "." ] [ "" ] version;
|
||||||
# Use `./update.sh <version>` to generate the below
|
# Use `./update.sh` to generate the entries below
|
||||||
srcUrl = {
|
srcUrl = {
|
||||||
i686-linux = {
|
i686-linux = {
|
||||||
url = "https://www.rarlab.com/rar/rarlinux-x32-${downloadVersion}.tar.gz";
|
url = "https://www.rarlab.com/rar/rarlinux-x32-${downloadVersion}.tar.gz";
|
||||||
|
@ -61,6 +61,8 @@ stdenv.mkDerivation {
|
||||||
installManPage ${manSrc}
|
installManPage ${manSrc}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
passthru.updateScript = ./update.sh;
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
description = "Utility for RAR archives";
|
description = "Utility for RAR archives";
|
||||||
homepage = "https://www.rarlab.com/";
|
homepage = "https://www.rarlab.com/";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env nix-shell
|
#!/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
|
set -euo pipefail
|
||||||
|
|
||||||
|
@ -8,8 +8,31 @@ readonly DIRNAME
|
||||||
readonly NIXPKGS_ROOT="../../../.."
|
readonly NIXPKGS_ROOT="../../../.."
|
||||||
readonly NIX_FLAGS=(--extra-experimental-features 'nix-command flakes')
|
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 version="${1//./}"
|
||||||
local -r arch="$2"
|
local -r arch="$2"
|
||||||
local -r os="$3"
|
local -r os="$3"
|
||||||
|
@ -22,25 +45,28 @@ updateHash()
|
||||||
sed -i "s|$currentHash|$hash|g" "$DIRNAME/default.nix"
|
sed -i "s|$currentHash|$hash|g" "$DIRNAME/default.nix"
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVersion()
|
updateVersion() {
|
||||||
{
|
|
||||||
local -r version="$1"
|
local -r version="$1"
|
||||||
sed -i "s|version = \"[0-9.]*\";|version = \"$version\";|g" "$DIRNAME/default.nix"
|
sed -i "s|version = \"[0-9.]*\";|version = \"$version\";|g" "$DIRNAME/default.nix"
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: get latest version
|
latestVersion="${1:-}"
|
||||||
readonly latestVersion="${1:-}"
|
|
||||||
|
|
||||||
if [[ -z "$latestVersion" ]]; then
|
if [[ -z "$latestVersion" ]]; then
|
||||||
echo "usage: $0 <version to update>"
|
latestVersion=$(
|
||||||
exit 1
|
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
|
fi
|
||||||
|
readonly latestVersion
|
||||||
|
echo "Latest version: $latestVersion"
|
||||||
|
|
||||||
currentVersion=$(cd "$DIRNAME" && nix "${NIX_FLAGS[@]}" eval --raw "$NIXPKGS_ROOT#legacyPackages.x86_64-linux.rar.version")
|
currentVersion=$(cd "$DIRNAME" && nix "${NIX_FLAGS[@]}" eval --raw "$NIXPKGS_ROOT#legacyPackages.x86_64-linux.rar.version")
|
||||||
readonly currentVersion
|
readonly currentVersion
|
||||||
|
echo "Current version: $currentVersion"
|
||||||
|
|
||||||
if [[ "$currentVersion" == "$latestVersion" ]]; then
|
if [[ "$currentVersion" == "$latestVersion" ]]; then
|
||||||
echo "rar is up-to-date: ${currentVersion}"
|
echo "rar is up-to-date"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue