This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild_all.sh
executable file
·393 lines (336 loc) · 13.5 KB
/
build_all.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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#!/bin/bash
echo
echo "Welcome to the iNethi builder system for Ubuntu"
sleep 1
# Detect OS
# 1 = LINUX
# 2 = MACOS
myos=1
res=$(echo $OSTYPE)
res3=${res:0:3}
if [ "$res3" = "dar" ]; then
myos=2
echo "Operating System discovered: MACOSX"
else
echo "Operating System discovered: LINUX"
fi
# install all dependencies
echo "Docker and Docker compose are needed to build this system (note docker needs to be able to run as non-root)"
sleep 2
echo "Is this an Ubuntu System and do you wish to set this up now? (Yes=1/No=2)"
select yn in "Yes" "No"; do
case $yn in
Yes ) sudo apt-get update || exit 1;
sudo apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release || exit 1;
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg || exit 1;
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null || exit 1;
sudo apt-get update || exit 1;
# For Raspberry PI
echo "Is this a Raspberry PI setup (Yes=1/No=2)"
select yn in "Yes" "No"; do
case $yn in
Yes ) curl -fsSL https://get.docker.com -o get-docker.sh || exit 1
sudo sh get-docker.sh || exit 1
break;;
No ) sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin || exit 1;
break;;
esac
done
sudo apt-get -y install docker-compose || exit 1;
# Make docker run as non root
sudo usermod -aG docker $USER || echo "Cannot change permissions..."; exit 1;
sudo chmod 666 /var/run/docker.sock; echo "Please restart your machine now and rerun the script"; sleep 5; exit 0; break;;
No ) echo; break;;
esac
done
# customize with your own.
STORAGE_FOLDER=/mnt/data
if [ $myos == 2 ]; then
CWD=$(pwd)
STORAGE_FOLDER="$CWD/data"
fi
echo "/mnt/data is set as the main storage directory for Ubuntu"
echo "Do you wish to change this? (Yes=1/No=2)"
select yn in "Yes" "No"; do
case $yn in
Yes ) read -p 'storage folder: ' STORAGE_FOLDER; break;;
No ) echo "Default storage folder selected"; break;;
esac
done
echo "$STORAGE_FOLDER" "is being used as the storage folder"
sudo mkdir -p "$STORAGE_FOLDER"
sleep 2
# make sure all future data in this folder can be created as non root
if [ "$myos" = 1 ]; then
sudo chown $USER:$USER "$STORAGE_FOLDER" || exit 1;
else
sudo chown $USER:staff "$STORAGE_FOLDER" || exit 1;
fi
## NOTES
options=("Nginx-Splash" "Keycloak" "Nextcloud" "Jellyfin" "Wordpress" "Payment and User Management")
entrypoint=web
echo
menu() {
echo "iNethi version 0.1.0 builder"
echo "Available options:"
for i in ${!options[@]}; do
printf "%3d%s) %s\n" $((i+1)) "${choices[i]:- }" "${options[i]}"
done
if [[ "$msg" ]]; then echo "$msg"; fi
}
prompt="Select which iNethi components you want (again to uncheck, ENTER when done): "
while menu && read -rp "$prompt" num && [[ "$num" ]]; do
[[ "$num" != *[![:digit:]]* ]] &&
(( num > 0 && num <= ${#options[@]} )) ||
{ msg="Invalid option: $num"; continue; }
((num--));
[[ "${choices[num]}" ]] && choices[num]="" || choices[num]="+"
done
echo
echo Set General master secure password for all services
read -p 'master password: ' MASTER_PASSWORD
# Select default email address
read -p 'Default email address: ' emailAddress
# Select https or http
echo "Do you wish to deploy a secure site with https?"
select yn in "Yes" "No"; do
case $yn in
Yes ) entrypoint=websecure; break;;
No ) entrypoint=web; break;;
esac
done
# Check if using default domain
echo "Do you wish to use the default iNethi domain: inethilocal.net?"
select yn in "Yes" "No"; do
case $yn in
Yes ) defaultDomain=1; domainName=inethilocal.net; wget https://splash.inethicloud.net/acme.json -P ./my-certificates || exit 1; break;;
No ) defaultDomain=0; read -p 'Domain name: ' domainName; break;;
esac
done
if [ "$defaultDomain" = 0 ];
then
echo "You are using a custom domain"
echo "Please ensure your acme.json file is in the ./my-certificates/ folder..."
echo "Is your file present? (yes=1/no=2)"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Your domain is "; echo "$domainName"; break;;
esac
done
if test -f ./my-certificates/acme.json; then
echo "acme.json exists"
else
echo "ERROR: acme.json does not exist"
exit 1
fi
else
echo "You are using the default iNethi domain"
fi
echo "Would you like iNethi to run a DNS to redirect hosts to your inethi domain"
select yn in "Yes" "No"; do
case $yn in
Yes ) installDNS=1; break;;
No ) installDNS=0; break;;
esac
done
echo
printf "You selected"; msg=" nothing"
for i in ${!options[@]}; do
[[ "${choices[i]}" ]] && {
printf " %s" "[${options[i]}]"; msg="";
}
done
echo "$msg"
if [ "$entrypoint" = websecure ]; then
echo You chose secure Domain Name: https://$domainName
echo
if test -f traefikssl/secrets/secret_keys.env; then
echo API key file exists
cat traefikssl/secrets/secret_keys.env
else
if [ "$defaultDomain" = 1 ]; then
AWS_ACCESS_KEY_ID=xxx
AWS_SECRET_ACCESS_KEY=xxx
AWS_HOSTED_ZONE_ID=xxx
else
echo API keys are needed to setup https certificates
read -p 'AWS_ACCESS_KEY_ID: ' AWS_ACCESS_KEY_ID
read -p 'AWS_SECRET_ACCESS_KEY: ' AWS_SECRET_ACCESS_KEY
read -p 'AWS_HOSTED_ZONE_ID: ' AWS_HOSTED_ZONE_ID
fi
mkdir -p ./traefikssl/secrets/
echo AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID > ./traefikssl/secrets/secret_keys.env
echo AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY >> ./traefikssl/secrets/secret_keys.env
echo AWS_HOSTED_ZONE_ID=$AWS_HOSTED_ZONE_ID >> ./traefikssl/secrets/secret_keys.env
fi
else
echo You chose insecure Domain Name: http://$domainName
fi
echo
printf "Starting to build dockers ... "
echo
sleep 1
# Send the environmental variables to other scripts
echo export inethiDN=$domainName > ./root.conf
echo export TRAEFIK_ENTRYPOINT=$entrypoint >> ./root.conf
echo export email=$emailAddress >> ./root.conf
printf "Create docker traefik bridge: traefik-bridge ..."
echo
docker network create --attachable -d bridge inethi-bridge-traefik
# Build traefik - compulsory docker
[ "$entrypoint" = websecure ] && {
printf "Building Traefik docker... "
traefik_storgage="TRAEFIKSSL_VOLUME=${STORAGE_FOLDER}/traefikssl"
traefik_storgage_secrets="TRAEFIKSSL_VOLUME_SECRETS=${STORAGE_FOLDER}/traefikssl"
echo export $traefik_storgage >> ./root.conf || exit 1
echo export $traefik_storgage_secrets >> ./root.conf || exit 1
cd ./traefikssl
./local_build.sh
cd ..
}
[ "$entrypoint" = web ] && {
printf "Building Traefik docker... "
cd ./traefik
./local_build.sh
cd ..
}
[[ "${choices[0]}" ]] && {
printf "Building nginx(splash) docker ... "
splash_storage="NGINX_VOLUME=${STORAGE_FOLDER}/nginx"
echo export $splash_storage >> ./root.conf || exit 1
cd ./nginx-splash
./local_build.sh
cd ..
}
[[ "${choices[1]}" ]] && {
printf "Building keycloak docker ... with admin user and inethi user"
my_sql_storage="MYSQLDB_VOLUME=${STORAGE_FOLDER}/mysql_keycloak"
mysql_root_pass="KEYCLOAK_ADMIN_PASSWORD=${MASTER_PASSWORD}"
mysql_pass="KEYCLOAK_PASSWORD=${MASTER_PASSWORD}"
mysql_storage="MYSQLDB_VOLUME=${STORAGE_FOLDER}/keycloak"
echo export $mysql_storage >> ./root.conf || exit 1
echo export $mysql_root_pass >> ./root.conf || exit 1
echo export $mysql_pass >> ./root.conf || exit 1
cd ./keycloak
./local_build.sh
cd ..
}
[[ "${choices[2]}" ]] && {
printf "Building Nextcloud docker ... "
# Set passwords for Nextcloud
mkdir -p ./nextcloud/secrets
echo export MYSQL_ROOT_PASSWORD=$MASTER_PASSWORD > ./nextcloud/secrets/secret_passwords.env
echo export MYSQL_PASSWORD=$MASTER_PASSWORD >> ./nextcloud/secrets/secret_passwords.env
nextcloud_volume="NEXTCLOUD_VOLUME=${STORAGE_FOLDER}/nextcloud"
mysql_volume="MYSQL_VOLUME=${STORAGE_FOLDER}/nextcloud-mysql"
share_volume="NEXTCLOUD_SHARE_VOLUME=${STORAGE_FOLDER}/share"
rshare_volume="NEXTCLOUD_RSHARE_VOLUME=${STORAGE_FOLDER}/share/Rshare"
rvideo_volume="NEXTCLOUD_RVIDEO_VOLUME=${STORAGE_FOLDER}/share/Rvideo"
rphoto_volume="NEXTCLOUD_RPHOTO_VOLUME=${STORAGE_FOLDER}/share/Rphoto"
rmusic_volume="NEXTCLOUD_RMUSIC_VOLUME=${STORAGE_FOLDER}/share/Rmusic"
echo export $nextcloud_volume >> ./root.conf || exit 1
echo export $mysql_volume >> ./root.conf || exit 1
echo export $rshare_volume >> ./root.conf || exit 1
echo export $share_volume >> ./root.conf || exit 1
echo export $rvideo_volume >> ./root.conf || exit 1
echo export $rphoto_volume >> ./root.conf || exit 1
echo export $rmusic_volume >> ./root.conf || exit 1
cd ./nextcloud
./local_build.sh
cd ..
}
[[ "${choices[3]}" ]] && {
printf "Building Jellyfin docker ... "
jellyfin_volume="JELLYFIN_VOLUME=${STORAGE_FOLDER}/jellyfin"
rshare_volume="NEXTCLOUD_RSHARE_VOLUME=${STORAGE_FOLDER}/share/Rshare"
rvideo_volume="NEXTCLOUD_RVIDEO_VOLUME=${STORAGE_FOLDER}/share/Rvideo"
rphoto_volume="NEXTCLOUD_RPHOTO_VOLUME=${STORAGE_FOLDER}/share/Rphoto"
rmusic_volume="NEXTCLOUD_RMUSIC_VOLUME=${STORAGE_FOLDER}/share/Rmusic"
echo export $jellyfin_volume >> ./root.conf || exit 1
echo export $rshare_volume >> ./root.conf || exit 1
echo export $rvideo_volume >> ./root.conf || exit 1
echo export $rphoto_volume >> ./root.conf || exit 1
echo export $rmusic_volume >> ./root.conf || exit 1
cd ./jellyfin
./local_build.sh
cd ..
}
[[ "${choices[4]}" ]] && {
printf "Building wordpress docker ... "
wordpress_volume="WORDPRESS_MOUNT=${STORAGE_FOLDER}/wordpress"
mariadb_volume="MARIADB_MOUNT=${STORAGE_FOLDER}/wordpress-mariadb"
db_pass="WORDPRESS_DB_PASSWORD=${MASTER_PASSWORD}"
mysql_pass="MYSQL_ROOT_PASSWORD=${MASTER_PASSWORD}"
echo export $wordpress_volume >> ./root.conf || exit 1
echo export $mariadb_volume >> ./root.conf || exit 1
echo export $db_pass >> ./root.conf || exit 1
echo export $mysql_pass >> ./root.conf || exit 1
cd ./wordpress
./local_build.sh
cd ..
}
[[ "${choices[5]}" ]] && {
printf "Building Radiusdesk docker ... "
rd_volume="RADIUSDESK_VOLUME=${STORAGE_FOLDER}/radiusdesk"
echo export $rd_volume >> ./root.conf || exit 1
cd ./radiusdesk_2docker
./local_build.sh
cd ..
django_volume="DJANGO_MNT=${STORAGE_FOLDER}/user_management"
mysql_volume="MYSQL_MANAGEMENT_MNT=${STORAGE_FOLDER}/management-mysql"
echo export $django_volume >> ./root.conf || exit 1
echo export $mysql_volume >> ./root.conf || exit 1
cd ./inethi-management-system
cd ./inethi_management
cd ./inethi_management
read -p 'Please set the cost of a 30 minute voucher: ' TIME30M
read -p 'Please set the cost of a 1 hour voucher: ' TIME1H
read -p 'Please set the cost of a 24 hour voucher: ' TIME24H
read -p 'Please set the cost of a 1GB voucher: ' DATA1G
PACKAGE_MAP="PriceToPackageMap = {$TIME30M: ['TIME30M', 1800, '1W'], $TIME1H: ['TIME1H', 3600, '2W'], $TIME24H: ['TIME24H', 86400, '1M'], $DATA1G: ['DATA1G', 2592000, '3M']}"
# echo $PACKAGE_MAP
sed -i "14s/.*/${PACKAGE_MAP//\'/\\\'}/" views.py
cd ../
./local_build.sh
cd ../../
cd payments/services/web/endpoints
AMOUNT=" amount=$TIME30M"
sed -i "50s/.*/${AMOUNT}/" redeem.py
AMOUNT=" amount=$TIME1H"
sed -i "52s/.*/${AMOUNT}/" redeem.py
AMOUNT=" amount=$TIME24H"
sed -i "54s/.*/${AMOUNT}/" redeem.py
AMOUNT=" amount=$DATA1G"
sed -i "59s/.*/${AMOUNT}/" redeem.py
cd ../../..
./local_build.sh
echo "We will set up you Internet sales default payment limits now."
echo "How often do you want the default limit to reset (in seconds)?"
read -p "Reset after: " DURATION
read -p "How much can a user spend in this time limit (in units)? " PAYMENT_LIMIT
echo "Your time limit is $DURATION seconds and your spending limit is $PAYMENT_LIMIT"
echo "Updating database..."
VALUES="1, 4, $PAYMENT_LIMIT, $DURATION"
docker exec -it inethi-user-management-mysql mysql inethi-user-management-api -e "INSERT INTO inethi_management_servicetypes (description, pay_type, service_type_id) VALUES ('Internet', 1, 1);"
docker exec -it inethi-user-management-mysql mysql inethi-user-management-api -e "INSERT INTO inethi_management_defaultpaymentlimits (service_type_id, payment_method, payment_limit, payment_limit_period_sec) VALUES ($VALUES);"
echo "Done"
}
# Install DNS system last - TODO add a check to see if it works otherwise reverse changes
[ "$installDNS" = 1 ] && {
printf "Building iNethi DNS ... "
dnsmasq_volume="DNSMASQ_VOLUME=${STORAGE_FOLDER}/dnsmasq"
echo export $dnsmasq_volume >> ./root.conf || exit 1
cd ./dnsmasq
if [ "$myos" = 1 ]; then
./local_build.sh
else
./local_build_mac.sh
fi
cd ..
}