forked from kwankiu/archlinux-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharch-installer
1743 lines (1559 loc) · 61.3 KB
/
arch-installer
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
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#################################################################
# _ _ _ #
# /\ | | | | (_) #
# / \ _ __ ___| |__ | | _ _ __ _ ___ __ #
# / /\ \ | '__/ __| '_ \| | | | '_ \| | | \ \/ / #
# / ____ \| | | (__| | | | |____| | | | | |_| |> < #
# /_/ \_\_| \___|_| |_|______|_|_| |_|\__,_/_/\_\ __ #
# _____ _ _ _ ( __)/ \( _ \ #
# |_ _| | | | | | ) _)( O )) / #
# | | _ __ ___| |_ __ _| | | ___ _ __ (__) \__/(__\_) #
# | | | '_ \/ __| __/ _` | | |/ _ \ '__| /__\ ( _ \( \/ ) #
# _| |_| | | \__ \ || (_| | | | __/ | / \ ) // \/ \ #
# |_____|_| |_|___/\__\__,_|_|_|\___|_| \_/\_/(__\_)\_)(_/ #
# #
#################################################################
## Version Control ##
# Installer Version
# format : YYMMDDNN which NN is 01-99 of commits on the same day
installerver=24082001
# Required ACU version
acuver=0.1.5
# Installer Branch / Tag
branch=main
################################################################
## Installer variables ##
# Installer name string
title_string="Arch Linux Installer for ARM"
# Temporary home directory for installer
installer_home="/usr/lib/installer"
# Compiled Packages folder path
compiled_pkg_folder="$installer_home/packages"
# Dialog Theme config file path
dialog_theme_config="$installer_home/dialog.conf"
# Install using the generated configurations
install_config="$installer_home/install.yaml"
# Remote Installer URL
remote_installer_url="https://raw.githubusercontent.com/kwankiu/archlinux-installer/$branch/arch-installer"
# Remote Installer Config URL
remote_installer_config_url="https://raw.githubusercontent.com/kwankiu/archlinux-installer/$branch/config/acu_config.yaml"
# Full Language list
lang_list="https://raw.githubusercontent.com/kwankiu/archlinux-installer/$branch/config/language.yaml"
# Full Kernel list
kernel_list="https://raw.githubusercontent.com/kwankiu/archlinux-installer/$branch/config/kernel.yaml"
# Full Desktop Environment list
de_list="https://raw.githubusercontent.com/kwankiu/archlinux-installer/$branch/config/desktop.yaml"
# Full Post Install list
postinstall_list="https://raw.githubusercontent.com/kwankiu/archlinux-installer/$branch/config/postinstall.yaml"
# Ping server list for internet check
# ping Google, Cloudflare and China Mobile DNS (for China users)
ping_servers=("google.com" "1.1.1.1" "114.114.114.114")
# (Optional) Target Device for Installation (comment this to auto detect from devicetree)
#install_target="radxa-rock-5b"
################################################################
# Auto detect install target from devicetree
if [ -z "$install_target" ]; then
if [ -f "/proc/device-tree/compatible" ]; then
install_target="$(sed 's/\x00/ /g; s/,/ /g' /proc/device-tree/compatible | awk '{print $1, $2}' | tr ' ' '-')"
fi
if [ -z "$install_target" ]; then
install_target="generic"
fi
fi
################################################################
## Debug variable overrides ##
# (FOR DEVELOPMENT USE ONLY, MAKE SURE ALL OVERRIDES ARE COMMENTED FOR PRODUCTION USE)
# Remote Installer URL
#remote_installer_url="https://invalid.example" # use an invalid remote installer url to prevent accidental updates
# Use out folder of current directory as temporary home directory for installer
#installer_home="$(pwd)/out"
# Compiled Packages folder path
#compiled_pkg_folder="$installer_home/packages"
# Dialog Theme config file path
#dialog_theme_config="$installer_home/dialog.conf"
# Install using the generated configurations
#install_config="$installer_home/install.yaml"
# Dialog override for debugging CLI Fallback
#dialog () { return 1; }
# Ping server list for internet check
#ping_servers=("invalid.example") # debug test case: simulate no internet
#ping_servers=("0.0.0.0") # debug test case: bypass internet
################################################################
# Tools for formatting / styling
# Customize terminal/tty console colors
echo -en "\e]P41a73e8" #darkblue
echo -en "\e]PC1a73e8" #blue
echo -en "\e]P653cced" #darkcyan
echo -en "\e]PE53cced" #cyan
echo -en "\e]P21ea446" #darkgreen
echo -en "\e]PA1ea446" #green
echo -en "\e]P7dedede" #lightgray
# Define terminal color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;36m'
NC='\033[0m' # No Color
# Status bar theme color
BARCOLOR='\033[40;97m'
# Define cursor positions
SAVECURSOR='\033[s'
RESTORECURSOR='\033[u'
TOPLEFTCURSOR='\033[1;1H'
# Echo with colors
colorecho() {
color="$1"
text="$2"
echo -e "${color}${text}${NC}"
}
# Sudo override
sudo () {
local command=$@
if [ "$(id -u)" -eq 0 ]; then
#echo "Running in root."
command "$@"
else
#echo "Running with sudo."
command sudo "$@"
fi
}
# Store values across subshell/scripts
store_var() {
mkdir -p /tmp/arch-installer
echo "$2" > /tmp/arch-installer/$1
}
# Read values accessible across subshell/scripts
read_var() {
if [ -f "/tmp/arch-installer/$1" ]; then
cat /tmp/arch-installer/$1
fi
}
# Delete tmp files when script stopped
trap "rm -rf /tmp/arch-installer; exit" INT
# Generate Title Logo
titlelogo_string() {
# Check if the argument count is provided
if [ -z "$1" ]; then
local count=8
else
local count=$1
fi
# Generate the linespacing string with the specified count of spaces
local linespacing=$(printf "%${count}s")
local logostring="$linespacing _ _ _ \n$linespacing /\ | | | | (_) \n$linespacing / \ _ __ ___| |__ | | _ _ __ _ ___ __\n$linespacing / /\ \ | '__/ __| '_ \| | | | '_ \| | | \ \/ /\n$linespacing / ____ \| | | (__| | | | |____| | | | | |_| |> < \n$linespacing/_/ \_\_| \___|_| |_|______|_|_| |_|\__,_/_/\_\ __\n$linespacing _____ _ _ _ ( __)/ \( _ \ \n$linespacing|_ _| | | | | | ) _)( O )) / \n$linespacing | | _ __ ___| |_ __ _| | | ___ _ __ (__) \__/(__\_)\n$linespacing | | | '_ \/ __| __/ _\` | | |/ _ \ '__| /__\ ( _ \( \/ )\n$linespacing _| |_| | | \__ \ || (_| | | | __/ | / \ ) // \/ \ \n$linespacing|_____|_| |_|___/\__\__,_|_|_|\___|_| \_/\_/(__\_)\_)(_/\n$linespacing"
# Echo the logo string
echo "$logostring"
}
# Generates Dash Lines
dash_string() {
# Check if the argument count is provided
if [ -z "$1" ]; then
local count=80
else
local count=$1
fi
for ((i = 0; i < count; i++)); do
echo -n "-"
done
}
# Status Bar
status_bar() {
local checked_for_updates
local ntp_synced
while true; do
# Check Internet Status
internet_available=$(internet_status)
store_var "internet_available" "$internet_available"
# Get the terminal width
terminal_width=$(tput cols)
# Calculate the width of each item
item_left=$(( (terminal_width - 4) / 3 )) # Subtracting 4 for the brackets and spaces
item_center=$(( ((terminal_width - 4) / 6) + 3 )) # Subtracting 4 for the brackets and spaces
item_right=$(( ((terminal_width - 4) / 2) - 3 )) # Subtracting 4 for the brackets and spaces
# Left Item
menu_header=$(read_var "menu_header")
if [ -n "$menu_header" ]; then
left_item="[$title_string - $menu_header]"
else
left_item="[$title_string]"
fi
# Center Item
center_item="$(date +"%b %e %H:%M")"
#Right Item
if [ "$internet_available" = 1 ]; then
right_item="[Internet Connected]"
elif [ "$internet_available" = 2 ]; then
right_item="[No Internet]"
else
right_item="[Waiting for Network]"
fi
# Print the items with alignment
printf "${SAVECURSOR}${TOPLEFTCURSOR}$BARCOLOR %-${item_left}s%${item_center}s%${item_right}s $NC${RESTORECURSOR}" "$left_item" "$center_item" "$right_item"
if [ "$internet_available" = 1 ]; then
if [ -z "$checked_for_updates" ]; then
if curl -s https://raw.githubusercontent.com/ >/dev/null; then
store_var "ssl_check" "1"
check_installer_updates
checked_for_updates=1
elif [ -z "$ntp_synced" ]; then
#NTP Sync
sudo rm -rf /etc/systemd/network/*
sudo systemctl restart systemd-networkd
sleep 1
sudo timedatectl set-ntp false
sudo timedatectl set-ntp true
ntp_synced=1
fi
fi
fi
sleep 0.5
done
}
# Print Title Logo
title() {
clear
text="$1"
echo "$(dash_string)"
colorecho "$BLUE" "$(titlelogo_string)"
echo "$(dash_string)"
}
################################################################
# CLI and TUI Menus and Functions
# TUI Theme (dialog)
create_dialog_theme() {
colorecho "$GREEN" "Generating Installer Theme ..."
sudo mkdir -p $(dirname $dialog_theme_config)
sudo tee "$dialog_theme_config" <<EOF
# Arch Linux Installer for ARM
# Run-time configuration theme for dialog
#
# Types of values:
#
# Number - <number>
# String - "string"
# Boolean - <ON|OFF>
# Attribute - (foreground,background,highlight?,underline?,reverse?)
# Screen color
screen_color = (WHITE,WHITE,ON)
# Shadow color
shadow_color = (BLUE,BLUE,OFF)
# Dialog box color
dialog_color = (BLACK,WHITE,ON)
# Dialog box border color
border_color = (BLUE,WHITE,OFF)
# Menu box border color
menubox_border_color = border_color
# Inactive button label color
button_label_inactive_color = (BLUE,WHITE,ON)
# Dialog box border2 color
border2_color = (BLUE,WHITE,ON)
EOF
sudo chmod +x $dialog_theme_config
}
# CLI Select Menu
function select_option_cli {
# Little helpers for terminal print control and key input
ESC=$( printf "\033")
cursor_blink_on() { printf "$ESC[?25h"; }
cursor_blink_off() { printf "$ESC[?25l"; }
cursor_to() { printf "$ESC[$1;${2:-1}H"; }
print_option() { printf " $1 "; }
print_selected() { printf " $ESC[7m $1 $ESC[27m"; }
get_cursor_row() { IFS=';' read -sdR -p $'\E[6n' ROW COL; echo ${ROW#*[}; }
key_input() { read -s -n3 key 2>/dev/null >&2
if [[ $key = $ESC[A ]]; then echo up; fi
if [[ $key = $ESC[B ]]; then echo down; fi
if [[ $key = "" ]]; then echo enter; fi; }
# Initially print empty new lines (scroll down if at bottom of screen)
for opt; do printf "\n"; done
# Determine current screen position for overwriting the options
local lastrow=`get_cursor_row`
local startrow=$(($lastrow - $#))
# Ensure cursor and input echoing back on upon a ctrl+c during read -s
trap "cursor_blink_on; stty echo; printf '\n'; exit" 2
cursor_blink_off
local selected=0
while true; do
# Print options by overwriting the last lines
local idx=0
local max_width=$(tput cols)
for opt; do
cursor_to $(($startrow + $idx))
local formatted_opt="$((idx + 1)) \t $opt"
local formatted_opt=$(echo "$formatted_opt" | cut -c1-$((max_width - 3)))
if [ $idx -eq $selected ]; then
print_selected "$formatted_opt"
else
print_option "$formatted_opt"
fi
((idx++))
done
# User key control
case `key_input` in
enter) break;;
up) ((selected--));
if [ $selected -lt 0 ]; then selected=$(($# - 1)); fi;;
down) ((selected++));
if [ $selected -ge $# ]; then selected=0; fi;;
esac
done
# Cursor position back to normal
cursor_to $lastrow
printf "\n"
cursor_blink_on
return $selected
}
# TUI Select Menu
select_option() {
export DIALOGRC=$dialog_theme_config
local i=0
print_option() { echo "$1"; }
# menu header
store_var "menu_header" "$menu_header"
if [ -n "$menu_header" ]; then
dialog_title="$menu_header"
else
dialog_title="Welcome to Arch Linux !"
fi
# menu option title
if [ -z "$menu_option_title" ]; then
menu_option_title="Select an option:"
fi
# Create options string for dialog
declare -a options_string=()
for opt; do
options_string+=("$((i + 1))" "$(print_option "$opt")")
((i++))
done
# launch TUI using dialog
choice=$(dialog --colors \
--title " $dialog_title " --ok-label "Next" --nocancel \
--menu "\n\Zb\Z4$(titlelogo_string) \n\n $menu_option_title \Zn" 0 0 0 "${options_string[@]}" \
3>&1 1>&2 2>&3 3>&- # Swap stdout with stderr to capture returned dialog text
)
case $? in
0)
choice=$((choice - 1))
return $choice
;;
*)
# CLI Fallback
title
colorecho "$BLUE" "${dialog_title//\\Z[0-7bun]/}"
echo "$(dash_string)"
colorecho "$GREEN" "${menu_option_title//\\Z[0-7bun]/}"
echo
select_option_cli "$@"
;;
esac
}
# TUI Info Box
alert() {
export DIALOGRC=$dialog_theme_config
local i=0
# menu header
store_var "menu_header" "$menu_header"
if [ -n "$menu_header" ]; then
dialog_title="$menu_header"
else
dialog_title="Info"
fi
for opt; do
((i++))
done
# launch TUI using dialog
if ! dialog --colors \
--title " $dialog_title " \
--infobox "\n\Zb\Z4$(titlelogo_string 2)\Zn \n$opt\n\n" 0 0; then
# CLI Fallback
title
colorecho "$BLUE" "${dialog_title//\\Z[0-7bun]/} $NC| ${opt//\\Z[0-7bun]/}"
fi
}
# TUI MSG Box
info() {
export DIALOGRC=$dialog_theme_config
local i=0
# menu header
store_var "menu_header" "$menu_header"
if [ -n "$menu_header" ]; then
dialog_title="$menu_header"
else
dialog_title="Info"
fi
for opt; do
((i++))
done
# launch TUI using dialog
if ! dialog --colors \
--title " $dialog_title " \
--msgbox "\n\Zb\Z4$(titlelogo_string 2)\Zn \n$opt\n\n" 0 0; then
# CLI Fallback
title
colorecho "$BLUE" "${dialog_title//\\Z[0-7bun]/} $NC| ${opt//\\Z[0-7bun]/}"
select_option_cli "OK"
fi
}
# TUI Confirm Box
confirm() {
export DIALOGRC=$dialog_theme_config
local i=0
local cfm
# menu header
store_var "menu_header" "$menu_header"
if [ -n "$menu_header" ]; then
dialog_title="$menu_header"
else
dialog_title="Confirm"
fi
for opt; do
((i++))
done
# launch TUI using dialog
if dialog --colors \
--title " $dialog_title " --yes-label "${menu_confirm_label[0]:-"Yes"}" --no-label "${menu_confirm_label[1]:-"No"}" \
--yesno "\n\Zb\Z4$(titlelogo_string 2)\Zn \n$opt\n\n" 0 0; then
return 0
elif [ ! -x "$(command -v dialog)" ]; then
# CLI Fallback
title
local p="$(colorecho "$BLUE" "${dialog_title//\\Z[0-7bun]/} $NC| ${opt//\\Z[0-7bun]/}") [Y/n]: "
read -p "$p" cfm
if [[ "$cfm" == [Yy] ]]; then
return 0
else
return 1
fi
else
return 1
fi
}
# TUI Input Box
input() {
export DIALOGRC=$dialog_theme_config
local i=0
# menu header
store_var "menu_header" "$menu_header"
if [ -n "$menu_header" ]; then
dialog_title="$menu_header"
else
dialog_title="Enter an input"
fi
for opt; do
((i++))
done
# launch TUI using dialog
local value=$(dialog --colors \
--title " $dialog_title " --nocancel \
--inputbox "\n\Zb\Z4$(titlelogo_string 2)\Zn \n$opt\n\n" 0 0 \
3>&1 1>&2 2>&3 3>&- # Swap stdout with stderr to capture returned dialog text
)
if [ -z "$value" ]; then
# CLI Fallback
local value
title > /dev/tty
local p="$(colorecho "$BLUE" "${dialog_title//\\Z[0-7bun]/} $NC| ${opt//\\Z[0-7bun]/}"): "
read -p "$p" value
fi
echo $value
}
# TUI Form Input Menu
form() {
export DIALOGRC=$dialog_theme_config
local i=0
print_option() { echo "$1"; }
# menu header
store_var "menu_header" "$menu_header"
if [ -n "$menu_header" ]; then
dialog_title="$menu_header"
else
dialog_title="Welcome to Arch Linux !"
fi
# menu option title
if [ -z "$menu_option_title" ]; then
menu_option_title="Select an option:"
fi
# Create options string for dialog
declare -a options_string=()
for opt; do
if [ -n "${menu_form_type[i]}" ]; then
options_string+=("$(print_option "$opt")" "$((i + 1))" "5" "${menu_form_value[i]}" "$((i + 1))" "40" "25" "0" "${menu_form_type[i]}")
else
options_string+=("$(print_option "$opt")" "$((i + 1))" "5" "${menu_form_value[i]}" "$((i + 1))" "40" "25" "0" "0")
fi
((i++))
done
# Reset form type list
menu_form_type=()
# launch TUI using dialog
local value=$(dialog --colors \
--title " $dialog_title " --ok-label "Next" --nocancel --insecure \
--mixedform "\n\Zb\Z4$(titlelogo_string) \n\n $menu_option_title \n\Zn (Use arrow key to switch column, press enter to confirm)" 0 0 0 \
"${options_string[@]}" \
3>&1 1>&2 2>&3 3>&- # Swap stdout with stderr to capture returned dialog text
)
if [ -z "$value" ]; then
## CLI Fallback
local value
title > /dev/tty
for ((i = 0; i < ${#options_string[@]}; i+=9)); do
local p="$(colorecho "$BLUE" "${dialog_title//\\Z[0-7bun]/} $NC| ${options_string[i]}")"
if [ -n "${options_string[i+3]}" ]; then
local dvalp="(${options_string[i+3]})"
else
local dvalp=""
fi
if [ "${options_string[i+8]}" = "0" ]; then
# Normal input
read -p "${p}: " input_value
elif [ "${options_string[i+8]}" = "1" ]; then
# Password input
read -s -p "${p}: " input_value
echo > /dev/tty
elif [ "${options_string[i+8]}" = "2" ]; then
# Readonly
echo -e "${p}: $dvalp" > /dev/tty
fi
if [ -z "$value" ]; then
value="$input_value"
else
value+=" $input_value"
fi
done
fi
echo $value
}
################################################################
# Internet Connection & Updates Check
internet_available=0
internet_status() {
for server in "${ping_servers[@]}"; do
if ping -q -c 1 "$server" >/dev/null 2>&1; then
internet_found_at="$server"
internet_available=1 # internet connected
break
elif ip link show | grep "state UP"; then
internet_available=2 # network connected but no internet access
else
internet_available=0 # no connection
fi
done
echo "$internet_available"
}
get_ssid() {
if [ $(nmcli -f TYPE connection show | head -n 2 | tail -n 1) = "wifi" ]; then
echo "$(nmcli -t -f NAME connection show | head -n 1)"
elif [ -n "$(wpa_cli status | grep -Po 'ssid=\K.*')" ]; then
echo "$(wpa_cli status | grep -Po 'ssid=\K.*')"
else
echo "Disconnected"
fi
}
network_menu() {
# Get Internet Status
internet_available=$(read_var "internet_available")
if [ "$internet_available" = 1 ]; then
internet_status="Connected"
elif [ "$internet_available" = 2 ]; then
internet_status="Connected (No Internet)"
else
internet_status="Disconnected"
fi
# Find Wireless Interface and get the first one if exist
if [ -n "$custom_iwdev" ]; then
iwdev=$custom_iwdev
else
for dev in /sys/class/net/*; do
if [ -e "$dev"/wireless ]; then
iwdev=${dev##*/};
break;
fi
done
fi
# Network Menu
menu_header="Network Options"
menu_option_title=""
options=("Back" "Network Status -> $internet_status" "Connect to a WiFi -> $(get_ssid)" "Change WiFi adapter -> ${iwdev:-"no adapter"}" "Update NTP Time Sync" "Ethernet Restart" "Edit Mirrorlist")
select_option "${options[@]}"
selected=$?
case $selected in
1)
menu_header="Network Status"
alert "Performing network connection test ..."
# Test connection
http_status="FAIL"
if curl -s http://example.com/ >/dev/null; then
http_status="OK"
fi
https_status="FAIL"
if curl -s https://example.com/ >/dev/null; then
https_status="OK"
fi
github_status="FAIL"
if curl -s https://github.com/ >/dev/null; then
github_status="OK"
fi
ghusercon_status="FAIL"
if curl -s https://raw.githubusercontent.com/ >/dev/null; then
ghusercon_status="OK"
fi
ipapi_status="FAIL"
if curl -s https://ipapi.co/ >/dev/null; then
ipapi_status="OK"
fi
# Get Local IP
local_ip=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n 1)
info "Internet Status: $internet_status \nWiFi SSID (if available): $(get_ssid) \nLocal IP address: ${local_ip:-"Unavailable"} \nHTTP Connection: $http_status \nHTTPS Connection: $https_status \nConnection to github.com: $github_status\nConnection to githubusercontent.com: $ghusercon_status\nConnection to ipapi.co: $ipapi_status \nInterface Status: \n$(ip link)"
network_menu
;;
2)
menu_header="Connecting to WiFi"
alert "Starting WiFi-Menu ..."
if sudo wifi-menu $iwdev; then
alert "Enabling netctl Auto Connect ..."
systemctl enable netctl-auto@$iwdev.service
fi
network_menu
;;
3)
menu_header="Change WiFi Adapter"
# Get all Wireless Interface
iwdevlist=()
for dev in /sys/class/net/*; do
if [ -e "$dev"/wireless ]; then
iwdevlist+=("${dev##*/}")
fi
done
select_option "Back" "Specify a wireless interface" "${iwdevlist[@]}"
selected=$?
case $selected in
0)
echo
;;
1)
custom_iwdev=$(input "Please specify the network device (e.g. wlan0): ")
;;
*)
custom_iwdev="${iwdevlist[selected]}"
;;
esac
network_menu
;;
4)
menu_header="Update NTP Time Sync"
alert "Updating NTP Time Sync ..."
sudo rm -rf /etc/systemd/network/*
sudo systemctl restart systemd-networkd
sleep 1
sudo timedatectl set-ntp false
sudo timedatectl set-ntp true
network_menu
;;
5)
menu_header="Ethernet Restart"
alert "Restarting Ethernet ..."
sudo systemctl restart systemd-networkd
sudo systemctl restart dhcpcd
sleep 1
network_menu
;;
6)
menu_header="Edit Mirrorlist"
alert "Edit Mirrorlist - Starting nano editor ..."
sudo nano /etc/pacman.d/mirrorlist
network_menu
;;
esac
}
advanced_menu() {
menu_header="Advanced Options"
menu_option_title=""
options=("Back" "Device Infomation" "Edit Pacman Configuration" "Bypass Internet Check (not recommended)" "File Editor (Experimental)" "Russian roulette (Mini Game)" "Exit to Shell (Experimental)" "Soft Reboot System (Experimental)" "Reboot System")
select_option "${options[@]}"
selected=$?
case $selected in
1)
menu_header="Device Infomation"
info "\n$(acu sysinfo | sed 's/$/\\n/')"
advanced_menu
;;
2)
menu_header="Edit Pacman Configuration"
alert "Edit Pacman Configuration - Starting nano editor ..."
sudo nano /etc/pacman.conf
advanced_menu
;;
3)
menu_header="Bypass Internet Check"
if confirm "Are you sure to bypass the Internet Check? \nInternet connection is required to perform an installation, if you bypass this, installation may fail."; then
bypass_internet=1
elif [ -n "$bypass_internet" ]; then
bypass_internet=""
fi
advanced_menu
;;
4)
file_editor() {
menu_header="File Editor"
# launch TUI using dialog
local value=$(dialog --colors \
--title " $menu_header " --ok-label "Open" --cancel-label "Back" --insecure \
--fselect / 0 0 \
3>&1 1>&2 2>&3 3>&- # Swap stdout with stderr to capture returned dialog text
)
if [ -n "$value" ]; then
alert "File Editor - Starting nano editor ..."
sudo nano $value
file_editor
fi
}
file_editor
advanced_menu
;;
5)
menu_header="Russian roulette"
if confirm "Let's play a mini game - Russian roulette?"; then
alert "Welcome to the Arch Linux Russian Roulette Challenge!"
sleep 2
alert "Are you feeling like a true Arch Linux warrior? Let's find out!"
sleep 2
info "Ready?"
local chambers=6
local bullet_chamber=$((RANDOM % chambers + 1))
local shot_chamber=$((RANDOM % chambers + 1))
info "The Arch Linux revolver has $chambers chambers. One of them contains a bullet. \n Press OK to spin the cylinder and take your shot..."
if [ $shot_chamber -eq $bullet_chamber ]; then
info "BANG Oh no, the bullet has struck! Better luck next time, brave Arch user."
info "Performing sudo rm -rf / ..."
info "Hey, relax! Just kidding lol ..."
else
info "click Phew, you've survived this round! Praise the Arch gods!"
fi
fi
advanced_menu
;;
6)
menu_header="Exit to Shell"
if confirm "Are you sure to exit this installer to shell? \nTips: To re-enter this installer, type > installer < or reboot."; then
exit 0
fi
advanced_menu
;;
7)
menu_header="Soft Reboot System"
if confirm "Are you sure to soft reboot this system?."; then
sudo systemctl soft-reboot
fi
advanced_menu
;;
8)
menu_header="Reboot System"
if confirm "Are you sure to force reboot this system?."; then
sudo reboot --force
fi
advanced_menu
;;
esac
}
# Check Installer Updates
check_installer_updates() {
if [ "$1" = "--util" ]; then
if [ "$(read_var "updates_available")" = 1 ]; then
alert "Getting updates infomation..."
else
alert "Checking for installer updates..."
fi
fi
remote_installerver=$(curl -s "$remote_installer_url" | grep -m1 'installerver=[0-9]*' | cut -d= -f2)
remote_acuver=$(curl -s "$remote_installer_url" | grep -m1 'acuver=[0-9]*' | cut -d= -f2)
if [ "${remote_installerver:="0"}" -gt "$installerver" ]; then
if [ "$1" = "--util" ]; then
menu_header="Updates Available"
menu_option_title="\Z2A newer version ($remote_installerver) of this installer is available. \n\Zn Do you want to update this installer?"
options=("Update this Installer" "Do not update this installer")
select_option "${options[@]}"
answer=$?
if [ "$answer" = 0 ]; then
# Updating Installer
alert "Downloading Installer ..."
local response_code=$(sudo curl --write-out '%{response_code}' -LJO "$remote_installer_url")
if [ "$response_code" = 200 ]; then
alert "Updating Installer ..."
# If install_target is set
if [ -n "$install_target" ]; then
sudo sed -i "s/^#install_target=\".*\"/install_target=\"$install_target\"/g" arch-installer
fi
sudo chmod +x arch-installer
sudo cp -r arch-installer /usr/bin/installer
sudo rm -rf arch-installer
# Update ACU
echo "Updating ACU (Configuration Utility) ..."
sudo curl -o /usr/bin/acu -L "https://raw.githubusercontent.com/kwankiu/acu/$remote_acuver/acu"
sudo chmod +x /usr/bin/acu
echo "Updating Installer ACU Config ..."
sudo curl -o /usr/lib/installer/.acu/config/config.yaml -L "$remote_installer_config_url"
# Reboot
alert "Installer updated. System will reboot now."
if ! sudo reboot --force; then
alert "Unable to reboot automatically, please reboot your device manually."
fi
else
alert "An Error is occurred. Installer is not updated."
sleep 3
fi
elif [ "$answer" = 1 ]; then
store_var "updates_available" 0
fi
else
store_var "menu_header" "Updates Available"
store_var "updates_available" 1
fi
elif [ "$1" = "--util" ]; then
menu_header="Check for Updates"
menu_option_title=" \Z1No updates available.\n\Zn Latest Version: $remote_installerver \n Current Version: $installerver \n ACU Version: $acuver \n Release Channel: $branch"
select_option "Back" "Check updates again" "Change release channel (Experimental)" "Update/Reinstall Installer"
selected=$?
case $selected in
1)
check_installer_updates --util
;;
2)
menu_header="Change release channel"
options=("Back" "main" "dev")
select_option "${options[@]}"
answer=$?
if [ ! "$answer" = 0 ]; then
branch="${options[answer]}"
fi
check_installer_updates --util
;;
3)
local localver=$installerver
local dummyver=0
installerver=$dummyver
check_installer_updates --util
installerver=$localver
;;
esac
fi
}
################################################################
# Installation - Part 1 (in root)
add_boot_part_fstab() {
alert "Updating fstab ..."
# Get the boot partition before rootfs partition (rootfs_part - 1)
boot_partition=$(fdisk -l "$rootfs_disk" | grep "$rootfs_disk" | awk -v partnum=${rootfs_partition: -1} 'NR==partnum{print $1}')
# Check if the boot_partition is not empty
if [ -z "$boot_partition" ]; then
echo "Unable to determine boot partition on $rootfs_disk"
exit 1
fi
# Add the line to /etc/fstab
new_line="$boot_partition /boot vfat dmask=000,fmask=0111,user 0 0"
# Check if the line already exists in /etc/fstab
if grep -qF "/boot vfat dmask=000,fmask=0111,user 0 0" /etc/fstab; then
echo "boot partition seems already configured in /etc/fstab to manage by system."
else
# Add the line to /etc/fstab
echo "$new_line" >> /etc/fstab
# Check if the addition was successful
if [ $? -eq 0 ]; then
cat /etc/fstab
echo "Line added to /etc/fstab successfully"
else
echo "Error adding line to /etc/fstab"
fi
fi
}
install_part1() {
local installation_file=$1
menu_header="Installation (Part 1)"
# Set Hostname
alert "Setting hostname ..."
hostnamectl set-hostname $install_hostname
# Get rootfs partition from the current mount point "/"
rootfs_partition=$(mount | grep "on / " | awk '{print $1}')
# Get disk path using rootfs partition path
rootfs_disk=$(echo "$rootfs_partition" | sed 's/[0-9]*$//')
rootfs_disk="${rootfs_disk%p*}"