-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·767 lines (589 loc) · 22.3 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·767 lines (589 loc) · 22.3 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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
#!/bin/bash
set -Eeo pipefail
if [[ "$(dirname "$(realpath -s "${0}")")" != "${PWD}" ]]; then
echo 'Unable to run script out of its parent directory.'
exit 1
fi
source src/commons/input.sh
source src/commons/error.sh
source src/commons/logger.sh
source src/commons/validators.sh
source src/commons/text.sh
source src/commons/math.sh
source src/commons/process.sh
LOGS_HOME=/var/log/stack
LOG_FILE="${LOGS_HOME}/install.log"
PROGRESS_FILE="${LOGS_HOME}/progress.log"
SETTINGS_FILE=./settings.json
# Initializes the installer.
init () {
# Reset logs
mkdir -p "${LOGS_HOME}"
echo '' > "${LOG_FILE}"
# Initialize settings file
echo '{}' > "${SETTINGS_FILE}"
}
# Shows the welcome screen to the user.
welcome () {
clear
log '░░░█▀▀░▀█▀░█▀█░█▀▀░█░█░░░'
log '░░░▀▀█░░█░░█▀█░█░░░█▀▄░░░'
log '░░░▀▀▀░░▀░░▀░▀░▀▀▀░▀░▀░░░'
log -n 'Welcome to the Stack Linux installer.'
log 'Base your development stack on Arch Linux.'
confirm -n 'Do you want to proceed?' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
if is_no "${REPLY}"; then
abort 'Sure, maybe next time!'
fi
}
# Detects any hardware data to collect extra
# required props to install the new system.
detect_system () {
local is_uefi
is_uefi () {
local uefi_mode='no'
if directory_exists '/sys/firmware/efi/efivars'; then
uefi_mode='yes'
fi
local settings=''
settings="$(jq -er ".uefi_mode = \"${uefi_mode}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save uefi_mode setting.'
}
local is_virtual_machine
is_virtual_machine () {
local vm_vendor=''
vm_vendor="$(systemd-detect-virt 2>&1)"
if is_not_empty "${vm_vendor}" && not_equals "${vm_vendor}" 'none'; then
local settings=''
settings="$(jq -er '.vm = "yes"' "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save vm setting.'
local settings=''
settings="$(jq -er ".vm_vendor = \"${vm_vendor}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save vm_vendor setting.'
else
local settings=''
settings="$(jq -er '.vm = "no"' "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save vm setting.'
fi
}
local resolve_cpu
resolve_cpu () {
local cpu_data=''
cpu_data="$(lscpu 2>&1)" ||
abort 'Unable to detect CPU data.'
local cpu_vendor='generic'
if grep -Eq 'AuthenticAMD' <<< "${cpu_data}"; then
cpu_vendor='amd'
elif grep -Eq 'GenuineIntel' <<< "${cpu_data}"; then
cpu_vendor='intel'
fi
local settings=''
settings="$(jq -er ".cpu_vendor = \"${cpu_vendor}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save cpu_vendor setting.'
}
local resolve_gpu
resolve_gpu () {
local gpu_data=''
gpu_data="$(lspci 2>&1)" ||
abort 'Unable to detect GPU data.'
local gpu_vendor='generic'
if grep -Eq 'NVIDIA|GeForce' <<< ${gpu_data}; then
gpu_vendor='nvidia'
elif grep -Eq 'Radeon|AMD' <<< ${gpu_data}; then
gpu_vendor='amd'
elif grep -Eq 'Integrated Graphics Controller' <<< ${gpu_data}; then
gpu_vendor='intel'
elif grep -Eq 'Intel Corporation UHD' <<< ${gpu_data}; then
gpu_vendor='intel'
fi
local settings=''
settings="$(jq -er ".gpu_vendor = \"${gpu_vendor}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save gpu_vendor setting.'
}
is_uefi &&
is_virtual_machine &&
resolve_cpu &&
resolve_gpu
}
# Asks the user the installation settings in order
# to collect all the required props to install the
# new system.
ask_user () {
local select_disk
select_disk () {
local fields='name,path,type,size,rm,ro,tran,hotplug,state,'
fields+='vendor,model,rev,serial,mountpoint,mountpoints,'
fields+='label,uuid,fstype,fsver,fsavail,fsused,fsuse%'
local query='[.blockdevices[]|select(.type == "disk")]'
local disks=''
disks="$(lsblk -J -o "${fields}" | jq -cer "${query}" 2> /dev/null)"
if has_failed; then
abort 'Unable to list disk block devices.'
fi
local trim='.|gsub("^\\s+|\\s+$";"")'
local vendor="\(.vendor|if . then .|${trim} else empty end)"
local model="\(.model|if . then .|${trim} else empty end)"
local value=''
value+="[\"${vendor}\", \"${model}\", .size]|join(\" \")"
value="\(${value}|if . != \"\" then \" [\(.|${trim})]\" else empty end)"
value="\(.path)${value}"
local query=''
query="[.[]|{key: .path, value: \"${value}\"}]"
disks="$(echo "${disks}" | jq -cer "${query}")"
if has_failed; then
abort 'Failed to parse disks data.'
fi
pick_one 'Select the installation disk:' "${disks}" 'vertical' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
local disk="${REPLY}"
local prompt=''
prompt+="All data in ${disk} disk will be lost!"
prompt+='\nDo you want to proceed with this disk?'
confirm "${prompt}" || abort
is_not_given "${REPLY}" && abort 'User input is required.'
if is_no "${REPLY}"; then
abort 'Sure, better be safe than sorry!'
fi
local settings=''
settings="$(jq -er ".disk = \"${disk}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save disk setting.'
local discards=''
discards="$(lsblk -dn --discard -o DISC-GRAN,DISC-MAX "${disk}" 2>&1)" ||
abort 'Unable to list disk block devices.'
local trim_disk='no'
if match "${discards}" ' *[1-9]+[TGMB] *[1-9]+[TGMB] *'; then
trim_disk='yes'
fi
local settings=''
settings="$(jq -er ".trim_disk = \"${trim_disk}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save trim_disk setting.'
}
local opt_in_swap_space
opt_in_swap_space () {
confirm 'Do you want to enable swap space?' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
if is_no "${REPLY}"; then
local settings=''
settings="$(jq -er '.swap_on = "no" | del(.swap_size, .swap_type)' "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save swap_on setting.'
return 0
fi
local settings=''
settings="$(jq -er '.swap_on = "yes"' "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save swap_on setting.'
ask 'Enter the size of the swap space in GBs:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
while is_not_integer "${REPLY}" '[1,]'; do
ask 'Please enter a valid swap space size in GBs:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
done
local swap_size="${REPLY}"
local settings=''
settings="$(jq -er ".swap_size = ${swap_size}" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save swap_size setting.'
local swap_types=''
swap_types+='{"key": "file", "value":"File"},'
swap_types+='{"key": "partition", "value":"Partition"}'
swap_types="[${swap_types}]"
pick_one 'Which type of swap to setup:' "${swap_types}" 'horizontal' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
local swap_type="${REPLY}"
local settings=''
settings="$(jq -er ".swap_type = \"${swap_type}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save swap_type setting.'
}
local select_mirrors
select_mirrors () {
local mirrors=''
mirrors="$(reflector --list-countries 2> /dev/null | tail -n +3 | awk '{
match($0, /(.*)([A-Z]{2})\s+([0-9]+)/, a)
gsub(/[ \t]+$/, "", a[1])
frm="{\"key\": \"%s\", \"value\": \"%s\"},"
printf frm, a[2], a[1]" ["a[3]"]"
}')"
if has_failed; then
abort 'Unable to fetch package databases mirrors.'
fi
# Remove the extra comma from the last element
mirrors="[${mirrors:+${mirrors::-1}}]"
pick_many 'Select package databases mirrors:' "${mirrors}" 'vertical' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
mirrors="${REPLY}"
local settings=''
settings="$(jq -er ".mirrors = ${mirrors}" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save mirrors setting.'
}
local select_timezone
select_timezone () {
local timezones=''
timezones="$(timedatectl list-timezones 2> /dev/null | awk '{
print "{\"key\":\""$0"\",\"value\":\""$0"\"},"
}')"
if has_failed; then
abort 'Unable to list timezones.'
fi
# Remove the extra comma after the last array element
timezones="[${timezones:+${timezones::-1}}]"
pick_one 'Select the system timezone:' "${timezones}" 'vertical' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
local timezone="${REPLY}"
local settings=''
settings="$(jq -er ".timezone = \"${timezone}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save timezone setting.'
}
local select_locales
select_locales () {
local locales=''
locales="$(cat /etc/locale.gen | tail -n +24 | grep -E '^\s*#.*' | tr -d '#' | trim | awk '{
print "{\"key\":\""$0"\",\"value\":\""$0"\"},"
}')"
if has_failed; then
abort 'Unable to list the locales.'
fi
# Removes the last comma delimiter from the last element
locales="[${locales:+${locales::-1}}]"
pick_many 'Select system locales by order:' "${locales}" 'vertical' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
locales="${REPLY}"
local settings=''
settings="$(jq -er ".locales = ${locales}" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save locales setting.'
}
local select_keyboard_model
select_keyboard_model () {
local models=''
models="$(localectl --no-pager list-x11-keymap-models 2> /dev/null | awk '{
print "{\"key\":\""$1"\",\"value\":\""$1"\"},"
}')"
if has_failed; then
abort 'Unable to list keyboard models.'
fi
# Remove the extra comma delimiter from the last element
models="[${models:+${models::-1}}]"
pick_one 'Select a keyboard model:' "${models}" 'vertical' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
local keyboard_model="${REPLY}"
local settings=''
settings="$(jq -er ".keyboard_model = \"${keyboard_model}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save keyboard_model setting.'
}
local select_keyboard_map
select_keyboard_map () {
local maps=''
maps="$(localectl --no-pager list-keymaps 2> /dev/null | awk '{
print "{\"key\":\""$0"\",\"value\":\""$0"\"},"
}')"
if has_failed; then
abort 'Unable to list keyboard maps.'
fi
# Remove extra comma delimiter from the last element
maps="[${maps:+${maps::-1}}]"
pick_one 'Select a keyboard map:' "${maps}" 'vertical' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
local keyboard_map="${REPLY}"
local settings=''
settings="$(jq -er ".keyboard_map = \"${keyboard_map}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save keyboard_map setting.'
}
local select_keyboard_layout
select_keyboard_layout () {
local layouts=''
layouts="$(localectl --no-pager list-x11-keymap-layouts 2> /dev/null | awk '{
print "{\"key\":\""$0"\",\"value\":\""$0"\"},"
}')"
if has_failed; then
abort 'Unable to list keyboard layouts.'
fi
# Remove the extra comma delimiter from last element
layouts="[${layouts:+${layouts::-1}}]"
pick_one 'Select a keyboard layout:' "${layouts}" 'vertical' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
local keyboard_layout="${REPLY}"
local settings=''
settings="$(jq -er ".keyboard_layout = \"${keyboard_layout}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save keyboard_layout setting.'
local variants='{"key": "default", "value": "default"},'
variants+="$(localectl --no-pager list-x11-keymap-variants "${keyboard_layout}" 2> /dev/null | awk '{
print "{\"key\":\""$0"\",\"value\":\""$0"\"},"
}')"
if has_failed; then
abort 'Unable to list layout variants.'
fi
# Remove the extra comma delimiter from last element
variants="[${variants:+${variants::-1}}]"
pick_one "Select a ${keyboard_layout} layout variant:" "${variants}" vertical || abort
is_not_given "${REPLY}" && abort 'User input is required.'
local layout_variant="${REPLY}"
local settings=''
settings="$(jq -er ".layout_variant = \"${layout_variant}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save layout_variant setting.'
}
local select_keyboard_options
select_keyboard_options () {
local options=''
options="$(localectl --no-pager list-x11-keymap-options 2> /dev/null | awk '{
print "{\"key\":\""$0"\",\"value\":\""$0"\"},"
}')"
if has_failed; then
abort 'Unable to list keyboard options.'
fi
# Remove extra comma delimiter from last element
options="[${options:+${options::-1}}]"
pick_one 'Select the keyboard options value:' "${options}" 'vertical' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
local keyboard_options="${REPLY}"
local settings=''
settings="$(jq -er ".keyboard_options = \"${keyboard_options}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save keyboard_options setting.'
}
local enter_host_name
enter_host_name () {
ask 'Enter the name of the host:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
while not_match "${REPLY}" '^[a-z][a-z0-9_-]+$'; do
ask 'Please enter a valid host name:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
done
local host_name="${REPLY}"
local settings=''
settings="$(jq -er ".host_name = \"${host_name}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save host_name setting.'
}
local enter_user_name
enter_user_name () {
ask 'Enter the name of the user:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
while not_match "${REPLY}" '^[a-z][a-z0-9_-]+$'; do
ask 'Please enter a valid user name:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
done
local user_name="${REPLY}"
local settings=''
settings="$(jq -er ".user_name = \"${user_name}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save user_name setting.'
}
local enter_user_password
enter_user_password () {
ask_secret 'Enter the user password (at least 4 chars):' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
while not_match "${REPLY}" '^[a-zA-Z0-9`~!@#\$%^&*()=+{};:",.<>/\?_-]{4,}$'; do
ask_secret 'Please enter a valid password:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
done
local password="${REPLY}"
ask_secret 'Re-type the given password:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
while not_equals "${REPLY}" "${password}"; do
ask_secret 'Not matched, please re-type the given password:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
done
local settings=''
settings="$(jq -er ".user_password = \"${password}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save user_password setting.'
}
local enter_root_password
enter_root_password () {
ask_secret 'Enter the root password (at least 4 chars):' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
while not_match "${REPLY}" '^[a-zA-Z0-9`~!@#\$%^&*()=+{};:",.<>/\?_-]{4,}$'; do
ask_secret 'Please enter a valid password:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
done
local password="${REPLY}"
ask_secret 'Re-type the given password:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
while not_equals "${REPLY}" "${password}"; do
ask_secret 'Not matched, please re-type the given password:' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
done
local settings=''
settings="$(jq -er ".root_password = \"${password}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save root_password setting.'
}
local select_kernel
select_kernel () {
local kernels=''
kernels+='{"key": "stable", "value": "Stable"},'
kernels+='{"key": "lts", "value": "LTS"}'
kernels="[${kernels}]"
pick_one 'Select which linux kernel to install:' "${kernels}" 'horizontal' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
local kernel="${REPLY}"
local settings=''
settings="$(jq -er ".kernel = \"${kernel}\"" "${SETTINGS_FILE}")" &&
echo "${settings}" > "${SETTINGS_FILE}" ||
abort 'Failed to save kernel setting.'
}
while true; do
select_disk &&
opt_in_swap_space &&
select_mirrors &&
select_timezone &&
select_locales &&
select_keyboard_model &&
select_keyboard_map &&
select_keyboard_layout &&
select_keyboard_options &&
enter_host_name &&
enter_user_name &&
enter_user_password &&
enter_root_password &&
select_kernel
log 'Review your installation settings:'
jq 'del(.user_password, .root_password)' "${SETTINGS_FILE}" ||
abort -n 'Unable to read installation settings.'
confirm -n 'Do you want to ask for settings again?' || abort
is_not_given "${REPLY}" && abort 'User input is required.'
if is_no "${REPLY}"; then
break
fi
clear
done
local branch=''
branch="$(git branch --show-current)" ||
abort ERROR 'Failed to read the current branch.'
local disk=''
disk="$(jq -cer '.disk' "${SETTINGS_FILE}")" ||
abort 'Unable to read disk setting.'
local prompt=''
prompt+="Installing Stack Linux [${branch}].\n"
prompt+="All data in ${disk} disk will be lost!\n"
prompt+='Do you really want to proceed?'
confirm "${prompt}" || abort
is_not_given "${REPLY}" && abort 'User input is required.'
if is_no "${REPLY}"; then
abort 'Sure, maybe next time!'
fi
}
# Runs the disk partitioning tasks.
run_diskpart () {
log 'Partitioning the system disk...'
bash src/installer/diskpart.sh 2>&1 |
tee -a "${LOG_FILE}" |
grep --line-buffered -E '^(INFO|WARN|ERROR) ' >> "${PROGRESS_FILE}" &
spin $! "${PROGRESS_FILE}"
if has_failed; then
abort -n 'Oops, a fatal error has been occurred.'
fi
log -u 'System disk partitioning is ready.'
}
# Runs the bootstrap installation tasks.
run_bootstrap () {
log 'Installing the base packages...'
bash src/installer/bootstrap.sh 2>&1 |
tee -a "${LOG_FILE}" |
grep --line-buffered -E '^(INFO|WARN|ERROR) ' >> "${PROGRESS_FILE}" &
spin $! "${PROGRESS_FILE}"
if has_failed; then
abort -n 'Oops, a fatal error has been occurred.'
fi
log -u 'Base packages have been installed.'
}
# Setups the base system and installs system packages.
setup_system () {
log 'Setting up the base system...'
local target='/mnt/stack'
rm -rf "${target}" && rsync -qav /stack/ "${target}" ||
abort -n 'Oops, failed to copy installation files.'
local cmd='cd /stack && ./src/installer/system.sh'
arch-chroot /mnt runuser -u root -- bash -c "${cmd}" 2>&1 |
tee -a "${LOG_FILE}" |
grep --line-buffered -E '^(INFO|WARN|ERROR) ' >> "${PROGRESS_FILE}" &
spin $! "${PROGRESS_FILE}"
if has_failed; then
abort -n 'Oops, a fatal error has been occurred.'
fi
log -u 'System setup has been completed.'
}
# Executes the applications installation tasks.
install_apps () {
log 'Installing the extra applications...'
local user_name=''
user_name="$(jq -cer '.user_name' "${SETTINGS_FILE}")"
if has_failed; then
abort -n 'Unable to read user_name setting.'
fi
local cmd='cd /stack && ./src/installer/apps.sh'
arch-chroot /mnt runuser -u "${user_name}" -- bash -c "${cmd}" 2>&1 |
tee -a "${LOG_FILE}" |
grep --line-buffered -E '^(INFO|WARN|ERROR) ' >> "${PROGRESS_FILE}" &
spin $! "${PROGRESS_FILE}"
if has_failed; then
abort -n 'Oops, a fatal error has been occurred.'
fi
log -u 'Applications have been installed.'
}
# Grants temporary sudo permissions.
grant_perms () {
local rule='%wheel ALL=(ALL:ALL) NOPASSWD: ALL'
sed -i "s/^# \(${rule}\)/\1/" /mnt/etc/sudoers
if has_failed || ! grep -q "^${rule}" /mnt/etc/sudoers; then
abort -n 'Failed to grant permissions.'
fi
}
# Revokes temporarily granted sudo permissions.
revoke_perms () {
local rule='%wheel ALL=(ALL:ALL) NOPASSWD: ALL'
sed -i "s/^\(${rule}\)/# \1/" /mnt/etc/sudoers
if has_failed || ! grep -q "^# ${rule}" /mnt/etc/sudoers; then
log -n 'Failed to revoke permissions.'
fi
}
# Clean installation files and collect logs.
clean () {
# Remove installation files
rm -rf /mnt/stack ||
log 'Unable to remove installation files.'
# Copy the installation log files to the new system
mkdir -p "/mnt/${LOGS_HOME}" &&
cp ${LOG_FILE} "/mnt/${LOGS_HOME}" ||
log 'Unable to copy log file to the new system.'
# Clean redundant log files from live media
rm -f "${LOG_FILE}" "${PROGRESS_FILE}" ||
log 'Unable to remove log file from live media.'
}
# Restarts the system.
restart () {
log -n 'Installation process has been completed.'
log 'Rebooting the system in 15 secs...'
sleep 15
umount -R /mnt || log 'Ignoring busy mount points.'
reboot
}
init &&
welcome &&
detect_system &&
ask_user &&
run_diskpart &&
run_bootstrap &&
grant_perms &&
setup_system &&
install_apps &&
revoke_perms &&
clean &&
restart