1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p curl jq libxml2
3
4set -eu -o pipefail
5
6nixpkgs="$(git rev-parse --show-toplevel)"
7path="$nixpkgs/pkgs/os-specific/linux/prl-tools/default.nix"
8
9# Currently this script only supports Parallels 20
10# Please change the knowledge base url after each major release
11kb_url="https://kb.parallels.com/en/130212"
12content="$(curl -s "$kb_url")"
13
14# Parse HTML content and retrieve og:description for header metadata
15description=$(echo "$content" | xmllint --recover --html --xpath 'string(//meta[@property="og:description"]/@content)' - 2>/dev/null)
16regex='[^0-9]+([0-9]+\.[0-9]+\.[0-9]+)[^\(]+\(([0-9]+)\)'
17if [[ $description =~ $regex ]]; then
18 version="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}"
19 echo "Found latest version: $version"
20else
21 echo "Failed to extract version from $kb_url" >&2
22 echo "Retrived description: $description" >&2
23 exit 1
24fi
25
26# Extract and compare current version
27old_version="$(grep -o 'version = ".*"' "$path" | awk -F'"' '{print $2}')"
28if [[ "$old_version" > "$version" || "$old_version" == "$version" ]]; then
29 echo "Current version $old_version is up-to-date"
30 exit 0
31fi
32
33# Update version and hash
34major_version=$(echo $version | cut -d. -f1)
35dmg_url="https://download.parallels.com/desktop/v${major_version}/${version}/ParallelsDesktop-${version}.dmg"
36sha256="$(nix store prefetch-file $dmg_url --json | jq -r '.hash')"
37sed -i -e "s,version = \"$old_version\",version = \"$version\"," \
38 -e "s,hash = \"sha256-.*\",hash = \"$sha256\"," "$path"
39
40echo "Updated linuxPackages_latest.prl-tools $old_version -> $version"