-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharch-post-install.bash
executable file
·502 lines (391 loc) · 12 KB
/
arch-post-install.bash
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
#!/bin/bash
#=======================================================================================
# GLOBAL VARIABLES
#=======================================================================================
YELLOW='\033[1;33m'
GREEN='\033[1;32m'
RESET='\033[0m'
BOLD='\033[1;37m'
#=======================================================================================
# HELPER FUNCTIONS
#=======================================================================================
echo_line()
{
echo "---------------------------------------------------------------------------"
}
echo_header()
{
echo_line
echo -e "-- ${GREEN}ARCH LINUX POST-INSTALLATION${RESET}"
echo_line
echo
}
echo_keymap_start()
{
echo
echo_line
if [[ $1 == true ]]; then
echo -e "-- ${YELLOW}X${RESET} Execute ${YELLOW}M${RESET} Main Menu"
else
echo -e "-- ${YELLOW}X${RESET} Execute ${YELLOW}S${RESET} Skip ${YELLOW}M${RESET} Main Menu"
fi
echo_line
echo
}
echo_keymap_end()
{
echo
echo_line
if [[ $1 == true ]]; then
echo -e "-- ${YELLOW}R${RESET} Repeat ${YELLOW}M${RESET} Main Menu"
else
echo -e "-- ${YELLOW}R${RESET} Repeat ${YELLOW}N${RESET} Next ${YELLOW}M${RESET} Main Menu"
fi
echo_line
}
echo_progress_heading()
{
echo
echo_line
echo -e "-- ${GREEN}$1${RESET}"
echo_line
echo
}
echo_file_contents()
{
cat "$1"
}
get_user_confirm()
{
local ret_val=1
local yn_choice="n"
echo -e "${BOLD}"
read -s -e -n 1 -p "Are you sure you want to continue [y/N]: " yn_choice
echo -e -n "${RESET}"
[[ "${yn_choice,,}" == "y" ]] && ret_val=0
return $ret_val
}
#=======================================================================================
# INSTALLATION FUNCTIONS
#=======================================================================================
set_consolepermanent()
{
local kb_code
local console_font
read -e -p "Enter keyboard layout: " -i "it" kb_code
echo
read -e -p "Enter console font: " -i "ter-118b" console_font
echo
echo -e "Make keyboard layout ${GREEN}${kb_code}${RESET} permanent."
echo -e "Make console font ${GREEN}${console_font}${RESET} permanent."
if get_user_confirm; then
echo_progress_heading "Saving console settings"
cat > /etc/vconsole.conf <<-VCONSOLE_CONF
KEYMAP=$kb_code
FONT=$console_font
VCONSOLE_CONF
fi
}
set_timezone()
{
local time_zone
read -e -p "Enter timezone: " -i "Europe/Rome" time_zone
echo
echo -e "Set the timezone to ${GREEN}${time_zone}${RESET}."
if get_user_confirm; then
echo_progress_heading "Creating symlink for timezone"
ln -sf /usr/share/zoneinfo/$time_zone /etc/localtime
echo_progress_heading "Setting hardware clock to UTC"
hwclock --systohc --utc
fi
}
set_locale()
{
local locale_US
local locale_IE
read -e -p "Enter language locale: " -i "en_US" locale_US
echo
read -e -p "Enter format locale: " -i "en_IE" locale_IE
echo
echo -e "Set the language to ${GREEN}${locale_US}${RESET} and the format locale to ${GREEN}${locale_IE}${RESET}."
if get_user_confirm; then
echo_progress_heading "Setting language and format locales"
locale_US="$locale_US.UTF-8"
locale_IE="$locale_IE.UTF-8"
sed -i "/#$locale_US/ s/^#//" /etc/locale.gen
sed -i "/#$locale_IE/ s/^#//" /etc/locale.gen
locale-gen
cat > /etc/locale.conf <<-LOCALECONF
LANG=$locale_US
LC_MEASUREMENT=$locale_IE
LC_PAPER=$locale_IE
LC_TIME=$locale_IE
LOCALECONF
echo_progress_heading "Verifying file: /etc/locale.conf"
echo_file_contents "/etc/locale.conf"
fi
}
set_hostname()
{
local pc_name
read -e -p "Enter hostname: " -i "SamsungBook2" pc_name
echo
echo -e "Set the hostname to ${GREEN}${pc_name}${RESET}."
if get_user_confirm; then
echo_progress_heading "Setting hostname"
echo $pc_name > /etc/hostname
cat > /etc/hosts <<-HOSTSFILE
127.0.0.1 localhost
::1 localhost
127.0.1.1 ${pc_name}.localdomain ${pc_name}
HOSTSFILE
echo_progress_heading "Verifying file: /etc/hostname"
echo_file_contents "/etc/hostname"
echo_progress_heading "Verifying file: etc/hosts"
echo_file_contents "/etc/hosts"
fi
}
config_pacman()
{
echo -e "Enable color output and parallel downloads in ${GREEN}/etc/pacman.conf${RESET}."
echo -e "Disable debug packages and configure ZSTD compression in ${GREEN}/etc/makepkg.conf${RESET}."
if get_user_confirm; then
echo_progress_heading "Configuring pacman"
sed -i -f - /etc/pacman.conf <<-PACMAN_CONF
s/#Color/Color/
s/#ParallelDownloads/ParallelDownloads/
PACMAN_CONF
echo_progress_heading "Configuring makepkg"
sed -i -f - /etc/makepkg.conf <<-MAKEPKG_CONF
/^OPTIONS=/ s/ debug/ !debug/
/^COMPRESSZST=/ c COMPRESSZST=(zstd -c -T0 -)
MAKEPKG_CONF
fi
}
root_password()
{
echo "Set the password for the root user."
if get_user_confirm; then
echo_progress_heading "Setting password for root user"
passwd
fi
}
add_sudouser()
{
local new_user
local user_desc
read -e -p "Enter user name: " -i "drakkar" new_user
echo
read -e -p "Enter user description: " -i "draKKar" user_desc
echo
echo -e "Create new user ${GREEN}${new_user}${RESET} with sudo privileges."
if get_user_confirm; then
echo_progress_heading "Creating new user"
useradd -m -G wheel -c $user_desc -s /bin/bash $new_user
echo_progress_heading "Setting password for user"
passwd $new_user
echo_progress_heading "Enabling sudo privileges for user"
bash -c 'echo "%wheel ALL=(ALL) ALL" | (EDITOR="tee -a" visudo -f /etc/sudoers.d/99_wheel)'
echo_progress_heading "Verifying user identity"
id $new_user
fi
}
install_bootloader()
{
echo "Install the GRUB bootloader."
if get_user_confirm; then
# Install GRUB
echo_progress_heading "Installing GRUB bootloader"
pacman -S grub efibootmgr
grub-install --target=x86_64-efi --efi-directory=/boot --removable
# Install microcode
echo_progress_heading "Installing microcode package"
rm -f /boot/intel-ucode.img
pacman -S intel-ucode
# Fix suspend issue / disable watchdogs
local kernel_params=$(cat /etc/default/grub | grep 'GRUB_CMDLINE_LINUX_DEFAULT=' | cut -f2 -d'"')
echo_progress_heading "Fixing Suspend Issue"
local suspend_param="button.lid_init_state=open"
if [[ $kernel_params != *"$suspend_param"* ]]; then kernel_params+=" $suspend_param"; fi
echo_progress_heading "Disabling Watchdogs"
local watchdog_param="modprobe.blacklist=iTCO_wdt"
if [[ $kernel_params != *"$watchdog_param"* ]]; then kernel_params+=" $watchdog_param"; fi
sed -i "/GRUB_CMDLINE_LINUX_DEFAULT=/ c GRUB_CMDLINE_LINUX_DEFAULT=\"$kernel_params\"" /etc/default/grub
# Add custom GRUB entries
echo_progress_heading "Adding custom GRUB entries"
if ! grep -i -q "menuentry" /etc/grub.d/40_custom; then
cat >> /etc/grub.d/40_custom <<-CUSTOM_GRUB
menuentry 'System shutdown' --class shutdown {
echo 'System shutting down...'
halt
}
menuentry 'System restart' --class restart {
echo 'System rebooting...'
reboot
}
CUSTOM_GRUB
fi
# Generate GRUB config file
echo_progress_heading "Generating GRUB config file"
grub-mkconfig -o /boot/grub/grub.cfg
fi
}
display_drivers()
{
echo "Install Mesa OpenGL and Intel VA-API (hardware accel) drivers."
if get_user_confirm; then
echo_progress_heading "Installing Intel display drivers"
pacman -S --needed --asdeps mesa
pacman -S intel-media-driver libva-utils
fi
}
install_pipewire()
{
echo "Install the PipeWire multimedia framework."
if get_user_confirm; then
echo_progress_heading "Installing PipeWire"
pacman -S --asdeps pipewire pipewire-pulse wireplumber gst-plugin-pipewire rtkit
fi
}
install_gnome()
{
local gnome_ignore
read -e -p "Enter GNOME packages to ignore: " -i "epiphany,gnome-characters,gnome-clocks,gnome-contacts,gnome-logs,gnome-maps,gnome-music,gnome-software,gnome-tour,orca,rygel,totem" gnome_ignore
echo
echo "Install the GNOME desktop environment."
if get_user_confirm; then
echo_progress_heading "Installing Network Manager"
pacman -S networkmanager
echo_progress_heading "Installing GNOME"
# Get array of packages to ignore from string
local ignore_pkgs=()
IFS=',' read -r -a ignore_pkgs <<< "$gnome_ignore"
# Get array with full list of GNOME packages
local gnome_pkgs=()
IFS=$'\n' read -d "" -r -a gnome_pkgs < <(pacman -Sgq gnome)
# Remove packages to ignore from array
for pkg in "${ignore_pkgs[@]}"; do
gnome_pkgs=(${gnome_pkgs[@]//$pkg})
done
unset pkg
# Install remaining GNOME packages
echo "If prompted to select provider(s), select default options"
echo
pacman -S "${gnome_pkgs[@]}"
# Install optional GNOME control center dependencies
echo_progress_heading "Installing Optional GNOME Control Center Dependencies"
pacman -S power-profiles-daemon fwupd system-config-printer
# Install GNOME extras
echo_progress_heading "Installing GNOME Extras"
pacman -S gnome-tweaks file-roller dconf-editor
echo_progress_heading "Enabling GDM service"
systemctl enable gdm.service
echo_progress_heading "Enabling Network Manager service"
systemctl enable NetworkManager.service
fi
}
enable_bluetooth()
{
echo "Install and enable Bluetooth."
if get_user_confirm; then
echo_progress_heading "Installing Bluetooth packages"
pacman -S --needed bluez bluez-utils
echo_progress_heading "Enabling power status reporting"
mkdir -p /etc/systemd/system/bluetooth.service.d
cat > /etc/systemd/system/bluetooth.service.d/10-experimental.conf <<-BLUETOOTH_POWER
[Service]
ExecStart=
ExecStart=/usr/lib/bluetooth/bluetoothd -E
BLUETOOTH_POWER
echo_progress_heading "Enabling Bluetooth service"
systemctl enable bluetooth.service
fi
}
install_codecs()
{
echo "Install multimedia codecs."
if get_user_confirm; then
echo_progress_heading "Installing codecs"
pacman -S --needed libmad gstreamer gst-libav gst-plugins-base gst-plugins-bad gst-plugins-good gst-plugins-ugly gstreamer-vaapi
fi
}
#=======================================================================================
# MAIN FUNCTION
#=======================================================================================
main()
{
MENU_ITEMS=("Make Console Settings Permanent|set_consolepermanent"
"Configure Timezone|set_timezone"
"Configure Locale|set_locale"
"Configure Hostname|set_hostname"
"Configure pacman|config_pacman"
"Configure Root Password|root_password"
"Add New User with Sudo Privileges|add_sudouser"
"Install Boot Loader|install_bootloader"
"Install Display Drivers|display_drivers"
"Install PipeWire|install_pipewire"
"Install GNOME Desktop Environment|install_gnome"
"Enable Bluetooth|enable_bluetooth"
"Install Multimedia Codecs|install_codecs")
local menu_index=1
local quit=0
while (( $quit == 0 )); do
clear
echo_header
local item_name=$(echo ${MENU_ITEMS[$menu_index-1]} | cut -f1 -d'|')
echo -e " ${BOLD}STEP ${menu_index} / ${#MENU_ITEMS[@]}: ${item_name}${RESET}"
if (( $menu_index <= $((${#MENU_ITEMS[@]}-1)) )); then
echo_keymap_start false
else
echo_keymap_start true
fi
while true; do
local start_choice
read -r -s -n 1 start_choice
# Return to main menu
if [[ "${start_choice,,}" == "m" ]]; then
quit=1
break
fi
# Skip and go to next step
if [[ "${start_choice,,}" == "s" ]]; then
if (( $menu_index <= $((${#MENU_ITEMS[@]}-1)) )); then
menu_index=$(($menu_index+1))
break
fi
fi
# Execute current step
if [[ "${start_choice,,}" == "x" ]]; then
local item_func=$(echo ${MENU_ITEMS[$menu_index-1]} | cut -f2 -d'|')
${item_func}
if (( $menu_index <= $((${#MENU_ITEMS[@]}-1)) )); then
echo_keymap_end false
else
echo_keymap_end true
fi
while true; do
local end_choice
read -r -s -n 1 end_choice
# Return to main menu
if [[ "${end_choice,,}" == "m" ]]; then
quit=1
break
fi
# Repeat step
if [[ "${end_choice,,}" == "r" ]]; then
break
fi
# Go to next step
if [[ "${end_choice,,}" == "n" ]]; then
if (( $menu_index <= $((${#MENU_ITEMS[@]}-1)) )); then
menu_index=$(($menu_index+1))
break
fi
fi
done
break
fi
done
done
}
main