Initial commit: merged geosite build pipeline
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
#!/bin/sh
|
||||
# auto-build-push.sh — builds the merged geosite.dat and pushes it to a
|
||||
# Gitea repo, so it can be served the same way rules.yaml already is
|
||||
# (https://<gitea>/<owner>/<repo>/raw/branch/<branch>/geosite.dat).
|
||||
#
|
||||
# Required environment variables (set these in the Portainer stack, not
|
||||
# baked into the image):
|
||||
# GITEA_URL e.g. https://git.5838.ru
|
||||
# GITEA_REPO e.g. Payroll3042/geosite-build (must already exist, empty is fine)
|
||||
# GITEA_TOKEN a Gitea personal access token with repo write access
|
||||
# GIT_USER_NAME e.g. geosite-bot
|
||||
# GIT_USER_EMAIL e.g. geosite-bot@5838.ru
|
||||
# Optional:
|
||||
# GITEA_BRANCH defaults to main
|
||||
|
||||
set -eu
|
||||
|
||||
: "${GITEA_URL:?GITEA_URL is required}"
|
||||
: "${GITEA_REPO:?GITEA_REPO is required, e.g. Payroll3042/geosite-build}"
|
||||
: "${GITEA_TOKEN:?GITEA_TOKEN is required}"
|
||||
: "${GIT_USER_NAME:?GIT_USER_NAME is required}"
|
||||
: "${GIT_USER_EMAIL:?GIT_USER_EMAIL is required}"
|
||||
GITEA_BRANCH="${GITEA_BRANCH:-main}"
|
||||
|
||||
WORKDIR=/tmp/build
|
||||
OUTDIR=/tmp/output
|
||||
CUSTOM_DIR=/app/data-custom
|
||||
|
||||
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) ==> Starting build"
|
||||
|
||||
rm -rf "$WORKDIR" "$OUTDIR"
|
||||
mkdir -p "$WORKDIR" "$OUTDIR"
|
||||
cd "$WORKDIR"
|
||||
|
||||
echo "==> Cloning v2fly/domain-list-community"
|
||||
git clone --depth 1 -q https://github.com/v2fly/domain-list-community.git v2fly
|
||||
|
||||
echo "==> Cloning hydraponique/roscomvpn-geosite"
|
||||
git clone --depth 1 -q https://github.com/hydraponique/roscomvpn-geosite.git roscomvpn-src
|
||||
|
||||
echo "==> Merging data directories"
|
||||
mkdir -p v2fly/data/roscomvpn v2fly/data/custom
|
||||
cp -r roscomvpn-src/data/. v2fly/data/roscomvpn/
|
||||
if [ -d "$CUSTOM_DIR" ]; then
|
||||
cp -r "$CUSTOM_DIR/." v2fly/data/custom/
|
||||
fi
|
||||
|
||||
echo "==> Compiling merged geosite.dat"
|
||||
cd v2fly
|
||||
go run main.go
|
||||
|
||||
if [ ! -f dlc.dat ]; then
|
||||
echo "ERROR: build did not produce dlc.dat"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp dlc.dat "$OUTDIR/geosite.dat"
|
||||
echo "==> Build produced $(wc -c < "$OUTDIR/geosite.dat") bytes"
|
||||
|
||||
echo "==> Cloning target Gitea repo"
|
||||
GITEA_HOST="$(echo "$GITEA_URL" | sed -e 's~https\?://~~')"
|
||||
PUSH_URL="https://${GITEA_TOKEN}@${GITEA_HOST}/${GITEA_REPO}.git"
|
||||
|
||||
cd /tmp
|
||||
rm -rf repo
|
||||
git clone -q --branch "$GITEA_BRANCH" "$PUSH_URL" repo || git clone -q "$PUSH_URL" repo
|
||||
cd repo
|
||||
|
||||
git config user.name "$GIT_USER_NAME"
|
||||
git config user.email "$GIT_USER_EMAIL"
|
||||
|
||||
cp "$OUTDIR/geosite.dat" ./geosite.dat
|
||||
|
||||
if git diff --quiet -- geosite.dat 2>/dev/null && [ -f geosite.dat ]; then
|
||||
echo "==> No changes since last build, skipping commit"
|
||||
else
|
||||
git add geosite.dat
|
||||
git commit -q -m "Auto-build $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||
git push -q origin "HEAD:${GITEA_BRANCH}"
|
||||
echo "==> Pushed updated geosite.dat to ${GITEA_URL}/${GITEA_REPO}"
|
||||
fi
|
||||
|
||||
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) ==> Done"
|
||||
Reference in New Issue
Block a user