forked from router-for-me/CLIProxyAPIPlus
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-init.sh
More file actions
115 lines (96 loc) · 4.05 KB
/
docker-init.sh
File metadata and controls
115 lines (96 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh
# docker-init.sh - Docker entrypoint script for CLIProxyAPI++
# This script handles initialization tasks before starting the main application.
# It enables "out-of-the-box" Docker deployment without manual config creation.
set -e
CONFIG_FILE="${CONFIG_FILE:-/CLIProxyAPI/config.yaml}"
CONFIG_EXAMPLE="${CONFIG_EXAMPLE:-/CLIProxyAPI/config.example.yaml}"
AUTH_DIR="${AUTH_DIR:-/root/.cli-proxy-api}"
LOGS_DIR="${LOGS_DIR:-/CLIProxyAPI/logs}"
<<<<<<< HEAD
=======
# Normalize CONFIG_FILE when mount points incorrectly create a directory.
if [ -d "${CONFIG_FILE}" ]; then
CONFIG_FILE="${CONFIG_FILE%/}/config.yaml"
fi
>>>>>>> archive/pr-234-head-20260223
# Create auth directory if it doesn't exist
if [ ! -d "${AUTH_DIR}" ]; then
echo "[docker-init] Creating auth directory: ${AUTH_DIR}"
mkdir -p "${AUTH_DIR}"
fi
<<<<<<< HEAD
=======
chmod 700 "${AUTH_DIR}"
>>>>>>> archive/pr-234-head-20260223
# Create logs directory if it doesn't exist
if [ ! -d "${LOGS_DIR}" ]; then
echo "[docker-init] Creating logs directory: ${LOGS_DIR}"
mkdir -p "${LOGS_DIR}"
fi
# Check if config file exists, if not create from example
if [ ! -f "${CONFIG_FILE}" ]; then
echo "[docker-init] Config file not found, creating from example..."
<<<<<<< HEAD
=======
mkdir -p "$(dirname "${CONFIG_FILE}")"
>>>>>>> archive/pr-234-head-20260223
if [ -f "${CONFIG_EXAMPLE}" ]; then
cp "${CONFIG_EXAMPLE}" "${CONFIG_FILE}"
echo "[docker-init] Created ${CONFIG_FILE} from example"
else
echo "[docker-init] WARNING: Example config not found at ${CONFIG_EXAMPLE}"
echo "[docker-init] Creating minimal config..."
cat > "${CONFIG_FILE}" << 'EOF'
# CLIProxyAPI++ Configuration - Auto-generated by docker-init.sh
# Edit this file to customize your deployment
host: ""
port: 8317
api-keys:
- "your-api-key-here"
debug: false
remote-management:
allow-remote: false
secret-key: ""
disable-control-panel: false
routing:
strategy: "round-robin"
auth-dir: "~/.cli-proxy-api"
EOF
echo "[docker-init] Created minimal config at ${CONFIG_FILE}"
fi
fi
# Apply environment variable overrides if set
# These take precedence over config file values
if [ -n "${CLIPROXY_HOST}" ]; then
echo "[docker-init] Setting host from env: ${CLIPROXY_HOST}"
sed -i "s/^host:.*/host: \"${CLIPROXY_HOST}\"/" "${CONFIG_FILE}" 2>/dev/null || \
sed -i '' "s/^host:.*/host: \"${CLIPROXY_HOST}\"/" "${CONFIG_FILE}" 2>/dev/null || true
fi
if [ -n "${CLIPROXY_PORT}" ]; then
echo "[docker-init] Setting port from env: ${CLIPROXY_PORT}"
sed -i "s/^port:.*/port: ${CLIPROXY_PORT}/" "${CONFIG_FILE}" 2>/dev/null || \
sed -i '' "s/^port:.*/port: ${CLIPROXY_PORT}/" "${CONFIG_FILE}" 2>/dev/null || true
fi
if [ -n "${CLIPROXY_SECRET_KEY}" ]; then
echo "[docker-init] Setting management secret-key from env"
sed -i "s/secret-key:.*/secret-key: \"${CLIPROXY_SECRET_KEY}\"/" "${CONFIG_FILE}" 2>/dev/null || \
sed -i '' "s/secret-key:.*/secret-key: \"${CLIPROXY_SECRET_KEY}\"/" "${CONFIG_FILE}" 2>/dev/null || true
fi
if [ -n "${CLIPROXY_ALLOW_REMOTE}" ]; then
echo "[docker-init] Setting allow-remote from env: ${CLIPROXY_ALLOW_REMOTE}"
sed -i "s/allow-remote:.*/allow-remote: ${CLIPROXY_ALLOW_REMOTE}/" "${CONFIG_FILE}" 2>/dev/null || \
sed -i '' "s/allow-remote:.*/allow-remote: ${CLIPROXY_ALLOW_REMOTE}/" "${CONFIG_FILE}" 2>/dev/null || true
fi
if [ -n "${CLIPROXY_DEBUG}" ]; then
echo "[docker-init] Setting debug from env: ${CLIPROXY_DEBUG}"
sed -i "s/^debug:.*/debug: ${CLIPROXY_DEBUG}/" "${CONFIG_FILE}" 2>/dev/null || \
sed -i '' "s/^debug:.*/debug: ${CLIPROXY_DEBUG}/" "${CONFIG_FILE}" 2>/dev/null || true
fi
if [ -n "${CLIPROXY_ROUTING_STRATEGY}" ]; then
echo "[docker-init] Setting routing strategy from env: ${CLIPROXY_ROUTING_STRATEGY}"
sed -i "s/strategy:.*/strategy: \"${CLIPROXY_ROUTING_STRATEGY}\"/" "${CONFIG_FILE}" 2>/dev/null || \
sed -i '' "s/strategy:.*/strategy: \"${CLIPROXY_ROUTING_STRATEGY}\"/" "${CONFIG_FILE}" 2>/dev/null || true
fi
echo "[docker-init] Starting CLIProxyAPI++..."
exec ./cliproxyapi++ "$@"