mirror of
https://github.com/halfwaystudent/douyin-sparkflow.git
synced 2026-08-28 03:29:54 +08:00
Add Docker Compose one-click deployment
This commit is contained in:
Regular → Executable
+67
-7
@@ -1,9 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
APP_ROOT=/opt/douyin-sparkflow
|
||||
SUB_URL='https://liangxin.xyz/api/v1/liangxin?OwO=6981c5a8452d44e8521c78f9f7bf1eea'
|
||||
curl -fsSL -A 'clash-verge/1.7.7' "$SUB_URL" -o "$APP_ROOT/proxy/config.yaml"
|
||||
if grep -q '^allow-lan:' "$APP_ROOT/proxy/config.yaml"; then sed -i 's/^allow-lan:.*/allow-lan: true/' "$APP_ROOT/proxy/config.yaml"; else echo 'allow-lan: true' >> "$APP_ROOT/proxy/config.yaml"; fi
|
||||
if grep -q '^bind-address:' "$APP_ROOT/proxy/config.yaml"; then sed -i "s#^bind-address:.*#bind-address: '*'#" "$APP_ROOT/proxy/config.yaml"; else echo "bind-address: '*'" >> "$APP_ROOT/proxy/config.yaml"; fi
|
||||
if grep -q '^external-controller:' "$APP_ROOT/proxy/config.yaml"; then sed -i "s#^external-controller:.*#external-controller: '0.0.0.0:9090'#" "$APP_ROOT/proxy/config.yaml"; else echo "external-controller: '0.0.0.0:9090'" >> "$APP_ROOT/proxy/config.yaml"; fi
|
||||
docker compose -f "$APP_ROOT/docker-compose.yml" restart proxy
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
APP_ROOT_OVERRIDE="${APP_ROOT:-}"
|
||||
ENV_FILE="$SCRIPT_DIR/.env"
|
||||
|
||||
read_env_value() {
|
||||
local key="$1"
|
||||
if [ ! -f "$ENV_FILE" ]; then
|
||||
return 0
|
||||
fi
|
||||
local raw
|
||||
raw="$(grep -E "^${key}=" "$ENV_FILE" | tail -n 1 | cut -d= -f2- || true)"
|
||||
raw="${raw%\"}"
|
||||
raw="${raw#\"}"
|
||||
raw="${raw%\'}"
|
||||
raw="${raw#\'}"
|
||||
printf '%s' "$raw"
|
||||
}
|
||||
|
||||
APP_ROOT="${APP_ROOT_OVERRIDE:-$SCRIPT_DIR}"
|
||||
PROXY_SUB_URL="${PROXY_SUB_URL:-$(read_env_value PROXY_SUB_URL)}"
|
||||
PROXY_USER_AGENT="${PROXY_USER_AGENT:-$(read_env_value PROXY_USER_AGENT)}"
|
||||
|
||||
CONFIG_DIR="$APP_ROOT/proxy"
|
||||
CONFIG_FILE="$CONFIG_DIR/config.yaml"
|
||||
EXAMPLE_CONFIG="$CONFIG_DIR/config.example.yaml"
|
||||
USER_AGENT="${PROXY_USER_AGENT:-clash-verge/1.7.7}"
|
||||
|
||||
mkdir -p "$CONFIG_DIR"
|
||||
|
||||
if [ -n "${PROXY_SUB_URL:-}" ]; then
|
||||
tmp_file="$(mktemp)"
|
||||
curl -fsSL -A "$USER_AGENT" "$PROXY_SUB_URL" -o "$tmp_file"
|
||||
mv "$tmp_file" "$CONFIG_FILE"
|
||||
echo "Proxy subscription refreshed: $CONFIG_FILE"
|
||||
elif [ ! -f "$CONFIG_FILE" ]; then
|
||||
if [ ! -f "$EXAMPLE_CONFIG" ]; then
|
||||
echo "Missing $CONFIG_FILE and $EXAMPLE_CONFIG. Set PROXY_SUB_URL or provide a Mihomo config." >&2
|
||||
exit 1
|
||||
fi
|
||||
cp "$EXAMPLE_CONFIG" "$CONFIG_FILE"
|
||||
echo "PROXY_SUB_URL is empty. Created a DIRECT-only proxy config from config.example.yaml."
|
||||
else
|
||||
echo "PROXY_SUB_URL is empty. Keeping existing proxy/config.yaml."
|
||||
fi
|
||||
|
||||
ensure_line() {
|
||||
local key="$1"
|
||||
local value="$2"
|
||||
if grep -q "^${key}:" "$CONFIG_FILE"; then
|
||||
sed -i "s#^${key}:.*#${key}: ${value}#" "$CONFIG_FILE"
|
||||
else
|
||||
printf '%s: %s\n' "$key" "$value" >> "$CONFIG_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_line "mixed-port" "7890"
|
||||
ensure_line "allow-lan" "true"
|
||||
ensure_line "bind-address" "'*'"
|
||||
ensure_line "external-controller" "'0.0.0.0:9090'"
|
||||
|
||||
if command -v docker >/dev/null 2>&1 && [ -f "$APP_ROOT/docker-compose.yml" ]; then
|
||||
proxy_id="$(docker compose -f "$APP_ROOT/docker-compose.yml" ps -q proxy 2>/dev/null || true)"
|
||||
if [ -n "$proxy_id" ]; then
|
||||
docker compose -f "$APP_ROOT/docker-compose.yml" restart proxy
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user