otadump: init at 0.1.2 (#329129)
[NixPkgs.git] / pkgs / by-name / ya / yazi-unwrapped / update.sh
blobe87b94dfc2419c8a9e9bc69e9561628c51899f5b
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p bash nix-update curl coreutils jq common-updater-scripts nix-prefetch
4 set -eux
6 NIXPKGS_DIR="$PWD"
7 SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
9 # Get latest release
10 YAZI_RELEASE=$(
11 curl --silent ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
12 https://api.github.com/repos/sxyazi/yazi/releases/latest
15 # Get release information
16 latestBuildDate=$(echo "$YAZI_RELEASE" | jq -r ".published_at")
17 latestVersion=$(echo "$YAZI_RELEASE" | jq -r ".tag_name")
19 latestBuildDate="${latestBuildDate%T*}" # remove the timestamp and get the date
20 latestVersion="${latestVersion:1}" # remove first char 'v'
22 oldVersion=$(nix eval --raw -f "$NIXPKGS_DIR" yazi-unwrapped.version)
24 if [[ "$oldVersion" == "$latestVersion" ]]; then
25 echo "Yazi is up-to-date: ${oldVersion}"
26 exit 0
29 echo "Updating Yazi"
31 # Version
32 update-source-version yazi-unwrapped "${latestVersion}"
34 pushd "$SCRIPT_DIR"
35 # Build date
36 sed -i 's#env.VERGEN_BUILD_DATE = "[^"]*"#env.VERGEN_BUILD_DATE = "'"${latestBuildDate}"'"#' package.nix
38 # Hashes
39 cargoHash=$(nix-prefetch "{ sha256 }: (import $NIXPKGS_DIR {}).yazi-unwrapped.cargoDeps.overrideAttrs (_: { outputHash = sha256; })")
40 sed -i -E 's#\bcargoHash = ".*?"#cargoHash = "'"$cargoHash"'"#' package.nix
41 popd