Skip to content

Commit

Permalink
v2fly-geodata: add update script
Browse files Browse the repository at this point in the history
Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
  • Loading branch information
1715173329 committed Sep 30, 2023
1 parent 1e18f5e commit 0adc0a0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions v2fly-geodata/update.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 0adc0a0

Please sign in to comment.