2020-04-24 23:36:52 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#!nix-shell -i bash -p curl jq
|
|
|
|
set -eo pipefail
|
2020-07-18 16:06:22 +00:00
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-07-18 16:06:22 +00:00
|
|
|
version_nix=./default.nix
|
|
|
|
deps_nix=./deps.nix
|
|
|
|
nixpkgs=../../../..
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-07-18 16:06:22 +00:00
|
|
|
old_core_rev=$(sed -En 's/.*\bversion = "(.*?)".*/\1/p' "$version_nix")
|
2020-04-24 23:36:52 +00:00
|
|
|
old_geoip_rev=$(sed -En 's/.*\bgeoipRev = "(.*?)".*/\1/p' "$version_nix")
|
|
|
|
old_geosite_rev=$(sed -En 's/.*\bgeositeRev = "(.*?)".*/\1/p' "$version_nix")
|
|
|
|
echo "Current version:" >&2
|
|
|
|
echo "core: $old_core_rev, geoip: $old_geoip_rev, geosite: $old_geosite_rev" >&2
|
|
|
|
|
|
|
|
function fetch_latest_rev {
|
2020-11-21 19:51:51 +00:00
|
|
|
curl "https://api.github.com/repos/v2fly/$1/releases" |
|
2020-04-24 23:36:52 +00:00
|
|
|
jq '.[0].tag_name' --raw-output
|
|
|
|
}
|
|
|
|
|
|
|
|
core_rev=$(fetch_latest_rev 'v2ray-core')
|
2020-07-18 16:06:22 +00:00
|
|
|
core_rev=${core_rev:1}
|
2020-04-24 23:36:52 +00:00
|
|
|
geoip_rev=$(fetch_latest_rev 'geoip')
|
|
|
|
geosite_rev=$(fetch_latest_rev 'domain-list-community')
|
|
|
|
echo "Latest version:" >&2
|
|
|
|
echo "core: $core_rev, geoip: $geoip_rev, geosite: $geosite_rev" >&2
|
|
|
|
|
|
|
|
if [[ $core_rev != $old_core_rev ]]; then
|
|
|
|
echo "Prefetching core..." >&2
|
|
|
|
{ read hash; read store_path; } < <(
|
2020-11-21 19:51:51 +00:00
|
|
|
nix-prefetch-url --unpack --print-path "https://github.com/v2fly/v2ray-core/archive/v$core_rev.zip"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
sed --in-place \
|
2020-07-18 16:06:22 +00:00
|
|
|
-e "s/\bversion = \".*\"/version = \"$core_rev\"/" \
|
2020-04-24 23:36:52 +00:00
|
|
|
-e "s/\bsha256 = \".*\"/sha256 = \"$hash\"/" \
|
2020-07-18 16:06:22 +00:00
|
|
|
-e "s/\bvendorSha256 = \".*\"/vendorSha256 = \"0000000000000000000000000000000000000000000000000000\"/" \
|
2020-04-24 23:36:52 +00:00
|
|
|
"$version_nix"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $geoip_rev != $old_geoip_rev ]]; then
|
|
|
|
echo "Prefetching geoip..." >&2
|
2020-11-21 19:51:51 +00:00
|
|
|
hash=$(nix-prefetch-url "https://github.com/v2fly/geoip/releases/download/$geoip_rev/geoip.dat")
|
2020-04-24 23:36:52 +00:00
|
|
|
sed --in-place \
|
|
|
|
-e "s/\bgeoipRev = \".*\"/geoipRev = \"$geoip_rev\"/" \
|
|
|
|
-e "s/\bgeoipSha256 = \".*\"/geoipSha256 = \"$hash\"/" \
|
|
|
|
"$version_nix"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $geosite_rev != $old_geosite_rev ]]; then
|
|
|
|
echo "Prefetching geosite..." >&2
|
2020-11-21 19:51:51 +00:00
|
|
|
hash=$(nix-prefetch-url "https://github.com/v2fly/domain-list-community/releases/download/$geosite_rev/dlc.dat")
|
2020-04-24 23:36:52 +00:00
|
|
|
sed --in-place \
|
|
|
|
-e "s/\bgeositeRev = \".*\"/geositeRev = \"$geosite_rev\"/" \
|
|
|
|
-e "s/\bgeositeSha256 = \".*\"/geositeSha256 = \"$hash\"/" \
|
|
|
|
"$version_nix"
|
|
|
|
fi
|
2020-07-18 16:06:22 +00:00
|
|
|
|
|
|
|
echo "Prebuilding..." >&2
|
|
|
|
set +o pipefail
|
|
|
|
vendorSha256=$(
|
|
|
|
nix-build "$nixpkgs" -A v2ray --no-out-link 2>&1 |
|
|
|
|
tee /dev/stderr |
|
2021-03-09 03:18:52 +00:00
|
|
|
sed -nE 's/.*got:\s*(sha256\S+)$/\1/p'
|
2020-07-18 16:06:22 +00:00
|
|
|
)
|
|
|
|
[[ "$vendorSha256" ]]
|
|
|
|
sed --in-place \
|
|
|
|
-e "s/vendorSha256 = \".*\"/vendorSha256 = \"$vendorSha256\"/" \
|
|
|
|
"$version_nix"
|
|
|
|
|
|
|
|
echo "vendorSha256 updated" >&2
|