-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvoid-linux-installer.sh
executable file
·971 lines (859 loc) · 24.5 KB
/
void-linux-installer.sh
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
#!/bin/bash
# Exit on error
set -e
# Make terminal clean
clear
echo '*********************************************'
echo '*********************************************'
echo '**** VOID LINUX MUSL x86_64 INSTALLATION ****'
echo '**** EFI Stub Boot ****'
echo '*********************************************'
echo '*********************************************'
#############################################
#############################################
#### [!] START OF USER CONFIGURATION [!] ####
#############################################
#############################################
# Change font to be more legible
setfont Lat2-Terminus16
# Ignored Packages
echo "ignorepkg=sudo" > /etc/xbps.d/10-ignore.conf
# Prerequisites
# setting password requires pam
prereqs='gptfdisk pam dosfstools'
# System Packages
pkg_listsys='base-minimal'\
' void-repo-nonfree'\
' void-release-keys'\
' signify'
# Common Packages
pkg_listc='aria2'\
' atool'\
' bash'\
' bwm-ng'\
' chrony'\
' dosfstools'\
' dracut'\
' exfat-utils'\
' ntfs-3g'\
' fcron'\
' python3-pip'\
' fd'\
' sshuttle'\
' newsboat'\
' ffmpeg'\
' glances'\
' hddtemp'\
' inetutils'\
' inxi'\
' iproute2'\
' kbd'\
' exa'\
' linux-firmware'\
' linux-firmware-intel'\
' lm_sensors'\
' lnav'\
' lr'\
' mle'\
' nano'\
' ncurses'\
' ncurses-devel'\
' nfs-utils'\
' opendoas'\
' openssh'\
' p7zip'\
' pciutils'\
' PopCorn'\
' rsnapshot'\
' smartmontools'\
' socklog-void'\
' tree'\
' vsv'\
' wget'\
' xterm'\
' gcc'\
' dtach'\
' make'\
' git'\
' pkg-config'\
' man-pages'\
' mdocml'\
' curl'\
' gptfdisk'\
' unzip'\
' unrar'\
' zstd'\
' lzip'\
' ranger'\
' font-tamsyn'\
' starship'\
' xz'\
' lshw'\
' fuse-sshfs'\
' borg'\
' restic'\
' ncdu'\
' lsscsi'\
' lsof'\
' pam'\
' detox'\
' ipmitool'
# Desktop Packages
pkg_list='chromium'\
' gcompat'\
' filezilla'\
' firefox'\
' herbstluftwm'\
' iwd'\
' ddrescue'\
' zpaq'\
' kid3'\
' libinput-gestures'\
' linux-firmware-nvidia'\
' micro'\
' smplayer'\
' mplayer'\
' mpv'\
' sndio'\
' tlp'\
' xf86-input-wacom'\
' xorg-minimal'\
' sakura'\
' mesa'\
' mesa-demos'\
' mesa-vulkan-intel'\
' mesa-nouveau-dri'\
' mesa-intel-dri'\
' mesa-dri'\
' mesa-vaapi'\
' mesa-vdpau'\
' autorandr'\
' w3m-img'\
' sxiv'\
' xwallpaper'\
' mupdf'\
' aerc'\
' bind-utils'\
' unbound'\
' dnscrypt-proxy'\
' imlib2-devel'\
' pam-devel'\
' libgcrypt-devel'\
' libXrender-devel'\
' ffmpeg-devel'\
' libavcodec'\
' libavformat'\
' libavutil'\
' wavpack-devel'\
' libmp4v2-devel'\
' libflac-devel'\
' libsndfile-devel'\
' libvorbis-devel'\
' mpg123-devel'\
' faad2-devel'\
' sndio-devel'\
' opusfile-devel'\
' papirus-icon-theme'\
' aucatctl'\
' sox'\
' polybar'\
' libwnck'\
' vlc'\
' xset'\
' fontmanager'\
' libmnl-devel'\
' dialog'\
' ghostwriter'\
' dunst'\
' udiskie'\
' keychain'\
' nemo'\
' nemo-fileroller'\
' ffmpegthumbnailer'\
' gvfs'\
' gvfs-afp'\
' gvfs-cdda'\
' gvfs-smb'\
' gvfs-afc'\
' gvfs-mtp'\
' gvfs-gphoto2'\
' gnome-epub-thumbnailer'\
' alsa-utils'\
' libopenal'\
' upower'\
' gtk+3'\
' qalculate'\
' xclip'\
' rofi'\
' rofi-calc'\
' fzy'\
' fzf'\
' xwininfo'\
' redshift-gtk'\
' xbanish'\
' gthumb'\
' arc-theme'\
' arc-icon-theme'\
' faience-icon-theme'\
' faenza-icon-theme'\
' xsetroot'\
' recoll'\
' i3lock-color'\
' dbus-elogind-x11'\
' elogind'\
' asciiquarium'\
' astroid'\
' nerd-fonts'\
' noto-fonts-cjk'\
' overpass-otf'\
' google-fonts-ttf'\
' font-iosevka'\
' emacs-x11'\
' autocutsel'\
' shellcheck'\
' caddy'\
' automake'
# Server Packages
pkg_listsrv='lftp'\
' xfsprogs'\
' e2fsprogs'\
' snapraid'\
' mergerfs'\
' castget'\
' minidlna'
###################
##### Desktop #####
###################
username="void"
groups="wheel,storage,video,audio,lp,cdrom,optical,scanner,socklog"
services="caddy dnscrypt-proxy unbound cupsd cups-browsed sshd chronyd fcron iwd socklog-unix nanoklogd hddtemp popcorn tlp sndiod dbus statd rpcbind cgmanager polkitd"
hostname="void"
### /home/$USER/.bashrc
bashrc="$(cat <<'EOF'
# --------------------
# Eternal bash history.
# ---------------------
# Undocumented feature which sets the size to "unlimited".
# http://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.
# http://superuser.com/questions/20900/bash-history-loss
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
# --------------------
eval "$(starship init bash)"
PATH="$HOME/.local/bin:$PATH"
alias poweroff='doas /sbin/poweroff'
alias reboot='doas /sbin/reboot'
EOF
)"
bashrcwm="$(cat <<'EOF'
sh buffquote
# export PS1="\n\[\e[0;32m\]\u@\h[\t]\[\e[0;31m\] \['\$PWD'\] \[\e[0;32m\]\[\e[0m\]\[\e[0;32m\]>>>\[\e[0m\]\n "
export TERMINAL=sakura
export EXA_COLORS=da=37:di=36:uu=33:un=31
# Weather Check
alias weath='curl wttr.in/?0'
alias weather="curl wttr.in/~Adelaide"
alias clips="clipster -o -n 10000 -0 | fzf --read0 --no-sort --reverse --preview='echo {}' | sed -ze 's/\n$//' | clipster"
alias clipsr="clipster --delete"
alias clipsc="clipster --erase-entire-board"
alias key="awk /Mod/ ~/.config/herbstluftwm/autostart | sed 's/hc\ //g' | rofi -dmenu"
# Firefox has a habit of not responding and 'killall' doesn't always work
alias kf="pgrep -f firefox | xargs kill -9"
EOF
)"
### /home/$USER/.bash_profile
bashprofile="$(cat <<'EOF'
# Uncomment 'startx' after sym linking 'config/.config/herbstluftwm'
# Disallow 'ssh' login
# exec startx
# Allow 'ssh' login
# [[ -z $DISPLAY && -z $SSH_CLIENT ]] && exec startx
EOF
)"
### /home/$USER/.xinitrc
xinitrc="$(cat <<'EOF'
# [!] 'startx' will exit immediately if program cannot be found
#
# xss-lock -- ~/.config/i3/lock.sh -l &
# xss-lock -- sakura -s -x asciiquarium & alock -bg none; xdotool key --clearmodifiers q
# polkit-gnome needed to start gparted as $USER
/usr/libexec/polkit-gnome-authentication-agent-1 &
exec dbus-launch --exit-with-session --sh-syntax herbstluftwm --locked
EOF
)"
##################
##### Server #####
##################
usernamesrv="void-srv"
groupsrv="wheel,storage,cdrom,optical,socklog"
servicessrv="sshd acpid chronyd fcron socklog-unix nanoklogd hddtemp popcorn statd rpcbind smartd"
hostnamesrv="void-srv"
##################
##### System #####
##################
### /etc/doas.conf
doasconf="$(cat <<'EOF'
permit persist :wheel
permit nopass :wheel as root cmd /sbin/poweroff
permit nopass :wheel as root cmd /sbin/reboot
EOF
)"
### Hardrive Label
labelroot="VOID_LINUX"
labelfat="EFI"
### /etc/rc.conf
KEYMAP="us"
TIMEZONE="Australia/Adelaide"
HARDWARECLOCK="UTC"
FONT="Tamsyn8x16r"
### Create directories /home/$USER/
dirs="exclusions src"
###################
##### Network #####
###################
### For dhcp leave ipstaticeth0 empty and install dhcpd ie ndhc
ipstaticeth0="192.168.1.10"
### For dhcp leave ipstaticwlan0 empty (iwd includes dhcp)
ipstaticwlan0=""
routerssid=""
gateway="192.168.1.1"
wifipassword=""
### openresolv is required for iwd (wifi) to access internet
# and uses /etc/resolvconf.conf with optional /etc/resolv.conf
openresolv="YES" # any other value if not used
### nameserver0 is for dnscrypt-proxy (not needed if using openresolv)
nameserver0="127.0.0.1"
### nameserver{1,2} is for /etc/resolv.conf or resolvconf.conf
# Cloudflare "1.0.0.1" "1.1.1.1" # Google "8.8.4.4" "8.8.8.8"
nameserver1="1.0.0.1"
nameserver2="1.1.1.1"
######################
##### Repository #####
######################
### [!] Leave repopath & cachedir empty to use default repository /var/cache/xbps [!]
### Path to packages that have already been downloaded
# xbps-install --repository $repopath $pkg_list
repopath=""
### Save packages to somewhere other then /var/cache/xbps
# xbps-install --repository $repo0..2 --download-only --cachedir $cachedir $pkg_list && cd $repopath && xbps-rindex --add *xbps
cachedir="/opt/void_pkgs"
### Repository Urls /etc/xbps.d/00-repository-{main.conf,nonfree.conf}
repo0="https://ftp.swin.edu.au/voidlinux/current/musl"
repo1="https://mirror.aarnet.edu.au/pub/voidlinux/current/musl" # connection tends to be flaky
repo2="https://repo-fi.voidlinux.org/current/musl"
###########################################
###########################################
#### [!] END OF USER CONFIGURATION [!] ####
###########################################
###########################################
echo ''
echo '************************************************'
echo -e '******************* \x1B[1;31m WARNING \x1B[0m ******************'
echo '************************************************'
echo '**** Script is preconfigured for UEFI & GPT ****'
echo '**** ****'
echo '**** Partition Layout : Fat-32 EFI of 550MB ****'
echo '**** : / 100% ****'
echo '************************************************'
# Detect if we're in UEFI or legacy mode
[[ -d /sys/firmware/efi ]] && UEFI=1
if [[ $UEFI ]]; then
echo -e "\x1B[1;92m [!] Found UEFI [!] \x1B[0m"
pkg_list="$pkg_list efibootmgr"
else
echo -e "\x1B[1;31m [!] UEFI Not found [!] \x1B[0m"
exit 1
fi
lsblk -f -l | grep -e sd -e mmcblk
echo ''
echo '****************************************'
echo '[!] Verify Connected Drive Is Listed [!]'
echo '****************************************'
# /dev/mmcblk0 is SDCARD on Lenovo Thinkpad T420 & T520
# Generate drive options dynamically
PS3="Select drive to format: "
echo ''
select device in $(blkid | grep -e sd -e mmcblk0 | cut -d : -f 1 | sed -e 's/\p//g' -e 's/[1-9]\+$//' | uniq | sort)
do
if [[ $device = "" ]]; then
echo "try again"
continue
fi
break
done
echo "$device has been selected"
echo
# PS3='Select your device: '
# options=('sda' 'sdb' 'sdc')
# select opt in "${options[@]}"
# do
# case $opt in
# 'sda')
# devname='/dev/sda'
# break
# ;;
# 'sdb')
# devname='/dev/sdb'
# break
# ;;
# 'sdc')
# devname='/dev/sdc'
# break
# ;;
# *)
# echo 'This option is invalid.'
# ;;
# esac
# done
PS3="Select installation type : "
options=('Desktop' 'Server')
select opt in "${options[@]}"
do
case $opt in
'Desktop')
pkg_list="$pkg_list $pkg_listc $pkg_listsys $prereqs"
username="$username"
services="$services"
groups="$groups"
hostname="$hostname"
bashrc="$bashrc
$bashrcwm"
break
;;
'Server')
pkg_list="$pkg_listsrv $pkg_listc $pkg_listsys $prereqs"
username="$usernamesrv"
services="$servicessrv"
groups="$groupsrv"
hostname="$hostnamesrv"
bashrc="$bashrc"
break
;;
*)
echo 'This option is invalid.'
;;
esac
done
# Add repositories to live USB/Cd
tee /etc/xbps.d/00-repository-main.conf <<-EOF
repository=$repo0
repository=$repo1
repository=$repo2
EOF
tee /etc/xbps.d/10-repository-nonfree.conf <<-EOF
repository=$repo0/nonfree
repository=$repo1/nonfree
repository=$repo2/nonfree
EOF
# Detect if we're on an Intel system
cpu_vendor=$(grep vendor_id /proc/cpuinfo | awk '{print $3}')
if [[ $cpu_vendor = GenuineIntel ]]; then
pkg_list="$pkg_list intel-ucode"
fi
if [[ $openresolv = YES ]]; then
pkg_list="$pkg_list openresolv"
fi
echo ''
echo '************************************'
echo '**** FILE SYSTEM TYPE SELECTION ****'
echo '************************************'
echo ''
echo '[!] Retry if valid selection fails [!]'
echo ''
PS3='Select file system to format partition: '
filesystems=('btrfs' 'ext4' 'xfs' 'f2fs')
select filesysformat in "${filesystems[@]}"
do
case $filesysformat in
'btrfs')
fsys1='btrfs'
pkg_list="$pkg_list btrfs-progs"
fstype="btrfs-progs"
break
;;
'xfs')
fsys1='xfs'
pkg_list="$pkg_list xfsprogs"
fstype="xfsprogs"
break
;;
'ext4')
fsys2='ext4'
pkg_list="$pkg_list e2fsprogs"
fstype="e2fsprogs"
break
;;
'f2fs')
fsys3='f2fs'
pkg_list="$pkg_list f2fs-tools"
fstype="f2fs-tools"
break
;;
*)
echo 'This option is invalid.'
esac
done
# Install Prerequisites to Live USB/Cd
if [[ $repopath != "" ]]; then
cd $repopath
xbps-rindex -a *xbps
xbps-install -u -y xbps -R $repopath
xbps-install -R $repopath -y $prereqs $fstype
else
xbps-install -S
xbps-install -u -y xbps
xbps-install -S
xbps-install -y $prereqs $fstype
fi
# Erase partition table
# wipefs -a /dev/$devname
# dd if=/dev/zero of=/dev/$devname bs=1M count=100
# Create partitions
# xbps-install -y -S -f parted
# if [[ $UEFI ]]; then
# parted /dev/${DEVNAME} mklabel gpt
# parted -a optimal /dev/${devname} mkpart primary 2048s 100M
# parted -a optimal /dev/${devname} mkpart primary 100M 100%
# else
# parted /dev/${devname} mklabel msdos
# parted -a optimal /dev/${devname} mkpart primary 2048s 512M
# parted -a optimal /dev/${devname} mkpart primary 512M 100%
# fi
# parted /dev/${devname} set 1 boot on
# Create GPT partition table
if [[ $UEFI ]]; then
sgdisk --zap-all $device
sgdisk -n 1:2048:550M -t 1:ef00 $device
sgdisk -n 2:0:0 -t 2:8300 $device
sgdisk --verify $device
fi
clear
# Format filesystems
# fat-32
if [[ $UEFI && $device = /dev/mmcblk0 ]]; then
mkfs.vfat -F 32 -n EFI ${device}p1
elif [[ $UEFI && $device != /dev/mmcblk0 ]]; then
mkfs.vfat -F 32 -n $labelfat ${device}1
fi
# ${fsys1} -f -L
# btrfs
# xfs
if [[ $fsys1 && $device = /dev/mmcblk0 ]]; then
mkfs.$fsys1 -f -L $labelroot ${device}p2
elif [[ $fsys1 && $device != /dev/mmcblk0 ]]; then
mkfs.$fsys1 -f -L $labelroot ${device}2
fi
# ${fsys2} -F -L
# ext4
if [[ $fsys2 && $device = /dev/mmcblk0 ]]; then
mkfs.$fsys2 -F -L $labelroot ${device}p2
elif [[ $fsys2 && $device != /dev/mmcblk0 ]]; then
mkfs.$fsys2 -F -L $labelroot ${device}2
fi
if [[ $fsys3 ]]; then
echo "1) Encrypt = encrypt,extra_attr,sb_checksum,inode_checksum,lost_found"
echo "2) No Encryption = extra_attr,sb_checksum,inode_checksum,lost_found"
echo "3) No Checksums = lost_found"
echo "4) None = No Options"
echo
echo "Notes: f2fs-tools v1.14"
echo " | encrypt does not work with 'casefold/utf8'"
echo " | casefold doesn't work without utf8"
echo " | compression unknown option"
echo " | keyboard functioned intermittently (casefold was used)"
PS3='Select f2fs options to use: '
select opts in "Encrypt" "No Encryption" "No Checksums" "None"; do
case $opts in
'Encrypt')
fsys3="$fsys3 -O encrypt,extra_attr,sb_checksum,inode_checksum,lost_found"
break
;;
'No Encryption')
fsys3="$fsys3 -O extra_attr,sb_checksum,inode_checksum,lost_found"
break
;;
'No Checksums')
fsys3="$fsys3 -O lost_found"
break
;;
'None')
fsys3="$fsys3"
break
;;
*) echo Try again
esac
done
fi
# ${fsys3} -f -l
# f2fs
if [[ $fsys3 && $device = /dev/mmcblk0 ]]; then
mkfs.$fsys3 -f -l $labelroot ${device}p2
elif [[ $fsys3 && $device != /dev/mmcblk0 ]]; then
mkfs.$fsys3 -f -l $labelroot ${device}2
fi
# Mount them
if [[ $device = /dev/mmcblk0 ]]; then
mount ${device}p2 /mnt
elif [[ $device != /dev/mmcblk0 ]]; then
mount ${device}2 /mnt
fi
if [[ $UEFI ]]; then
mkdir -p /mnt/boot/efi
[[ $device = /dev/mmcblk0 ]] && \
mount ${device}p1 /mnt/boot/efi
[[ $device != /dev/mmcblk0 ]] && \
mount ${device}1 /mnt/boot/efi
fi
# Create Chroot Gaol
mkdir /mnt/{dev,proc,sys}
mount -o bind /dev /mnt/dev
mount -o bind /proc /mnt/proc
# EFI varibles
# /sys/firmware/efi/efivars/
mount --rbind /sys /mnt/sys
# Alternative mount options
# Conflicting information abounds
# mount -t proc proc /mnt/proc
# mount -t sysfs sys /mnt/sys
# mount -o bind /dev /mnt/dev
# mount -t devpts pts /mnt/dev/pts
#
# mount -t proc /proc proc/
# mount --rbind /sys sys/
# mount --rbind /dev dev/
#
# mount --rbind /sys /mnt/sys && mount --make-rslave /mnt/sys
# mount --rbind /dev /mnt/dev && mount --make-rslave /mnt/dev
# mount --rbind /proc /mnt/proc && mount --make-rslave /mnt/proc
# Import keys from live image to prevent prompt for key confirmation
mkdir -p /mnt/var/db/xbps/keys/
cp -a /var/db/xbps/keys/* /mnt/var/db/xbps/keys/
echo '**********************************'
echo '**** CHECKING KERNEL VERSIONS ****'
echo '**********************************'
# Get currently running kernel version
kver=$(xbps-query linux | awk '$1 == "pkgver:" { print $2 }' | sed -e 's/linux-//' -e 's/_.*$//')
echo "Live CD kernel version $kver"
echo '**************************'
echo 'Choose a kernel to install'
echo '**************************'
PS3="Select kernel: "
select kernel in $(xbps-query --regex -Rs '^linux[0-9.]+-[0-9._]+' | sed -e 's/\[-\] //' -e 's/_.*$//' | cut -d - -f 1 | sort | uniq)
do
if [[ $kernel = "" ]]; then
echo "$REPLY is not valid"
continue
fi
break
done
pkg_list="$pkg_list $kernel"
# Add repositories
mkdir -p /mnt/etc/xbps.d
# cp /mnt/usr/share/xbps.d/*-repository-*.conf /mnt/etc/xbps.d
cp /etc/xbps.d/10-ignore.conf /mnt/etc/xbps.d
cp /etc/xbps.d/00-repository-main.conf /mnt/etc/xbps.d
cp /etc/xbps.d/10-repository-nonfree.conf /mnt/etc/xbps.d
# Package Installation
if [[ $repopath != "" ]]; then
cd $repopath
xbps-rindex -a *xbps
xbps-install -R $repopath -r /mnt $pkg_list -y
elif [[ $cachedir != "" ]]; then
xbps-install --download-only --cachedir $cachedir $pkg_list -y
cd $cachedir
xbps-rindex -a *xbps
xbps-install -R $cachedir -r /mnt $pkg_list -y
elif [[ $cachedir = "" && $repopath = "" ]]; then
xbps-install -S -r /mnt $pkg_list -y
fi
# Keep kernel from updating
xbps-pkgdb -m hold "$kernel" -r /mnt
# Activate services
for srv in $services; do
chroot /mnt ln -s /etc/sv/$srv /etc/runit/runsvdir/default/
done
# Get / UUID
rootuuid=$(blkid -s UUID -o value ${device}2 | cut -d = -f 3 | cut -d " " -f 1 | grep - | tr -d '"')
# Configure efibootmgr
# efibootmgr -c -d /dev/sda -p 1 -l '\vmlinuz-5.7.7_1' -L 'Void' initrd=\initramfs-5.7.7_1.img root=/dev/sda2
cp /etc/default/efibootmgr-kernel-hook /mnt/etc/default/efibootmgr-kernel-hook.orig
# Pressure Stall Information (PSI)
# OPTIONS=root="${device}2" >> boot will fail if OS is on /dev/sdb and /dev/sda is removed
if [[ $device != /dev/mmcblk0 ]]; then
tee /mnt/etc/default/efibootmgr-kernel-hook <<-EOF
MODIFY_EFI_ENTRIES=1
OPTIONS="root=UUID=$rootuuid loglevel=4 Page_Poison=1 psi=1"
DISK="$device"
PART=1
EOF
elif [[ $device = /dev/mmcblk0 ]]; then
tee /mnt/etc/default/efibootmgr-kernel-hook <<-EOF
MODIFY_EFI_ENTRIES=1
OPTIONS=root="${device}p2 loglevel=4 Page_Poison=1"
DISK="$device"
PART=1
EOF
fi
# Add fstab entries
if [[ $UEFI && $device = /dev/mmcblk0 ]]; then
echo "${device}p1 /boot/efi vfat defaults 0 0" >> /mnt/etc/fstab
elif [[ $UEFI && $device != /dev/mmcblk0 ]]; then
echo "LABEL=$labelfat /boot/efi vfat defaults 0 0" >> /mnt/etc/fstab
fi
# echo "LABEL=root / ext4 rw,relatime,data=ordered,discard 0 0" > /mnt/etc/fstab
# echo "LABEL=boot /boot ext4 rw,relatime,data=ordered,discard 0 0" >> /mnt/etc/fstab
if [[ $fsys3 ]]; then
echo "# Boot fails if fsck.f2fs <pass> is enabled" >> /mnt/etc/fstab
echo "UUID=$rootuuid / f2fs defaults 0 0" >> /mnt/etc/fstab
else
echo "UUID=$rootuuid / $fsys1 $fsys2 defaults 0 1" >> /mnt/etc/fstab
fi
if [[ $opt = Server ]]; then
echo "# /Volumes/data* /Volumes/storage fuse.mergerfs category.create=mfs,defaults,allow_other,minfreespace=20G,fsname=mergerfsPool 0 0" >> /mnt/etc/fstab
echo "# /mnt/storage/$USER /home/$USER none bind,rw 0 0" >> /mnt/etc/fstab
fi
# Reconfigure kernel and create initramfs (dracut) and efi boot entry (efibootmgr)
xbps-reconfigure -fa -r /mnt $kernel
cp /mnt/boot/initramfs* /mnt/boot/efi
cp /mnt/boot/vmlinuz* /mnt/boot/efi
# Networking
# iwd requires openresolv to connect to internet which interns uses /etc/resolvconf.conf
# resolvconf -u # updates /etc/resolv.conf
if [[ -f /mnt/etc/resolvconf.conf && -f /mnt/sbin/dnscrypt-proxy ]]; then
echo "resolv_conf_options=edns0" >> /mnt/etc/resolvconf.conf
elif [[ ! -f /mnt/etc/resolvconf.conf && -f /mnt/sbin/dnscrypt-proxy ]]; then
echo "nameserver $nameserver0" >> /mnt/etc/resolv.conf
echo "options edns0" >> /mnt/etc/resolv.conf
elif [[ ! -f /mnt/etc/resolvconf.conf && ! -f /mnt/sbin/dnscrypt-proxy ]]; then
echo "nameserver $nameserver1" >> /mnt/etc/resolv.conf
echo "nameserver $nameserver2" >> /mnt/etc/resolv.conf
elif [[ -f /mnt/etc/resolvconf.conf && ! -f /mnt/sbin/dnscrypt-proxy ]]; then
echo "nameserver $nameserver1" >> /mnt/etc/resolvconf.conf
echo "nameserver $nameserver2" >> /mnt/etc/resolvconf.conf
fi
# Static IP configuration via iproute2
eth=$(ip link | grep enp | cut -d : -f 2)
echo "ip link set dev $eth up" >> /mnt/etc/rc.local
echo "ip addr add $ipstaticeth0/24 brd + dev $eth" >> /mnt/etc/rc.local
echo "ip route add default via $gateway" >> /mnt/etc/rc.local
# Use static Wifi (dynamic is default)
if [[ $ipstaticwlan0 ]]; then
tee /mnt/etc/iwd/main.conf <<-EOF
[General]
EnableNetworkConfiguration=true
EOF
fi
# Set static ip address for wifi
if [[ $ipstaticwlan0 ]]; then
tee /mnt/var/lib/iwd/${routerssid}.psk <<-EOF
[IPv4]
Address="${ipstaticwlan0}"
#Netmask=255.255.255.0
Gateway="$gateway"
#Broadcast=192.168.1.255
#DNS=""
EOF
fi
# Overwrite LIVE ISO hostname
# [!] Not changing hostname will fail at boot with the following error:
# [!] Kernel Panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
echo $hostname > /mnt/etc/hostname
# Locale setup
# mv /mnt/etc/hosts /mnt/etc/hosts.orig
# Adding hostname to hosts is not needed
# echo "127.0.0.1 $HOSTNAME localhost" > /mnt/etc/hosts
echo "TIMEZONE=$TIMEZONE" >> /mnt/etc/rc.conf
echo "HARDWARECLOCK=$HARDWARECLOCK" >> /mnt/etc/rc.conf
echo "KEYMAP=$KEYMAP" >> /mnt/etc/rc.conf
echo "FONT=$FONT" >> /mnt/etc/rc.conf
# Set "root" privileges
# test doas.conf
# $ doas -C /etc/doas.conf
# check permission of command
# $ doas -C /etc/doas.conf command
echo "$doasconf" > /mnt/etc/doas.conf
# Configure user accounts
echo '--------------------------------------------------'
echo -e "[!] Create \x1B[1;31m root \x1B[0m password [!]"
echo '--------------------------------------------------'
while true; do
passwd -R /mnt root && break
echo 'Password did not match. Please try again'
sleep 3s
done
echo '-----------------------------------------------------------------'
echo -e "[!] Create password for user \x1B[01;96m $username \x1B[0m [!]"
echo '-----------------------------------------------------------------'
useradd --root /mnt --user-group --groups $groups --create-home $username
# Bug? useradd -R /mnt
# error: configuration error unknown item 'HOME_MODE' (notify administrator)
# home directory is still created
while true; do
passwd -R /mnt $username && break
echo 'Password did not match. Please try again'
sleep 3s
echo ''
done
# Setup $HOME
echo "$bashrc" >> /mnt/home/$username/.bashrc
if [[ $opt = Desktop ]]; then
echo "$bashprofile" >> /mnt/home/$username/.bash_profile
echo "$xinitrc" > /mnt/home/$username/.xinitrc
chown 1000:1000 /mnt/home/$username/.xinitrc
fi
# Herbstluftwm
# chroot --userspec=$username:users /mnt mkdir -p home/$username/.config/herbstluftwm
# chroot --userspec=$username:users /mnt cp etc/xdg/herbstluftwm/autostart home/$username/.config/herbstluftwm
# Create $HOME directories
for dir in $dirs; do
chroot --userspec=$username:$username /mnt mkdir -p home/$username/$dir
done
# Create list of installed packages
xbps-query -r /mnt --list-pkgs > /mnt/home/$username/void-pkgs.log
echo '**********************************************************'
echo '**********************************************************'
echo -e "[!] Check \x1B[1;92m BootOrder: \x1B[1;0m is correct [!]"
echo ' Boot entry needs to be towards the top of list otherwise '
echo ' it will not appear in the UEFI boot menu. '
echo ' '
echo ' Resetting BIOS will restore default boot order. '
echo '**********************************************************'
echo '**********************************************************'
efibootmgr | grep BootOrder
efibootmgr | grep vmlinuz
echo '**********************************************************'
echo '**********************************************************'
echo -e "\x1B[1;32m [!] VOID LINUX INSTALL IS COMPLETE [!] \x1B[0m"
echo '**********************************************************'
echo '**********************************************************'
echo ''
echo "(U)nmount $device and exit"
echo ''
echo '(E)xit'
echo ''
echo '(R)eboot'
echo ''
echo '(P)oweroff'
echo ''
read -n 1 -p "[ U \ E \ R \ P ]: " ans
# Use 'umount --lazy --recursive' if umount fails.
case $ans in
r|R)
reboot;;
p|P)
poweroff;;
e|E)
exit;;
u|U)
umount -R /mnt
exit
esac
#########################
# FIN
#########################