This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sequenzia
executable file
·416 lines (413 loc) · 18 KB
/
sequenzia
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
#!/bin/sh
echo "Sequenzia Server Control (Alpha)"
# Using specific lines as config to prevent compatibility issues with using specific commands that are not supported by Win, Linux,and Unix.
DCL=''
DFL='-f docker-compose.yaml'
getServices() {
for i in $(sed -n '1p' ./common/config/controller.dat 2> /dev/null || echo 'default proxy'); do
case "$i" in
default) ;;
core)
DCL="database mq framework authware";;
uploader)
DCL="mq framework fileworker";;
external)
echo "WARNING! Backend SQL and MQ ports are exposed!";
DFL="${DFL} -f docker-compose-external.yaml";;
manager)
DFL="${DFL} -f docker-compose-manager.yaml";;
router)
DFL="${DFL} -f docker-compose-router.yaml";;
proxy)
DFL="${DFL} -f docker-compose-frontend.yaml";;
samba)
DFL="${DFL} -f docker-compose-share.yaml";;
cms-twitter)
DFL="${DFL} -f docker-compose-cms-twitter.yaml";;
cms-pixiv)
DFL="${DFL} -f docker-compose-cms-pixiv.yaml";;
cms-rss)
DFL="${DFL} -f docker-compose-cms-rss.yaml";;
cms-spider)
DFL="${DFL} -f docker-compose-cms-spider.yaml";;
*)
DCL="${DCL} ${i}";;
esac
done
}
ALL_DFL='-f docker-compose.yaml -f docker-compose-frontend.yaml -f docker-compose-router.yaml -f docker-compose-external.yaml -f docker-compose-manager.yaml -f docker-compose-share.yaml -f docker-compose-cms-twitter.yaml -f docker-compose-cms-pixiv.yaml -f docker-compose-cms-rss.yaml -f docker-compose-cms-spider.yaml'
full_stop() {
docker compose ${ALL_DFL} down;
}
comp_name() {
docker compose ${DFL} ps $1 | tail -n +2 | awk '{ print $1 }'
}
is_running() {
case "$(comp_name $1)" in
no*) echo "n";;
*) echo "y";;
esac
}
if [ -n "$1" ]
then
getServices;
# shellcheck disable=SC2086
case "$1" in
mode)
if [ -n "$2" ]
then
case "$2" in
append)
if [ -n "$3" ]
then
echo "$(cat ./common/config/controller.dat 2> /dev/null || echo 'default proxy') $3" > ./common/config/controller.dat
else
echo "You need to specify a mode to append"
fi;;
*) echo "$2" > ./common/config/controller.dat;;
esac
fi
echo "Operator Mode to: $(cat ./common/config/controller.dat 2> /dev/null || echo 'default proxy')"
;;
test-core) docker compose up database mq framework authware;;
test)
if [ -n "$2" ]
then
docker compose ${DFL} up $2
else
docker compose ${DFL} up ${DCL}
fi;;
start)
if [ -n "$2" ]
then
docker compose ${DFL} up $2 -d
else
docker compose ${DFL} up ${DCL} -d
fi;;
stop)
if [ -n "$2" ]
then
docker compose ${DFL} stop $2 &&
docker compose ${DFL} rm -f $2
else
full_stop
fi;;
restart)
if [ -n "$2" ]
then
docker compose ${DFL} restart $2
else
docker compose ${DFL} restart ${DCL}
fi;;
reset)
if [ -n "$2" ]
then
docker compose ${DFL} stop $2
docker compose ${DFL} rm $2
docker compose ${DFL} up $2 -d
else
full_stop &&
docker compose ${DFL} up ${DCL} -d;
fi;;
config) nano common/config/user-config.json ;;
env) nano common/config/user-config.env ;;
setupaw) nano common/config/setup-authware.env ;;
status) docker compose ${ALL_DFL} ps;;
logs) docker compose ${ALL_DFL} logs $2 -f;;
certs)
if [ -n "$2" ]
then
case "$2" in
request)
if [ "$(is_running frontend)" = "y" ]; then
docker exec -it "$(comp_name frontend)" sh -c 'mkdir -p /certs/certbot && certbot certonly --config-dir /certs/certbot --webroot-path="/www-root/" --webroot -d $EXTERNAL_FQDN --email $CERT_EMAIL --non-interactive --expand --agree-tos'
docker compose -f docker-compose.yaml -f docker-compose-frontend.yaml down frontend &&
docker compose -f docker-compose.yaml -f docker-compose-frontend.yaml up frontend -d &&
echo "The server should be available soon, Please visit your domain name to confirm your certificates are correctly loaded!"
else
echo "Frontend Proxy is not running or is not configured!"
fi;;
selfsigned)
if [ "$(is_running frontend)" = "y" ]; then
docker exec -it "$(comp_name frontend)" openssl req -new -x509 -nodes -days 365 -sha256 -subj "/C=JP/ST=Tokyo/L=Academy City/O=Academy City Research - Non-Affiliated Subsidiary/CN=localhost" -addext "subjectAltName=DNS:localhost" -newkey rsa:2048 -keyout /certs/frontend.key -out /certs/frontend.crt &&
docker compose -f docker-compose.yaml -f docker-compose-frontend.yaml stop frontend &&
docker compose -f docker-compose.yaml -f docker-compose-frontend.yaml up frontend -d &&
echo "IMPORTANT! MAC OS handles self signed certificates poorly and you will have to get a real certificate from certbot once your ready to complete"
else
echo "Frontend Proxy is not running or is not configured!"
fi;;
reset) rm -rf ./common/keys/certbot ;;
*) echo "Invalid command";;
esac
else
echo "Missing command"
fi
;;
build)
if [ -n "$2" ]
then
docker compose ${ALL_DFL} stop $2 &&
docker compose ${DFL} build --no-cache $2 &&
docker compose ${ALL_DFL} up $2 -d &&
docker system prune -f &&
echo "################################################################" &&
echo "Build of $2 Completed Successfully and Restarted" &&
echo "################################################################"
else
git pull &&
full_stop &&
docker system prune -f &&
docker compose ${DFL} build --no-cache &&
echo "################################################################" &&
echo "Build Completed Successfully" &&
echo "################################################################" &&
echo "" &&
docker compose ${DFL} up ${DCL} -d
fi
;;
router)
if [ -n "$2" ]
then
case "$2" in
start)
if [ "$(is_running watchdog)" = "y" ]; then
docker exec -it "$(comp_name lantis-router)" sh -c "cd /lantis; bash ./lantis.bash -L"
else
echo "LANTIS Router is not running"
fi;;
stop)
if [ "$(is_running watchdog)" = "y" ]; then
docker exec -it "$(comp_name lantis-router)" sh -c "cd /lantis; bash ./lantis.bash -K"
else
echo "LANTIS Router is not running"
fi;;
keygen-setup)
ssh-keygen -f ./common/keys/setup.key -N '' -b 2048 &&
echo "Your Setup Public Key is:" &&
cat ./common/keys/setup.key.pub &&
echo '';;
keygen-master)
ssh-keygen -f ./common/keys/lantis.key -N '' -b 2048 &&
echo "Your LANTIS Public Key is:" &&
cat ./common/keys/setup.key.pub &&
echo '';;
pubkeys)
echo "Your Setup Public Key is:" &&
cat ./common/keys/setup.key.pub &&
echo ' ' &&
echo "Your LANTIS Public Key is:" &&
cat ./common/keys/setup.key.pub &&
echo '';;
config) nano ./common/config/connections/*.rc;;
*) echo "Invalid command";;
esac
else
echo "Missing command"
fi
;;
refresh)
echo "Updating to latest commit..."
UPDATE_COMMAND='git fetch && git reset --hard origin && npm install'
if [ "$(is_running watchdog)" = "y" ]; then
docker exec -it "$(comp_name watchdog)" sh -c "cd /across/watchdog/ && " &&
docker compose restart watchdog &&
sleep 5 &&
docker exec -it "$(comp_name watchdog)" sh -c '/wait && mysql -h "$DATABASE_HOST" -u "$DATABASE_USERNAME" -p"$DATABASE_PASSWORD" kanmi_system < /across/compliance_v20.sql';
fi
if [ "$(is_running authware)" = "y" ]; then
docker exec -it "$(comp_name authware)" sh -c "cd /across/sequenzia-framework/ && ${UPDATE_COMMAND}" &&
docker compose restart authware
fi
if [ "$(is_running framework)" = "y" ]; then
docker exec -it "$(comp_name framework)" sh -c "cd /across/sequenzia-framework/ && ${UPDATE_COMMAND}" &&
docker compose restart framework
fi
if [ "$(is_running fileworker)" = "y" ]; then
docker exec -it "$(comp_name fileworker)" sh -c "cd /across/sequenzia-framework/ && ${UPDATE_COMMAND}" &&
docker compose restart fileworker
fi
if [ "$(is_running web)" = "y" ]; then
docker exec -it "$(comp_name web)" sh -c "cd /across/sequenzia-web/ && ${UPDATE_COMMAND}" &&
docker compose restart web
fi
if [ "$(is_running lantis-router)" = "y" ]; then
docker exec -it "$(comp_name lantis-router)" sh -c "cd /lantis && git fetch && git reset" &&
docker compose restart lantis-router
fi
echo "################################################################" &&
echo "Refresh Completed - This is NOT persistent and you will need to" &&
echo "build to persistently update the images" &&
echo "################################################################" &&
echo "";;
prerelease)
echo "Updating to latest prerelease commit..."
if [ "$(git rev-parse --abbrev-ref HEAD)" = "prerelease" ]; then
UPDATE_COMMAND='git fetch; [ "$(git show-ref prerelease | wc -l)" -eq 0 ] && echo "No Update Available" && exit 1 || git reset --hard "origin/prerelease" && npm install'
if [ -n "$2" ]
then
if [ "$(is_running $2)" = "y" ]; then
if [ "$2" == "web" ]; then
docker exec -it "$(comp_name $2)" sh -c "cd /across/sequenzia-web/ && ${UPDATE_COMMAND}"
elif [ "$2" == "watchdog" ]; then
docker exec -it "$(comp_name $2)" sh -c "cd /across/watchdog/ && ${UPDATE_COMMAND}"
else
docker exec -it "$(comp_name $2)" sh -c "cd /across/sequenzia-framework/ && ${UPDATE_COMMAND}"
fi
docker compose restart $2;
fi
else
if [ "$(is_running watchdog)" = "y" ]; then
docker exec -it "$(comp_name watchdog)" sh -c "cd /across/watchdog/ && ${UPDATE_COMMAND}" &&
docker compose restart watchdog &&
sleep 5;
docker exec -it "$(comp_name watchdog)" sh -c '/wait && mysql -h "$DATABASE_HOST" -u "$DATABASE_USERNAME" -p"$DATABASE_PASSWORD" kanmi_system < /across/compliance_v20.sql'
fi
if [ "$(is_running authware)" = "y" ]; then
docker exec -it "$(comp_name authware)" sh -c "cd /across/sequenzia-framework/ && ${UPDATE_COMMAND}" &&
docker compose restart authware;
fi
if [ "$(is_running framework)" = "y" ]; then
docker exec -it "$(comp_name framework)" sh -c "cd /across/sequenzia-framework/ && ${UPDATE_COMMAND}" &&
docker compose restart framework;
fi
if [ "$(is_running fileworker)" = "y" ]; then
docker exec -it "$(comp_name fileworker)" sh -c "cd /across/sequenzia-framework/ && ${UPDATE_COMMAND}" &&
docker compose restart fileworker;
fi
if [ "$(is_running web)" = "y" ]; then
docker exec -it "$(comp_name web)" sh -c "cd /across/sequenzia-web/ && ${UPDATE_COMMAND}" &&
docker compose restart web;
fi
fi
echo "################################################################" &&
echo "Prerelease Refresh Completed - So things may be broken..." &&
echo "This is NOT persistent and you will need to update environment" &&
echo "file to use prerelease and build to persistently update the images" &&
echo "################################################################" &&
echo ""
else
echo "Please run 'git checkout prerelease' to update the compose scripts. This is to ensure that the latest compliance file is used (if needed)."
fi;;
fbuild)
git pull &&
docker build --no-cache -t kihara/across-base:latest ./base &&
docker tag kihara/across-base:latest kihara/across-base:v20 &&
full_stop &&
docker compose build --no-cache &&
docker system prune -f &&
echo "################################################################" &&
echo "Build Completed Successfully" &&
echo "################################################################" &&
echo "" &&
echo "Please use your appropriate start command or just use 'start'"
;;
publish) docker push kihara/across-base:latest && docker push kihara/across-base:v20;;
backup)
docker compose up database -d &&
docker exec -it "$(docker compose ps database | tail -n +2 | awk '{ print $1 }')" sh /backup.sh
echo "DANGER!!! BACKUP FILES CONTAIN UNENCRYPTED USER DATA AND ARE CONSIDERED PROTECTED CONFIDENTIAL DATA"
echo "YOU ARE RESPONSIBLE FOR THE SECURITY OF THESE FILES, ACADEMY CITY RESEARCH AND DIGITAL ARTIFACTS LLC"
echo "IS NOT RESPONSIBLE FOR ANY DAMAGES CAUSED BY IMPROPER HANDLING OF BACKUP FILES";;
restore)
cp "$(ls -Art ./common/data/backup/database-* | tail -n 1)" ./common/data/backup/restore.sqldump.bz2;
full_stop &&
docker compose up database -d &&
docker exec -it "$(docker compose ps database | tail -n +2 | awk '{ print $1 }')" sh /restore.sh &&
echo "You can now start Sequenzia normally!";;
export)
full_stop &&
docker compose up database -d &&
docker exec -it "$(docker compose ps database | tail -n +2 | awk '{ print $1 }')" sh /backup.sh kickstart.sql &&
tar --exclude=./common/config/compliance* \
--exclude=./common/config/example.* \
--exclude=./common/data/upload \
--exclude=./common/data/.temp \
--exclude=./common/data/.web-upload \
--exclude=./common/data/backup/database-* \
-cvjf "./sequenzia-kickstart-$(date +%Y-%m-%d_%H-%M).tar.bz2" \
./common/data/ \
./common/config/ \
./common/www-root/ \
./common/persistent/ \
./common/ssl/ \
./common/keys/ \
./sequenzia-web/public &&
rm ./common/data/backup/kickstart.sql &&
full_stop &&
echo "Export Completed, Please take the kickstart file to your new server or store this for later!"
echo ""
echo "DANGER!!! KICKSTART FILES CONTAIN UNENCRYPTED USER DATA AND ARE CONSIDERED PROTECTED CONFIDENTIAL DATA"
echo "YOU ARE RESPONSIBLE FOR THE SECURITY OF THESE FILES, ACADEMY CITY RESEARCH AND DIGITAL ARTIFACTS LLC"
echo "IS NOT RESPONSIBLE FOR ANY DAMAGES CAUSED BY IMPROPER HANDLING OF KICKSTART FILES";;
import)
if [ "$(ls -Art ./sequenzia-kickstart* | wc -l)" -gt 0 ]; then
tar xvf "$(ls -Art ./sequenzia-kickstart* | tail -n 1)" &&
full_stop &&
docker compose build --no-cache &&
docker compose up database -d &&
docker exec -it "$(docker compose ps database | tail -n +2 | awk '{ print $1 }')" sh /restore.sh kickstart.sql
rm ./common/data/backup/kickstart.sql &&
echo "Import Completed, Ready to start Sequenzia!"
else
echo "No kickstart file found!"
fi;;
upload)
docker compose up database -d &&
docker exec -it "$(docker compose ps database | tail -n +2 | awk '{ print $1 }')" sh /backup.sh && cp common/data/backup/database-* common/data/upload/Backup
echo "The backup file should now be uploading to Sequenzia's Backup folder."
echo ""
echo "If you removed that folder then your in big fucking trouble, because it will upload to the data channel..."
echo "DANGER!!! BACKUP FILES CONTAIN UNENCRYPTED USER DATA AND ARE CONSIDERED PROTECTED CONFIDENTIAL DATA"
echo "YOU ARE RESPONSIBLE FOR THE SECURITY OF THESE FILES, ACADEMY CITY RESEARCH AND DIGITAL ARTIFACTS LLC"
echo "IS NOT RESPONSIBLE FOR ANY DAMAGES CAUSED BY IMPROPER HANDLING OF BACKUP FILES";;
*) echo "$1 is not an valid command" ;;
esac
else
echo ""
echo "start - Boot server"
echo "stop - Shutdown server"
echo "restart - Restart server"
echo "reset - Reset server OS"
echo ' [?] Above commands support specifying a component or "list"'
echo 'mode - Show or Set Operator Mode'
echo '- append - Append mode to operator mode'
echo ''
echo 'router - Interface with embedded LANTIS router (must be enabled)'
echo '- start - Start all routes'
echo '- stop - Kill all routes'
echo '- keygen-setup - Generate a new keypair for setup'
echo '- keygen-master - Generate a new keypair for transport'
echo '- pubkeys - Display public keys'
echo '- config - Edit the Connections'
echo ''
echo "status - Status of components"
echo "logs - Show components logs"
echo ""
echo "test - Boot server in foreground"
echo "test-core - Boot Core Components in foreground"
echo ""
echo "config - Edit User Configuration File"
echo "env - Edit User Environment File"
echo "setupaw - Edit AuthWare Configuration File"
echo ""
echo 'certs - Manage SSL Certificates'
echo '- request - Request new certificate from Certbot'
echo '- selfsigned - Generate self signed certificate'
echo '- reset - Remove Certbot Certificates and Settings'
echo ''
echo '[!] You MUST have configured a valid "EXTERNAL_FQDN", "CERT_EMAIL", and'
echo ' have configured LANTIS or Port Forwarding for remote access'
echo ""
echo "refresh - Update to latest commit (Non-Persistent)"
echo "prerelease - Update to latest prerelease commit (Non-Persistent)"
echo "build - Rebuild Element(s) and Reload Static Files"
echo "fbuild - Rebuild ACROSS, Update base files, and Build Elements"
echo "publish - Publish ACROSS Images (Contributors Only)"
echo ""
echo "upload - Backup Database to Discord #backup Channel"
echo "backup - Backup Database to /common/data/backup"
echo "restore - Restore last Database from /common/data/backup"
echo ""
echo "export - Export Kickstart Tarball"
echo "import - Import Kickstart Tarball"
fi