-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmirrorctl
More file actions
executable file
·163 lines (146 loc) · 4.11 KB
/
mirrorctl
File metadata and controls
executable file
·163 lines (146 loc) · 4.11 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env bash
set -e
if [[ $EUID -ne 0 ]]; then
echo Run as root!
exit 1
fi
if ! docker compose --version &>/dev/null; then
echo "Docker compose v2 doesn't seem to be installed."
exit 1
fi
if [ -z "$COMPOSE_FLAGS" ]; then
COMPOSE_FLAGS=("-d" "--remove-orphans")
fi
function stop() {
docker compose --profile cloudflared --profile letsencrypt --profile nossl down
}
function run() {
if [ ! -e ./.env ]; then
read -r -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
else
read -p "Do you want to use LetsEncrypt for SSL certificates? Port 80 and 443 will be mandatory. y/N " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -r -p 'Your email address: ' email
echo "EMAIL=$email" >>./.env
else
echo "NO_SSL=true" >>./.env
read -p "Enter port to serve the mirror (default 80): " -r port
if [ -n "$port" ]; then
echo "NGINX_PORT=$port" >>./.env
else
echo "NGINX_PORT=80" >>./.env
fi
fi
fi
else
read -p "Webroot path (optional): " -r webroot
if [ -n "$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
docker compose -f docker-compose.yml run --rm cloudflared login
docker compose -f docker-compose.yml run --rm cloudflared --origincert /root/.cloudflared/cert.pem tunnel create "$DOMAIN_NAME"
docker compose -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
# Create ACME state directory for nginx ACME module
if [ ! -d "./data/acme-letsencrypt" ]; then
mkdir -p ./data/acme-letsencrypt
# nginx container runs as user 101 (nginx user)
chown -R 101:101 ./data/acme-letsencrypt
fi
fi
if [ ! -d ./http-root/chaotic-aur ]; then
# Convert legacy
if [ -d ./repo ]; then
if [ "$NO_WEB" != "true" ]; then
stop
mkdir ./http-root
mv ./repo ./http-root/chaotic-aur
fi
elif [ -n "$WEBROOT" ]; then
mkdir -p "$WEBROOT"/chaotic-aur/.stfolder
chown -R 1000:1000 "$WEBROOT"/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
if [ -n "$UPDATE_IMAGES" ]; then
COMPOSE_FLAGS+=("--pull" "always" "--build")
fi
if [ "$NO_WEB" == "true" ]; then
docker compose up "${COMPOSE_FLAGS[@]}"
elif [ "$USE_TUNNELS" == "true" ]; then
docker compose --profile cloudflared up "${COMPOSE_FLAGS[@]}"
elif [ "$NO_SSL" == "true" ]; then
docker compose --profile nossl up "${COMPOSE_FLAGS[@]}"
else
docker compose --profile letsencrypt up "${COMPOSE_FLAGS[@]}"
fi
}
function update() {
if [ -f ./.env ]; then
stop
fi
if [ ! -d "./.git" ]; then
if [ "$(git rev-parse --is-inside-work-tree || true)" == "true" ]; then
echo "Please run this script in the main directory"
exit 1
fi
git init --initial-branch=main
git remote add origin https://github.com/chaotic-aur/docker-mirror
git fetch
git reset --hard origin/main
elif [ ! -f ./custom.diff ]; then
git pull || {
echo "Git pull failed, please fix the issue at hand."
exit 1
}
else
git fetch
git reset --hard origin/main
git apply ./custom.diff
fi
if [ "$SELFUPDATE" != 1 ]; then
SELFUPDATE=1 exec ./mirrorctl update
fi
UPDATE_IMAGES=true run
}
case "${1:-}" in
"update")
update
;;
"stop")
stop
;;
"run")
run
;;
*)
echo "Usage: $0 {update|stop|run}"
echo " update: Stop, update with latest images, and start the containers"
echo " stop: Stop all the containers"
echo " run: Start all the containers"
exit 1
;;
esac