| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/usr/bin/env bash
- set -euo pipefail
- APP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
- CONFIG_PATH="${1:-${APP_DIR}/config.json}"
- DOMAIN_FILE="${APP_DIR}/runtime/current_domain.txt"
- before=""
- if [[ -f "$DOMAIN_FILE" ]]; then
- before="$(tr -d '\r\n' < "$DOMAIN_FILE")"
- fi
- /usr/bin/python3 "${APP_DIR}/scripts/domain_updater.py" --config "$CONFIG_PATH"
- after=""
- if [[ -f "$DOMAIN_FILE" ]]; then
- after="$(tr -d '\r\n' < "$DOMAIN_FILE")"
- fi
- if [[ -z "$after" ]]; then
- echo "[vmess-domain-rotator] empty selected domain, skip git commit"
- exit 0
- fi
- if [[ "$before" == "$after" ]]; then
- echo "[vmess-domain-rotator] domain unchanged (${after}), skip git commit"
- exit 0
- fi
- if ! command -v git >/dev/null 2>&1; then
- echo "[vmess-domain-rotator] git not found, skip git commit"
- exit 0
- fi
- if ! git -C "$APP_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
- echo "[vmess-domain-rotator] not a git repo, skip git commit"
- exit 0
- fi
- git -C "$APP_DIR" add runtime/current_domain.txt runtime/current_domain.json runtime/state.json runtime/substore_vars.json || true
- if git -C "$APP_DIR" diff --cached --quiet; then
- echo "[vmess-domain-rotator] no staged changes, skip git commit"
- exit 0
- fi
- commit_name="${GIT_COMMIT_NAME:-vmess-domain-rotator}"
- commit_email="${GIT_COMMIT_EMAIL:-vmess-domain-rotator@localhost}"
- ts="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
- git -C "$APP_DIR" \
- -c user.name="$commit_name" \
- -c user.email="$commit_email" \
- commit -m "chore: rotate preferred domain to ${after} (${ts})"
- echo "[vmess-domain-rotator] committed domain change: ${before} -> ${after}"
|