diff options
author | schnusch <schnusch@users.noreply.github.com> | 2021-12-15 15:38:00 +0100 |
---|---|---|
committer | schnusch <schnusch@users.noreply.github.com> | 2022-03-12 12:16:33 +0100 |
commit | d697ee65ebec9c26250bc1e272ee61b8cffb650d (patch) | |
tree | 5484def7da524b4e5d5ded6e53e0b98157e83b1a | |
parent | 970d249d39ccac356c705e6e4db6318ffe93dd42 (diff) |
invidious: add update script
based on mpvScripts.sponsorblock's update script
-rw-r--r-- | pkgs/servers/invidious/default.nix | 6 | ||||
-rwxr-xr-x | pkgs/servers/invidious/update.sh | 84 |
2 files changed, 89 insertions, 1 deletions
diff --git a/pkgs/servers/invidious/default.nix b/pkgs/servers/invidious/default.nix index a50c128b03f57..ef4df055adb22 100644 --- a/pkgs/servers/invidious/default.nix +++ b/pkgs/servers/invidious/default.nix @@ -88,7 +88,11 @@ crystal.buildCrystalPackage rec { INVIDIOUS_CONFIG="database_url: sqlite3:///dev/null" $out/bin/invidious --help ''; - passthru.tests = { inherit (nixosTests) invidious; }; + passthru = { + inherit lsquic; + tests = { inherit (nixosTests) invidious; }; + updateScript = ./update.sh; + }; meta = with lib; { description = "An open source alternative front-end to YouTube"; diff --git a/pkgs/servers/invidious/update.sh b/pkgs/servers/invidious/update.sh new file mode 100755 index 0000000000000..2824f8aaab984 --- /dev/null +++ b/pkgs/servers/invidious/update.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p common-updater-scripts curl crystal2nix jq git gnused nix nix-prefetch-git nix-update +git_url='https://github.com/iv-org/invidious.git' +git_branch='master' +git_dir='/var/tmp/invidious.git' +nix_file="$(dirname "${BASH_SOURCE[0]}")/default.nix" +pkg='invidious' + +set -euo pipefail + +info() { + if [ -t 2 ]; then + set -- '\033[32m%s\033[39m\n' "$@" + else + set -- '%s\n' "$@" + fi + printf "$@" >&2 +} + +old_rev=$(nix-instantiate --eval --strict --json -A "$pkg.src.rev" | jq -r) +old_version=$(nix-instantiate --eval --strict --json -A "$pkg.version" | jq -r) +today=$(LANG=C date -u +'%Y-%m-%d') + +info "fetching $git_url..." +if [ ! -d "$git_dir" ]; then + git init --initial-branch="$git_branch" "$git_dir" + git -C "$git_dir" remote add origin "$git_url" +fi +git -C "$git_dir" fetch origin "$git_branch" + +# use latest commit before today, we should not call the version *today* +# because there might still be commits coming +# use the day of the latest commit we picked as version +new_rev=$(git -C "$git_dir" log -n 1 --format='format:%H' --before="${today}T00:00:00Z" "origin/$git_branch") +new_version="unstable-$(git -C "$git_dir" log -n 1 --format='format:%cs' "$new_rev")" +info "latest commit before $today: $new_rev" + +if [ "$new_rev" = "$old_rev" ]; then + info "$pkg is up-to-date." + exit +fi + +new_sha256=$(nix-prefetch-git --rev "$new_rev" "$git_dir" | jq -r .sha256) +update-source-version "$pkg" \ + "$new_version" \ + "$new_sha256" \ + --rev="$new_rev" +git add "$nix_file" +commit_msg="$pkg: $old_version -> $new_version" + +cd "${nix_file%/*}" +if git -C "$git_dir" diff-tree --quiet "${old_rev}..${new_rev}" -- 'shard.lock'; then + info "shard.lock did not change since $old_rev." +else + info "Updating shards.nix..." + git -C "$git_dir" reset --hard "$new_rev" + crystal2nix -- "$git_dir/shard.lock" # argv's index seems broken + git add 'shards.nix' + + lsquic_old_version=$(nix-instantiate --eval --strict --json -A "${pkg}.lsquic.version" '../../..' | jq -r) + lsquic_new_version=$(nix eval --raw -f 'shards.nix' lsquic.rev \ + | sed -e 's/^v//' -e 's/-[0-9]*$//') + if [ "$lsquic_old_version" != "$lsquic_new_version" ]; then + info "Updating lsquic to $lsquic_new_version..." + nix-update --version "$lsquic_new_version" -f '../../..' invidious.lsquic + if git diff-index --quiet HEAD -- 'lsquic.nix'; then + info "lsquic is up-to-date." + else + boringssl_new_version=$(curl -LSsf "https://github.com/litespeedtech/lsquic/raw/v${lsquic_new_version}/README.md" \ + | grep -Pom1 '(?<=^git checkout ).*') + boringssl_new_sha256=$(nix-prefetch-git --rev "$boringssl_new_version" 'https://boringssl.googlesource.com/boringssl' \ + | jq -r .sha256) + sed -e "0,/^ *version = .*/ s// version = \"$boringssl_new_version\";/" \ + -e "0,/^ *sha256 = .*/ s// sha256 = \"$boringssl_new_sha256\";/" \ + -i lsquic.nix + git add 'lsquic.nix' + commit_msg="$commit_msg + +lsquic: $lsquic_old_version -> $lsquic_new_version" + fi + fi +fi + +git commit --verbose --message "$commit_msg" |