-
Notifications
You must be signed in to change notification settings - Fork 5
/
postinstall
executable file
·471 lines (406 loc) · 13.2 KB
/
postinstall
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
#!/bin/bash
# import {{{
if [[ -f "$(pwd)/common" ]]; then
source common
else
print_error 'missing file: common'
fi
if [[ -f "$(pwd)/utilities" ]]; then
source utilities
else
print_error 'missing file: utilities'
fi
# }}}
check_multilib(){ #{{{
local architect="$(uname -m)"
print_progress 'Enable 32-bit application on 64-bit system'
if [[ $architect == x86_64 ]]; then
local has_multilib="$(grep -n "\[multilib\]" /etc/pacman.conf | cut -f1 -d:)" # get line number contains "[multilib]"
if [[ -z "$has_multilib" ]]; then
echo '[multilib]' >> /etc/pacman.conf
echo 'Include = /etc/pacman.d/mirrorlist' >> /etc/pacman.conf
else
sed -i "${has_multilib}s/^#//" /etc/pacman.conf
local has_multilib=$((${has_multilib} + 1))
sed -i "${has_multilib}s/^#//" /etc/pacman.conf
fi
fi
}
# }}}
update_bootloader() { # {{{
# cannot run os-prober to detect other os when using arch-chroot in install script
# because grub-mkconfig fails to connect to lvmetad. You have to reboot to make it works
print_progress 'Update bootloader to detect other os (useful when dual-boot)'
install_package os-prober
if [[ ! -f /boot/grub/grub.cfg.aui ]]; then
cp -v /boot/grub/grub.cfg /boot/grub/grub.cfg.aui
os-prober
grub-mkconfig -o /boot/grub/grub.cfg
fi
}
# }}}
configure_sudo() { # {{{
print_progress 'Configure sudo'
install_package 'sudo'
if [[ ! -f /etc/sudoers.aui ]]; then
cp -v /etc/sudoers /etc/sudoers.aui
# uncomment to allow members of group wheel to execute any command
sed -i '/%wheel ALL=(ALL) ALL/s/^#//' /etc/sudoers
# This config is especially helpful for those using terminal multiplexers like screen, tmux, or ratpoison, and those using sudo from scripts/cronjobs:
echo "" >> /etc/sudoers
echo 'Defaults !requiretty, !tty_tickets, !umask' >> /etc/sudoers
echo 'Defaults visiblepw, path_info, insults, lecture=always' >> /etc/sudoers
echo 'Defaults loglinelen=0, logfile =/var/log/sudo.log, log_year, log_host, syslog=auth' >> /etc/sudoers
echo 'Defaults passwd_tries=3, passwd_timeout=1' >> /etc/sudoers
echo 'Defaults env_reset, always_set_home, set_home, set_logname' >> /etc/sudoers
echo 'Defaults !env_editor, editor="/usr/bin/nvim:/usr/bin/vi:/usr/bin/nano"' >> /etc/sudoers
echo 'Defaults timestamp_timeout=15' >> /etc/sudoers
echo 'Defaults passprompt="[sudo] password for %u: "' >> /etc/sudoers
echo 'Defaults lecture=never' >> /etc/sudoers
fi
}
# }}}
install_requirements() { # {{{
print_progress 'Install script dependencies'
setup_console_font
install_package 'git'
# install figlet to draw big ascii title
install_package 'figlet'
install_package 'vim'
# a python script to sort mirrorlist
install_package 'python reflector'
}
# }}}
create_user_account() { # {{{
print_title 'ACCOUNT'
print_info 'Create your user account'
read -p 'Username: ' USERNAME
update_option 'USERNAME'
useradd -m -g users -G wheel -s /bin/bash "$USERNAME"
passwd "$USERNAME"
enter_to_continue
}
# }}}
set_mirrorlist() { # {{{
local mirrorlist_opts
OPTION=n
while [[ "$OPTION" == n ]]; do
print_title "MIRRORLIST"
print_info 'Packages to be installed must be downloaded from mirror servers, which are defined in /etc/pacman.d/mirrorlist.'
print_info 'The higher a mirror is placed in the list, the more priority it is given when downloading a package. You may want to edit the file accordingly, and move the geographically closest mirrors to the top of the list, although other criteria should be taken into account.'
print_info 'This file will later be copied to the new system by pacstrap, so it is worth getting right.'
print_paragraph 'Here you can choose to sort the mirror list by download speed or leave it to default. Sorting the mirror list will take for a while'
mirrorlist_opts=('default' 'sort by download speed')
select opt in "${mirrorlist_opts[@]}"; do
if contains_element "${opt}" "${mirrorlist_opts[@]}"; then
MIRRORLIST="$opt"
break
else
invalid_option
fi
done
confirm_yes "Confirm mirror list option ($MIRRORLIST)"
done
}
# }}}
configure_mirrorlist() { # {{{
ask_default_option "$MIRRORLIST" set_mirrorlist
update_option 'MIRRORLIST'
print_progress 'Backing up the original mirrorlist...'
mv -i /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.orig
tmpfile=$(mktemp --suffix=-mirrorlist)
case "$MIRRORLIST" in
'default')
# Get latest mirror list and save to tmpfile
curl -so "$tmpfile" 'https://www.archlinux.org/mirrorlist/all/'
sed -i 's/^#Server/Server/g' "$tmpfile"
;;
'sort by download speed')
reflector --verbose --connection-timeout 3 --latest 200 --number 40 --sort rate --save "$tmpfile"
;;
*)
invalid_option
;;
esac
# replace current mirrorlist file (if new file is non-zero)
if [[ -s "$tmpfile" ]]; then
mv -i "$tmpfile" /etc/pacman.d/mirrorlist
# allow global read access (required for non-root yaourt execution)
chmod +r /etc/pacman.d/mirrorlist
$EDITOR /etc/pacman.d/mirrorlist
else
print_warning 'Unable to update'
fi
enter_to_continue
}
# }}}
install_aur_helper() { # {{{
print_title 'AUR HELPER'
print_info "AUR helpers automate certain tasks for using the Arch User Repository. Most helpers automate the process of retrieving a package's PKGBUILD from the AUR and building the package."
if ! has_package trizen; then
echo
print_progress 'Install trizen..'
# running makepkg as root is not allowed as it can cause permanent, catastrophic damage to your system
su --login "$USERNAME" -c '
mkdir -p /tmp/aui_packages
cd /tmp/aui_packages
curl -o PKGBUILD https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=trizen
makepkg --install --clean --syncdeps --needed --noconfirm PKGBUILD
'
else
print_warning 'trizen has already been installed'
fi
enter_to_continue
}
# }}}
set_desktop_environment() { # {{{
local desktop_envs
OPTION=n
while [[ "$OPTION" == n ]]; do
print_title 'DESKTOP ENVIRONMENT'
print_info 'A DE provide a complete GUI for a system by bundling together a variety of X clients written using a common widget toolkit and set of libraries.'
print_info "A window manager is one component of a system's graphical user interface."
desktop_envs=(KDE XFCE I3)
select opt in ${desktop_envs[@]}; do
if contains_element "${opt}" "${desktop_envs[@]}"; then
DESKTOP_ENVIRONMENT="$opt"
break
else
invalid_option
fi
done
confirm_yes "Confirm desktop environtment ($DESKTOP_ENVIRONMENT)"
done
}
# }}}
install_desktop_environment() { # {{{
ask_default_option "$DESKTOP_ENVIRONMENT" set_desktop_environment
update_option 'DESKTOP_ENVIRONMENT'
print_progress 'Installing X-Server (req. for Desktopenvironment, GPU Drivers, Keyboardlayout,...)'
install_package 'xorg xorg-xinit'
case "$DESKTOP_ENVIRONMENT" in
KDE)
install_package 'plasma-desktop' # minimum plasma DE
install_package 'sddm' # display manager
install_package 'ark' # archive
install_package 'konsole' # terminal
install_package 'dolphin' # file manager
install_package 'bluedevel' # bluetooth for KDE
install_package 'plasma-nm' # networkmanager for KDE
install_package 'plasma-pa' # puluseaudio for KDE
install_package 'kinfocenter' # see system information
install_package 'kdeconnect' # Adds communication between KDE and your smartphone
install_package 'spectacle' # screenshot utility
install_package 'kcolorchooser' # color picker on desktop screen
install_package 'plasma5-applets-redshift-control' # redshift applet for KDE
install_package 'ktorrent' # torrent app for KDE
install_package 'sddm-kcm' # sddm config gui for KDE
install_package 'arc-kde' # arc theme for KDE
install_package 'breeze-kde4' # breeze theme for KDE
install_package 'latte-dock' # dock for KDE
install_package 'okular' # pdf reader for KDE
install_package 'qalculte-gtk' # calculator
install_package 'kde-gtk-config' # configure gtk in KDE
setup_xinitrc 'startkde'
;;
XFCE)
install_package 'xfce4 xfce4-goodies xarchiver'
setup_xinitrc 'startxfce4'
;;
I3)
install_package 'nitrogen' # wallpaper app
install_package 'termite' # terminal
install_aur_package 'polybar' # a highly customizable taskbar
install_aur_package 'vtop' # a console task manager with vim-like shortcuts
install_package 'ranger' # a console file manager
install_package 'rofi' # menu to launch anything you want
install_package 'gnome-calculator' # calculator
install_package 'zathura' # pdf reader
install_aur_package 'dunstify' # notification manager, like dunst but have --replace option https://github.com/NearHuscarl/dotfiles/blob/7ae6df76ca9f87a87bf68f2a38775e0ab9a4de04/bin/volume#L82
install_package 'sxiv' # image viewer
install_package 'compton' # compositor
setup_xinitrc 'i3'
;;
esac
install_display_manager
install_theme
enter_to_continue
}
# }}}
install_display_manager() { # {{{
print_progress 'Install display manager'
install_package 'sddm'
systemctl enable sddm
sddm --example-config > /etc/sddm.conf
sed -i 's/Current=/Current=breeze/' /etc/sddm.conf
sed -i 's/CursorTheme=/CursorTheme=breeze_cursors/' /etc/sddm.conf
sed -i 's/Numlock=none/Numlock=on/' /etc/sddm.conf
}
# }}}
install_base() { # {{{
local arch_packages npm_packages pip_packages
arch_packages="$(read_packages "$PROJECT_ROOT/packages")"
npm_packages="$(read_packages "$PROJECT_ROOT/packages.npm")"
pip_packages="$(read_packages "$PROJECT_ROOT/packages.pip")"
for package in ${arch_packages[@]}; do
if is_package_available "$package"; then
install_package "$package"
else
install_aur_package "$package"
fi
done
npm_install "$npm_packages"
pip_install "$pip_packages"
if has_package networkmanager; then
local wired_device="$(wired_device)"
# disable dhcpcd used when installing live (cant have 2 managers run at the same time)
systemctl stop "dhcpcd@${wired_device}.service"
systemctl disable "dhcpcd@${wired_device}.service"
systemctl enable NetworkManager.service
fi
if has_package teamviewer; then
systemctl enable teamviewerd.service
fi
enter_to_continue
}
# }}}
set_dotfiles() { # {{{
local dotfiles_list
OPTION=n
while [[ "$OPTION" == n ]]; do
print_title 'DOTFILES'
print_progress 'Set up dotfiles...'
echo
dotfiles_list=('NearHuscarl dotfiles' 'Custom dotfiles')
select dotfiles in "${dotfiles_list[@]}"; do
if contains_element "${dotfiles}" "${dotfiles_list[@]}"; then
DOTFILES="$dotfiles"
break
else
invalid_option
fi
done
confirm_yes "Confirm dotfiles ($DOTFILES)"
done
}
# }}}
clone_dotfiles() { # {{{
local dotfile_tmp url="$1"
su --login "$USERNAME" -c "git clone --recursive $url /tmp/dotfiles-$USERNAME"
print_progress "copy dotfiles to /home/$USERNAME/"
cp -af "/tmp/dotfiles-$USERNAME/." "/home/$USERNAME/"
rm -rf "/tmp/dotfiles-$USERNAME"
}
# }}}
setup_dotfiles() { # {{{
ask_default_option "$DOTFILES" set_dotfiles
update_option 'DOTFILES'
case "$DOTFILES" in
'NearHuscarl dotfiles')
clone_dotfiles 'https://github.com/NearHuscarl/dotfiles'
if [[ -e "/home/$USERNAME/setup.sh" ]]; then
su --login "$USERNAME" -c "/home/$USERNAME/setup.sh"
else
print_warning 'dotfiles setup file not found'
fi
;;
'Custom dotfiles')
read -p 'Github Username: ' github_username
read -p 'Github Repo: ' github_repo
clone_dotfiles "https://github.com/$github_username/$github_repo"
;;
esac
enter_to_continue
}
# }}}
install_fonts() { # {{{
print_progress 'Install some nice fonts'
install_aur_package 'ttf-material-icons'
install_package 'ttf-inconsolata ttf-roboto ttf-font-awesome'
enter_to_continue
}
# }}}
install_theme() { # {{{
print_progress 'Install theme and icon for desktop environment'
# install_package 'arc-gtk-theme'
install_package 'breeze breeze-gtk'
install_package 'papirus-icon-theme'
}
# }}}
finish() { # {{{
print_title "INSTALL COMPLETED"
confirm_yes 'Reboot system'
if [[ "$OPTION" != n ]]; then
reboot
fi
exit 0
}
# }}}
install() { # {{{
local checklist
checklist=(0 0 0 0 0 0 0 0 0 0 0 0 0)
while true; do
print_title 'ARCHLINUX INSTALLER'
echo " 1. $(mainmenu_item "${checklist[0]}" 'Create user account' "$USERNAME")"
echo " 2. $(mainmenu_item "${checklist[1]}" 'Configure mirror list' "$MIRRORLIST")"
echo " 3. $(mainmenu_item "${checklist[2]}" 'Install AUR helper')"
echo " 4. $(mainmenu_item "${checklist[3]}" 'Install desktop environment' "$DESKTOP_ENVIRONMENT")"
echo " 5. $(mainmenu_item "${checklist[4]}" 'Install base')"
echo " 6. $(mainmenu_item "${checklist[5]}" 'Setup dotfiles' "$DOTFILES")"
echo " 7. $(mainmenu_item "${checklist[6]}" 'Install fonts')"
echo " 8. $(mainmenu_item "${checklist[7]}" 'Finish')"
echo
read -p "Enter option (1-13): " OPTION
case "$OPTION" in
1)
create_user_account
checklist[0]=1
;;
2)
configure_mirrorlist
checklist[1]=1
;;
3)
install_aur_helper
checklist[2]=1
;;
4)
install_desktop_environment
checklist[3]=1
;;
5)
install_base
checklist[4]=1
;;
6)
setup_dotfiles
checklist[5]=1
;;
7)
install_fonts
checklist[6]=1
;;
8)
finish
checklist[7]=1
;;
*)
invalid_option
;;
esac
done
}
# }}}
main() { # {{{
check_root
check_archlinux
check_connection
check_multilib
update_system
update_bootloader
configure_sudo
install_requirements
install
}
# }}}
main