chromium,chromedriver: 129.0.6668.91 -> 129.0.6668.100
[NixPkgs.git] / pkgs / by-name / mi / miru / update.sh
blobe2d2cba736a645f0139c78fba463f83f2424042d
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl jq gnused
4 set -euo pipefail
6 ROOT="$(dirname "$(readlink -f "$0")")"
7 if [[ ! "$(basename $ROOT)" == "miru" || ! -f "$ROOT/package.nix" ]]; then
8 echo "error: Not in the miru folder" >&2
9 exit 1
12 PACKAGE_NIX="$ROOT/package.nix"
13 LINUX_NIX="$ROOT/linux.nix"
14 DARWIN_NIX="$ROOT/darwin.nix"
16 MIRU_LATEST_VER="$(curl -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} "https://api.github.com/repos/ThaUnknown/miru/releases/latest" | jq -r .tag_name | sed 's/^v//')"
17 MIRU_CURRENT_VER="$(grep -oP 'version = "\K[^"]+' "$PACKAGE_NIX")"
19 if [[ "$MIRU_LATEST_VER" == "null" ]]; then
20 echo "error: could not fetch miru latest version from GitHub API" >&2
21 exit 1
24 if [[ "$MIRU_LATEST_VER" == "$MIRU_CURRENT_VER" ]]; then
25 echo "miru is up-to-date"
26 exit 0
29 get_hash() {
30 # $1: URL
31 nix-hash --to-sri --type sha256 "$(nix-prefetch-url --type sha256 "$1")"
34 replace_hash_in_file() {
35 # $1: file
36 # $2: new hash
37 sed -i "s#hash = \".*\"#hash = \"$2\"#g" "$1"
40 replace_version_in_file() {
41 # $1: file
42 # $2: new version
43 sed -i "s#version = \".*\";#version = \"$2\";#g" "$1"
46 MIRU_LINUX_HASH="$(get_hash "https://github.com/ThaUnknown/miru/releases/download/v${MIRU_LATEST_VER}/linux-Miru-${MIRU_LATEST_VER}.AppImage")"
47 MIRU_DARWIN_HASH="$(get_hash "https://github.com/ThaUnknown/miru/releases/download/v${MIRU_LATEST_VER}/mac-Miru-${MIRU_LATEST_VER}-mac.zip")"
49 replace_hash_in_file "$LINUX_NIX" "$MIRU_LINUX_HASH"
50 replace_hash_in_file "$DARWIN_NIX" "$MIRU_DARWIN_HASH"
52 replace_version_in_file "$PACKAGE_NIX" "$MIRU_LATEST_VER"