discos 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/.github/PRIVACY_POLICY.md +29 -0
  2. package/.github/TERMS_OF_SERVICE.md +56 -0
  3. package/LICENSE +201 -0
  4. package/README.md +70 -0
  5. package/dist/common.d.ts +157 -0
  6. package/dist/common.d.ts.map +1 -0
  7. package/dist/common.js +226 -0
  8. package/dist/common.js.map +1 -0
  9. package/dist/config.d.ts +18 -0
  10. package/dist/config.d.ts.map +1 -0
  11. package/dist/config.js +20 -0
  12. package/dist/config.js.map +1 -0
  13. package/dist/ext/langMap.d.ts +2 -0
  14. package/dist/ext/langMap.d.ts.map +1 -0
  15. package/dist/ext/langMap.js +275 -0
  16. package/dist/ext/langMap.js.map +1 -0
  17. package/dist/index.d.ts +3 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +21 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/modules/admin.d.ts +4 -0
  22. package/dist/modules/admin.d.ts.map +1 -0
  23. package/dist/modules/admin.js +281 -0
  24. package/dist/modules/admin.js.map +1 -0
  25. package/dist/modules/clear.d.ts +3 -0
  26. package/dist/modules/clear.d.ts.map +1 -0
  27. package/dist/modules/clear.js +82 -0
  28. package/dist/modules/clear.js.map +1 -0
  29. package/dist/modules/command.d.ts +5 -0
  30. package/dist/modules/command.d.ts.map +1 -0
  31. package/dist/modules/command.js +89 -0
  32. package/dist/modules/command.js.map +1 -0
  33. package/dist/modules/debug.d.ts +4 -0
  34. package/dist/modules/debug.d.ts.map +1 -0
  35. package/dist/modules/debug.js +47 -0
  36. package/dist/modules/debug.js.map +1 -0
  37. package/dist/modules/file.d.ts +7 -0
  38. package/dist/modules/file.d.ts.map +1 -0
  39. package/dist/modules/file.js +141 -0
  40. package/dist/modules/file.js.map +1 -0
  41. package/dist/modules/watch.d.ts +4 -0
  42. package/dist/modules/watch.d.ts.map +1 -0
  43. package/dist/modules/watch.js +63 -0
  44. package/dist/modules/watch.js.map +1 -0
  45. package/dist/shared/consts.d.ts +3 -0
  46. package/dist/shared/consts.d.ts.map +1 -0
  47. package/dist/shared/consts.js +6 -0
  48. package/dist/shared/consts.js.map +1 -0
  49. package/dist/shared/index.d.ts +3 -0
  50. package/dist/shared/index.d.ts.map +1 -0
  51. package/dist/shared/index.js +19 -0
  52. package/dist/shared/index.js.map +1 -0
  53. package/dist/shared/interfaces.d.ts +13 -0
  54. package/dist/shared/interfaces.d.ts.map +1 -0
  55. package/dist/shared/interfaces.js +3 -0
  56. package/dist/shared/interfaces.js.map +1 -0
  57. package/dist/slash-commands.d.ts +2 -0
  58. package/dist/slash-commands.d.ts.map +1 -0
  59. package/dist/slash-commands.js +242 -0
  60. package/dist/slash-commands.js.map +1 -0
  61. package/dist/startup.d.ts +2 -0
  62. package/dist/startup.d.ts.map +1 -0
  63. package/dist/startup.js +200 -0
  64. package/dist/startup.js.map +1 -0
  65. package/dist/tools/backend.d.ts +5 -0
  66. package/dist/tools/backend.d.ts.map +1 -0
  67. package/dist/tools/backend.js +155 -0
  68. package/dist/tools/backend.js.map +1 -0
  69. package/dist/tools/ipcServer.d.ts +4 -0
  70. package/dist/tools/ipcServer.d.ts.map +1 -0
  71. package/dist/tools/ipcServer.js +83 -0
  72. package/dist/tools/ipcServer.js.map +1 -0
  73. package/dist/tools/queue-utils.d.ts +9 -0
  74. package/dist/tools/queue-utils.d.ts.map +1 -0
  75. package/dist/tools/queue-utils.js +70 -0
  76. package/dist/tools/queue-utils.js.map +1 -0
  77. package/dist/tools/validateDb.d.ts +2 -0
  78. package/dist/tools/validateDb.d.ts.map +1 -0
  79. package/dist/tools/validateDb.js +111 -0
  80. package/dist/tools/validateDb.js.map +1 -0
  81. package/dist/tools/validateDotenv.d.ts +2 -0
  82. package/dist/tools/validateDotenv.d.ts.map +1 -0
  83. package/dist/tools/validateDotenv.js +117 -0
  84. package/dist/tools/validateDotenv.js.map +1 -0
  85. package/dist/types/db.d.ts +9 -0
  86. package/dist/types/db.d.ts.map +1 -0
  87. package/dist/types/db.js +3 -0
  88. package/dist/types/db.js.map +1 -0
  89. package/dist/types/queues.d.ts +6 -0
  90. package/dist/types/queues.d.ts.map +1 -0
  91. package/dist/types/queues.js +3 -0
  92. package/dist/types/queues.js.map +1 -0
  93. package/package.json +71 -0
  94. package/setup/install.sh +527 -0
@@ -0,0 +1,527 @@
1
+ #!/bin/bash
2
+
3
+ ############### Cleanup ###############
4
+ cleanup() {
5
+ echo -e "\nCleaning up..."
6
+ rm -rf "$TEMP_DIR"
7
+ }
8
+
9
+
10
+ ############### Trap ###############
11
+ trap '
12
+ EXIT_CODE=$?
13
+ cleanup
14
+ if [ $EXIT_CODE -eq 0 ]; then
15
+ echo -e "DiscOS installation completed successfully.\n"
16
+ else
17
+ echo -e "DiscOS installation aborted!\n"
18
+ fi' EXIT
19
+
20
+
21
+ ############### Privilige check ###############
22
+ if [[ "$EUID" -ne 0 ]]; then
23
+ echo "DiscOS install script must run as root."
24
+ exit 1
25
+ fi
26
+
27
+
28
+ ############### Error management ###############
29
+ set -e
30
+ on_error() { echo "DiscOS install script failed. Error on line: $1."; }
31
+ trap 'on_error $LINENO' ERR
32
+
33
+
34
+ ############### Distro-agnostic package installer ###############
35
+ need() {
36
+ PKG="$1"
37
+
38
+ # Check if the binary is already installed
39
+ if command -v "$PKG" >/dev/null 2>&1; then
40
+ return 0
41
+ fi
42
+
43
+ echo "Installing $PKG..."
44
+
45
+ if command -v apt-get >/dev/null 2>&1; then
46
+ apt-get update -y && apt-get install -y "$PKG"
47
+ elif command -v dnf >/dev/null 2>&1; then
48
+ dnf install -y "$PKG"
49
+ elif command -v yum >/dev/null 2>&1; then
50
+ yum install -y "$PKG"
51
+ elif command -v zypper >/dev/null 2>&1; then
52
+ zypper install -y "$PKG"
53
+ elif command -v pacman >/dev/null 2>&1; then
54
+ pacman -S --noconfirm "$PKG"
55
+ elif command -v apk >/dev/null 2>&1; then
56
+ apk add "$PKG"
57
+ else
58
+ echo "No supported package manager found. Please install $PKG manually."
59
+ return 1
60
+ fi
61
+ }
62
+
63
+
64
+ ############### Preparation ###############
65
+ echo -e "\nStarting DiscOS installation..."
66
+
67
+ echo -e "\nInstalling dependencies..."
68
+
69
+ # Install deps for this script
70
+ need sed
71
+ need awk
72
+ need grep
73
+ need git
74
+ need curl
75
+ need tee
76
+ need tail
77
+
78
+ # Install deps for DiscOS
79
+ need cat
80
+ need base64
81
+ need dos2unix
82
+
83
+ echo -e "All dependencies installed."
84
+
85
+
86
+ # Clone the DiscOS repository to a temp directory
87
+ echo -e "\nCloning DiscOS repository into a temporary directory..."
88
+
89
+ TEMP_DIR=$(mktemp -d)
90
+ chmod 777 "$TEMP_DIR" # discos user (Systemd install) can access it
91
+
92
+ if ! git clone --branch main --single-branch --depth 1 https://github.com/BrNi05/DiscOS.git "$TEMP_DIR" &>/dev/null; then
93
+ echo "Failed to clone DiscOS repository."
94
+ exit 1
95
+ fi
96
+
97
+ cd "$TEMP_DIR" || (echo "Failed to enter temp directory." && exit 1)
98
+
99
+
100
+ ############### .env setup ###############
101
+ setup_dotenv() {
102
+ local OPERATOR="$1"
103
+
104
+ echo -e "\nSetting up .env file..."
105
+
106
+ read -rp "If not already, set up your bot. Refer to the docs: https://github.com/BrNi05/DiscOS/wiki/03.-Creating-your-bot. Press any key to continue..."
107
+
108
+ echo
109
+ read -rp "Enter your bot token: " BOT_TOKEN
110
+ read -rp "Enter your bot's app ID (Application ID): " APP_ID
111
+ read -rp "Enter the IDs of the servers where the bot should be active (comma-separated): " GUILD_IDS
112
+ read -rp "Select command queue max size (press Enter for default: 50): " CMD_QUEUE_SIZE
113
+ read -rp "Enter external backend URL (if not used, press Enter): " EXTERNAL_BACKEND_URL
114
+ read -rp "Enter max size for file uploads in MB (press Enter for default: 8): " MAX_FILE_SIZE_MB
115
+ read -rp "Choose text editor overrides (press Enter for default: nano,less,cat,more,vim): " TEXT_EDITOR_OVERRIDES
116
+ read -rp "Choose QuickView filextensions (press Enter for default: .txt,.log,.md,.mdx,.json,.yaml,.yml,.html,.sh,.conf,.csv,.xml,.env,.): " QUICKVIEW_FILE_EXTENSIONS
117
+ read -rp "Choose QuickView max text length (press Enter for default: 2000): " QUICKVIEW_MAX_TEXT_LENGTH
118
+
119
+ DOTENV="$TEMP_DIR/setup/.env"
120
+
121
+ sed -i "s/^BOT_TOKEN=.*/BOT_TOKEN=$BOT_TOKEN/" "$DOTENV"
122
+ sed -i "s/^APP_ID=.*/APP_ID=$APP_ID/" "$DOTENV"
123
+ sed -i "s/^GUILD_IDS=.*/GUILD_IDS=$GUILD_IDS/" "$DOTENV"
124
+ [ -n "$CMD_QUEUE_SIZE" ] && sed -i "s/^CMD_QUEUE_MAX_SIZE=.*/CMD_QUEUE_MAX_SIZE=$CMD_QUEUE_SIZE/" "$DOTENV"
125
+ [ -n "$EXTERNAL_BACKEND_URL" ] && sed -i "s|^BACKEND=.*|BACKEND=$EXTERNAL_BACKEND_URL|" "$DOTENV"
126
+ [ -n "$MAX_FILE_SIZE_MB" ] && sed -i "s/^FILE_MAX_SIZE=.*/FILE_MAX_SIZE=$MAX_FILE_SIZE_MB/" "$DOTENV"
127
+ [ -n "$TEXT_EDITOR_OVERRIDES" ] && sed -i "s|^READ_BIN_OVERRIDE=.*|READ_BIN_OVERRIDE=$TEXT_EDITOR_OVERRIDES|" "$DOTENV"
128
+ [ -n "$QUICKVIEW_FILE_EXTENSIONS" ] && sed -i "s|^QUICK_VIEW=.*|QUICK_VIEW=$QUICKVIEW_FILE_EXTENSIONS|" "$DOTENV"
129
+ [ -n "$QUICKVIEW_MAX_TEXT_LENGTH" ] && sed -i "s/^QUICK_VIEW_MAX_LENGTH=.*/QUICK_VIEW_MAX_LENGTH=$QUICKVIEW_MAX_TEXT_LENGTH/" "$DOTENV"
130
+
131
+ if [ "$OPERATOR" = "write" ]; then
132
+ # Copy .env from CWD to discos home
133
+ cp "$DOTENV" "$DISCOS_HOME/.env"
134
+ chown discos:discos "$DISCOS_HOME/.env"
135
+ chmod 660 "$DISCOS_HOME/.env"
136
+ elif [ "$OPERATOR" = "disp" ]; then
137
+ echo -e "\nGenerated .env content:\n"
138
+ cat "$DOTENV"
139
+ echo -e "\n\nSupply these env vars to your environment as needed."
140
+ else
141
+ # A path was provided - generating there
142
+ cp "$DOTENV" "$OPERATOR/.env"
143
+ chown root:root "$OPERATOR/.env"
144
+ chmod 660 "$OPERATOR/.env"
145
+ fi
146
+
147
+ # Security - since the temp dir can be accessed by any user
148
+ rm -f "$DOTENV"
149
+
150
+ echo -e "\n.env setup process completed."
151
+ }
152
+
153
+
154
+ ############### DB setup ###############
155
+ setup_db() {
156
+ local OPERATOR="$1"
157
+
158
+ echo -e "\nCreating the initial database..."
159
+
160
+ echo -e "You will be added as a DiscOS admin.\n"
161
+
162
+ read -rp "Enter your Discord UID: " DISCORD_UID
163
+ read -rp "Enter the local username that you want to use as the given Discord user: " LOCAL_USERNAME
164
+ read -rp "Enter a single channel ID which DiscOS has already joined: " CHANNEL_ID
165
+
166
+ DB="$TEMP_DIR/setup/db.json"
167
+
168
+ sed -i "s/DC_UID/$DISCORD_UID/g" "$DB"
169
+ sed -i "s/LOCAL_USER/$LOCAL_USERNAME/g" "$DB"
170
+ sed -i "s/CHANNEL_ID/$CHANNEL_ID/g" "$DB"
171
+
172
+ if [ "$OPERATOR" = "write" ]; then
173
+ # Copy db.json from CWD to discos home
174
+ cp "$DB" "$DISCOS_HOME/db.json"
175
+ chown discos:discos "$DISCOS_HOME/db.json"
176
+ chmod 660 "$DISCOS_HOME/db.json"
177
+ elif [ "$OPERATOR" = "disp" ]; then
178
+ echo -e "\nManually create the db.json file where needed."
179
+ echo -e "Generated db.json content:\n"
180
+ cat "$DB"
181
+ echo
182
+ else
183
+ # A path was provided - generating there
184
+
185
+ # Docker release overrides
186
+ sed -i "s/true,/false,/g" "$DB"
187
+
188
+ cp "$DB" "$OPERATOR/db.json"
189
+ chown root:root "$OPERATOR/db.json"
190
+ chmod 660 "$OPERATOR/db.json"
191
+ fi
192
+
193
+ # Security - since the temp dir can be accessed by any user
194
+ rm -f "$DB"
195
+
196
+ echo
197
+ echo "Some default values were set:"
198
+ echo " - Standalone mode: enabled"
199
+ echo " - Safemode: enabled"
200
+ echo " - Lockdown mode: disabled"
201
+ echo "You can change these settings with admos slash commands later."
202
+
203
+ echo -e "\nDatabase setup process completed."
204
+ }
205
+
206
+
207
+ ############### Node.js LTS updater ###############
208
+ setup_node_updater() {
209
+ echo -e "\nAn updater script will be installed and a Systemd service will be created to keep Node.js up to date."
210
+ echo "NOTE: old Node.js versions will NOTE be removed automatically."
211
+
212
+ SCRIPT_PATH='/usr/local/bin/update-node.sh'
213
+ printf '%s\n' '#!/bin/bash' \
214
+ 'export NVM_DIR="$HOME/.nvm"' \
215
+ '[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"' \
216
+ '' \
217
+ 'nvm install --lts' > "$SCRIPT_PATH"
218
+
219
+ chown discos:discos "$SCRIPT_PATH"
220
+ chmod 770 "$SCRIPT_PATH"
221
+
222
+ printf '%s\n' \
223
+ '[Unit]' \
224
+ 'Description=Update Node.js LTS for discos user' \
225
+ '' \
226
+ '[Service]' \
227
+ 'Type=oneshot' \
228
+ 'User=discos' \
229
+ "ExecStart=$SCRIPT_PATH" \
230
+ > /etc/systemd/system/discos-node-updater.service
231
+
232
+ printf '%s\n' \
233
+ '[Unit]' \
234
+ 'Description=Run Node.js LTS update daily' \
235
+ '' \
236
+ '[Timer]' \
237
+ 'OnCalendar=daily' \
238
+ 'Persistent=true' \
239
+ '' \
240
+ '[Install]' \
241
+ 'WantedBy=timers.target' \
242
+ > /etc/systemd/system/discos-node-updater.timer
243
+
244
+ systemctl daemon-reload
245
+ systemctl enable --now discos-node-updater.timer
246
+
247
+ echo -e "Node.js updater script and service installed."
248
+ }
249
+
250
+
251
+ ############### Compose setup ###############
252
+ setup_compose() {
253
+ echo -e "\nSetting up compose file...\n"
254
+
255
+ echo "The latest DiscOS image will be used. Feel free to pin to a specific version if you want manual updates."
256
+
257
+ read -rp "Container name (default DiscOS): " CONTAINER_NAME
258
+ sed -i "s/SERVICE_NAME/${CONTAINER_NAME:-DiscOS}/g" "$COMPOSE_FILE"
259
+ sed -i "s/CONTAINER_NAME/${CONTAINER_NAME:-DiscOS}/g" "$COMPOSE_FILE"
260
+
261
+ read -rp "Logging will use json-file driver. Choose max size (default 10M): " LOG_MAX_SIZE
262
+ sed -i "s/MAX_LOG_SIZE/${LOG_MAX_SIZE:-10M}/g" "$COMPOSE_FILE"
263
+
264
+ read -rp "Choose max number of log files to keep (default 3): " LOG_MAX_FILE
265
+ sed -i "s/MAX_LOG_COUNT/${LOG_MAX_FILE:-3}/g" "$COMPOSE_FILE"
266
+
267
+ echo
268
+ }
269
+
270
+
271
+ ############### cmdex setup ###############
272
+
273
+ setup_cmdex() {
274
+ echo -e "\nSetting up command executor..."
275
+
276
+ cp "$TEMP_DIR/src/.sh/cmd-executor.sh" "/usr/local/bin/cmdex.sh"
277
+ chown discos:discos "/usr/local/bin/cmdex.sh" || (chown root:root "/usr/local/bin/cmdex.sh" && echo "cmdex will be owned by root.")
278
+ chmod 770 "/usr/local/bin/cmdex.sh"
279
+ ln -s "/usr/local/bin/cmdex.sh" "/usr/local/bin/cmdex" >/dev/null 2>&1 || echo "Symlink for cmdex already exists."
280
+
281
+ # Sudoers change
282
+ echo "discos ALL=(ALL) NOPASSWD: /usr/local/bin/cmdex.sh, /usr/local/bin/cmdex" | tee /etc/sudoers.d/cmdex >/dev/null
283
+ chmod 440 /etc/sudoers.d/cmdex
284
+
285
+ echo -e "Command executor setup completed."
286
+ }
287
+
288
+
289
+ ############### Systemd release ###############
290
+ install_systemd() {
291
+ echo -e "\nStarting Systemd release installation..."
292
+
293
+ if ! id -u discos &>/dev/null; then
294
+ useradd --system -m -s "$(command -v nologin)" discos
295
+ echo "Created system user: discos."
296
+ fi
297
+
298
+ DISCOS_HOME=$(getent passwd discos | cut -d: -f6)
299
+
300
+ DISCOS_DIR="$DISCOS_HOME/DiscOS"
301
+
302
+ if [[ "$1" != "update" ]]; then
303
+ echo -e "\nSetting up Node.js..."
304
+ read -rp "Do you have a global / user-scoped Node.js install (y/n)? " NODE_ANSWER
305
+ if [[ "$NODE_ANSWER" = "y" || "$NODE_ANSWER" = "Y" ]]; then
306
+ if ! sudo -u discos bash -euo pipefail -c '
307
+ export NVM_DIR="$HOME/.nvm"
308
+ [ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
309
+ command -v node
310
+ ' >/dev/null 2>&1; then
311
+ echo "ERROR: Node.js not found."
312
+ exit 1
313
+ fi
314
+ else
315
+ echo -e "\nInstalling Node.js via nvm..."
316
+ sudo -u discos bash -euo pipefail -c '
317
+ export NVM_DIR="$HOME/.nvm"
318
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
319
+ [ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
320
+ nvm install --lts
321
+ nvm use --lts
322
+ '
323
+
324
+ echo -e "Node.js installed."
325
+ setup_node_updater
326
+ fi
327
+
328
+ # .env setup
329
+ setup_dotenv "write"
330
+
331
+ # DB setup
332
+ setup_db "write"
333
+
334
+ # Command executor setup
335
+ setup_cmdex
336
+ else
337
+ # Stop the service for before the update process
338
+ systemctl stop discos.service || echo "DiscOS service could not be stopped."
339
+ fi
340
+
341
+ # Compile DiscOS
342
+ echo -e "\nCompiling DiscOS..."
343
+ DISCOS_DIR="$DISCOS_HOME"
344
+
345
+ sudo -u discos bash -euo pipefail -c "
346
+ TEMP_DIR=\"$TEMP_DIR\"
347
+ DISCOS_DIR=\"$DISCOS_DIR\"
348
+
349
+ # Source nvm
350
+ export NVM_DIR=\"\$HOME/.nvm\"
351
+ [ -s \"\$NVM_DIR/nvm.sh\" ] && source \"\$NVM_DIR/nvm.sh\"
352
+
353
+ # Build in the temp dir
354
+ cd \"\$TEMP_DIR\" || { echo 'Failed to enter temp download directory.'; exit 1; }
355
+ echo \"CWD: \$TEMP_DIR\"
356
+ echo 'Installing dependencies...'
357
+ npm ci --silent --ignore-scripts
358
+ npm run build
359
+
360
+ # Copy dist and install only prod deps
361
+ mkdir -p \"\$DISCOS_DIR\"
362
+ rm -rf \"\$DISCOS_DIR/dist\"
363
+ cp -r \"\$TEMP_DIR/dist\" \"\$DISCOS_DIR\"
364
+ cp \"\$TEMP_DIR/package.json\" \"\$DISCOS_DIR\"
365
+ cp \"\$TEMP_DIR/package-lock.json\" \"\$DISCOS_DIR\"
366
+ chmod -R 770 \"\$DISCOS_DIR\"
367
+
368
+ cd \"\$DISCOS_DIR\" || { echo 'Failed to enter DiscOS directory.'; exit 1; }
369
+ npm ci --silent --omit=dev --omit=optional
370
+
371
+ # Remove package.json and package-lock.json
372
+ rm -f package*.json
373
+ "
374
+
375
+ echo -e "\nDiscOS compiled successfully."
376
+
377
+ if [[ "$1" != "update" ]]; then
378
+ # Systemd service and timer setup
379
+ echo -e "\nSetting up DiscOS service..."
380
+ SERVICE_FILE="$TEMP_DIR/setup/discos.service"
381
+
382
+ read -rp "If you have a template service for error handling, enter its name (like: error@.service -> enter: error). If not, press Enter: " ERROR_SERVICE
383
+ if [ -n "$ERROR_SERVICE" ]; then
384
+ sed -i "s/ERROR/$ERROR_SERVICE/g" "$SERVICE_FILE"
385
+ else
386
+ sed -i '/^OnFailure=ERROR@%n\.service$/d' "$SERVICE_FILE"
387
+ fi
388
+
389
+ sed -i "s|WD_PATH|$DISCOS_DIR|g" "$SERVICE_FILE"
390
+
391
+ cp "$SERVICE_FILE" /etc/systemd/system/discos.service
392
+ rm -f "$SERVICE_FILE"
393
+ systemctl daemon-reload
394
+
395
+ read -rp "Do you want DiscOS to start on every boot? (y/n): " START_ON_BOOT
396
+ if [[ "$START_ON_BOOT" == "y" || "$START_ON_BOOT" == "Y" ]]; then
397
+ systemctl enable discos.service
398
+ fi
399
+
400
+ read -rp "Do you want DiscOS to start now? (y/n): " START_NOW
401
+ if [[ "$START_NOW" == "y" || "$START_NOW" == "Y" ]]; then
402
+ systemctl start discos.service
403
+ fi
404
+
405
+ echo -e "\nBe sure the regulary check for updates. You can use this script to install a new version."
406
+
407
+ echo -e "DiscOS service setup completed."
408
+ else
409
+ systemctl start discos.service
410
+ echo -e "\nDiscOS updated successfully."
411
+ fi
412
+ }
413
+
414
+
415
+ ############### npm package release ###############
416
+ install_npm() {
417
+ echo -e "\nStarting npm package release installation...\n"
418
+
419
+ read -rp "Do you plan to run your code in a Docker container (y/Y) or not (n/N)? " IN_DOCKER
420
+ if [[ "$IN_DOCKER" = "y" || "$IN_DOCKER" = "Y" ]]; then
421
+ COMPOSE_FILE="$TEMP_DIR/setup/docker-compose.yaml"
422
+ setup_compose
423
+ echo -e "Compose file will be displayed below. Now rewrite it according to your needs but make sure mounts and env var settings are kept.\n"
424
+ cat "$COMPOSE_FILE"
425
+ echo
426
+ else
427
+ echo "Maybe Systemd then... make sure env vars are loaded into the service."
428
+ fi
429
+
430
+ echo
431
+
432
+ read -rp "Press any key to continue with .env generation. It will only be displayed, copy it where needed."
433
+ setup_dotenv "disp"
434
+
435
+ echo
436
+
437
+ read -rp "Press any key to continue with database generation. It will only be displayed, copy it where needed."
438
+ setup_db "disp"
439
+
440
+ # Command executor setup
441
+ setup_cmdex
442
+
443
+ echo -e "\nnpm release installation process completed."
444
+ }
445
+
446
+
447
+ ############### Docker release ###############
448
+ install_docker() {
449
+ echo -e "\nStarting Docker release installation..."
450
+
451
+ COMPOSE_FILE="$TEMP_DIR/setup/docker-compose.yaml"
452
+ setup_compose
453
+
454
+ read -rp "Do you have an existing compose file (y/Y) or should the script generate on for you (n/N)? " COMPOSE_EXIST
455
+
456
+ if [[ "$COMPOSE_EXIST" = "y" || "$COMPOSE_EXIST" = "Y" ]]; then
457
+ echo -e "DiscOS installer will now display the service:\n"
458
+ tail -n +2 "$COMPOSE_FILE"
459
+ echo
460
+ echo -e "\nPaste this into your compose file."
461
+
462
+ echo
463
+ read -rp "Provide the absolute path to to the directory where your compose file is: " COMPOSE_PATH
464
+ cd "$COMPOSE_PATH" || (echo "Failed to enter compose file directory." && exit 1)
465
+ else
466
+ echo "DiscOS installer will now generate the compose file..."
467
+
468
+ echo
469
+ read -rp "Provide the absolute path to to the directory where your compose should be: " COMPOSE_PATH
470
+ cd "$COMPOSE_PATH" || (echo "Failed to enter compose file directory." && exit 1)
471
+ cp "$COMPOSE_FILE" "$COMPOSE_PATH/docker-compose.yaml"
472
+ chown root:root "$COMPOSE_PATH/docker-compose.yaml"
473
+ chmod 660 "$COMPOSE_PATH/docker-compose.yaml"
474
+ fi
475
+
476
+ echo
477
+
478
+ read -rp "Press any key to continue with .env generation. It will be located in the compose file dir."
479
+ setup_dotenv "$COMPOSE_PATH"
480
+
481
+ echo
482
+
483
+ read -rp "Press any key to continue with database generation. It will be located in the compose file dir."
484
+ setup_db "$COMPOSE_PATH"
485
+
486
+ # Command executor setup
487
+ setup_cmdex
488
+
489
+ echo -e "\nDocker release installation process completed."
490
+ }
491
+
492
+
493
+ ############### Systemd update mode ###############
494
+ if [[ "$1" == "update" ]]; then
495
+ install_systemd "update"
496
+ exit 0
497
+ fi
498
+
499
+
500
+ ############### Release selection ###############
501
+
502
+ echo -e "\nHow do you want to use DiscOS?"
503
+ echo " 1 - as a Systemd service"
504
+ echo " 2 - as an npm package"
505
+ echo " 3 - in a Docker container"
506
+ echo " 4 - other"
507
+
508
+ read -rp "Enter your choice (1-4): " INSTALL_TYPE
509
+
510
+ case $INSTALL_TYPE in
511
+ 1)
512
+ install_systemd
513
+ ;;
514
+ 2)
515
+ install_npm
516
+ ;;
517
+ 3)
518
+ install_docker
519
+ ;;
520
+ 4)
521
+ echo -e "\nPlease refer to the documentation for more information: https://github.com/BrNi05/DiscOS/wiki/01.-Home"
522
+ ;;
523
+ *)
524
+ echo "Invalid choice."
525
+ exit 1
526
+ ;;
527
+ esac