-
Notifications
You must be signed in to change notification settings - Fork 6
/
entry.sh
61 lines (47 loc) · 1.84 KB
/
entry.sh
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
#!/usr/bin/env bash
set -Eeuo pipefail
if [ ! -S /var/run/docker.sock ]; then
echo "ERROR: Docker socket is missing? Please bind /var/run/docker.sock in your compose file." && exit 13
fi
if ! docker network inspect umbrel_main_network &>/dev/null; then
if ! docker network create --driver=bridge --subnet="10.21.0.0/16" umbrel_main_network >/dev/null; then
echo "ERROR: Failed to create network 'umbrel_main_network'!" && exit 14
fi
if ! docker network inspect umbrel_main_network &>/dev/null; then
echo "ERROR: Network 'umbrel_main_network' does not exist?" && exit 15
fi
fi
target=$(hostname)
if ! docker inspect "$target" &>/dev/null; then
echo "ERROR: Failed to find a container with name '$target'!" && exit 16
fi
resp=$(docker inspect "$target")
network=$(echo "$resp" | jq -r '.[0].NetworkSettings.Networks["umbrel_main_network"]')
if [ -z "$network" ] || [[ "$network" == "null" ]]; then
if ! docker network connect umbrel_main_network "$target"; then
echo "ERROR: Failed to connect container to network!" && exit 17
fi
fi
mount=$(echo "$resp" | jq -r '.[0].Mounts[] | select(.Destination == "/data").Source')
if [ -z "$mount" ] || [[ "$mount" == "null" ]] || [ ! -d "/data" ]; then
echo "ERROR: You did not bind the /data folder!" && exit 18
fi
# Create directories
mkdir -p "/images"
# Convert Windows paths to Linux path
if [[ "$mount" == *":\\"* ]]; then
mount="${mount,,}"
mount="${mount//\\//}"
mount="//${mount/:/}"
fi
if [[ "$mount" != "/"* ]]; then
echo "ERROR: Please bind the /data folder to an absolute path!" && exit 19
fi
# Mirror external folder to local filesystem
if [[ "$mount" != "/data" ]]; then
mkdir -p "$mount"
rm -rf "$mount"
ln -s /data "$mount"
fi
trap "pkill -SIGINT -f umbreld; while pgrep umbreld >/dev/null; do sleep 1; done" SIGINT SIGTERM
umbreld --data-directory "$mount" & wait $!