forked from jasonwong1991/easy_proxies
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·76 lines (65 loc) · 2.7 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·76 lines (65 loc) · 2.7 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
#!/bin/sh
# Prepare /etc/easy_proxies (auto-generate missing files, guard against
# Docker bind-mount foot-guns), then exec easy_proxies.
CONFIG_DIR="/etc/easy_proxies"
CONFIG_FILE="$CONFIG_DIR/config.yaml"
NODES_FILE="$CONFIG_DIR/nodes.txt"
EXAMPLE_CONFIG="/app/config.example.yaml"
# When a host bind-mount targets a single file that does not exist yet
# (e.g. -v ./data/nodes.txt:/etc/easy_proxies/nodes.txt), Docker creates a
# HOST DIRECTORY at that path and mounts it. The container then sees a
# directory where a file is expected and the app fails opaquely. Detect
# this and exit with a concrete fix instead of a confusing runtime crash.
die() {
echo "[easy_proxies] ERROR: $1" >&2
echo "$2" >&2
exit 1
}
fix_perm_hint="Ensure the mounted directory is writable by the container user:
mkdir -p data && chown -R $(id -u):$(id -g) data"
# --- config.yaml: reject directory, generate if absent ---
if [ -d "$CONFIG_FILE" ]; then
die "$CONFIG_FILE is a directory, not a file." \
"This happens when you bind-mount a host file that does not exist yet; Docker
creates a directory instead. Fix depends on your mount configuration:
Directory mount (-v ./data:/etc/easy_proxies):
rm -rf ./data/config.yaml
cp config.example.yaml ./data/config.yaml
docker compose up -d
File mount (-v ./config.yaml:/etc/easy_proxies/config.yaml):
rm -rf ./config.yaml
cp config.example.yaml ./config.yaml
docker compose up -d"
fi
if [ ! -e "$CONFIG_FILE" ]; then
[ -w "$CONFIG_DIR" ] || die "Cannot create $CONFIG_FILE ($CONFIG_DIR not writable)." "$fix_perm_hint"
cp "$EXAMPLE_CONFIG" "$CONFIG_FILE"
echo "[easy_proxies] Generated default config from $EXAMPLE_CONFIG"
fi
# --- nodes.txt: reject directory, create empty file if absent ---
if [ -d "$NODES_FILE" ]; then
die "$NODES_FILE is a directory, not a file." \
"This happens when you bind-mount a host file that does not exist yet; Docker
creates a directory instead. Fix depends on your mount configuration:
Directory mount (-v ./data:/etc/easy_proxies):
rm -rf ./data/nodes.txt
touch ./data/nodes.txt
docker compose up -d
File mount (-v ./nodes.txt:/etc/easy_proxies/nodes.txt):
rm -rf ./nodes.txt
touch ./nodes.txt
docker compose up -d"
fi
if [ ! -e "$NODES_FILE" ]; then
[ -w "$CONFIG_DIR" ] || die "Cannot create $NODES_FILE ($CONFIG_DIR not writable)." "$fix_perm_hint"
touch "$NODES_FILE"
echo "[easy_proxies] Created empty nodes.txt"
fi
# --- final readability check ---
if [ ! -r "$CONFIG_FILE" ]; then
die "Cannot read $CONFIG_FILE (permission denied)." \
"Fix on the host:
chown -R $(id -u):$(id -g) data
chmod 644 data/config.yaml data/nodes.txt"
fi
exec /usr/local/bin/easy_proxies "$@"