67 lines
2.0 KiB
Bash
Executable File
67 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
SURGE_DIR="$ROOT_DIR/rule/Surge"
|
|
SINGBOX_DIR="$ROOT_DIR/rule/sing-box"
|
|
UPSTREAM_BASE="https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Surge"
|
|
LOCAL_SYNC_ENV_FILE="$ROOT_DIR/.sync.env"
|
|
|
|
if [[ -f "$LOCAL_SYNC_ENV_FILE" ]]; then
|
|
source "$LOCAL_SYNC_ENV_FILE"
|
|
fi
|
|
|
|
GITEA_REPO_OWNER="${GITEA_REPO_OWNER:-yuanzhen869}"
|
|
GITEA_REPO_NAME="${GITEA_REPO_NAME:-ios-rule-script-subset}"
|
|
GITEA_SYNC_USERNAME="${GITEA_SYNC_USERNAME:-yuanzhen869}"
|
|
GITEA_SYNC_EMAIL="${GITEA_SYNC_EMAIL:-yuanzhen869@gmail.com}"
|
|
GITEA_SYNC_PASSWORD="${GITEA_SYNC_PASSWORD:-${GITEA_SYNC_TOKEN:-}}"
|
|
|
|
if [[ -z "${GITEA_SYNC_PASSWORD}" ]]; then
|
|
echo "missing push credential: set GITEA_SYNC_TOKEN" >&2
|
|
exit 1
|
|
fi
|
|
|
|
GITEA_REMOTE_URL="https://${GITEA_SYNC_USERNAME}:${GITEA_SYNC_PASSWORD}@git.halonice.com/${GITEA_REPO_OWNER}/${GITEA_REPO_NAME}.git"
|
|
|
|
mkdir -p "$SURGE_DIR"
|
|
mkdir -p "$SINGBOX_DIR"
|
|
|
|
while IFS='|' read -r target src; do
|
|
[[ -z "$target" ]] && continue
|
|
tmp="$SURGE_DIR/.${target}.tmp"
|
|
curl -fsSL "$UPSTREAM_BASE/$src" -o "$tmp"
|
|
mv "$tmp" "$SURGE_DIR/$target"
|
|
done <<'EOF'
|
|
Lan.list|Lan/Lan.list
|
|
Apple.list|Apple/Apple.list
|
|
OpenAI.list|OpenAI/OpenAI.list
|
|
Gemini.list|Gemini/Gemini.list
|
|
Claude.list|Claude/Claude.list
|
|
China.list|China/China.list
|
|
ChinaIPs.list|ChinaIPs/ChinaIPs.list
|
|
Proxy.list|Proxy/Proxy.list
|
|
EOF
|
|
|
|
python3 "$ROOT_DIR/scripts/build_singbox_rules.py"
|
|
|
|
cd "$ROOT_DIR"
|
|
|
|
if [[ ! -d .git ]]; then
|
|
git init -b main >/dev/null
|
|
git remote add origin "$GITEA_REMOTE_URL"
|
|
else
|
|
git remote set-url origin "$GITEA_REMOTE_URL"
|
|
fi
|
|
|
|
git add README.md .gitignore scripts/sync_subset.sh scripts/build_singbox_rules.py rule/Surge rule/sing-box
|
|
|
|
if git diff --cached --quiet; then
|
|
echo "No upstream changes."
|
|
exit 0
|
|
fi
|
|
|
|
git -c user.name="$GITEA_SYNC_USERNAME" -c user.email="$GITEA_SYNC_EMAIL" commit -m "Sync subset from blackmatrix7/ios_rule_script" >/dev/null
|
|
|
|
git push origin main
|