-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·1103 lines (805 loc) · 33.8 KB
/
build.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
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
set -Eeo pipefail
DIST_DIR=.dist
WORK_DIR="${DIST_DIR}/work"
AUR_DIR="${DIST_DIR}/aur"
PROFILE_DIR="${DIST_DIR}/profile"
ROOT_FS="${PROFILE_DIR}/airootfs"
# Prints an error message and exits the process immediately.
fail () {
echo -e 'Exiting the build process...'
exit 1
}
# Adds the package with the given name into the list of packages
# Arguments:
# name: the name of a package
add_package () {
local name="${1}"
local pkgs_file="${PROFILE_DIR}/packages.x86_64"
if [[ ! -f "${pkgs_file}" ]]; then
echo -e "Unable to locate file ${pkgs_file}"
return 1
fi
if grep -Eq "^${name}$" "${pkgs_file}"; then
echo -e "Skipping package ${name}"
return 0
fi
echo "${name}" >> "${pkgs_file}"
}
# Removes the package with the given name from the list of packages
# Arguments:
# name: the name of a package
remove_package () {
local name="${1}"
local pkgs_file="${PROFILE_DIR}/packages.x86_64"
if [[ ! -f "${pkgs_file}" ]]; then
echo -e "Unable to locate file ${pkgs_file}"
return 1
fi
if ! grep -Eq "^${name}$" "${pkgs_file}"; then
echo -e "Unable to remove package ${name}"
return 1
fi
sed -Ei "/^${name}$/d" "${pkgs_file}" || return 1
echo -e "Removing package ${name}"
}
# Initializes build and distribution files.
init () {
if [[ -d "${DIST_DIR}" ]]; then
rm -rf "${DIST_DIR}" || return 1
echo -e 'Existing .dist/ folder has been removed'
fi
mkdir -p "${DIST_DIR}" || return 1
echo -e 'A clean .dist/ folder has been created'
}
# Copies the archiso custom profile.
copy_profile () {
echo -e 'Copying the custom archiso profile...'
local releng_path="/usr/share/archiso/configs/releng"
if [[ ! -d "${releng_path}" ]]; then
echo -e 'Unable to locate releng archiso profile'
return 1
fi
cp -r "${releng_path}" "${PROFILE_DIR}" || return 1
echo -e "The releng profile copied to ${PROFILE_DIR}"
}
# Sets the distribution names and os release meta files.
rename_distro () {
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
printf '%s\n' \
'NAME="Stack Linux"' \
'PRETTY_NAME="Stack Linux"' \
'ID=stack' \
'ID_LIKE=arch' \
'IMAGE_ID=stack' \
"IMAGE_VERSION=$(date +%Y.%m.%d)" \
'BUILD_ID=rolling' \
'ANSI_COLOR="38;2;23;147;209"' \
'HOME_URL="https://github.com/tzeikob/stack.git/"' \
'DOCUMENTATION_URL="https://github.com/tzeikob/stack.git/"' \
'SUPPORT_URL="https://github.com/tzeikob/stack.git/"' \
'BUG_REPORT_URL="https://github.com/tzeikob/stack/issues"' \
'PRIVACY_POLICY_URL="https://github.com/tzeikob/stack/blob/master/LICENSE"' \
'LOGO=stack-logo' > "${ROOT_FS}/etc/stack-release" || return 1
echo -e 'Release metadata set to /etc/stack-release'
mkdir -p "${ROOT_FS}/etc/pacman.d/scripts" || return 1
local fix_release="${ROOT_FS}/etc/pacman.d/scripts/fix-release"
printf '%s\n' \
'#!/bin/bash' \
'' \
'rm -f /etc/arch-release' \
'cat /etc/stack-release > /usr/lib/os-release' \
'[[ -f /etc/lsb-release ]] &&' \
' echo "DISTRIB_ID=\"Stack\"" > /etc/lsb-release &&' \
' echo "DISTRIB_RELEASE=\"rolling\"" >> /etc/lsb-release &&' \
' echo "DISTRIB_DESCRIPTION=\"Stack Linux\"" >> /etc/lsb-release' >> "${fix_release}" || return 1
local fix_release_hook="${ROOT_FS}/etc/pacman.d/hooks/90-fix-release.hook"
printf '%s\n' \
'[Trigger]' \
'Type = Package' \
'Operation = Install' \
'Operation = Upgrade' \
'Target = lsb-release' \
'' \
'[Action]' \
'Description = Fix os release data and meta files' \
'When = PostTransaction' \
'Exec = /bin/bash /etc/pacman.d/scripts/fix-release' >> "${fix_release_hook}" || return 1
echo -e 'Fix release hook has been created'
echo -e 'stackiso' > "${ROOT_FS}/etc/hostname"
echo -e 'Host name set to stackiso'
if [[ ! -d "${PROFILE_DIR}" ]]; then
echo -e 'Unable to locate the releng profile folder'
return 1
fi
local profile_def="${PROFILE_DIR}/profiledef.sh"
sed -i 's|^\(iso_name=\).*|\1\"stacklinux\"|' "${profile_def}" &&
sed -i 's|^\(iso_label="\)ARCH_\(.*\)|\1STACK_\2|' "${profile_def}" &&
sed -i 's|^\(iso_publisher=\).*|\1\"Stack Linux <https://github.com/tzeikob/stack.git>\"|' "${profile_def}" &&
sed -i 's|^\(iso_application=\).*|\1\"Stack Linux Live Media\"|' "${profile_def}" &&
sed -i 's|^\(install_dir=\).*|\1\"stack\"|' "${profile_def}" || return 1
echo -e 'Release info updated in profile definition file'
}
# Sets up the bios and uefi boot loaders.
setup_boot_loaders () {
if [[ ! -d "${PROFILE_DIR}" ]]; then
echo -e 'Unable to locate the releng profile folder'
return 1
fi
rm -rf "${PROFILE_DIR}/efiboot" || return 1
echo -e 'EFI boot loader has been removed'
rm -f "${PROFILE_DIR}/syslinux/archiso_pxe.cfg" \
"${PROFILE_DIR}/syslinux/archiso_pxe-linux.cfg" || return 1
local syslinux_cfg="${PROFILE_DIR}/syslinux/syslinux.cfg"
sed -i 's/APPEND -pxe- pxe -sys- sys -iso- sys/APPEND -sys- sys -iso- sys/' "${syslinux_cfg}" &&
sed -i '/LABEL pxe/,+3d' "${syslinux_cfg}" || return 1
echo -e 'PXE bios modes have been removed'
sed -i 's/Arch/Stack/' "${PROFILE_DIR}/syslinux/archiso_sys-linux.cfg" &&
sed -i '/# Accessibility boot option/,$d' "${PROFILE_DIR}/syslinux/archiso_sys-linux.cfg" &&
sed -i '/TEXT HELP/,/ENDTEXT/d' "${PROFILE_DIR}/syslinux/archiso_sys-linux.cfg" &&
sed -i '/LABEL existing/,+9d' "${PROFILE_DIR}/syslinux/archiso_tail.cfg" &&
sed -i '/TEXT HELP/,/ENDTEXT/d' "${PROFILE_DIR}/syslinux/archiso_tail.cfg" || return 1
rm -rf "${PROFILE_DIR}/syslinux/splash.png" || return 1
printf '%s\n' \
'SERIAL 0 115200' \
'UI vesamenu.c32' \
'MENU TITLE Stack Linux Live Media' \
'MENU BACKGROUND #ff000000' \
'MENU WIDTH 78' \
'MENU MARGIN 4' \
'MENU ROWS 6' \
'MENU VSHIFT 6' \
'MENU TABMSGROW 14' \
'MENU CMDLINEROW 14' \
'MENU HELPMSGROW 16' \
'MENU HELPMSGENDROW 29' \
'MENU COLOR border 0 #ffffffff #00000000 none' \
'MENU COLOR title 37;40 #ffffffff #00000000 none' \
'MENU COLOR sel 37;40 #ff000000 #ffffffff none' \
'MENU COLOR unsel 37;40 #ffffffff #00000000 none' \
'MENU COLOR help 37;40 #ffffffff #00000000 none' \
'MENU COLOR timeout_msg 37;40 #ffffffff #00000000 none' \
'MENU COLOR timeout 37;40 #ffffffff #00000000 none' \
'MENU COLOR msg07 37;40 #ffffffff #00000000 none' \
'MENU COLOR tabmsg 37;40 #ffffffff #00000000 none' \
'MENU CLEAR' \
'MENU IMMEDIATE' > "${PROFILE_DIR}/syslinux/archiso_head.cfg" || return 1
echo -e 'Syslinux boot loader menus have been modified'
local grub_cfg="${PROFILE_DIR}/grub/grub.cfg"
sed -i "/--id 'archlinux-accessibility'/,+5d" "${grub_cfg}" &&
sed -i 's/archlinux/stacklinux/' "${grub_cfg}" &&
sed -i 's/Arch Linux/Stack Linux/' "${grub_cfg}" || return 1
local loopback_cfg="${PROFILE_DIR}/grub/loopback.cfg"
sed -i "/--id 'archlinux-accessibility'/,+5d" "${loopback_cfg}" &&
sed -i 's/archlinux/stacklinux/' "${loopback_cfg}" &&
sed -i 's/Arch Linux/Stack Linux/' "${loopback_cfg}" || return 1
echo -e 'Grup boot loader menus have been modified'
}
# Adds the pakacge dependencies into the list of packages.
add_packages () {
echo -e 'Adding system and desktop packages...'
local pkgs=()
# Add the base and system packages
pkgs+=(
reflector rsync sudo
base-devel pacman-contrib pkgstats grub mtools dosfstools ntfs-3g exfatprogs gdisk fuseiso veracrypt
python-pip parted curl wget udisks2 udiskie gvfs gvfs-smb bash-completion
man-db man-pages texinfo cups cups-pdf cups-filters usbutils bluez bluez-utils unzip terminus-font
vim nano git tree arch-audit atool zip xz unace p7zip gzip lzop feh hsetroot
bzip2 unrar dialog inetutils dnsutils openssh nfs-utils ipset xsel
neofetch age imagemagick gpick fuse2 rclone smartmontools glib2 jq jc sequoia-sq xf86-input-wacom
cairo bc xdotool python-tqdm libqalculate nftables iptables-nft virtualbox-guest-utils
)
# Add the display server and graphics packages
pkgs+=(
xorg xorg-xinit xorg-xrandr xorg-xdpyinfo xf86-video-qxl
)
# Add various hardware and driver packages
pkgs+=(
acpi acpi_call acpid tlp xcalib
networkmanager networkmanager-openvpn wireless_tools netctl wpa_supplicant
nmap dhclient smbclient libnma alsa-utils xf86-input-synaptics
)
# Add the desktop prerequisite packages
pkgs+=(
picom bspwm sxhkd polybar rofi dunst
trash-cli cool-retro-term helix firefox torbrowser-launcher
irssi ttf-font-awesome noto-fonts-emoji
)
local pkg=''
for pkg in "${pkgs[@]}"; do
add_package "${pkg}" || return 1
done
# Remove conflicting no x server virtualbox utils
remove_package virtualbox-guest-utils-nox || return 1
echo -e 'All packages added into the package list'
}
# Builds and adds the AUR packages into the packages list
# via a local custom repo.
add_aur_packages () {
echo -e 'Building the AUR package files...'
local previous_dir=${PWD}
if [[ ! -d "${PROFILE_DIR}" ]]; then
echo -e 'Unable to locate the releng profile folder'
return 1
fi
local repo_home="${PROFILE_DIR}/local/repo"
mkdir -p "${repo_home}" || return 1
local names=(
yay smenu xkblayout-state-git
)
local name=''
for name in "${names[@]}"; do
# Build the next AUR package
git clone "https://aur.archlinux.org/${name}.git" "${AUR_DIR}/${name}" || return 1
cd "${AUR_DIR}/${name}"
makepkg || return 1
cd ${previous_dir}
# Create the custom local repo database
cp ${AUR_DIR}/${name}/${name}-*-x86_64.pkg.tar.zst "${repo_home}" || return 1
repo-add "${repo_home}/custom.db.tar.gz" ${repo_home}/${name}-*-x86_64.pkg.tar.zst || return 1
add_package "${name}" || return 1
done
rm -rf "${AUR_DIR}" || return 1
echo -e 'The AUR package files have been built'
local pacman_conf="${PROFILE_DIR}/pacman.conf"
if [[ ! -f "${pacman_conf}" ]]; then
echo -e "Unable to locate file ${pacman_conf}"
return 1
fi
printf '%s\n' \
'' \
'[custom]' \
'SigLevel = Optional TrustAll' \
"Server = file://$(realpath "${repo_home}")" >> "${pacman_conf}" || return 1
echo -e 'The custom local repo added to pacman'
echo -e 'All AUR packages added into the package list'
}
# Copies the files of the installer.
copy_installer () {
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
local installer_home="${ROOT_FS}/opt/stack"
mkdir -p "${installer_home}" || return 1
cp -r configs "${installer_home}" &&
cp -r resources "${installer_home}" &&
cp -r rules "${installer_home}" &&
cp -r scripts "${installer_home}" &&
cp -r services "${installer_home}" &&
cp -r tools "${installer_home}" &&
cp install.sh "${installer_home}" || return 1
# Create a global alias to launch the installer
local bin_home="${ROOT_FS}/usr/local/bin"
mkdir -p "${bin_home}" || return 1
ln -sf /opt/stack/install.sh "${bin_home}/install_os" || return 1
echo -e 'Installer files have been copied'
}
# Copies the files of the settings tools.
copy_settings_tools () {
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
local tools_home="${ROOT_FS}/opt/tools"
mkdir -p "${tools_home}" || return 1
# Copy settings tools needed to the live media only
cp -r tools/displays "${tools_home}" &&
cp -r tools/desktop "${tools_home}" &&
cp -r tools/clock "${tools_home}" &&
cp -r tools/networks "${tools_home}" &&
cp -r tools/disks "${tools_home}" &&
cp -r tools/bluetooth "${tools_home}" &&
cp -r tools/langs "${tools_home}" &&
cp -r tools/notifications "${tools_home}" &&
cp -r tools/power "${tools_home}" &&
cp -r tools/printers "${tools_home}" &&
cp -r tools/trash "${tools_home}" &&
cp tools/utils "${tools_home}" || return 1
# Remove LC_CTYPE on smenu calls as live media doesn't need it
sed -i 's/\(.*\)LC_CTYPE=.* \(smenu .*\)/\1\2/' "${tools_home}/utils" || return 1
# Disable init scratchpad command for the live media
local desktop_main="${tools_home}/desktop/main"
sed -i "/.*scratchpad.*/d" "${desktop_main}" || return 1
# Create global aliases for each setting tool main entry
local bin_home="${ROOT_FS}/usr/local/bin"
mkdir -p "${bin_home}" || return 1
ln -sf /opt/tools/displays/main "${bin_home}/displays" &&
ln -sf /opt/tools/desktop/main "${bin_home}/desktop" &&
ln -sf /opt/tools/clock/main "${bin_home}/clock" &&
ln -sf /opt/tools/networks/main "${bin_home}/networks" &&
ln -sf /opt/tools/disks/main "${bin_home}/disks" &&
ln -sf /opt/tools/bluetooth/main "${bin_home}/bluetooth" &&
ln -sf /opt/tools/langs/main "${bin_home}/langs" &&
ln -sf /opt/tools/notifications/main "${bin_home}/notifications" &&
ln -sf /opt/tools/power/main "${bin_home}/power" &&
ln -sf /opt/tools/printers/main "${bin_home}/printers" &&
ln -sf /opt/tools/trash/main "${bin_home}/trash" || return 1
echo -e 'Settings tools have been copied'
}
# Sets to skip login prompt and auto login the root user.
setup_auto_login () {
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
local auto_login="${ROOT_FS}/etc/systemd/system/getty@tty1.service.d/autologin.conf"
local exec_start="ExecStart=-/sbin/agetty -o '-p -f -- \\\\\\\u' --noissue --noclear --skip-login --autologin root - \$TERM"
sed -i "s;^ExecStart=-/sbin/agetty.*;${exec_start};" "${auto_login}" || return 1
echo -e 'Login prompt set to skip and autologin'
# Remove the default welcome message
rm -rf "${ROOT_FS}/etc/motd" || return 1
# Create the welcome message to be shown after login
local welcome=''
welcome+='░░░█▀▀░▀█▀░█▀█░█▀▀░█░█░░░\n'
welcome+='░░░▀▀█░░█░░█▀█░█░░░█▀▄░░░\n'
welcome+='░░░▀▀▀░░▀░░▀░▀░▀▀▀░▀░▀░░░\n\n'
welcome+='Welcome to live media of \u001b[36mStack OS\u001b[0m, more information\n'
welcome+='can be found on https://github.com/tzeikob/stack.git.\n\n'
welcome+='Connect to a wireless network using the networks tool via\n'
welcome+='the command \u001b[36mnetworks add wifi <device> <ssid> <secret>\u001b[0m.\n'
welcome+='Ethernet, WALN and WWAN networks should work automatically.\n\n'
welcome+='To install a new system run \u001b[36minstall_os\u001b[0m to launch\n'
welcome+='the installation process of the Stack OS.\n'
echo -e "${welcome}" > "${ROOT_FS}/etc/welcome"
echo -e 'Welcome message has been set to /etc/welcome'
}
# Sets up the display server configuration and hooks.
setup_display_server () {
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
local xinitrc_file="${ROOT_FS}/root/.xinitrc"
cp configs/xorg/xinitrc "${xinitrc_file}" || return 1
# Keep functionality relatated to live media only
sed -i '/system -qs check updates &/d' "${xinitrc_file}" &&
sed -i '/displays -qs restore layout/d' "${xinitrc_file}" &&
sed -i '/displays -qs restore colors &/d' "${xinitrc_file}" &&
sed -i '/security -qs init locker &/d' "${xinitrc_file}" &&
sed -i '/cloud -qs mount remotes &/d' "${xinitrc_file}" || return 1
echo -e 'The .xinitrc file copied to /root/.xinitrc'
mkdir -p "${ROOT_FS}/etc/X11" || return 1
cp configs/xorg/xorg.conf "${ROOT_FS}/etc/X11" || return 1
echo -e 'The xorg.conf file copied to /etc/X11/xorg.conf'
local zlogin_file="${ROOT_FS}/root/.zlogin"
if [[ ! -f "${zlogin_file}" ]]; then
echo -e "Unable to locate file ${zlogin_file}"
return 1
fi
printf '%s\n' \
'' \
"echo -e 'Starting desktop environment...'" \
'startx' >> "${zlogin_file}" || return 1
echo -e 'Xorg server set to be started after login'
}
# Sets up the keyboard settings.
setup_keyboard () {
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
echo 'KEYMAP=us' > "${ROOT_FS}/etc/vconsole.conf" || return 1
echo -e 'Keyboard map keys has been set to us'
mkdir -p "${ROOT_FS}/etc/X11/xorg.conf.d" || return 1
printf '%s\n' \
'Section "InputClass"' \
' Identifier "system-keyboard"' \
' MatchIsKeyboard "on"' \
' Option "XkbLayout" "us"' \
' Option "XkbModel" "pc105"' \
' Option "XkbOptions" "grp:alt_shift_toggle"' \
'EndSection' > "${ROOT_FS}/etc/X11/xorg.conf.d/00-keyboard.conf" || return 1
echo -e 'Xorg keyboard settings have been set'
# Save keyboard settings to the user langs json file
local config_home="${ROOT_FS}/root/.config/stack"
mkdir -p "${config_home}" || return 1
printf '%s\n' \
'{' \
' "keymap": "us",' \
' "model": "pc105",' \
' "options": "grp:alt_shift_toggle",' \
' "layouts": [{"code": "us", "variant": "default"}]' \
'}' > "${config_home}/langs.json" || return 1
echo -e 'Keyboard langs settings have been set'
}
# Sets up various system power settings.
setup_power () {
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
rm -rf "${ROOT_FS}/etc/systemd/logind.conf.d" &&
mkdir -p "${ROOT_FS}/etc/systemd/logind.conf.d" || return 1
local logind_conf="${ROOT_FS}/etc/systemd/logind.conf.d/00-main.conf"
printf '%s\n' \
'[Login]' \
'HandleHibernateKey=ignore' \
'HandleHibernateKeyLongPress=ignore' \
'HibernateKeyIgnoreInhibited=no' \
'HandlePowerKey=suspend' \
'HandleRebootKey=reboot' \
'HandleSuspendKey=suspend' \
'HandleLidSwitch=suspend' \
'HandleLidSwitchDocked=ignore' > "${logind_conf}" || return 1
echo -e 'Logind action handlers have been set'
rm -rf "${ROOT_FS}/etc/systemd/sleep.conf.d" &&
mkdir -p "${ROOT_FS}/etc/systemd/sleep.conf.d" || return 1
local sleep_conf="${ROOT_FS}/etc/systemd/sleep.conf.d/00-main.conf"
printf '%s\n' \
'[Sleep]' \
'AllowSuspend=yes' \
'AllowHibernation=no' \
'AllowSuspendThenHibernate=no' \
'AllowHybridSleep=no' > "${sleep_conf}" || return 1
echo -e 'Sleep action handlers have been set'
mkdir -p "${ROOT_FS}/etc/tlp.d" || return 1
local tlp_conf="${ROOT_FS}/etc/tlp.d/00-main.conf"
printf '%s' \
'SOUND_POWER_SAVE_ON_AC=0' \
'SOUND_POWER_SAVE_ON_BAT=0' > "${tlp_conf}" || return 1
echo -e 'Battery action handlers have been set'
local config_home="${ROOT_FS}/root/.config/stack"
mkdir -p "${config_home}" || return 1
printf '%s\n' \
'{' \
' "screensaver": {"interval": 15}' \
'}' > "${config_home}/power.json" || return 1
echo -e 'Screensaver interval setting has been set'
}
# Sets up the sheel environment files.
setup_shell_environment () {
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
local zshrc_file="${ROOT_FS}/root/.zshrc"
# Set the defauilt terminal and text editor
echo -e 'export TERMINAL=cool-retro-term' >> "${zshrc_file}"
echo -e 'Default terminal set to cool-retro-term'
echo -e 'export EDITOR=helix' >> "${zshrc_file}"
echo -e 'Default editor set to helix'
# Set up trash-cli aliases
echo -e "\nalias sudo='sudo '" >> "${zshrc_file}"
echo "alias tt='trash-put -i'" >> "${zshrc_file}"
echo "alias rm='rm -i'" >> "${zshrc_file}"
echo -e 'Command aliases added to /root/.zshrc'
printf '%s\n' \
'' \
'if [[ "${SHOW_WELCOME_MSG}" == "true" ]]; then' \
' cat /etc/welcome' \
'fi' >> "${zshrc_file}" || return 1
echo -e 'Welcome message set to be shown after login'
}
# Sets up the corresponding configurations for
# each desktop module.
setup_desktop () {
echo -e 'Setting up the desktop configurations...'
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
local config_home="${ROOT_FS}/root/.config"
# Copy the picom configuration files
local picom_home="${config_home}/picom"
mkdir -p "${picom_home}" || return 1
cp configs/picom/picom.conf "${picom_home}" || return 1
echo -e 'Picom configuration has been set'
# Copy windows manager configuration files
local bspwm_home="${config_home}/bspwm"
mkdir -p "${bspwm_home}" || return 1
cp configs/bspwm/bspwmrc "${bspwm_home}" &&
cp configs/bspwm/resize "${bspwm_home}" &&
cp configs/bspwm/rules "${bspwm_home}" &&
cp configs/bspwm/swap "${bspwm_home}" || return 1
# Remove init scratchpad initializer from the bspwmrc
sed -i '/desktop -qs init scratchpad &/d' "${bspwm_home}/bspwmrc" || return 1
sed -i '/bspc rule -a scratch sticky=off state=floating hidden=on/d' "${bspwm_home}/bspwmrc" || return 1
# Add a hook to open the welcome terminal once at login
printf '%s\n' \
'[ "$@" -eq 0 ] && {' \
' SHOW_WELCOME_MSG=true cool-retro-term &' \
'}' >> "${bspwm_home}/bspwmrc" || return 1
echo -e 'Bspwm configuration has been set'
# Copy polybar configuration files
local polybar_home="${config_home}/polybar"
mkdir -p "${polybar_home}" || return 1
cp configs/polybar/config.ini "${polybar_home}" &&
cp configs/polybar/modules.ini "${polybar_home}" &&
cp configs/polybar/theme.ini "${polybar_home}" || return 1
local config_ini="${polybar_home}/config.ini"
# Remove modules not needed by the live media
sed -i "s/\(modules-right = \)cpu.*/\1 alsa-audio date time/" "${config_ini}" || return 1
sed -i "s/\(modules-right = \)notifications.*/\1 flash-drives keyboard/" "${config_ini}" || return 1
sed -i "s/\(modules-left = \)wlan.*/\1 wlan eth/" "${config_ini}" || return 1
mkdir -p "${polybar_home}/scripts" || return 1
# Keep only scripts needed by the live media
cp -r configs/polybar/scripts/flash-drives "${polybar_home}/scripts" || return 1
cp -r configs/polybar/scripts/time "${polybar_home}/scripts" || return 1
echo -e 'Polybar configuration has been set'
# Copy sxhkd configuration files
local sxhkd_home="${config_home}/sxhkd"
mkdir -p "${sxhkd_home}" || return 1
cp configs/sxhkd/sxhkdrc "${sxhkd_home}" || return 1
local sxhkdrc_file="${sxhkd_home}/sxhkdrc"
# Remove key bindings not needed by the live media
sed -i '/# Lock the screen./,+3d' "${sxhkdrc_file}" &&
sed -i '/# Take a screen shot./,+3d' "${sxhkdrc_file}" &&
sed -i '/# Start recording your screen./,+3d' "${sxhkdrc_file}" &&
sed -i '/# Show and hide the scratchpad termimal./,+3d' "${sxhkdrc_file}" || return 1
echo -e 'Sxhkd configuration has been set'
# Copy rofi configuration files
local rofi_home="${config_home}/rofi"
mkdir -p "${rofi_home}" || return 1
cp configs/rofi/config.rasi "${rofi_home}" || return 1
cp configs/rofi/launch "${rofi_home}" || return 1
local launch_file="${rofi_home}/launch"
sed -i "/options+='Lock\\\n'/d" "${launch_file}" &&
sed -i "/options+='Blank\\\n'/d" "${launch_file}" &&
sed -i "/options+='Logout'/d" "${launch_file}" &&
sed -i "s/\( local exact_lines='listview {lines:\) 6\(;}'\)/\1 3\2/" "${launch_file}" &&
sed -i "/'Lock') security -qs lock screen;;/d" "${launch_file}" &&
sed -i "/'Blank') power -qs blank;;/d" "${launch_file}" &&
sed -i "/'Logout') security -qs logout user;;/d" "${launch_file}" || return 1
echo -e 'Rofi configuration has been set'
# Copy dunst configuration files
local dunst_home="${config_home}/dunst"
mkdir -p "${dunst_home}" || return 1
cp configs/dunst/dunstrc "${dunst_home}" || return 1
cp configs/dunst/hook "${dunst_home}" || return 1
echo -e 'Dunst configuration has been set'
}
# Sets up the theme of the desktop environment.
setup_theme () {
echo -e 'Setting up the desktop theme...'
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
local themes_home="${ROOT_FS}/usr/share/themes"
mkdir -p "${themes_home}" || return 1
local theme_url='https://github.com/dracula/gtk/archive/master.zip'
curl "${theme_url}" -sSLo "${themes_home}/Dracula.zip" &&
unzip -q "${themes_home}/Dracula.zip" -d "${themes_home}" &&
mv "${themes_home}/gtk-master" "${themes_home}/Dracula" &&
rm -f "${themes_home}/Dracula.zip" || return 1
echo -e 'Desktop theme has been installed'
echo -e 'Setting up the desktop icons...'
local icons_home="${ROOT_FS}/usr/share/icons"
mkdir -p "${icons_home}" || return 1
local icons_url='https://github.com/dracula/gtk/files/5214870/Dracula.zip'
curl "${icons_url}" -sSLo "${icons_home}/Dracula.zip" &&
unzip -q "${icons_home}/Dracula.zip" -d "${icons_home}" &&
rm -f "${icons_home}/Dracula.zip" || return 1
echo -e 'Desktop icons have been installed'
echo -e 'Setting up the desktop cursors...'
local cursors_home="${ROOT_FS}/usr/share/icons"
mkdir -p "${cursors_home}" || return 1
local cursors_url='https://www.dropbox.com/s/mqt8s1pjfgpmy66/Breeze-Snow.tgz?dl=1'
wget "${cursors_url}" -qO "${cursors_home}/breeze-snow.tgz" &&
tar -xzf "${cursors_home}/breeze-snow.tgz" -C "${cursors_home}" &&
rm -f "${cursors_home}/breeze-snow.tgz" || return 1
mkdir -p "${cursors_home}/default" || return 1
echo '[Icon Theme]' >> "${cursors_home}/default/index.theme"
echo 'Inherits=Breeze-Snow' >> "${cursors_home}/default/index.theme"
echo -e 'Desktop cursors have been installed'
local gtk_home="${ROOT_FS}/root/.config/gtk-3.0"
mkdir -p "${gtk_home}" || return 1
cp configs/gtk/settings.ini "${gtk_home}" || return 1
echo -e 'Gtk settings file has been set'
echo -e 'Setting the desktop wallpaper...'
local wallpapers_home="${ROOT_FS}/root/.local/share/wallpapers"
mkdir -p "${wallpapers_home}" || return 1
cp resources/wallpapers/* "${wallpapers_home}" || return 1
local settings_home="${ROOT_FS}/root/.config/stack"
mkdir -p "${settings_home}" || return 1
local settings='{"wallpaper": {"name": "default.jpeg", "mode": "fill"}}'
echo "${settings}" > "${settings_home}/desktop.json"
echo -e 'Desktop wallpaper has been set'
}
# Sets up some extra system fonts.
setup_fonts () {
echo -e 'Setting up extra system fonts...'
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
local fonts_home="${ROOT_FS}/usr/share/fonts/extra-fonts"
mkdir -p "${fonts_home}" || return 1
local fonts=(
"FiraCode https://github.com/tonsky/FiraCode/releases/download/6.2/Fira_Code_v6.2.zip"
"JetBrainsMono https://github.com/JetBrains/JetBrainsMono/releases/download/v2.242/JetBrainsMono-2.242.zip"
"Mononoki https://github.com/madmalik/mononoki/releases/download/1.3/mononoki.zip"
"VictorMono https://rubjo.github.io/victor-mono/VictorMonoAll.zip"
"PixelMix https://dl.dafont.com/dl/?f=pixelmix"
)
local font=''
for font in "${fonts[@]}"; do
local name=''
name="$(echo "${font}" | cut -d ' ' -f 1)" || return 1
local url=''
url="$(echo "${font}" | cut -d ' ' -f 2)" || return 1
curl "${url}" -sSLo "${fonts_home}/${name}.zip" &&
unzip -q "${fonts_home}/${name}.zip" -d "${fonts_home}/${name}" &&
chmod -R 755 "${fonts_home}/${name}" &&
rm -f "${fonts_home}/${name}.zip" || return 1
echo -e "Font ${name} installed"
done
echo -e 'Fonts have been setup'
}
# Sets up various system sound resources.
setup_sounds () {
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
local sounds_home="${ROOT_FS}/usr/share/sounds/stack"
mkdir -p "${sounds_home}" || return 1
cp resources/sounds/normal.wav "${sounds_home}" || return 1
cp resources/sounds/critical.wav "${sounds_home}" || return 1
echo -e 'Extra system sounds have been set'
}
# Enables various system services.
enable_services () {
echo -e 'Enabling system services...'
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
mkdir -p "${ROOT_FS}/etc/systemd/system" || return 1
ln -s /usr/lib/systemd/system/NetworkManager-dispatcher.service \
"${ROOT_FS}/etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service" || return 1
mkdir -p "${ROOT_FS}/etc/systemd/system/multi-user.target.wants" || return 1
ln -s /usr/lib/systemd/system/NetworkManager.service \
"${ROOT_FS}/etc/systemd/system/multi-user.target.wants/NetworkManager.service" || return 1
mkdir -p "${ROOT_FS}/etc/systemd/system/network-online.target.wants" || return 1
ln -s /usr/lib/systemd/system/NetworkManager-wait-online.service \
"${ROOT_FS}/etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service" || return 1
echo -e 'Network manager services enabled'
ln -s /usr/lib/systemd/system/bluetooth.service \
"${ROOT_FS}/etc/systemd/system/dbus-org.bluez.service" || return 1
mkdir -p "${ROOT_FS}/etc/systemd/system/bluetooth.target.wants" || return 1
ln -s /usr/lib/systemd/system/bluetooth.service \
"${ROOT_FS}/etc/systemd/system/bluetooth.target.wants/bluetooth.service" || return 1
echo -e 'Bluetooth services enabled'
ln -s /usr/lib/systemd/system/acpid.service \
"${ROOT_FS}/etc/systemd/system/multi-user.target.wants/acpid.service" || return 1
echo -e 'Acpid service enabled'
mkdir -p "${ROOT_FS}/etc/systemd/system/printer.target.wants" || return 1
ln -s /usr/lib/systemd/system/cups.service \
"${ROOT_FS}/etc/systemd/system/printer.target.wants/cups.service" || return 1
ln -s /usr/lib/systemd/system/cups.service \
"${ROOT_FS}/etc/systemd/system/multi-user.target.wants/cups.service" || return 1
mkdir -p "${ROOT_FS}/etc/systemd/system/sockets.target.wants" || return 1
ln -s /usr/lib/systemd/system/cups.socket \
"${ROOT_FS}/etc/systemd/system/sockets.target.wants/cups.socket" || return 1
ln -s /usr/lib/systemd/system/cups.path \
"${ROOT_FS}/etc/systemd/system/multi-user.target.wants/cups.path" || return 1
echo -e 'Cups services enabled'
ln -s /usr/lib/systemd/system/nftables.service \
"${ROOT_FS}/etc/systemd/system/multi-user.target.wants/nftables.service" || return 1
echo -e 'Nftables service enabled'
mkdir -p "${ROOT_FS}/root/.config/systemd/user" || return 1
cp services/init-pointer.service \
"${ROOT_FS}/root/.config/systemd/user/init-pointer.service" || return 1
echo -e 'Pointer init service enabled'
cp services/init-tablets.service \
"${ROOT_FS}/root/.config/systemd/user/init-tablets.service" || return 1
echo -e 'Tablets init service enabled'
cp services/fix-layout.service \
"${ROOT_FS}/root/.config/systemd/user/fix-layout.service" || return 1
sed -i 's;^\(Environment=HOME\).*;\1=/root;' \
"${ROOT_FS}/root/.config/systemd/user/fix-layout.service" || return 1
sed -i 's;^\(Environment=XAUTHORITY\).*;\1=/root/.Xauthority;' \
"${ROOT_FS}/root/.config/systemd/user/fix-layout.service" || return 1
echo -e 'Fix layout service enabled'
}
# Adds input and output devices rules.
add_device_rules () {
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi
local rules_home="${ROOT_FS}/etc/udev/rules.d"
mkdir -p "${rules_home}" || return 1
cp rules/90-init-pointer.rules "${rules_home}" &&
cp rules/91-init-tablets.rules "${rules_home}" &&
cp rules/92-fix-layout.rules "${rules_home}" || return 1
echo -e 'Device rules have been set'
}
# Adds various extra sudoers rules.
add_sudoers_rules () {
if [[ ! -d "${ROOT_FS}" ]]; then
echo -e 'Unable to locate the airootfs folder'
return 1
fi