From 0adc0a0cc1ecd3ad6735d49adafc88a11a18a620 Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Sat, 30 Sep 2023 19:49:05 +0800 Subject: [PATCH] v2fly-geodata: add update script Signed-off-by: Tianling Shen --- v2fly-geodata/update.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 v2fly-geodata/update.sh diff --git a/v2fly-geodata/update.sh b/v2fly-geodata/update.sh new file mode 100644 index 0000000..8a6bdef --- /dev/null +++ b/v2fly-geodata/update.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -x + +export CURDIR="$(cd "$(dirname $0)"; pwd)" + +function update_geodata() { + local type="$1" + local repo="$2" + local res="$3" + local tag ver sha line + + tag="$(curl -H "Authorization: $GITHUB_TOKEN" -sL "https://api.github.com/repos/$repo/releases/latest" | jq -r ".tag_name")" + [ -n "$tag" ] || return 1 + + ver="$(awk -F "${type}_VER:=" '{print $2}' "$CURDIR/Makefile" | xargs)" + [ "$tag" != "$ver" ] || return 2 + + sha="$(curl -fsSL "https://github.com/$repo/releases/download/$tag/$res.dat.sha256sum" | awk '{print $1}')" + [ -n "$sha" ] || return 1 + + line="$(awk "/FILE:=\\$\(${type}_FILE\)/ {print NR}" "$CURDIR/Makefile")" + sed -i -e "s/${type}_VER:=.*/${type}_VER:=$tag/" \ + -e "$((line + 1))s/HASH:=.*/HASH:=$sha/" \ + "$CURDIR/Makefile" +} + +update_geodata "GEOIP" "v2fly/geoip" "geoip" +update_geodata "GEOSITE" "v2fly/domain-list-community" "dlc"