forked from boschkundendienst/guacamole-docker-compose
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·88 lines (77 loc) · 3.09 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·88 lines (77 loc) · 3.09 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
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOCKER_COMPOSE_DIR="$SCRIPT_DIR"
DOCKER_COMPOSE_FILE="$DOCKER_COMPOSE_DIR/docker-compose.yml"
usage() {
echo "Usage: $(basename "$0") [Option]"
echo
echo "Options:"
echo " -n, --no-funnel Disable Tailscale funnel after starting Docker services."
echo " -c, --cloudflare Start free cloudflare tunnel in addition to Tailscale funnel."
echo " -h, --help Show this help message and exit."
exit 1
}
# --- Parse arguments ---
DISABLE_FUNNEL=0
ENABLE_CLOUDFLARE=0
if [[ $# -gt 1 ]]; then
echo "Error: Too many arguments."
usage
fi
if [[ $# -eq 1 ]]; then
case "$1" in
-n|--no-funnel)
DISABLE_FUNNEL=1
echo "Tailscale funnel will not be enabled if it is disabled."
echo "It will not be disabled if it was already running."
;;
-c|--cloudflare)
ENABLE_CLOUDFLARE=1
echo "Cloudflare tunnel will be enabled in addition to Tailscale funnel."
;;
-h|--help)
usage
;;
*)
echo "Error: Unknown option '$1'"
usage
;;
esac
fi
echo "Starting Docker containers"
# delete folder which can be created when docker starts automatically after unexpected power cycle of docker host and tries to recreate the volumes automatically I think
rm -rf "$SCRIPT_DIR/nginx/tailscale_funnel_redirect.conf"
# Create a default empty config, so Docker doesn't try to create a directory at that place to mount it as a volume dir in nginx container
echo > "$SCRIPT_DIR/nginx/tailscale_funnel_redirect.conf"
if [[ $ENABLE_CLOUDFLARE -eq 1 && $DISABLE_FUNNEL -eq 0 ]]; then
echo "Starting cloudflare tunnel container"
docker compose -f "$DOCKER_COMPOSE_FILE" up cloudflared -d --wait
if [[ $? -ne 0 ]]; then
echo "Error: Failed to start cloudflare tunnel container."
exit 1
fi
fi
DNS=""
if [[ $DISABLE_FUNNEL -eq 0 && $DOCKER_STATUS -eq 0 ]]; then
DNS=$(tailscale status --json | jq -r '.Self.DNSName')
DNS="${DNS%.}"
echo "return 302 https://$DNS;" > "$SCRIPT_DIR/nginx/tailscale_funnel_redirect.conf"
fi
docker compose -f "$DOCKER_COMPOSE_FILE" up -d
DOCKER_STATUS=$?
echo "done"
# --- Start Tailscale funnel if enabled ---
if [[ $DISABLE_FUNNEL -eq 0 && $DOCKER_STATUS -eq 0 ]]; then
echo "Starting Tailscale funnel"
tailscale funnel --bg https+insecure://127.0.0.1:8443
echo "done"
if [[ $ENABLE_CLOUDFLARE -eq 1 ]]; then
echo "Cloudflare tunnel is enabled in addition to Tailscale funnel."
echo "It is accessible under /cf path on the Tailscale Funnel domain:"
echo "https://$DNS/cf"
echo "and will redirect to:"
cat "$SCRIPT_DIR/cloudflared/cloudflare_redirect.conf" | grep -m1 -oE 'https://[a-zA-Z0-9-]+\.trycloudflare\.com'
echo "There is also a redirect to Taislcale funnel domain on the root path from the Cloudflare domain:"
echo "$(cat "$SCRIPT_DIR/cloudflared/cloudflare_redirect.conf" | grep -m1 -oE 'https://[a-zA-Z0-9-]+\.trycloudflare\.com')/tc"
fi
fi