2019-10-02 20:05:07 +01:00
|
|
|
#!/usr/bin/env nix-shell
|
2019-11-27 18:09:18 +00:00
|
|
|
#!nix-shell -i bash -p curl jq
|
2019-10-02 20:05:07 +01:00
|
|
|
set -eo pipefail
|
2020-07-08 18:14:28 +01:00
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
2019-10-02 20:05:07 +01:00
|
|
|
|
2020-07-08 18:14:28 +01:00
|
|
|
version_nix=./default.nix
|
|
|
|
deps_nix=./deps.nix
|
|
|
|
nixpkgs=../../../..
|
2019-10-02 20:05:07 +01:00
|
|
|
|
2020-07-08 18:14:28 +01:00
|
|
|
old_core_rev=$(sed -En 's/.*\bversion = "(.*?)".*/\1/p' "$version_nix")
|
2019-10-02 20:05:07 +01:00
|
|
|
echo "Current version:" >&2
|
2021-12-14 08:13:01 +00:00
|
|
|
echo "core: $old_core_rev" >&2
|
2019-10-02 20:05:07 +01:00
|
|
|
|
|
|
|
function fetch_latest_rev {
|
2020-11-09 17:08:43 +00:00
|
|
|
curl "https://api.github.com/repos/v2fly/$1/releases" |
|
2019-10-02 20:05:07 +01:00
|
|
|
jq '.[0].tag_name' --raw-output
|
|
|
|
}
|
|
|
|
|
|
|
|
core_rev=$(fetch_latest_rev 'v2ray-core')
|
2020-07-08 18:14:28 +01:00
|
|
|
core_rev=${core_rev:1}
|
2019-10-02 20:05:07 +01:00
|
|
|
echo "Latest version:" >&2
|
2021-12-14 08:13:01 +00:00
|
|
|
echo "core: $core_rev" >&2
|
2019-10-02 20:05:07 +01:00
|
|
|
|
|
|
|
if [[ $core_rev != $old_core_rev ]]; then
|
|
|
|
echo "Prefetching core..." >&2
|
|
|
|
{ read hash; read store_path; } < <(
|
2020-11-09 17:08:43 +00:00
|
|
|
nix-prefetch-url --unpack --print-path "https://github.com/v2fly/v2ray-core/archive/v$core_rev.zip"
|
2019-10-02 20:05:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
sed --in-place \
|
2020-07-08 18:14:28 +01:00
|
|
|
-e "s/\bversion = \".*\"/version = \"$core_rev\"/" \
|
2019-10-02 20:05:07 +01:00
|
|
|
-e "s/\bsha256 = \".*\"/sha256 = \"$hash\"/" \
|
2020-07-08 18:14:28 +01:00
|
|
|
-e "s/\bvendorSha256 = \".*\"/vendorSha256 = \"0000000000000000000000000000000000000000000000000000\"/" \
|
2019-10-02 20:05:07 +01:00
|
|
|
"$version_nix"
|
|
|
|
fi
|
|
|
|
|
2020-07-08 18:14:28 +01:00
|
|
|
echo "Prebuilding..." >&2
|
|
|
|
set +o pipefail
|
|
|
|
vendorSha256=$(
|
|
|
|
nix-build "$nixpkgs" -A v2ray --no-out-link 2>&1 |
|
|
|
|
tee /dev/stderr |
|
2021-03-08 18:18:07 +00:00
|
|
|
sed -nE 's/.*got:\s*(sha256\S+)$/\1/p'
|
2020-07-08 18:14:28 +01:00
|
|
|
)
|
|
|
|
[[ "$vendorSha256" ]]
|
|
|
|
sed --in-place \
|
2021-03-17 07:22:10 +00:00
|
|
|
-e "s#vendorSha256 = \".*\"#vendorSha256 = \"$vendorSha256\"#" \
|
2020-07-08 18:14:28 +01:00
|
|
|
"$version_nix"
|
|
|
|
|
|
|
|
echo "vendorSha256 updated" >&2
|