-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.sh
More file actions
executable file
·395 lines (354 loc) · 14.5 KB
/
main.sh
File metadata and controls
executable file
·395 lines (354 loc) · 14.5 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
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
#!/bin/sh
#
# Copyright (C) 2025 Archetypum
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>
NETBSD_WEBSITE="www.netbsd.org"
AUTOINSTALL_CONF_FILE="etc/autoinstall.conf"
PROFILE_CONF_FILE="etc/profile.conf"
warranty()
{
echo "PrototypeNetBSD Copyright (C) 2025 Archetypum"
echo ""
echo "This program comes with ABSOLUTELY NO WARRANTY; for details check LICENSE-GPLv3.md"
echo "This is free software, and you are welcome to redistribute it"
echo "under certain conditions; check LICENSE-GPLv3.md for details."
}
list_of_commands()
{
echo "Usage:"
echo " -h | --help - This message."
echo " -c | --colors - Launches PrototypeNetBSD WITH colored text."
echo " -n | --no-colors - Launches PrototypeNetBSD WITHOUT colored text."
echo " -w | --warranty - Shows information about warranty."
}
check_internet_connection()
{
# Checks Internet connection by pinging NetBSD website.
# Lets hope that www.netbsd.org will be online forever.
echo "${BOLD}[*] Checking Internet connection by pinging $NETBSD_WEBSITE...${NC}"
if ping -c 1 "$NETBSD_WEBSITE" >/dev/null 2>&1; then
echo "${GREEN}[*] [check_internet_connection()]: Internet connection is available.${NC}"
return 0
else
echo "${RED}[!] [check_internet_connection()]: No internet connection detected. Installation cannot proceed.${NC}"
return 1
fi
}
introduction()
{
# Prints out PrototypeNetBSD ASCII logo and other information.
clear
echo "${BOLD}-----------------------------------------------------------------------------------${NC}"
echo "${CYAN} _____ _ _ _ _ _ ____ _____ _____ ${NC}"
echo "${CYAN} | __ \ | | | | | \ | | | | | _ \ / ____| __ \ ${NC}"
echo "${CYAN} | |__) | __ ___ | |_ ___ | |_ _ _ _ __ ___| \| | ___| |_| |_) | (___ | | | |${NC}"
echo "${CYAN} | ___/ '__/ _ \| __/ _ \| __| | | | '_ \ / _ \ . |/ _ \ __| _< \___ \ | | | |${NC}"
echo "${CYAN} | | | | | (_) | || (_) | |_| |_| | |_) | __/ |\ | __/ |_| |_) |____) | |__| |${NC}"
echo "${CYAN} |_| |_| \___/ \__\___/ \__|\__, | .__/ \___|_| \_|\___|\__|____/|_____/|_____/ ${NC}"
echo "${CYAN} __/ | | ${NC}"
echo "${CYAN} |___/|_|${NC} ${BOLD}$(cat etc/prototype_version) for NetBSD $(cat etc/last_netbsd_version)""${NC}"
echo "${BOLD}-----------------------------------------------------------------------------------${NC}"
echo "${BOLD}Made by ${NC}${CYAN}Archetypum${NC}${BOLD}, licensed under ${NC}${CYAN}GNU GPL v3${NC}${BOLD}.${NC}"
echo "${BOLD}Source code available at ${NC}${CYAN}https://github.com/Archetypum/PrototypeNetBSD${NC}"
echo "${BOLD}-----------------------------------------------------------------------------------${NC}"
}
get_automatic_or_manual()
{
# Gets automatic or manual installation choice and stores the results in etc/autoinstall.conf
echo "${BOLD}[?] Enable automatic installation? (y/N)${NC}"
while true; do
read -r ANSWER
case "$ANSWER" in
[yY]*)
AUTOINSTALL_VALUE="true"
break
;;
[nN]*)
AUTOINSTALL_VALUE="false"
break
;;
"")
AUTOINSTALL_VALUE="false"
break
;;
*)
echo "${YELLOW}[!] Please answer 'y' or 'n'.${NC}"
;;
esac
done
if [ ! -f "$AUTOINSTALL_CONF_FILE" ]; then
echo "${YELLOW}[!] Warning! [get_automatic_or_manual()]: Autoinstall configuration file not found. Corrupted installation?${NC}"
echo "$AUTOINSTALL_VALUE" > "$AUTOINSTALL_CONF_FILE"
echo "${GREEN}[*] Success! [get_automatic_or_manual()]: Created autoinstall configuration file: $AUTOINSTALL_CONF_FILE with value: $AUTOINSTALL_VALUE.${NC}"
else
echo "$AUTOINSTALL_VALUE" > "$AUTOINSTALL_CONF_FILE"
echo "${GREEN}[*] Success! [get_automatic_or_manual()]: Log configuration set to: $AUTOINSTALL_VALUE in $AUTOINSTALL_CONF_FILE.${NC}"
fi
}
get_installation_profile()
{
# Gets system profile and stores the results in etc/profile.conf
echo "${BOLD}Available system profiles:"
echo " 1. minimal."
echo " 2. x11."
echo " 3. desktop."
echo " 4. server-openssh."
echo " 5. server-ftp."
echo " 6. server-openvpn."
echo " 7. server-wireguard."
echo " 8. server-dhcp."
echo " 9. server-webserver-apache."
echo " 10. server-webserver-bozotic."
echo " 11. server-webserver-nginx."
echo " 12. server-samba.${NC}"
echo "${BOLD}[==> Enter desired system profile: ${NC}"
while true; do
read -r ANSWER
case "$ANSWER" in
"1")
INSTALLATION_PROFILE="minimal"
break
;;
"2")
INSTALLATION_PROFILE="x11"
break
;;
"3")
INSTALLATION_PROFILE="desktop"
break
;;
"4")
INSTALLATION_PROFILE="server-openssh"
break
;;
"5")
INSTALLATION_PROFILE="server-ftp"
break
;;
"6")
INSTALLATION_PROFILE="server-openvpn"
break
;;
"7")
INSTALLATION_PROFILE="server-wireguard"
break
;;
"8")
INSTALLATION_PROFILE="server-dhcp"
break
;;
"9")
INSTALLATION_PROFILE="server-webserver-apache"
break
;;
"10")
INSTALLATION_PROFILE="server-webserver-bozotic"
break
;;
"11")
INSTALLATION_PROFILE="server-webserver-nginx"
break
;;
"12")
INSTALLATION_PROFILE="server-samba"
break
;;
"")
INSTALLATION_PROFILE="server-openssh"
break
;;
*)
echo "${YELLOW}[!] Please enter a valid installation profile.${NC}"
;;
esac
done
if [ ! -f "$PROFILE_CONF_FILE" ]; then
echo "${YELLOW}[!] Warning! [get_installation_profile()]: Installation profile configuration file not found. Corrupted installation?${NC}"
echo "$INSTALLATION_PROFILE" > "$PROFILE_CONF_FILE"
echo "${GREEN}[*] Success! [create_config_file()]: Created autoinstall configuration file: $AUTOINSTALL_CONF_FILE with value: $INSTALLATION_PROFILE.${NC}"
else
echo "$INSTALLATION_PROFILE" > "$PROFILE_CONF_FILE"
echo "${GREEN}[*] Success! [get_installation_profile()]: Log configuration set to: $INSTALLATION_PROFILE in $PROFILE_CONF_FILE.${NC}"
fi
}
begin_installation()
{
AUTOINSTALL_MODE=$(cat etc/autoinstall.conf)
INSTALLATION_PROFILE=$(cat etc/profile.conf)
confirm_script_execution()
{
if [ "$AUTOINSTALL_MODE" = "false" ]; then
echo "${BOLD}[?] Execute $1? (y/N)${NC}"
while true; do
read -r ANSWER
case "$ANSWER" in
[yY]*)
return 0
;;
[nN]*)
echo "${GREEN}[!] Skipping $1.${NC}"
return 1
;;
"")
echo "${GREEN}[!] Skipping $1 (default).${NC}"
return 1
;;
*)
echo "${YELLOW}[!] Please answer 'y' or 'n'.${NC}"
;;
esac
done
else
return 0
fi
}
execute_script_with_confirmation()
{
SCRIPT_PATH="$1"
SCRIPT_NAME=$(basename "$SCRIPT_PATH")
if confirm_script_execution "$SCRIPT_NAME"; then
sh "$SCRIPT_PATH"
fi
if [ "$SCRIPT_NAME" = "setup_wireguard.sh" ]; then
bash "$SCRIPT_PATH"
fi
if [ "$SCRIPT_NAME" = "setup_openvpn.sh" ]; then
bash "$SCRIPT_PATH"
fi
}
if [ "$INSTALLATION_PROFILE" = "minimal" ]; then
execute_script_with_confirmation "src/install_scripts/fetch_pkgin.sh"
execute_script_with_confirmation "src/install_scripts/install_main.sh"
fi
if [ "$INSTALLATION_PROFILE" = "x11" ]; then
execute_script_with_confirmation "src/install_scripts/fetch_pkgin.sh"
execute_script_with_confirmation "src/install_scripts/install_main.sh"
execute_script_with_confirmation "src/install_scripts/configure_x11.sh"
fi
if [ "$INSTALLATION_PROFILE" = "desktop" ]; then
execute_script_with_confirmation "src/install_scripts/fetch_pkgin.sh"
execute_script_with_confirmation "src/install_scripts/fetch_pkgsrc.sh"
execute_script_with_confirmation "src/install_scripts/install_main.sh"
execute_script_with_confirmation "src/install_scripts/configure_x11.sh"
execute_script_with_confirmation "src/install_scripts/install_dm.sh"
execute_script_with_confirmation "src/install_scripts/install_de.sh"
execute_script_with_confirmation "src/install_scripts/install_misc.sh"
fi
if [ "$INSTALLATION_PROFILE" = "server-openssh" ]; then
execute_script_with_confirmation "src/install_scripts/fetch_pkgin.sh"
execute_script_with_confirmation "src/install_scripts/install_main.sh"
execute_script_with_confirmation "src/install_scripts/install_openssh.sh"
execute_script_with_confirmation "src/install_scripts/install_sshield.sh"
execute_script_with_confirmation "src/install_scripts/install_thesuffocater.sh"
execute_script_with_confirmation "src/install_scripts/install_theunixmanager_bash.sh"
fi
if [ "$INSTALLATION_PROFILE" = "server-ftp" ]; then
execute_script_with_confirmation "src/install_scripts/fetch_pkgin.sh"
execute_script_with_confirmation "src/install_scripts/install_main.sh"
execute_script_with_confirmation "src/install_scripts/install_ftp.sh"
execute_script_with_confirmation "src/install_scripts/install_openssh.sh"
execute_script_with_confirmation "src/install_scripts/install_sshield.sh"
fi
if [ "$INSTALLATION_PROFILE" = "server-dhcp" ]; then
execute_script_with_confirmation "src/install_scripts/fetch_pkgin.sh"
execute_script_with_confirmation "src/install_scripts/install_main.sh"
execute_script_with_confirmation "src/install_scripts/setup_dhcp.sh"
execute_script_with_confirmation "src/install_scripts/install_openssh.sh"
execute_script_with_confirmation "src/install_scripts/install_sshield.sh"
fi
if [ "$INSTALLATION_PROFILE" = "server-webserver-apache" ]; then
execute_script_with_confirmation "src/install_scripts/fetch_pkgin.sh"
execute_script_with_confirmation "src/install_scripts/install_main.sh"
execute_script_with_confirmation "src/install_scripts/install_openssh.sh"
execute_script_with_confirmation "src/install_scripts/setup_webserver_apache.sh"
fi
if [ "$INSTALLATION_PROFILE" = "server-webserver-bozotic" ]; then
execute_script_with_confirmation "src/install_scripts/fetch_pkgin.sh"
execute_script_with_confirmation "src/install_scripts/install_main.sh"
execute_script_with_confirmation "src/install_scripts/install_openssh.sh"
execute_script_with_confirmation "src/install_scripts/setup_webserver_bozotic.sh"
fi
if [ "$INSTALLATION_PROFILE" = "server-webserver-nginx" ]; then
execute_script_with_confirmation "src/install_scripts/fetch_pkgin.sh"
execute_script_with_confirmation "src/install_scripts/install_main.sh"
execute_script_with_confirmation "src/install_scripts/install_openssh.sh"
execute_script_with_confirmation "src/install_scripts/setup_webserver_nginx.sh"
fi
if [ "$INSTALLATION_PROFILE" = "server-samba" ]; then
execute_script_with_confirmation "src/install_scripts/fetch_pkgin.sh"
execute_script_with_confirmation "src/install_scripts/fetch_pkgsrc.sh"
execute_script_with_confirmation "src/install_scripts/install_main.sh"
execute_script_with_confirmation "src/install_scripts/install_openssh.sh"
execute_script_with_confirmation "src/install_scripts/setup_samba.sh"
fi
}
finish_installation()
{
# Prints out helpful resources and finishes the execution of the program.
clear
echo "${BOLD}NetBSD related resources:${NC}"
echo "${BOLD} - Official NetBSD website:${NC} ${CYAN}https://www.netbsd.org/${NC}"
echo "${BOLD} - Official pkgsrc website:${NC} ${CYAN}https://www.pkgsrc.org/${NC}"
echo "${BOLD} - NetBSD manual pages:${NC} ${CYAN}https://man.netbsd.org/${NC}"
echo "${BOLD} - NetBSD mailing lists:${NC} ${CYAN}https://www.netbsd.org/mailinglists/${NC}"
echo "${BOLD} - Wikipedia:${NC} ${CYAN}https://en.wikipedia.org/wiki/NetBSD${NC}"
echo "${BOLD} - The guide:${NC} ${CYAN}https://www.netbsd.org/docs/guide/en/${NC}"
echo "${GREEN}[*] The installation is finished.${NC}"
exit 0
}
main()
{
# [*] MAIN FUNCTION [*]
if ! check_internet_connection; then
echo "${RED}[!] [main()]: Installation aborted due to missing internet connection.${NC}"
exit 1
fi
introduction
get_installation_profile
get_automatic_or_manual
begin_installation
finish_installation
}
parse_args()
{
if [ $# -eq 0 ]; then
. src/color_codes.sh
main
fi
while [ $# -gt 0 ]; do
case "$1" in
"-h" | "--help")
list_of_commands
exit 0
;;
"-c" | "--colors")
. src/color_codes.sh
main
;;
"-n" | "--no-colors")
main
;;
"-w" | "--warranty")
warranty
exit 0
;;
*)
echo "[!] Unknown argument: $1."
exit 1
;;
esac
done
}
parse_args "$@"