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'
5 git_dir
='/var/tmp/invidious.git'
10 cd "$(dirname "${BASH_SOURCE[0]}")"
14 set -- '\033[32m%s\033[39m\n' "$@"
22 jq
-r "$1" < 'versions.json'
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."
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."
67 info
"Updating shards.nix..."
68 (cd "$git_dir" && crystal2nix
)
69 mv "$git_dir/shards.nix" .