Merge pull request #329823 from ExpidusOS/fix/pkgsllvm/elfutils
[NixPkgs.git] / pkgs / servers / invidious / update.sh
blob2ba5c3452c6c680eef9f5484609b6c105ab55dd5
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl crystal crystal2nix jq git moreutils nix nix-prefetch pkg-config pcre gnugrep
3 git_url='https://github.com/iv-org/invidious.git'
4 git_branch='master'
5 git_dir='/var/tmp/invidious.git'
6 pkg='invidious'
8 set -euo pipefail
10 cd "$(dirname "${BASH_SOURCE[0]}")"
12 info() {
13 if [ -t 2 ]; then
14 set -- '\033[32m%s\033[39m\n' "$@"
15 else
16 set -- '%s\n' "$@"
18 printf "$@" >&2
21 json_get() {
22 jq -r "$1" < 'versions.json'
25 json_set() {
26 jq --arg x "$2" "$1 = \$x" < 'versions.json' | sponge 'versions.json'
29 old_version=$(json_get '.invidious.version')
30 today=$(LANG=C date -u +'%Y-%m-%d')
32 info "fetching $git_url..."
33 if [ ! -d "$git_dir" ]; then
34 git init --initial-branch="$git_branch" "$git_dir"
35 git -C "$git_dir" remote add origin "$git_url"
37 git -C "$git_dir" fetch origin --tags "$git_branch"
39 new_tag="$(git -C "$git_dir" ls-remote --tags --sort=committerdate origin | head -n1 | grep -Po '(?<=refs/tags/).*')"
40 new_version="${new_tag#v}"
42 if [ "$new_version" = "$old_version" ]; then
43 info "$pkg is up-to-date."
44 exit
47 commit="$(git -C "$git_dir" rev-list "$new_tag" --max-count=1 --abbrev-commit)"
48 date="$(git -C "$git_dir" log -1 --format=%cd --date=format:%Y.%m.%d)"
49 json_set '.invidious.date' "$date"
50 json_set '.invidious.commit' "$commit"
51 json_set '.invidious.version' "$new_version"
53 new_hash=$(nix-prefetch -I 'nixpkgs=../../..' "$pkg")
54 json_set '.invidious.hash' "$new_hash"
56 # fetch video.js dependencies
57 info "Running scripts/fetch-player-dependencies.cr..."
58 git -C "$git_dir" reset --hard "$new_tag"
59 (cd "$git_dir" && crystal run scripts/fetch-player-dependencies.cr -- --minified)
60 rm -f "$git_dir/assets/videojs/.gitignore"
61 videojs_new_hash=$(nix-hash --type sha256 --sri "$git_dir/assets/videojs")
62 json_set '.videojs.hash' "$videojs_new_hash"
64 if git -C "$git_dir" diff-tree --quiet "v${old_version}..${new_tag}" -- 'shard.lock'; then
65 info "shard.lock did not change since v$old_version."
66 else
67 info "Updating shards.nix..."
68 (cd "$git_dir" && crystal2nix)
69 mv "$git_dir/shards.nix" .