Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 50 lines 1.5 kB view raw
1#!/usr/bin/env nix-shell 2#!nix-shell -i bash -p curl jq git 3#shellcheck shell=bash 4 5set -euo pipefail 6 7SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) 8 9function prefetch-sri() { 10 nix-prefetch-url "$1" 2>/dev/null | 11 xargs nix --experimental-features nix-command hash to-sri --type sha256 12} 13 14declare -A platforms=( 15 [x86_64-unknown-linux-musl]="x86_64-linux" 16 [x86_64-apple-darwin]="x86_64-darwin" 17 [aarch64-apple-darwin]="aarch64-darwin" 18) 19 20old_version="$(jq -r '.version' "$SCRIPT_DIR/sources.json")" 21new_version="$(curl -sS https://update.tabnine.com/bundles/version)" 22 23echo "Updating $old_version -> $new_version" 24 25sources_tmp="$(mktemp)" 26trap 'rm -f "$sources_tmp"' EXIT 27 28cat <<EOF >"$sources_tmp" 29{ 30 "version": "$new_version", 31 "platforms": {} 32} 33EOF 34 35for platform in "${!platforms[@]}"; do 36 url="https://update.tabnine.com/bundles/${new_version}/${platform}/TabNine.zip" 37 hash="$(prefetch-sri "$url")" 38 nix_platform="${platforms[$platform]}" 39 cat <<<"$(jq --arg nix_platform "$nix_platform" --arg platform "$platform" --arg hash "$hash" '.platforms += {($nix_platform): {name: $platform, hash: $hash}}' "$sources_tmp")" >"$sources_tmp" 40done 41 42cp "$sources_tmp" "$SCRIPT_DIR/sources.json" 43 44if [[ `git status --porcelain "$SCRIPT_DIR/sources.json"` ]]; then 45 git add "$SCRIPT_DIR/sources.json" 46 git commit -m "tabnine: $old_version -> $new_version" 47else 48 echo "No changes made to $SCRIPT_DIR/sources.json, skipping commit" 49fi 50