-
Notifications
You must be signed in to change notification settings - Fork 3
/
run
executable file
·119 lines (104 loc) · 3.28 KB
/
run
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
116
117
118
119
#!/bin/bash
set -e
if [[ $EUID -ne 0 ]]; then
echo Run as root!
exit 1
fi
function command_exists() {
builtin type -P "$1" &> /dev/null || eval "$1" &> /dev/null
}
# docker compose v2 is not a python package (`docker-compose`),
# but a reimplementation in Go (`docker compose`).
# Either of them works for us.
POSSIBLE_DOCKER_COMPOSE=( "docker-compose" "docker compose" )
for cmd in "${POSSIBLE_DOCKER_COMPOSE[@]}"; do
if command_exists "$cmd"; then
echo "'$cmd' exists, using that."
export DC_CMD="$cmd"
break
fi
done
if [[ -z "$DC_CMD" ]]; then
echo Docker compose doesn\'t seem to be installed.
exit 1
fi
if [ -z "$COMPOSEFLAGS" ]; then
COMPOSEFLAGS=("-d" "--remove-orphans")
fi
if [ ! -e ./.env ]; then
read -p 'Domain that will serve the mirror: ' domain
echo "DOMAIN_NAME=$domain" > ./.env
read -p "Automatically manage web server (letsencrypt, cloudflare tunnels) y/N " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "Use cloudflare tunnels y/N " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "USE_TUNNELS=true" >> ./.env
echo "SSL_FILE=/dev/null" >> ./.env
else
read -p 'Your email address: ' email
echo "EMAIL=$email" >> ./.env
fi
else
read -p "Webroot path (optional): " -r webroot
if [ ! -z "$webroot" ]; then
echo "WEBROOT=$webroot" >> ./.env
fi
echo "NO_WEB=true" >> ./.env
fi
fi
source .env
if [ "$USE_TUNNELS" == "true" ]; then
if [ ! -e "./data/cloudflared/home/.cloudflared/cert.pem" ]; then
"$DC_CMD" -f docker-compose.yml run --rm cloudflared login
"$DC_CMD" -f docker-compose.yml run --rm cloudflared --origincert /root/.cloudflared/cert.pem tunnel create $DOMAIN_NAME
"$DC_CMD" -f docker-compose.yml run --rm cloudflared --origincert /root/.cloudflared/cert.pem tunnel route dns $DOMAIN_NAME $DOMAIN_NAME
fi
elif [ "$NO_WEB" != "true" ]; then
if [ ! -e ./data/letsencrypt/etc/renewal/chaotic.conf ]; then
docker run -p 80:80 -p 443:443 --rm -v "$PWD/data/letsencrypt/etc:/etc/letsencrypt" -v "$PWD/data/letsencrypt/var:/var/lib/letsencrypt" certbot/certbot:${LETSENCRYPT_TAG:-latest} certonly --standalone --non-interactive --agree-tos --cert-name chaotic -n -m "$EMAIL" -d "$DOMAIN_NAME"
fi
fi
if [ ! -e ./http-root/chaotic-aur ] && [ "$NO_WEB" != "true" ]; then
# Convert legacy
if [ -d ./repo ]; then
./stop
mkdir ./http-root
mv ./repo ./http-root/chaotic-aur
else
mkdir -p ./http-root/chaotic-aur/.stfolder
chown -R 1000:1000 ./http-root/chaotic-aur/
fi
fi
if [ ! -e ./data/syncthing/config.xml ]; then
mkdir -p ./data/syncthing
cp ./preset/syncthing-config.xml ./data/syncthing/config.xml
chown -R 1000:1000 ./data/syncthing
fi
gawk -i inplace '/<folder id="jhcrt-m2dra"/ {
begin = 1
}
/<minDiskFree unit="">0<\/minDiskFree>/ {
if (begin) {
print " <minDiskFree unit=\"%\">1</minDiskFree>"
next
} else {
print
}
}
/<\/folder>/ {
begin = 0
}
1' ./data/syncthing/config.xml
if [ ! -z "$UPDATE_IMAGES" ]; then
COMPOSEFLAGS+=("--pull" "always")
fi
if [ "$NO_WEB" == "true" ]; then
"$DC_CMD" up "${COMPOSEFLAGS[@]}"
elif [ "$USE_TUNNELS" == "true" ]; then
"$DC_CMD" --profile cloudflared up "${COMPOSEFLAGS[@]}"
else
"$DC_CMD" --profile letsencrypt up "${COMPOSEFLAGS[@]}"
fi