· 9 years ago · Jul 30, 2017, 07:30 PM
1# !/bin/bash
2#
3# Arch Base Installation Framework (version 2.2.3 - 26-Mar-2016)
4#
5# Written by Carl Duff for PacBang Linux
6#
7# This program is free software, provided under the GNU General Public License
8# as published by the Free Software Foundation. So feel free to copy, distribute,
9# or modify it as you wish.
10#
11
12######################################################################
13## ##
14## Installer Variables ##
15## ##
16######################################################################
17
18# #
19# ISO Specific Variables. READ CAREFULLY FOR YOUR DISTRO #
20# #
21
22# This MUST be the same as listed in /etc/hosts
23ISO_HOST="maroto" # ISO Host Name
24
25# This MUST be the same as the live account
26ISO_USER="liveuser" # Live user account.
27
28# Call this what you like
29VERSION="Maroto Installation Framework 2.2.3" # Installer Name / Version
30
31# This should not need to be changed
32TRANS_SRC="/abif-master" # Dir where translation files are stored
33
34# #
35# Other variables for installer #
36# #
37
38# Create a temporary file to store menu selections
39ANSWER="/tmp/.abif"
40
41# Installation
42BOOTLOADER="n/a" # Which bootloader has been installed?
43KEYMAP="us" # Virtual console keymap. Default is "us"
44XKBMAP="us" # X11 keyboard layout. Default is "us"
45ZONE="" # For time
46SUBZONE="" # For time
47LOCALE="en_US.UTF-8" # System locale. Default is "en_US.UTF-8"
48
49# Architecture
50ARCHI=$(uname -m) # Display whether 32 or 64 bit system
51SYSTEM="Unknown" # Display whether system is BIOS or UEFI. Default is "unknown"
52ROOT_PART="" # ROOT partition
53UEFI_PART="" # UEFI partition
54UEFI_MOUNT="" # UEFI mountpoint
55INST_DEV="" # Device where system has been installed
56HIGHLIGHT=0 # Highlight items for Main Menu
57HIGHLIGHT_SUB=0 # Highlight items for submenus
58SUB_MENU="" # Submenu to be highlighted
59
60# Logical Volume Management
61LVM=0 # Logical Volume Management Detected?
62LVM_SEP_BOOT=0 # 1 = Seperate /boot, 2 = seperate /boot & LVM
63LVM_VG="" # Name of volume group to create or use
64LVM_VG_MB=0 # MB remaining of VG
65LVM_LV_NAME="" # Name of LV to create or use
66LV_SIZE_INVALID=0 # Is LVM LV size entered valid?
67VG_SIZE_TYPE="" # Is VG in Gigabytes or Megabytes?
68
69# LUKS
70LUKS=0 # Luks Detected?
71LUKS_DEV="" # If encrypted, partition
72LUKS_NAME="" # Name given to encrypted partition
73LUKS_UUID="" # UUID used for comparison purposes
74LUKS_OPT="" # Default or user-defined?
75
76# Installation
77MOUNTPOINT="/mnt" # Installation
78AIROOTIMG="" # Root image to install
79BYPASS="$MOUNTPOINT/bypass/" # Root image mountpoint
80BTRFS=0 # BTRFS used? "1" = btrfs alone, "2" = btrfs + subvolume(s)
81MOUNT_OPTS="/tmp/.mnt_opts" # Filesystem Mount options
82FS_OPTS="" # FS mount options available
83CHK_NUM=16 # Used for FS mount options checklist length
84
85# Language Support
86CURR_LOCALE="en_US.UTF-8" # Default Locale
87FONT="" # Set new font if necessary
88
89# Edit Files
90FILE="" # Which file is to be opened?
91
92######################################################################
93## ##
94## Core Functions ##
95## ##
96######################################################################
97
98# Add locale on-the-fly and sets source translation file for installer
99select_language() {
100
101 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " Select Language " --menu "\nLanguage / sprache / taal / sprÃ¥k / lingua / idioma / nyelv / lÃngua" 0 0 9 \
102 "1" $"English (en_**)" \
103 "2" $"Español (es_ES)" \
104 "3" $"Português [Brasil] (pt_BR)" \
105 "4" $"Português (pt_PT)" \
106 "5" $"Français (fr_FR)" \
107 "6" $"Russkiy (ru_RU)" \
108 "7" $"Italiano (it_IT)" \
109 "8" $"Nederlands (nl_NL)" \
110 "9" $"Magyar (hu_HU)" 2>${ANSWER}
111
112 case $(cat ${ANSWER}) in
113 "1") source /abif-master/english.trans
114 CURR_LOCALE="en_US.UTF-8"
115 ;;
116 "2") source /abif-master/spanish.trans
117 CURR_LOCALE="es_ES.UTF-8"
118 ;;
119 "3") source /abif-master/portuguese_brasil.trans
120 CURR_LOCALE="pt_BR.UTF-8"
121 ;;
122 "4") source /abif-master/portuguese.trans
123 CURR_LOCALE="pt_PT.UTF-8"
124 ;;
125 "5") source /abif-master/french.trans
126 CURR_LOCALE="fr_FR.UTF-8"
127 ;;
128 "6") source /abif-master/russian.trans
129 CURR_LOCALE="ru_RU.UTF-8"
130 FONT="LatKaCyrHeb-14.psfu"
131 ;;
132 "7") source /abif-master/italian.trans
133 CURR_LOCALE="it_IT.UTF-8"
134 ;;
135 "8") source /abif-master/dutch.trans
136 CURR_LOCALE="nl_NL.UTF-8"
137 ;;
138 "9") source /abif-master/hungarian.trans
139 CURR_LOCALE="hu_HU.UTF-8"
140 FONT="lat2-16.psfu"
141 ;;
142 *) exit 0
143 ;;
144 esac
145
146 # Generate the chosen locale and set the language
147 sed -i "s/#${CURR_LOCALE}/${CURR_LOCALE}/" /etc/locale.gen
148 locale-gen >/dev/null 2>&1
149 export LANG=${CURR_LOCALE}
150 [[ $FONT != "" ]] && setfont $FONT
151}
152
153
154
155# Check user is root, and that there is an active internet connection
156# Seperated the checks into seperate "if" statements for readability.
157check_requirements() {
158
159 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ChkTitle " --infobox "$_PlsWaitBody" 0 0
160 sleep 2
161
162 if [[ $(whoami) != "root" ]]; then
163 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_Erritle " --infobox "$_RtFailBody" 0 0
164 sleep 2
165 exit 1
166 fi
167
168 # The error log is also cleared, just in case something is there from a previous use of the installer.
169 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ReqMetTitle " --infobox "$_ReqMetBody" 0 0
170 sleep 2
171 clear
172 echo "" > /tmp/.errlog
173}
174
175# Adapted from AIS. Checks if system is made by Apple, whether the system is BIOS or UEFI,
176# and for LVM and/or LUKS.
177id_system() {
178
179 # Apple System Detection
180 if [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Inc.' ]] || [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Computer, Inc.' ]]; then
181 modprobe -r -q efivars || true # if MAC
182 else
183 modprobe -q efivarfs # all others
184 fi
185
186 # BIOS or UEFI Detection
187 if [[ -d "/sys/firmware/efi/" ]]; then
188 # Mount efivarfs if it is not already mounted
189 if [[ -z $(mount | grep /sys/firmware/efi/efivars) ]]; then
190 mount -t efivarfs efivarfs /sys/firmware/efi/efivars
191 fi
192 SYSTEM="UEFI"
193 else
194 SYSTEM="BIOS"
195 fi
196
197
198}
199
200
201# Adapted from AIS. An excellent bit of code!
202arch_chroot() {
203 arch-chroot $MOUNTPOINT /bin/bash -c "${1}"
204}
205
206# If there is an error, display it, clear the log and then go back to the main menu (no point in continuing).
207check_for_error() {
208
209 if [[ $? -eq 1 ]] && [[ $(cat /tmp/.errlog | grep -i "error") != "" ]]; then
210 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$(cat /tmp/.errlog)" 0 0
211 echo "" > /tmp/.errlog
212 main_menu
213 fi
214
215}
216
217# Ensure that a partition is mounted
218check_mount() {
219
220 if [[ $(lsblk -o MOUNTPOINT | grep ${MOUNTPOINT}) == "" ]]; then
221 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_ErrNoMount" 0 0
222 main_menu
223 fi
224
225}
226
227# Ensure that Arch has been installed
228check_base() {
229
230 if [[ ! -e ${MOUNTPOINT}/etc ]]; then
231 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_ErrNoBase" 0 0
232 main_menu
233 fi
234
235}
236
237# Simple code to show devices / partitions.
238show_devices() {
239 lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT | grep "disk\|part\|lvm\|crypt\|NAME\|MODEL\|TYPE\|FSTYPE\|SIZE\|MOUNTPOINT" > /tmp/.devlist
240 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_DevShowOpt " --textbox /tmp/.devlist 0 0
241}
242
243
244
245######################################################################
246## ##
247## Configuration Functions ##
248## ##
249######################################################################
250
251# virtual console keymap
252set_keymap() {
253
254 KEYMAPS=""
255 for i in $(ls -R /usr/share/kbd/keymaps | grep "map.gz" | sed 's/\.map\.gz//g' | sort); do
256 KEYMAPS="${KEYMAPS} ${i} -"
257 done
258
259 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_VCKeymapTitle " \
260 --menu "$_VCKeymapBody" 20 40 16 ${KEYMAPS} 2>${ANSWER} || prep_menu
261 KEYMAP=$(cat ${ANSWER})
262
263 echo -e "KEYMAP=${KEYMAP}\nFONT=${FONT}" > /tmp/vconsole.conf
264 }
265
266# Set keymap for X11
267 set_xkbmap() {
268
269 XKBMAP_LIST=""
270 keymaps_xkb=("af al am at az ba bd be bg br bt bw by ca cd ch cm cn cz de dk ee es et eu fi fo fr gb ge gh gn gr hr hu ie il in iq ir is it jp ke kg kh kr kz la lk lt lv ma md me mk ml mm mn mt mv ng nl no np pc ph pk pl pt ro rs ru se si sk sn sy tg th tj tm tr tw tz ua us uz vn za")
271
272 for i in ${keymaps_xkb}; do
273 XKBMAP_LIST="${XKBMAP_LIST} ${i} -"
274 done
275
276 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepKBLayout " --menu "$_XkbmapBody" 0 0 16 ${XKBMAP_LIST} 2>${ANSWER} || install_graphics_menu
277 XKBMAP=$(cat ${ANSWER} |sed 's/_.*//')
278 echo -e "Section "\"InputClass"\"\nIdentifier "\"system-keyboard"\"\nMatchIsKeyboard "\"on"\"\nOption "\"XkbLayout"\" "\"${XKBMAP}"\"\nEndSection" > /tmp/01-keyboard-layout.conf
279
280 setxkbmap $XKBMAP 2>/tmp/.errlog
281 check_for_error
282
283}
284
285# locale array generation code adapted from the Manjaro 0.8 installer
286set_locale() {
287
288 LOCALES=""
289 for i in $(cat /etc/locale.gen | grep -v "# " | sed 's/#//g' | sed 's/ UTF-8//g' | grep .UTF-8); do
290 LOCALES="${LOCALES} ${i} -"
291 done
292
293 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseSysLoc " --menu "$_localeBody" 0 0 12 ${LOCALES} 2>${ANSWER} || config_base_menu
294
295 LOCALE=$(cat ${ANSWER})
296
297 echo "LANG=\"${LOCALE}\"" > ${MOUNTPOINT}/etc/locale.conf
298 sed -i "s/#${LOCALE}/${LOCALE}/" ${MOUNTPOINT}/etc/locale.gen 2>/tmp/.errlog
299 arch_chroot "locale-gen" >/dev/null 2>>/tmp/.errlog
300 check_for_error
301}
302
303# Set Zone and Sub-Zone
304set_timezone() {
305
306 ZONE=""
307 for i in $(cat /usr/share/zoneinfo/zone.tab | awk '{print $3}' | grep "/" | sed "s/\/.*//g" | sort -ud); do
308 ZONE="$ZONE ${i} -"
309 done
310
311 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseTimeHC " --menu "$_TimeZBody" 0 0 10 ${ZONE} 2>${ANSWER} || config_base_menu
312 ZONE=$(cat ${ANSWER})
313
314 SUBZONE=""
315 for i in $(cat /usr/share/zoneinfo/zone.tab | awk '{print $3}' | grep "${ZONE}/" | sed "s/${ZONE}\///g" | sort -ud); do
316 SUBZONE="$SUBZONE ${i} -"
317 done
318
319 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseTimeHC " --menu "$_TimeSubZBody" 0 0 11 ${SUBZONE} 2>${ANSWER} || config_base_menu
320 SUBZONE=$(cat ${ANSWER})
321
322 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseTimeHC " --yesno "$_TimeZQ ${ZONE}/${SUBZONE}?" 0 0
323
324 if [[ $? -eq 0 ]]; then
325 arch_chroot "ln -sf /usr/share/zoneinfo/${ZONE}/${SUBZONE} /etc/localtime" 2>/tmp/.errlog
326 check_for_error
327 else
328 config_base_menu
329 fi
330}
331
332set_hw_clock() {
333
334 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseTimeHC " --menu "$_HwCBody" 0 0 2 \
335 "utc" "-" "localtime" "-" 2>${ANSWER}
336
337 [[ $(cat ${ANSWER}) != "" ]] && arch_chroot "hwclock --systohc --$(cat ${ANSWER})" 2>/tmp/.errlog && check_for_error
338}
339
340# Generate the installed system's FSTAB
341generate_fstab() {
342
343 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseFstab " --menu "$_FstabBody" 0 0 4 \
344 "genfstab -p" "$_FstabDevName" \
345 "genfstab -L -p" "$_FstabDevLabel" \
346 "genfstab -U -p" "$_FstabDevUUID" \
347 "genfstab -t PARTUUID -p" "$_FstabDevPtUUID" 2>${ANSWER}
348
349 if [[ $(cat ${ANSWER}) != "" ]]; then
350 if [[ $SYSTEM == "BIOS" ]] && [[ $(cat ${ANSWER}) == "genfstab -t PARTUUID -p" ]]; then
351 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_FstabErr" 0 0
352 generate_fstab
353 else
354 $(cat ${ANSWER}) ${MOUNTPOINT} > ${MOUNTPOINT}/etc/fstab 2>/tmp/.errlog
355 check_for_error
356 [[ -f ${MOUNTPOINT}/swapfile ]] && sed -i "s/\\${MOUNTPOINT}//" ${MOUNTPOINT}/etc/fstab
357 fi
358 fi
359
360 #### COMENTED ####
361 # Determine if there is a swapfile before copying over appropriate OB configs
362 #if [[ $(cat $MOUNTPOINT/etc/fstab | grep "swap") != "" ]]; then
363 #cp -f /inst/rc2.xml $MOUNTPOINT/etc/skel/.config/openbox/menu.xml 2>/tmp/.errlog
364 #cp -f /inst/rc2.xml $MOUNTPOINT/home/$ISO_USER/.config/openbox/menu.xml 2>/tmp/.errlog
365
366 #cp -f /inst/menu2.xml $MOUNTPOINT/etc/skel/.config/openbox/menu.xml 2>/tmp/.errlog
367 #cp -f /inst/menu2.xml $MOUNTPOINT/home/$ISO_USER/.config/openbox/menu.xml 2>/tmp/.errlog
368 #else
369 #cp -f /inst/rc.xml $MOUNTPOINT/etc/skel/.config/openbox/menu.xml 2>/tmp/.errlog
370 #cp -f /inst/rc.xml $MOUNTPOINT/home/$ISO_USER/.config/openbox/menu.xml 2>/tmp/.errlog
371
372 #cp -f /inst/menu.xml $MOUNTPOINT/etc/skel/.config/openbox/menu.xml 2>/tmp/.errlog
373 #cp -f /inst/menu.xml $MOUNTPOINT/home/$ISO_USER/.config/openbox/menu.xml 2>/tmp/.errlog
374 #fi
375 #check_for_error
376
377}
378
379# Set the installed system's hostname
380set_hostname() {
381
382 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseHost " --inputbox "$_HostNameBody" 0 0 "archiso" 2>${ANSWER} || config_base_menu
383
384 echo "$(cat ${ANSWER})" > ${MOUNTPOINT}/etc/hostname 2>/tmp/.errlog
385 check_for_error
386}
387
388# Set the installed system's root password
389set_root_password() {
390
391 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrRoot " --clear --insecure --passwordbox "$_PassRtBody" 0 0 2> ${ANSWER} || config_base_menu
392 PASSWD=$(cat ${ANSWER})
393
394 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrRoot " --clear --insecure --passwordbox "$_PassReEntBody" 0 0 2> ${ANSWER} || config_base_menu
395 PASSWD2=$(cat ${ANSWER})
396
397 if [[ $PASSWD == $PASSWD2 ]]; then
398 echo -e "${PASSWD}\n${PASSWD}" > /tmp/.passwd
399 arch_chroot "passwd root" < /tmp/.passwd >/dev/null 2>/tmp/.errlog
400 rm /tmp/.passwd
401 check_for_error
402 else
403 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_PassErrBody" 0 0
404 set_root_password
405 fi
406
407}
408
409# Create new user(s) for installed system. First user is created by renaming the live account.
410# All others are brand new.
411create_new_user() {
412
413 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_NUsrTitle " --inputbox "$_NUsrBody" 0 0 "" 2>${ANSWER} || config_base_menu
414 USER=$(cat ${ANSWER})
415
416 # Loop while user name is blank, has spaces, or has capital letters in it.
417 while [[ ${#USER} -eq 0 ]] || [[ $USER =~ \ |\' ]] || [[ $USER =~ [^a-z0-9\ ] ]]; do
418 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_NUsrTitle " --inputbox "$_NUsrErrBody" 0 0 "" 2>${ANSWER} || config_base_menu
419 USER=$(cat ${ANSWER})
420 done
421
422 # Enter password. This step will only be reached where the loop has been skipped or broken.
423 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrNew " --clear --insecure --passwordbox "$_PassNUsrBody $USER\n\n" 0 0 2> ${ANSWER} || config_base_menu
424 PASSWD=$(cat ${ANSWER})
425
426 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrNew " --clear --insecure --passwordbox "$_PassReEntBody" 0 0 2> ${ANSWER} || config_base_menu
427 PASSWD2=$(cat ${ANSWER})
428
429 # loop while passwords entered do not match.
430 while [[ $PASSWD != $PASSWD2 ]]; do
431 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_PassErrBody" 0 0
432
433 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrNew " --clear --insecure --passwordbox "$_PassNUsrBody $USER\n\n" 0 0 2> ${ANSWER} || config_base_menu
434 PASSWD=$(cat ${ANSWER})
435
436 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrNew " --clear --insecure --passwordbox "$_PassReEntBody" 0 0 2> ${ANSWER} || config_base_menu
437 PASSWD2=$(cat ${ANSWER})
438 done
439
440 # create new user. This step will only be reached where the password loop has been skipped or broken.
441 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfUsrNew " --infobox "$_NUsrSetBody" 0 0
442 sleep 2
443 echo -e "${PASSWD}\n${PASSWD}" > /tmp/.passwd
444
445 # If the first (or only) user account, then change the live account
446 if [[ -e ${MOUNTPOINT}/home/$ISO_USER ]]; then
447 arch_chroot "passwd $ISO_USER" < /tmp/.passwd >/dev/null 2>>/tmp/.errlog
448 check_for_error
449
450 # Distro-specific configuration for entered username
451 sed -i "s/$ISO_USER/$USER/g" ${MOUNTPOINT}/home/$ISO_USER/.gtkrc-2.0 2>/tmp/.errlog
452
453 # Convert live account to entered username - group, password, folder, and ownership
454 sed -i "s/$ISO_USER/$USER/g" ${MOUNTPOINT}/etc/group 2>>/tmp/.errlog
455 sed -i "s/$ISO_USER/$USER/g" ${MOUNTPOINT}/etc/gshadow 2>>/tmp/.errlog
456 sed -i "s/$ISO_USER/$USER/g" ${MOUNTPOINT}/etc/passwd 2>>/tmp/.errlog
457 sed -i "s/$ISO_USER/$USER/g" ${MOUNTPOINT}/etc/shadow 2>>/tmp/.errlog
458 mv ${MOUNTPOINT}/home/$ISO_USER ${MOUNTPOINT}/home/$USER 2>>/tmp/.errlog
459 chown -R $USER:users ${MOUNTPOINT}/home/$USER 2>>/tmp/.errlog
460
461 # Change sudoers file to require passwords for sudo commands
462 sed -i '/%wheel ALL=(ALL) ALL/s/^#//' ${MOUNTPOINT}/etc/sudoers 2>>/tmp/.errlog
463 sed -i '/%wheel ALL=(ALL) ALL NOPASSWD: ALL/s/#%wheel ALL=(ALL) ALL NOPASSWD: ALL//' ${MOUNTPOINT}/etc/sudoers 2>>/tmp/.errlog
464 check_for_error
465 else
466 # If the live account has already been changed, create a new user account
467 arch_chroot "useradd ${USER} -m -g users -G wheel,storage,power,network,video,audio,lp -s /bin/bash" 2>/tmp/.errlog
468 arch_chroot "passwd ${USER}" < /tmp/.passwd >/dev/null 2>>/tmp/.errlog
469
470 # Set up basic configuration files and ownership for new account
471 arch_chroot "cp -R /etc/skel/ /home/${USER}" 2>>/tmp/.errlog
472 arch_chroot "chown -R ${USER}:users /home/${USER}" 2>>/tmp/.errlog
473 check_for_error
474 fi
475 rm /tmp/.passwd
476}
477
478run_mkinitcpio() {
479
480 clear
481
482 KERNEL=""
483
484 # If LVM and/or LUKS used, add the relevant hook(s)
485 ([[ $LVM -eq 1 ]] && [[ $LUKS -eq 0 ]]) && sed -i 's/block filesystems/block lvm2 filesystems/g' ${MOUNTPOINT}/etc/mkinitcpio.conf 2>/tmp/.errlog
486 ([[ $LVM -eq 1 ]] && [[ $LUKS -eq 1 ]]) && sed -i 's/block filesystems/block encrypt lvm2 filesystems/g' ${MOUNTPOINT}/etc/mkinitcpio.conf 2>/tmp/.errlog
487 ([[ $LVM -eq 0 ]] && [[ $LUKS -eq 1 ]]) && sed -i 's/block filesystems/block encrypt filesystems/g' ${MOUNTPOINT}/etc/mkinitcpio.conf 2>/tmp/.errlog
488 check_for_error
489
490 arch_chroot "mkinitcpio -p linux" 2>>/tmp/.errlog
491 check_for_error
492
493}
494
495######################################################################
496## ##
497## System and Partitioning Functions ##
498## ##
499######################################################################
500
501
502
503# Unmount partitions.
504umount_partitions(){
505
506 MOUNTED=""
507 MOUNTED=$(mount | grep "${MOUNTPOINT}" | awk '{print $3}' | sort -r)
508 swapoff -a
509
510 for i in ${MOUNTED[@]}; do
511 umount $i >/dev/null 2>>/tmp/.errlog
512 done
513
514 check_for_error
515
516}
517
518# Revised to deal with partion sizes now being displayed to the user
519confirm_mount() {
520 if [[ $(mount | grep $1) ]]; then
521 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MntStatusTitle " --infobox "$_MntStatusSucc" 0 0
522 sleep 2
523 PARTITIONS=$(echo $PARTITIONS | sed "s~${PARTITION} [0-9]*[G-M]~~" | sed "s~${PARTITION} [0-9]*\.[0-9]*[G-M]~~" | sed s~${PARTITION}$' -'~~)
524 NUMBER_PARTITIONS=$(( NUMBER_PARTITIONS - 1 ))
525 else
526 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MntStatusTitle " --infobox "$_MntStatusFail" 0 0
527 sleep 2
528 prep_menu
529 fi
530}
531
532# This function does not assume that the formatted device is the Root installation device as
533# more than one device may be formatted. Root is set in the mount_partitions function.
534select_device() {
535
536 DEVICE=""
537 devices_list=$(lsblk -lno NAME,SIZE,TYPE | grep 'disk' | awk '{print "/dev/" $1 " " $2}' | sort -u);
538
539 for i in ${devices_list[@]}; do
540 DEVICE="${DEVICE} ${i}"
541 done
542
543 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_DevSelTitle " --menu "$_DevSelBody" 0 0 4 ${DEVICE} 2>${ANSWER} || prep_menu
544 DEVICE=$(cat ${ANSWER})
545
546 }
547
548# Finds all available partitions according to type(s) specified and generates a list
549# of them. This also includes partitions on different devices.
550find_partitions() {
551
552 PARTITIONS=""
553 NUMBER_PARTITIONS=0
554 partition_list=$(lsblk -lno NAME,SIZE,TYPE | grep $INCLUDE_PART | sed 's/part$/\/dev\//g' | sed 's/lvm$\|crypt$/\/dev\/mapper\//g' | awk '{print $3$1 " " $2}' | sort -u)
555
556 for i in ${partition_list}; do
557 PARTITIONS="${PARTITIONS} ${i}"
558 NUMBER_PARTITIONS=$(( NUMBER_PARTITIONS + 1 ))
559 done
560
561 # Double-partitions will be counted due to counting sizes, so fix
562 NUMBER_PARTITIONS=$(( NUMBER_PARTITIONS / 2 ))
563
564 # Deal with partitioning schemes appropriate to mounting, lvm, and/or luks.
565 case $INCLUDE_PART in
566 'part\|lvm\|crypt') # Deal with incorrect partitioning for main mounting function
567
568 if ([[ $SYSTEM == "UEFI" ]] && [[ $NUMBER_PARTITIONS -lt 2 ]]) || ([[ $SYSTEM == "BIOS" ]] && [[ $NUMBER_PARTITIONS -eq 0 ]]); then
569 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_PartErrBody" 0 0
570 create_partitions
571 fi
572 ;;
573 'part\|crypt') # Ensure there is at least one partition for LVM
574 if [[ $NUMBER_PARTITIONS -eq 0 ]]; then
575 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_LvmPartErrBody" 0 0
576 create_partitions
577 fi
578 ;;
579 'part\|lvm') # Ensure there are at least two partitions for LUKS
580 if [[ $NUMBER_PARTITIONS -lt 2 ]]; then
581 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_LuksPartErrBody" 0 0
582 create_partitions
583 fi
584 ;;
585 esac
586
587}
588
589
590# Create partitions.
591create_partitions(){
592
593# Securely destroy all data on a given device.
594secure_wipe(){
595
596 # Warn the user. If they proceed, wipe the selected device.
597 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PartOptWipe " --yesno "$_AutoPartWipeBody1 ${DEVICE} $_AutoPartWipeBody2" 0 0
598 if [[ $? -eq 0 ]]; then
599
600 clear
601 wipe -Ifre ${DEVICE}
602
603 # Alternate dd command - requires pv to be installed
604 #dd if=/dev/zero | pv | dd of=${DEVICE} iflag=nocache oflag=direct bs=4096 2>/tmp/.errlog
605 else
606 create_partitions
607 fi
608}
609
610
611# BIOS and UEFI
612auto_partition(){
613
614 # Provide warning to user
615 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepPartDisk " --yesno "$_AutoPartBody1 $DEVICE $_AutoPartBody2 $_AutoPartBody3" 0 0
616
617 if [[ $? -eq 0 ]]; then
618
619 # Find existing partitions (if any) to remove
620 parted -s ${DEVICE} print | awk '/^ / {print $1}' > /tmp/.del_parts
621
622 for del_part in $(tac /tmp/.del_parts); do
623 parted -s ${DEVICE} rm ${del_part} 2>/tmp/.errlog
624 check_for_error
625 done
626
627 # Identify the partition table
628 part_table=$(parted -s ${DEVICE} print | grep -i 'partition table' | awk '{print $3}')
629
630 # Create partition table if one does not already exist
631 ([[ $SYSTEM == "BIOS" ]] && [[ $part_table != "msdos" ]]) && parted -s ${DEVICE} mklabel msdos 2>/tmp/.errlog
632 ([[ $SYSTEM == "UEFI" ]] && [[ $part_table != "gpt" ]]) && parted -s ${DEVICE} mklabel gpt 2>/tmp/.errlog
633 check_for_error
634
635 # Create paritions (same basic partitioning scheme for BIOS and UEFI)
636 if [[ $SYSTEM == "BIOS" ]]; then
637 parted -s ${DEVICE} mkpart primary ext3 1MiB 513MiB 2>/tmp/.errlog
638 else
639 parted -s ${DEVICE} mkpart ESP fat32 1MiB 513MiB 2>/tmp/.errlog
640 fi
641
642 parted -s ${DEVICE} set 1 boot on 2>>/tmp/.errlog
643 parted -s ${DEVICE} mkpart primary ext3 513MiB 100% 2>>/tmp/.errlog
644 check_for_error
645
646 # Show created partitions
647 lsblk ${DEVICE} -o NAME,TYPE,FSTYPE,SIZE > /tmp/.devlist
648 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "" --textbox /tmp/.devlist 0 0
649 else
650 create_partitions
651 fi
652
653}
654
655 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_PartToolTitle" --menu "$_PartToolBody" 0 0 5 \
656 "$_PartOptWipe" "BIOS & UEFI" \
657 "$_PartOptAuto" "BIOS & UEFI" \
658 "gparted" "BIOS & UEFI" \
659 "cfdisk" "BIOS/MBR" \
660 "parted" "UEFI/GPT" 2>${ANSWER}
661
662 clear
663 # If something selected
664 if [[ $(cat ${ANSWER}) != "" ]]; then
665 if ([[ $(cat ${ANSWER}) != "$_PartOptWipe" ]] && [[ $(cat ${ANSWER}) != "$_PartOptAuto" ]]); then
666 $(cat ${ANSWER}) ${DEVICE}
667 else
668 [[ $(cat ${ANSWER}) == "$_PartOptWipe" ]] && secure_wipe && create_partitions
669 [[ $(cat ${ANSWER}) == "$_PartOptAuto" ]] && auto_partition
670 fi
671 fi
672
673}
674
675
676# Set static list of filesystems rather than on-the-fly. Partially as most require additional flags, and
677# partially because some don't seem to be viable.
678# Set static list of filesystems rather than on-the-fly.
679select_filesystem(){
680
681 # prep variables
682 fs_opts=""
683 CHK_NUM=0
684
685 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_FSTitle " --menu "$_FSBody" 0 0 12 \
686 "$_FSSkip" "-" \
687 "btrfs" "mkfs.btrfs -f" \
688 "ext2" "mkfs.ext2 -q" \
689 "ext3" "mkfs.ext3 -q" \
690 "ext4" "mkfs.ext4 -q" \
691 "f2fs" "mkfs.f2fs" \
692 "jfs" "mkfs.jfs -q" \
693 "nilfs2" "mkfs.nilfs2 -q" \
694 "ntfs" "mkfs.ntfs -q" \
695 "reiserfs" "mkfs.reiserfs -q" \
696 "vfat" "mkfs.vfat -F32" \
697 "xfs" "mkfs.xfs -f" 2>${ANSWER}
698
699 case $(cat ${ANSWER}) in
700 "$_FSSkip") FILESYSTEM="$_FSSkip" ;;
701 "btrfs") FILESYSTEM="mkfs.btrfs -f"
702 CHK_NUM=16
703 fs_opts="autodefrag compress=zlib compress=lzo compress=no compress-force=zlib compress-force=lzo discard noacl noatime nodatasum nospace_cache recovery skip_balance space_cache ssd ssd_spread"
704 modprobe btrfs
705 ;;
706 "ext2") FILESYSTEM="mkfs.ext2 -q" ;;
707 "ext3") FILESYSTEM="mkfs.ext3 -q" ;;
708 "ext4") FILESYSTEM="mkfs.ext4 -q"
709 CHK_NUM=8
710 fs_opts="data=journal data=writeback dealloc discard noacl noatime nobarrier nodelalloc"
711 ;;
712 "f2fs") FILESYSTEM="mkfs.f2fs"
713 fs_opts="data_flush disable_roll_forward disable_ext_identify discard fastboot flush_merge inline_xattr inline_data inline_dentry no_heap noacl nobarrier noextent_cache noinline_data norecovery"
714 CHK_NUM=16
715 modprobe f2fs
716 ;;
717 "jfs") FILESYSTEM="mkfs.jfs -q"
718 CHK_NUM=4
719 fs_opts="discard errors=continue errors=panic nointegrity"
720 ;;
721 "nilfs2") FILESYSTEM="mkfs.nilfs2 -q"
722 CHK_NUM=7
723 fs_opts="discard nobarrier errors=continue errors=panic order=relaxed order=strict norecovery"
724 ;;
725 "ntfs") FILESYSTEM="mkfs.ntfs -q" ;;
726 "reiserfs") FILESYSTEM="mkfs.reiserfs -q"
727 CHK_NUM=5
728 fs_opts="acl nolog notail replayonly user_xattr"
729 ;;
730 "vfat") FILESYSTEM="mkfs.vfat -F32" ;;
731 "xfs") FILESYSTEM="mkfs.xfs -f"
732 CHK_NUM=9
733 fs_opts="discard filestreams ikeep largeio noalign nobarrier norecovery noquota wsync"
734 ;;
735 *) prep_menu ;;
736 esac
737
738 # Warn about formatting!
739 if [[ $FILESYSTEM != $_FSSkip ]]; then
740 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_FSTitle " --yesno "\n$FILESYSTEM $PARTITION\n\n" 0 0
741 if [[ $? -eq 0 ]]; then
742 ${FILESYSTEM} ${PARTITION} >/dev/null 2>/tmp/.errlog
743 check_for_error
744 else
745 select_filesystem
746 fi
747 fi
748
749
750 }
751
752mount_partitions() {
753
754# This subfunction allows for special mounting options to be applied for relevant fs's.
755# Seperate subfunction for neatness.
756mount_opts() {
757
758 FS_OPTS=""
759 echo "" > ${MOUNT_OPTS}
760
761 for i in ${fs_opts}; do
762 FS_OPTS="${FS_OPTS} ${i} - off"
763 done
764
765 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $(echo $FILESYSTEM | sed "s/.*\.//g" | sed "s/-.*//g") " --checklist "$_btrfsMntBody" 0 0 $CHK_NUM \
766 $FS_OPTS 2>${MOUNT_OPTS}
767
768 # Now clean up the file
769 sed -i 's/ /,/g' ${MOUNT_OPTS}
770 sed -i '$s/,$//' ${MOUNT_OPTS}
771
772 # If mount options selected, confirm choice
773 if [[ $(cat ${MOUNT_OPTS}) != "" ]]; then
774 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MntStatusTitle " --yesno "\n${_btrfsMntConfBody}$(cat ${MOUNT_OPTS})\n" 10 75
775 [[ $? -eq 1 ]] && mount_opts
776 fi
777
778}
779
780# Subfunction to save repetition of code
781mount_current_partition(){
782
783 # Make the mount directory
784 mkdir -p ${MOUNTPOINT}${MOUNT} 2>/tmp/.errlog
785
786 # Get mounting options for appropriate filesystems
787 [[ $fs_opts != "" ]] && mount_opts
788
789 # Use special mounting options if selected, else standard mount
790 if [[ $(cat ${MOUNT_OPTS}) != "" ]]; then
791 mount -o $(cat ${MOUNT_OPTS}) ${PARTITION} ${MOUNTPOINT}${MOUNT} 2>>/tmp/.errlog
792 else
793 mount ${PARTITION} ${MOUNTPOINT}${MOUNT} 2>>/tmp/.errlog
794 fi
795
796 check_for_error
797 confirm_mount ${MOUNTPOINT}${MOUNT}
798
799 # Identify if mounted partition is type "crypt" (LUKS on LVM, or LUKS alone)
800 if [[ $(lsblk -lno TYPE ${PARTITION} | grep "crypt") != "" ]]; then
801
802 # cryptname for bootloader configuration either way
803 LUKS=1
804 LUKS_NAME=$(echo ${PARTITION} | sed "s~^/dev/mapper/~~g")
805
806 # Check if LUKS on LVM (parent = lvm /dev/mapper/...)
807 cryptparts=$(lsblk -lno NAME,FSTYPE,TYPE | grep "lvm" | grep -i "crypto_luks" | uniq | awk '{print "/dev/mapper/"$1}')
808 for i in ${cryptparts}; do
809 if [[ $(lsblk -lno NAME ${i} | grep $LUKS_NAME) != "" ]]; then
810 LUKS_DEV="$LUKS_DEV cryptdevice=${i}:$LUKS_NAME"
811 LVM=1
812 break;
813 fi
814 done
815
816 # Check if LUKS alone (parent = part /dev/...)
817 cryptparts=$(lsblk -lno NAME,FSTYPE,TYPE | grep "part" | grep -i "crypto_luks" | uniq | awk '{print "/dev/"$1}')
818 for i in ${cryptparts}; do
819 if [[ $(lsblk -lno NAME ${i} | grep $LUKS_NAME) != "" ]]; then
820 LUKS_UUID=$(lsblk -lno UUID,TYPE,FSTYPE ${i} | grep "part" | grep -i "crypto_luks" | awk '{print $1}')
821 LUKS_DEV="$LUKS_DEV cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME"
822 break;
823 fi
824 done
825
826 # If LVM logical volume....
827 elif [[ $(lsblk -lno TYPE ${PARTITION} | grep "lvm") != "" ]]; then
828 LVM=1
829
830 # First get crypt name (code above would get lv name)
831 cryptparts=$(lsblk -lno NAME,TYPE,FSTYPE | grep "crypt" | grep -i "lvm2_member" | uniq | awk '{print "/dev/mapper/"$1}')
832 for i in ${cryptparts}; do
833 if [[ $(lsblk -lno NAME ${i} | grep $(echo $PARTITION | sed "s~^/dev/mapper/~~g")) != "" ]]; then
834 LUKS_NAME=$(echo ${i} | sed s~/dev/mapper/~~g)
835 break;
836 fi
837 done
838
839 # Now get the device (/dev/...) for the crypt name
840 cryptparts=$(lsblk -lno NAME,FSTYPE,TYPE | grep "part" | grep -i "crypto_luks" | uniq | awk '{print "/dev/"$1}')
841 for i in ${cryptparts}; do
842 if [[ $(lsblk -lno NAME ${i} | grep $LUKS_NAME) != "" ]]; then
843 # Create UUID for comparison
844 LUKS_UUID=$(lsblk -lno UUID,TYPE,FSTYPE ${i} | grep "part" | grep -i "crypto_luks" | awk '{print $1}')
845
846 # Check if not already added as a LUKS DEVICE (i.e. multiple LVs on one crypt). If not, add.
847 if [[ $(echo $LUKS_DEV | grep $LUKS_UUID) == "" ]]; then
848 LUKS_DEV="$LUKS_DEV cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME"
849 LUKS=1
850 fi
851
852 break;
853 fi
854 done
855 fi
856
857
858}
859
860# Seperate function due to ability to cancel
861make_swap(){
862
863 # Ask user to select partition or create swapfile
864 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepMntPart " --menu "$_SelSwpBody" 0 0 7 "$_SelSwpNone" $"-" "$_SelSwpFile" $"-" ${PARTITIONS} 2>${ANSWER} || prep_menu
865
866 if [[ $(cat ${ANSWER}) != "$_SelSwpNone" ]]; then
867 PARTITION=$(cat ${ANSWER})
868
869 if [[ $PARTITION == "$_SelSwpFile" ]]; then
870 total_memory=$(grep MemTotal /proc/meminfo | awk '{print $2/1024}' | sed 's/\..*//')
871 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SelSwpFile " --inputbox "\nM = MB, G = GB\n" 9 30 "${total_memory}M" 2>${ANSWER} || make_swap
872 m_or_g=$(cat ${ANSWER})
873
874 while [[ $(echo ${m_or_g: -1} | grep "M\|G") == "" ]]; do
875 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SelSwpFile " --msgbox "\n$_SelSwpFile $_ErrTitle: M = MB, G = GB\n\n" 0 0
876 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SelSwpFile " --inputbox "\nM = MB, G = GB\n" 9 30 "${total_memory}M" 2>${ANSWER} || make_swap
877 m_or_g=$(cat ${ANSWER})
878 done
879
880 fallocate -l ${m_or_g} ${MOUNTPOINT}/swapfile 2>/tmp/.errlog
881 chmod 600 ${MOUNTPOINT}/swapfile 2>>/tmp/.errlog
882 mkswap ${MOUNTPOINT}/swapfile 2>>/tmp/.errlog
883 swapon ${MOUNTPOINT}/swapfile 2>>/tmp/.errlog
884 check_for_error
885
886 else # Swap Partition
887 # Warn user if creating a new swap
888 if [[ $(lsblk -o FSTYPE ${PARTITION} | grep -i "swap") != "swap" ]]; then
889 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepMntPart " --yesno "\nmkswap ${PARTITION}\n\n" 0 0
890 [[ $? -eq 0 ]] && mkswap ${PARTITION} >/dev/null 2>/tmp/.errlog || mount_partitions
891 fi
892 # Whether existing to newly created, activate swap
893 swapon ${PARTITION} >/dev/null 2>>/tmp/.errlog
894 check_for_error
895 # Since a partition was used, remove that partition from the list
896 PARTITIONS=$(echo $PARTITIONS | sed "s~${PARTITION} [0-9]*[G-M]~~" | sed "s~${PARTITION} [0-9]*\.[0-9]*[G-M]~~" | sed s~${PARTITION}$' -'~~)
897 NUMBER_PARTITIONS=$(( NUMBER_PARTITIONS - 1 ))
898 fi
899 fi
900
901}
902 #### ####
903 #### MOUNTING FUNCTION BEGINS HERE ####
904 #### ####
905
906 # prep variables
907 MOUNT=""
908 LUKS_NAME=""
909 LUKS_DEV=""
910 LUKS_UUID=""
911 LUKS=0
912 LVM=0
913
914 # Warn users that they CAN mount partitions without formatting them!
915 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepMntPart " --msgbox "$_WarnMount1 '$_FSSkip' $_WarnMount2" 0 0
916
917 # LVM Detection. If detected, activate.
918 lvm_detect
919
920 # Ensure partitions are unmounted (i.e. where mounted previously), and then list available partitions
921 INCLUDE_PART='part\|lvm\|crypt'
922 umount_partitions
923 find_partitions
924
925 # Identify and mount root
926 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepMntPart " --menu "$_SelRootBody" 0 0 7 ${PARTITIONS} 2>${ANSWER} || prep_menu
927 PARTITION=$(cat ${ANSWER})
928 ROOT_PART=${PARTITION}
929
930 # Format with FS (or skip)
931 select_filesystem
932
933 # Make the directory and mount. Also identify LUKS and/or LVM
934 mount_current_partition
935
936 # Identify and create swap, if applicable
937 make_swap
938
939 # Extra Step for VFAT UEFI Partition. This cannot be in an LVM container.
940 if [[ $SYSTEM == "UEFI" ]]; then
941
942 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepMntPart " --menu "$_SelUefiBody" 0 0 7 ${PARTITIONS} 2>${ANSWER} || prep_menu
943 PARTITION=$(cat ${ANSWER})
944 UEFI_PART=${PARTITION}
945
946 # If it is already a fat/vfat partition...
947 if [[ $(fsck -N $PARTITION | grep fat) ]]; then
948 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepMntPart " --yesno "$_FormUefiBody $PARTITION $_FormUefiBody2" 0 0 && mkfs.vfat -F32 ${PARTITION} >/dev/null 2>/tmp/.errlog
949 else
950 mkfs.vfat -F32 ${PARTITION} >/dev/null 2>/tmp/.errlog
951 fi
952 check_for_error
953
954 # Inform users of the mountpoint options and consequences
955 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepMntPart " --menu "$_MntUefiBody" 0 0 2 \
956 "/boot" "systemd-boot"\
957 "/boot/efi" "-" 2>${ANSWER}
958
959 [[ $(cat ${ANSWER}) != "" ]] && UEFI_MOUNT=$(cat ${ANSWER}) || prep_menu
960
961 mkdir -p ${MOUNTPOINT}${UEFI_MOUNT} 2>/tmp/.errlog
962 mount ${PARTITION} ${MOUNTPOINT}${UEFI_MOUNT} 2>>/tmp/.errlog
963 check_for_error
964 confirm_mount ${MOUNTPOINT}${UEFI_MOUNT}
965 fi
966
967 # All other partitions
968 while [[ $NUMBER_PARTITIONS > 0 ]]; do
969 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepMntPart " --menu "$_ExtPartBody" 0 0 7 "$_Done" $"-" ${PARTITIONS} 2>${ANSWER} || prep_menu
970 PARTITION=$(cat ${ANSWER})
971
972 if [[ $PARTITION == $_Done ]]; then
973 break;
974 else
975 MOUNT=""
976 select_filesystem
977
978 # Ask user for mountpoint. Don't give /boot as an example for UEFI systems!
979 [[ $SYSTEM == "UEFI" ]] && MNT_EXAMPLES="/home\n/var" || MNT_EXAMPLES="/boot\n/home\n/var"
980 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepMntPart $PARTITON " --inputbox "$_ExtPartBody1$MNT_EXAMPLES\n" 0 0 "/" 2>${ANSWER} || prep_menu
981 MOUNT=$(cat ${ANSWER})
982
983 # loop while the mountpoint specified is incorrect (is only '/', is blank, or has spaces).
984 while [[ ${MOUNT:0:1} != "/" ]] || [[ ${#MOUNT} -le 1 ]] || [[ $MOUNT =~ \ |\' ]]; do
985 # Warn user about naming convention
986 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_ExtErrBody" 0 0
987 # Ask user for mountpoint again
988 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepMntPart $PARTITON " --inputbox "$_ExtPartBody1$MNT_EXAMPLES\n" 0 0 "/" 2>${ANSWER} || prep_menu
989 MOUNT=$(cat ${ANSWER})
990 done
991
992 # Create directory and mount.
993 mount_current_partition
994
995 # Determine if a seperate /boot is used. 0 = no seperate boot, 1 = seperate non-lvm boot,
996 # 2 = seperate lvm boot. For Grub configuration
997 if [[ $MOUNT == "/boot" ]]; then
998 [[ $(lsblk -lno TYPE ${PARTITION} | grep "lvm") != "" ]] && LVM_SEP_BOOT=2 || LVM_SEP_BOOT=1
999 fi
1000
1001 fi
1002 done
1003}
1004
1005######################################################################
1006## ##
1007## Encryption (dm_crypt) Functions ##
1008## ##
1009######################################################################
1010
1011# Had to write it in this way due to (bash?) bug(?), as if/then statements in a single
1012# "create LUKS" function for default and "advanced" modes were interpreted as commands,
1013# not mere string statements. Not happy with it, but it works...
1014
1015# Save repetition of code.
1016luks_password(){
1017
1018 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepLUKS " --clear --insecure --passwordbox "$_LuksPassBody" 0 0 2> ${ANSWER} || prep_menu
1019 PASSWD=$(cat ${ANSWER})
1020
1021 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepLUKS " --clear --insecure --passwordbox "$_PassReEntBody" 0 0 2> ${ANSWER} || prep_menu
1022 PASSWD2=$(cat ${ANSWER})
1023
1024 if [[ $PASSWD != $PASSWD2 ]]; then
1025 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_PassErrBody" 0 0
1026 luks_password
1027 fi
1028
1029}
1030
1031luks_open(){
1032
1033 LUKS_ROOT_NAME=""
1034 INCLUDE_PART='part\|crypt\|lvm'
1035 umount_partitions
1036 find_partitions
1037
1038 # Select encrypted partition to open
1039 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LuksOpen " --menu "$_LuksMenuBody" 0 0 7 ${PARTITIONS} 2>${ANSWER} || luks_menu
1040 PARTITION=$(cat ${ANSWER})
1041
1042 # Enter name of the Luks partition and get password to open it
1043 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LuksOpen " --inputbox "$_LuksOpenBody" 10 50 "cryptroot" 2>${ANSWER} || luks_menu
1044 LUKS_ROOT_NAME=$(cat ${ANSWER})
1045 luks_password
1046
1047 # Try to open the luks partition with the credentials given. If successful show this, otherwise
1048 # show the error
1049 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LuksOpen " --infobox "$_PlsWaitBody" 0 0
1050 echo $PASSWD | cryptsetup open --type luks ${PARTITION} ${LUKS_ROOT_NAME} 2>/tmp/.errlog
1051 check_for_error
1052
1053 lsblk -o NAME,TYPE,FSTYPE,SIZE,MOUNTPOINT ${PARTITION} | grep "crypt\|NAME\|MODEL\|TYPE\|FSTYPE\|SIZE" > /tmp/.devlist
1054 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_DevShowOpt " --textbox /tmp/.devlist 0 0
1055
1056 luks_menu
1057}
1058
1059luks_setup(){
1060
1061 modprobe -a dm-mod dm_crypt
1062 INCLUDE_PART='part\|lvm'
1063 umount_partitions
1064 find_partitions
1065
1066 # Select partition to encrypt
1067 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LuksEncrypt " --menu "$_LuksCreateBody" 0 0 7 ${PARTITIONS} 2>${ANSWER} || luks_menu
1068 PARTITION=$(cat ${ANSWER})
1069
1070 # Enter name of the Luks partition and get password to create it
1071 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LuksEncrypt " --inputbox "$_LuksOpenBody" 10 50 "cryptroot" 2>${ANSWER} || luks_menu
1072 LUKS_ROOT_NAME=$(cat ${ANSWER})
1073 luks_password
1074}
1075
1076luks_default() {
1077
1078 # Encrypt selected partition or LV with credentials given
1079 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LuksEncrypt " --infobox "$_PlsWaitBody" 0 0
1080 sleep 2
1081 echo $PASSWD | cryptsetup -q luksFormat ${PARTITION} 2>/tmp/.errlog
1082
1083 # Now open the encrypted partition or LV
1084 echo $PASSWD | cryptsetup open ${PARTITION} ${LUKS_ROOT_NAME} 2>/tmp/.errlog
1085 check_for_error
1086
1087}
1088
1089luks_key_define() {
1090 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepLUKS " --inputbox "$_LuksCipherKey" 0 0 "-s 512 -c aes-xts-plain64" 2>${ANSWER} || luks_menu
1091
1092 # Encrypt selected partition or LV with credentials given
1093 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LuksEncryptAdv " --infobox "$_PlsWaitBody" 0 0
1094 sleep 2
1095
1096 echo $PASSWD | cryptsetup -q $(cat ${ANSWER}) luksFormat ${PARTITION} 2>/tmp/.errlog
1097 check_for_error
1098
1099 # Now open the encrypted partition or LV
1100 echo $PASSWD | cryptsetup open ${PARTITION} ${LUKS_ROOT_NAME} 2>/tmp/.errlog
1101 check_for_error
1102
1103}
1104
1105luks_show(){
1106
1107 echo -e ${_LuksEncruptSucc} > /tmp/.devlist
1108 lsblk -o NAME,TYPE,FSTYPE,SIZE ${PARTITION} | grep "part\|crypt\|NAME\|TYPE\|FSTYPE\|SIZE" >> /tmp/.devlist
1109 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LuksEncrypt " --textbox /tmp/.devlist 0 0
1110
1111 luks_menu
1112}
1113
1114luks_menu() {
1115
1116 LUKS_OPT=""
1117
1118 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepLUKS " --menu "$_LuksMenuBody$_LuksMenuBody2$_LuksMenuBody3" 0 0 4 \
1119 "$_LuksOpen" "cryptsetup open --type luks" \
1120 "$_LuksEncrypt" "cryptsetup -q luksFormat" \
1121 "$_LuksEncryptAdv" "cryptsetup -q -s -c luksFormat" \
1122 "$_Back" "-" 2>${ANSWER}
1123
1124 case $(cat ${ANSWER}) in
1125 "$_LuksOpen") luks_open ;;
1126 "$_LuksEncrypt") luks_setup
1127 luks_default
1128 luks_show ;;
1129 "$_LuksEncryptAdv") luks_setup
1130 luks_key_define
1131 luks_show ;;
1132 *) prep_menu ;;
1133 esac
1134
1135 luks_menu
1136
1137}
1138
1139
1140######################################################################
1141## ##
1142## Logical Volume Management Functions ##
1143## ##
1144######################################################################
1145
1146# LVM Detection.
1147lvm_detect() {
1148
1149 LVM_PV=$(pvs -o pv_name --noheading 2>/dev/null)
1150 LVM_VG=$(vgs -o vg_name --noheading 2>/dev/null)
1151 LVM_LV=$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)
1152
1153 if [[ $LVM_LV != "" ]] && [[ $LVM_VG != "" ]] && [[ $LVM_PV != "" ]]; then
1154 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepLVM " --infobox "$_LvmDetBody" 0 0
1155 modprobe dm-mod 2>/tmp/.errlog
1156 check_for_error
1157 vgscan >/dev/null 2>&1
1158 vgchange -ay >/dev/null 2>&1
1159 fi
1160}
1161
1162lvm_show_vg(){
1163
1164 VG_LIST=""
1165 vg_list=$(lvs --noheadings | awk '{print $2}' | uniq)
1166
1167 for i in ${vg_list}; do
1168 VG_LIST="${VG_LIST} ${i} $(vgdisplay ${i} | grep -i "vg size" | awk '{print $3$4}')"
1169 done
1170
1171 # If no VGs, no point in continuing
1172 if [[ $VG_LIST == "" ]]; then
1173 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_LvmVGErr" 0 0
1174 lvm_menu
1175 fi
1176
1177 # Select VG
1178 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepLVM " --menu "$_LvmSelVGBody" 0 0 5 \
1179 ${VG_LIST} 2>${ANSWER} || lvm_menu
1180}
1181
1182# Create Volume Group and Logical Volumes
1183lvm_create() {
1184
1185# subroutine to save a lot of repetition.
1186check_lv_size() {
1187
1188 LV_SIZE_INVALID=0
1189 chars=0
1190
1191 # Check to see if anything was actually entered and if first character is '0'
1192 ([[ ${#LVM_LV_SIZE} -eq 0 ]] || [[ ${LVM_LV_SIZE:0:1} -eq "0" ]]) && LV_SIZE_INVALID=1
1193
1194 # If not invalid so far, check for non numberic characters other than the last character
1195 if [[ $LV_SIZE_INVALID -eq 0 ]]; then
1196 while [[ $chars -lt $(( ${#LVM_LV_SIZE} - 1 )) ]]; do
1197 [[ ${LVM_LV_SIZE:chars:1} != [0-9] ]] && LV_SIZE_INVALID=1 && break;
1198 chars=$(( chars + 1 ))
1199 done
1200 fi
1201
1202 # If not invalid so far, check that last character is a M/m or G/g
1203 if [[ $LV_SIZE_INVALID -eq 0 ]]; then
1204 LV_SIZE_TYPE=$(echo ${LVM_LV_SIZE:$(( ${#LVM_LV_SIZE} - 1 )):1})
1205
1206 case $LV_SIZE_TYPE in
1207 "m"|"M"|"g"|"G") LV_SIZE_INVALID=0 ;;
1208 *) LV_SIZE_INVALID=1 ;;
1209 esac
1210
1211 fi
1212
1213 # If not invalid so far, check whether the value is greater than or equal to the LV remaining Size.
1214 # If not, convert into MB for VG space remaining.
1215 if [[ ${LV_SIZE_INVALID} -eq 0 ]]; then
1216
1217 case ${LV_SIZE_TYPE} in
1218 "G"|"g") if [[ $(( $(echo ${LVM_LV_SIZE:0:$(( ${#LVM_LV_SIZE} - 1 ))}) * 1000 )) -ge ${LVM_VG_MB} ]]; then
1219 LV_SIZE_INVALID=1
1220 else
1221 LVM_VG_MB=$(( LVM_VG_MB - $(( $(echo ${LVM_LV_SIZE:0:$(( ${#LVM_LV_SIZE} - 1 ))}) * 1000 )) ))
1222 fi
1223 ;;
1224 "M"|"m") if [[ $(echo ${LVM_LV_SIZE:0:$(( ${#LVM_LV_SIZE} - 1 ))}) -ge ${LVM_VG_MB} ]]; then
1225 LV_SIZE_INVALID=1
1226 else
1227 LVM_VG_MB=$(( LVM_VG_MB - $(echo ${LVM_LV_SIZE:0:$(( ${#LVM_LV_SIZE} - 1 ))}) ))
1228 fi
1229 ;;
1230 *) LV_SIZE_INVALID=1
1231 ;;
1232 esac
1233
1234 fi
1235
1236}
1237
1238 # #
1239 # LVM Create Starts Here #
1240 # #
1241
1242 # Prep Variables
1243 LVM_VG=""
1244 VG_PARTS=""
1245 LVM_VG_MB=0
1246
1247 # Find LVM appropriate partitions.
1248 INCLUDE_PART='part\|crypt'
1249 umount_partitions
1250 find_partitions
1251 # Amend partition(s) found for use in check list
1252 PARTITIONS=$(echo $PARTITIONS | sed 's/M\|G\|T/& off/g')
1253
1254 # Name the Volume Group
1255 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG " --inputbox "$_LvmNameVgBody" 0 0 "" 2>${ANSWER} || prep_menu
1256 LVM_VG=$(cat ${ANSWER})
1257
1258 # Loop while the Volume Group name starts with a "/", is blank, has spaces, or is already being used
1259 while [[ ${LVM_VG:0:1} == "/" ]] || [[ ${#LVM_VG} -eq 0 ]] || [[ $LVM_VG =~ \ |\' ]] || [[ $(lsblk | grep ${LVM_VG}) != "" ]]; do
1260 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ErrTitle" --msgbox "$_LvmNameVgErr" 0 0
1261
1262 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG " --inputbox "$_LvmNameVgBody" 0 0 "" 2>${ANSWER} || prep_menu
1263 LVM_VG=$(cat ${ANSWER})
1264 done
1265
1266 # Select the partition(s) for the Volume Group
1267 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG " --checklist "$_LvmPvSelBody $_UseSpaceBar" 0 0 7 ${PARTITIONS} 2>${ANSWER} || prep_menu
1268 [[ $(cat ${ANSWER}) != "" ]] && VG_PARTS=$(cat ${ANSWER}) || prep_menu
1269
1270 # Once all the partitions have been selected, show user. On confirmation, use it/them in 'vgcreate' command.
1271 # Also determine the size of the VG, to use for creating LVs for it.
1272 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG " --yesno "$_LvmPvConfBody1${LVM_VG} $_LvmPvConfBody2${VG_PARTS}" 0 0
1273
1274 if [[ $? -eq 0 ]]; then
1275 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG " --infobox "$_LvmPvActBody1${LVM_VG}.$_PlsWaitBody" 0 0
1276 sleep 1
1277 vgcreate -f ${LVM_VG} ${VG_PARTS} >/dev/null 2>/tmp/.errlog
1278 check_for_error
1279
1280 # Once created, get size and size type for display and later number-crunching for lv creation
1281 VG_SIZE=$(vgdisplay $LVM_VG | grep 'VG Size' | awk '{print $3}' | sed 's/\..*//')
1282 VG_SIZE_TYPE=$(vgdisplay $LVM_VG | grep 'VG Size' | awk '{print $4}')
1283
1284 # Convert the VG size into GB and MB. These variables are used to keep tabs on space available and remaining
1285 [[ ${VG_SIZE_TYPE:0:1} == "G" ]] && LVM_VG_MB=$(( VG_SIZE * 1000 )) || LVM_VG_MB=$VG_SIZE
1286
1287 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG " --msgbox "$_LvmPvDoneBody1 '${LVM_VG}' $_LvmPvDoneBody2 (${VG_SIZE} ${VG_SIZE_TYPE}).\n\n" 0 0
1288 else
1289 lvm_menu
1290 fi
1291
1292 #
1293 # Once VG created, create Logical Volumes
1294 #
1295
1296 # Specify number of Logical volumes to create.
1297 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG " --radiolist "$_LvmLvNumBody1 ${LVM_VG}. $_LvmLvNumBody2" 0 0 9 \
1298 "1" "-" off "2" "-" off "3" "-" off "4" "-" off "5" "-" off "6" "-" off "7" "-" off "8" "-" off "9 " "-" off 2>${ANSWER}
1299
1300 [[ $(cat ${ANSWER}) == "" ]] && lvm_menu || NUMBER_LOGICAL_VOLUMES=$(cat ${ANSWER})
1301
1302 # Loop while the number of LVs is greater than 1. This is because the size of the last LV is automatic.
1303 while [[ $NUMBER_LOGICAL_VOLUMES -gt 1 ]]; do
1304 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG (LV:$NUMBER_LOGICAL_VOLUMES) " --inputbox "$_LvmLvNameBody1" 0 0 "lvol" 2>${ANSWER} || prep_menu
1305 LVM_LV_NAME=$(cat ${ANSWER})
1306
1307 # Loop if preceeded with a "/", if nothing is entered, if there is a space, or if that name already exists.
1308 while [[ ${LVM_LV_NAME:0:1} == "/" ]] || [[ ${#LVM_LV_NAME} -eq 0 ]] || [[ ${LVM_LV_NAME} =~ \ |\' ]] || [[ $(lsblk | grep ${LVM_LV_NAME}) != "" ]]; do
1309 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_LvmLvNameErrBody" 0 0
1310 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG (LV:$NUMBER_LOGICAL_VOLUMES) " --inputbox "$_LvmLvNameBody1" 0 0 "lvol" 2>${ANSWER} || prep_menu
1311 LVM_LV_NAME=$(cat ${ANSWER})
1312 done
1313
1314 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG (LV:$NUMBER_LOGICAL_VOLUMES) " --inputbox "\n${LVM_VG}: ${VG_SIZE}${VG_SIZE_TYPE} (${LVM_VG_MB}MB $_LvmLvSizeBody1).$_LvmLvSizeBody2" 0 0 "" 2>${ANSWER} || prep_menu
1315 LVM_LV_SIZE=$(cat ${ANSWER})
1316 check_lv_size
1317
1318 # Loop while an invalid value is entered.
1319 while [[ $LV_SIZE_INVALID -eq 1 ]]; do
1320 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_LvmLvSizeErrBody" 0 0
1321 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG (LV:$NUMBER_LOGICAL_VOLUMES) " --inputbox "\n${LVM_VG}: ${VG_SIZE}${VG_SIZE_TYPE} (${LVM_VG_MB}MB $_LvmLvSizeBody1).$_LvmLvSizeBody2" 0 0 "" 2>${ANSWER} || prep_menu
1322 LVM_LV_SIZE=$(cat ${ANSWER})
1323 check_lv_size
1324 done
1325
1326 # Create the LV
1327 lvcreate -L ${LVM_LV_SIZE} ${LVM_VG} -n ${LVM_LV_NAME} 2>/tmp/.errlog
1328 check_for_error
1329 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG (LV:$NUMBER_LOGICAL_VOLUMES) " --msgbox "\n$_Done\n\nLV ${LVM_LV_NAME} (${LVM_LV_SIZE}) $_LvmPvDoneBody2.\n\n" 0 0
1330 NUMBER_LOGICAL_VOLUMES=$(( NUMBER_LOGICAL_VOLUMES - 1 ))
1331 done
1332
1333 # Now the final LV. Size is automatic.
1334 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG (LV:$NUMBER_LOGICAL_VOLUMES) " --inputbox "$_LvmLvNameBody1 $_LvmLvNameBody2 (${LVM_VG_MB}MB)." 0 0 "lvol" 2>${ANSWER} || prep_menu
1335 LVM_LV_NAME=$(cat ${ANSWER})
1336
1337 # Loop if preceeded with a "/", if nothing is entered, if there is a space, or if that name already exists.
1338 while [[ ${LVM_LV_NAME:0:1} == "/" ]] || [[ ${#LVM_LV_NAME} -eq 0 ]] || [[ ${LVM_LV_NAME} =~ \ |\' ]] || [[ $(lsblk | grep ${LVM_LV_NAME}) != "" ]]; do
1339 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_LvmLvNameErrBody" 0 0
1340 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG (LV:$NUMBER_LOGICAL_VOLUMES) " --inputbox "$_LvmLvNameBody1 $_LvmLvNameBody2 (${LVM_VG_MB}MB)." 0 0 "lvol" 2>${ANSWER} || prep_menu
1341 LVM_LV_NAME=$(cat ${ANSWER})
1342 done
1343
1344 # Create the final LV
1345 lvcreate -l +100%FREE ${LVM_VG} -n ${LVM_LV_NAME} 2>/tmp/.errlog
1346 check_for_error
1347 NUMBER_LOGICAL_VOLUMES=$(( NUMBER_LOGICAL_VOLUMES - 1 ))
1348 LVM=1
1349 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmCreateVG " --yesno "$_LvmCompBody" 0 0 \
1350 && show_devices || lvm_menu
1351
1352}
1353
1354lvm_del_vg(){
1355
1356 # Generate list of VGs for selection
1357 lvm_show_vg
1358
1359 # Ask for confirmation
1360 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmDelVG " --yesno "$_LvmDelQ" 0 0
1361
1362 # if confirmation given, delete
1363 if [[ $? -eq 0 ]]; then
1364 vgremove -f $(cat ${ANSWER}) >/dev/null 2>&1
1365 fi
1366
1367 lvm_menu
1368}
1369
1370lvm_del_all(){
1371
1372 LVM_PV=$(pvs -o pv_name --noheading 2>/dev/null)
1373 LVM_VG=$(vgs -o vg_name --noheading 2>/dev/null)
1374 LVM_LV=$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)
1375
1376 # Ask for confirmation
1377 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_LvmDelLV " --yesno "$_LvmDelQ" 0 0
1378
1379 # if confirmation given, delete
1380 if [[ $? -eq 0 ]]; then
1381
1382 for i in ${LVM_LV}; do
1383 lvremove -f /dev/mapper/${i} >/dev/null 2>&1
1384 done
1385
1386 for i in ${LVM_VG}; do
1387 vgremove -f ${i} >/dev/null 2>&1
1388 done
1389
1390 for i in ${LV_PV}; do
1391 pvremove -f ${i} >/dev/null 2>&1
1392 done
1393
1394 fi
1395
1396 lvm_menu
1397}
1398
1399lvm_menu(){
1400
1401 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepLVM $_PrepLVM2 " --infobox "$_PlsWaitBody" 0 0
1402 sleep 1
1403 lvm_detect
1404
1405 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepLVM $_PrepLVM2 " --menu "$_LvmMenu" 0 0 4 \
1406 "$_LvmCreateVG" "vgcreate -f, lvcreate -L -n" \
1407 "$_LvmDelVG" "vgremove -f" \
1408 "$_LvMDelAll" "lvrmeove, vgremove, pvremove -f" \
1409 "$_Back" "-" 2>${ANSWER}
1410
1411 case $(cat ${ANSWER}) in
1412 "$_LvmCreateVG") lvm_create ;;
1413 "$_LvmDelVG") lvm_del_vg ;;
1414 "$_LvMDelAll") lvm_del_all ;;
1415 *) prep_menu ;;
1416 esac
1417
1418
1419}
1420
1421######################################################################
1422## ##
1423## Installation Functions ##
1424## ##
1425######################################################################
1426
1427install_root(){
1428
1429 clear
1430
1431 # Change installation method depending on use of img or sfs #### COMENTED #### ELES RSYNC CHANGED TO CP -XAV /
1432 if [[ -e /run/archiso/sfs/airootfs/airootfs.img ]]; then
1433 AIROOTIMG="/run/archiso/sfs/airootfs/airootfs.img"
1434 mkdir -p ${BYPASS} 2>/tmp/.errlog
1435 mount ${AIROOTIMG} ${BYPASS} 2>>/tmp/.errlog
1436 rsync -a --progress ${BYPASS} ${MOUNTPOINT}/ 2>>/tmp/.errlog
1437 umount -l ${BYPASS}
1438 else
1439 AIROOTIMG="/run/archiso/sfs/airootfs/"
1440 cp -xav / ${MOUNTPOINT}/ 2>/tmp/.errlog
1441 fi
1442
1443 check_for_error
1444
1445 # Keyboard config for vc and x11
1446 [[ -e /tmp/vconsole.conf ]] && cp /tmp/vconsole.conf ${MOUNTPOINT}/etc/vconsole.conf 2>>/tmp/.errlog
1447 [[ -e /tmp/01-keyboard-layout.conf ]] && cp -f /tmp/01-keyboard-layout.conf ${MOUNTPOINT}/etc/X11/xorg.conf.d/$(ls ${MOUNTPOINT}/etc/X11/xorg.conf.d/ | grep "keyboard") 2>>/tmp/.errlog
1448
1449 # set up kernel for mkiniticpio
1450 cp /run/archiso/bootmnt/arch/boot/${ARCHI}/vmlinuz ${MOUNTPOINT}/boot/vmlinuz-linux 2>>/tmp/.errlog
1451
1452 # copy over new mirrorlist #### COMMENTED ####
1453 # cp /etc/pacman.d/mirrorlist ${MOUNTPOINT}/etc/pacman.d/mirrorlist 2>>/tmp/.errlog
1454
1455 # Clean up installation
1456 [[ -d ${MOUNTPOINT}/abif-master ]] && rm -R ${MOUNTPOINT}/abif-master 2>>/tmp/.errlog
1457 rm -rf ${MOUNTPOINT}/vomi 2>>/tmp/.errlog
1458 rm -rf ${BYPASS} 2>>/tmp/.errlog
1459 rm -rf ${MOUNTPOINT}/source 2>>/tmp/.errlog
1460 rm -rf ${MOUNTPOINT}/src 2>>/tmp/.errlog
1461 rmdir ${MOUNTPOINT}/bypass 2>>/tmp/.errlog
1462 rmdir ${MOUNTPOINT}/src 2>>/tmp/.errlog
1463 rmdir ${MOUNTPOINT}/source 2>>/tmp/.errlog
1464 rm -f ${MOUNTPOINT}/etc/sudoers.d/g_wheel 2>>/tmp/.errlog
1465 rm -f ${MOUNTPOINT}/var/lib/NetworkManager/NetworkManager.state 2>>/tmp/.errlog
1466 rm -f ${MOUNTPOINT}/update-abif 2>>/tmp/.errlog
1467 sed -i 's/.*pam_wheel\.so/#&/' ${MOUNTPOINT}/etc/pam.d/su 2>>/tmp/.errlog
1468
1469 # clean out archiso files from install #### COMMENTED ####
1470 #find ${MOUNTPOINT}/usr/lib/initcpio -name archiso* -type f -exec rm '{}' \;
1471
1472 # systemd #### COMMENTED AND ADDED ####
1473 #rm -R ${MOUNTPOINT}/etc/systemd/system/getty@tty1.service.d 2>>/tmp/.errlog
1474 #rm ${MOUNTPOINT}/etc/systemd/system/default.target 2>>/tmp/.errlog
1475 #
1476 arch_chroot "systemctl disable pacman-init.service choose-mirror.service"
1477 rm -r ${MOUNTPOINT}/etc/systemd/system/{choose-mirror.service,pacman-init.service,etc-pacman.d-gnupg.mount,getty@tty1.service.d}
1478 rm -r ${MOUNTPOINT}/etc/systemd/scripts/choose-mirror
1479 rm ${MOUNTPOINT}/etc/systemd/system/getty@tty1.service.d/autologin.conf
1480 rm ${MOUNTPOINT}/root/{.automated_script.sh,.zlogin}
1481 rm ${MOUNTPOINT}/etc/mkinitcpio-archiso.conf
1482 rm -r ${MOUNTPOINT}/etc/initcpio
1483 arch_chroot "systemctl disable multi-user.target"
1484 arch_chroot "systemctl enable sddm"
1485 arch_chroot mv ${MOUNTPOINT}/~ .xinitrc .xinitrc.bak
1486 arch_chroot mv ${MOUNTPOINT}/~ .xsession .xsession.bak
1487 arch_chroot mv ${MOUNTPOINT}/~ .bash_profile .bash_profile.bak
1488 arch_chroot mv ${MOUNTPOINT}/~ .bash_profile.comented .bash_profile
1489
1490 # Journal
1491 sed -i 's/volatile/auto/g' ${MOUNTPOINT}/etc/systemd/journald.conf 2>>/tmp/.errlog
1492
1493 # Stop pacman complaining
1494 arch_chroot "mkdir -p /var/lib/pacman/sync" 2>>/tmp/.errlog
1495 arch_chroot "touch /var/lib/pacman/sync/{core.db,extra.db,community.db}" 2>>/tmp/.errlog
1496
1497 # Fix NetworkManager
1498 arch_chroot "systemctl enable NetworkManager -f" 2>>/tmp/.errlog
1499
1500 # Keyboard config for vc and x11
1501 [[ -e /tmp/vconsole.conf ]] && cp /tmp/vconsole.conf ${MOUNTPOINT}/etc/vconsole.conf 2>>/tmp/.errlog
1502 [[ -e /tmp/01-keyboard-layout.conf ]] && cp -f /tmp/01-keyboard-layout.conf ${MOUNTPOINT}/etc/X11/xorg.conf.d/$(ls ${MOUNTPOINT}/etc/X11/xorg.conf.d/ | grep "keyboard") 2>>/tmp/.errlog
1503
1504 # Display Manager #### COMMENTED ####
1505 #arch_chroot "systemctl enable sddm" 2>>/tmp/.errlog
1506 #cp -f /inst/sddm.conf ${MOUNTPOINT}/etc/sddm/sddm.conf 2>>/tmp/.errlog
1507 #[[ -d ${MOUNTPOINT}/inst ]] && rm -R ${MOUNTPOINT}/inst &> /dev/null 2>>/tmp/.errlog
1508 #check_for_error
1509
1510 # Virtualbox Guest
1511 [[ $(lspci | grep -i "vga" | sed 's/.*://' | sed 's/(.*//' | sed 's/^[ \t]*//' | grep -i "virtualbox") != "" ]] && arch_chroot "systemctl enable vboxservice"
1512
1513}
1514
1515# Install Bootloader
1516install_bootloader() {
1517
1518bios_bootloader() {
1519
1520 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_InstBiosBtTitle" --menu "$_InstBiosBtBody" 0 0 3 \
1521 "grub" "-" "syslinux [MBR]" "-" "syslinux [/]" "-" 2>${ANSWER}
1522
1523 if [[ $(cat ${ANSWER}) == "grub" ]];then
1524 select_device
1525 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " Grub-install " --infobox "$_PlsWaitBody" 0 0
1526 arch_chroot "grub-install --target=i386-pc --recheck $DEVICE" 2>/tmp/.errlog
1527 check_for_error
1528
1529 arch_chroot "grub-mkconfig -o /boot/grub/grub.cfg" 2>/tmp/.errlog
1530 check_for_error
1531
1532 # if /boot is LVM (whether using a seperate /boot mount or not), amend grub
1533 if ( [[ $LVM -eq 1 ]] && [[ $LVM_SEP_BOOT -eq 0 ]] ) || [[ $LVM_SEP_BOOT -eq 2 ]]; then
1534 sed -i "s/GRUB_PRELOAD_MODULES=\"\"/GRUB_PRELOAD_MODULES=\"lvm\"/g" ${MOUNTPOINT}/etc/default/grub
1535 fi
1536
1537 # If encryption used amend grub
1538 [[ $LUKS_DEV != "" ]] && sed -i "s~GRUB_CMDLINE_LINUX=.*~GRUB_CMDLINE_LINUX=\"$LUKS_DEV\"~g" ${MOUNTPOINT}/etc/default/grub
1539
1540 arch_chroot "grub-mkconfig -o /boot/grub/grub.cfg" 2>>/tmp/.errlog
1541 check_for_error
1542 BOOTLOADER="grub"
1543
1544 elif ([[ $(cat ${ANSWER}) == "syslinux [MBR]" ]] || [[ $(cat ${ANSWER}) == "syslinux [/]" ]]);then
1545 [[ $(cat ${ANSWER}) == "syslinux [MBR]" ]] && arch_chroot "syslinux-install_update -iam" 2>/tmp/.errlog
1546 [[ $(cat ${ANSWER}) == "syslinux [/]" ]] && arch_chroot "syslinux-install_update -i" 2>/tmp/.errlog
1547 check_for_error
1548
1549 # Amend configuration file. First remove all existing entries, then input new ones.
1550 sed -i '/^LABEL.*$/,$d' ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1551
1552 # First the "main" entries
1553 [[ -e ${MOUNTPOINT}/boot/initramfs-linux.img ]] && echo -e "\n\nLABEL arch\n\tMENU LABEL $ISO_HOST Linux\n\tLINUX ../vmlinuz-linux\n\tAPPEND root=${ROOT_PART} rw\n\tINITRD ../initramfs-linux.img" >> ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1554 [[ -e ${MOUNTPOINT}/boot/initramfs-linux-lts.img ]] && echo -e "\n\nLABEL arch\n\tMENU LABEL $ISO_HOST Linux LTS\n\tLINUX ../vmlinuz-linux-lts\n\tAPPEND root=${ROOT_PART} rw\n\tINITRD ../initramfs-linux-lts.img" >> ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1555 [[ -e ${MOUNTPOINT}/boot/initramfs-linux-grsec.img ]] && echo -e "\n\nLABEL arch\n\tMENU LABEL $ISO_HOST Linux Grsec\n\tLINUX ../vmlinuz-linux-grsec\n\tAPPEND root=${ROOT_PART} rw\n\tINITRD ../initramfs-linux-grsec.img" >> ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1556 [[ -e ${MOUNTPOINT}/boot/initramfs-linux-zen.img ]] && echo -e "\n\nLABEL arch\n\tMENU LABEL $ISO_HOST Linux Zen\n\tLINUX ../vmlinuz-linux-zen\n\tAPPEND root=${ROOT_PART} rw\n\tINITRD ../initramfs-linux-zen.img" >> ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1557
1558 # Second the "fallback" entries
1559 [[ -e ${MOUNTPOINT}/boot/initramfs-linux.img ]] && echo -e "\n\nLABEL arch\n\tMENU LABEL $ISO_HOST Linux Fallback\n\tLINUX ../vmlinuz-linux\n\tAPPEND root=${ROOT_PART} rw\n\tINITRD ../initramfs-linux-fallback.img" >> ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1560 [[ -e ${MOUNTPOINT}/boot/initramfs-linux-lts.img ]] && echo -e "\n\nLABEL arch\n\tMENU LABEL $ISO_HOST Linux Fallback LTS\n\tLINUX ../vmlinuz-linux-lts\n\tAPPEND root=${ROOT_PART} rw\n\tINITRD ../initramfs-linux-lts-fallback.img" >> ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1561 [[ -e ${MOUNTPOINT}/boot/initramfs-linux-grsec.img ]] && echo -e "\n\nLABEL arch\n\tMENU LABEL $ISO_HOST Linux Fallback Grsec\n\tLINUX ../vmlinuz-linux-grsec\n\tAPPEND root=${ROOT_PART} rw\n\tINITRD ../initramfs-linux-grsec-fallback.img" >> ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1562 [[ -e ${MOUNTPOINT}/boot/initramfs-linux-zen.img ]] && echo -e "\n\nLABEL arch\n\tMENU LABEL $ISO_HOST Linux Fallbacl Zen\n\tLINUX ../vmlinuz-linux-zen\n\tAPPEND root=${ROOT_PART} rw\n\tINITRD ../initramfs-linux-zen-fallback.img" >> ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1563
1564 # Third, amend for LUKS
1565 [[ $LUKS_DEV != "" ]] && sed -i "s~rw~$LUKS_DEV rw~g" ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1566
1567 # Finally, re-add the "default" entries
1568 echo -e "\n\nLABEL hdt\n\tMENU LABEL HDT (Hardware Detection Tool)\n\tCOM32 hdt.c32" >> ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1569 echo -e "\n\nLABEL reboot\n\tMENU LABEL Reboot\n\tCOM32 reboot.c32" >> ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1570 echo -e "\n\n#LABEL windows\n\t#MENU LABEL Windows\n\t#COM32 chain.c32\n\t#APPEND root=/dev/sda2 rw" >> ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1571 echo -e "\n\nLABEL poweroff\n\tMENU LABEL Poweroff\n\tCOM32 poweroff.c32" ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1572
1573 BOOTLOADER="syslinux"
1574 fi
1575
1576}
1577
1578uefi_bootloader() {
1579
1580 #Ensure again that efivarfs is mounted
1581 [[ -z $(mount | grep /sys/firmware/efi/efivars) ]] && mount -t efivarfs efivarfs /sys/firmware/efi/efivars
1582
1583 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_InstUefiBtTitle " --menu "$_InstUefiBtBody" 0 0 2 \
1584 "grub" "-" "systemd-boot" "/boot" 2>${ANSWER}
1585
1586 if [[ $(cat ${ANSWER}) == "grub" ]];then
1587
1588 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " Grub-install " --infobox "$_PlsWaitBody" 0 0
1589 arch_chroot "grub-install --target=x86_64-efi --efi-directory=${UEFI_MOUNT} --bootloader-id=arch_grub --recheck" 2>/tmp/.errlog
1590
1591 # If encryption used amend grub
1592 [[ $LUKS_DEV != "" ]] && sed -i "s~GRUB_CMDLINE_LINUX=.*~GRUB_CMDLINE_LINUX=\"$LUKS_DEV\"~g" ${MOUNTPOINT}/etc/default/grub
1593
1594 # Generate config file
1595 arch_chroot "grub-mkconfig -o /boot/grub/grub.cfg" 2>>/tmp/.errlog
1596 check_for_error
1597
1598 # Ask if user wishes to set Grub as the default bootloader and act accordingly
1599 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_InstUefiBtTitle " --yesno "$_SetBootDefBody ${UEFI_MOUNT}/EFI/boot $_SetBootDefBody2" 0 0
1600
1601 if [[ $? -eq 0 ]]; then
1602 arch_chroot "mkdir ${UEFI_MOUNT}/EFI/boot" 2>/tmp/.errlog
1603 arch_chroot "cp -r ${UEFI_MOUNT}/EFI/arch_grub/grubx64.efi ${UEFI_MOUNT}/EFI/boot/bootx64.efi" 2>>/tmp/.errlog
1604 check_for_error
1605 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_InstUefiBtTitle " --infobox "\nGrub $_SetDefDoneBody" 0 0
1606 sleep 2
1607 fi
1608
1609 BOOTLOADER="grub"
1610
1611 elif [[ $(cat ${ANSWER}) == "systemd-boot" ]];then
1612
1613 arch_chroot "bootctl --path=${UEFI_MOUNT} install" 2>/tmp/.errlog
1614 check_for_error
1615
1616 # Deal with LVM Root
1617 [[ $(echo $ROOT_PART | grep "/dev/mapper/") != "" ]] && bl_root=$ROOT_PART \
1618 || bl_root=$"PARTUUID="$(blkid -s PARTUUID ${ROOT_PART} | sed 's/.*=//g' | sed 's/"//g')
1619
1620 # Create default config files. First the loader
1621 echo -e "default $ISO_HOST\ntimeout 10" > ${MOUNTPOINT}${UEFI_MOUNT}/loader/loader.conf 2>/tmp/.errlog
1622
1623 # Second, the kernel conf files
1624 [[ -e ${MOUNTPOINT}/boot/initramfs-linux.img ]] && echo -e "title\t$ISO_HOST Linux\nlinux\t/vmlinuz-linux\ninitrd\t/initramfs-linux.img\noptions\troot=${bl_root} rw" > ${MOUNTPOINT}${UEFI_MOUNT}/loader/entries/$ISO_HOST.conf
1625 [[ -e ${MOUNTPOINT}/boot/initramfs-linux-lts.img ]] && echo -e "title\t$ISO_HOST Linux LTS\nlinux\t/vmlinuz-linux-lts\ninitrd\t/initramfs-linux-lts.img\noptions\troot=${bl_root} rw" > ${MOUNTPOINT}${UEFI_MOUNT}/loader/entries/$ISO_HOST-lts.conf
1626 [[ -e ${MOUNTPOINT}/boot/initramfs-linux-grsec.img ]] && echo -e "title\t$ISO_HOST Linux Grsec\nlinux\t/vmlinuz-linux-grsec\ninitrd\t/initramfs-linux-grsec.img\noptions\troot=${bl_root} rw" > ${MOUNTPOINT}${UEFI_MOUNT}/loader/entries/$ISO_HOST-grsec.conf
1627 [[ -e ${MOUNTPOINT}/boot/initramfs-linux-zen.img ]] && echo -e "title\t$ISO_HOST Linux Zen\nlinux\t/vmlinuz-linux-zen\ninitrd\t/initramfs-linux-zen.img\noptions\troot=${bl_root} rw" > ${MOUNTPOINT}${UEFI_MOUNT}/loader/entries/$ISO_HOST-zen.conf
1628
1629 # Finally, amend kernel conf files for LUKS
1630 sysdconf=$(ls ${MOUNTPOINT}${UEFI_MOUNT}/loader/entries/$ISO_HOST*.conf)
1631 for i in ${sysdconf}; do
1632 [[ $LUKS_DEV != "" ]] && sed -i "s~rw~$LUKS_DEV rw~g" ${i}
1633 done
1634
1635 BOOTLOADER="systemd-boot"
1636 fi
1637
1638}
1639 # #
1640 # Bootloader function begins here #
1641 # #
1642 check_mount
1643 # Set the default PATH variable
1644 arch_chroot "PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl" 2>/tmp/.errlog
1645 check_for_error
1646
1647 if [[ $SYSTEM == "BIOS" ]]; then
1648 bios_bootloader
1649 else
1650 uefi_bootloader
1651 fi
1652}
1653
1654######################################################################
1655## ##
1656## Main Interfaces ##
1657## ##
1658######################################################################
1659
1660security_menu(){
1661
1662 if [[ $SUB_MENU != "security_menu" ]]; then
1663 SUB_MENU="security_menu"
1664 HIGHLIGHT_SUB=1
1665 else
1666 if [[ $HIGHLIGHT_SUB != 4 ]]; then
1667 HIGHLIGHT_SUB=$(( HIGHLIGHT_SUB + 1 ))
1668 fi
1669 fi
1670
1671 dialog --default-item ${HIGHLIGHT_SUB} --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SecMenuTitle " --menu "$_SecMenuBody" 0 0 4 \
1672 "1" "$_SecJournTitle" \
1673 "2" "$_SecCoreTitle" \
1674 "3" "$_SecKernTitle" \
1675 "4" "$_Back" 2>${ANSWER}
1676
1677 HIGHLIGHT_SUB=$(cat ${ANSWER})
1678 case $(cat ${ANSWER}) in
1679 "1") # systemd-journald
1680 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SecJournTitle " --menu "$_SecJournBody" 0 0 7 \
1681 "$_Edit" "/etc/systemd/journald.conf" \
1682 "10M" "SystemMaxUse=10M" \
1683 "20M" "SystemMaxUse=20M" \
1684 "50M" "SystemMaxUse=50M" \
1685 "100M" "SystemMaxUse=100M" \
1686 "200M" "SystemMaxUse=200M" \
1687 "$_Disable" "Storage=none" 2>${ANSWER}
1688
1689 if [[ $(cat ${ANSWER}) != "" ]]; then
1690 if [[ $(cat ${ANSWER}) == "$_Disable" ]]; then
1691 sed -i "s/#Storage.*\|Storage.*/Storage=none/g" ${MOUNTPOINT}/etc/systemd/journald.conf
1692 sed -i "s/SystemMaxUse.*/#&/g" ${MOUNTPOINT}/etc/systemd/journald.conf
1693 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SecJournTitle " --infobox "\n$_Done!\n\n" 0 0
1694 sleep 2
1695 elif [[ $(cat ${ANSWER}) == "$_Edit" ]]; then
1696 nano ${MOUNTPOINT}/etc/systemd/journald.conf
1697 else
1698 sed -i "s/#SystemMaxUse.*\|SystemMaxUse.*/SystemMaxUse=$(cat ${ANSWER})/g" ${MOUNTPOINT}/etc/systemd/journald.conf
1699 sed -i "s/Storage.*/#&/g" ${MOUNTPOINT}/etc/systemd/journald.conf
1700 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SecJournTitle " --infobox "\n$_Done!\n\n" 0 0
1701 sleep 2
1702 fi
1703 fi
1704 ;;
1705 "2") # core dump
1706 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SecCoreTitle " --menu "$_SecCoreBody" 0 0 2 \
1707 "$_Disable" "Storage=none" "$_Edit" "/etc/systemd/coredump.conf" 2>${ANSWER}
1708
1709 if [[ $(cat ${ANSWER}) == "$_Disable" ]]; then
1710 sed -i "s/#Storage.*\|Storage.*/Storage=none/g" ${MOUNTPOINT}/etc/systemd/coredump.conf
1711 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SecCoreTitle " --infobox "\n$_Done!\n\n" 0 0
1712 sleep 2
1713 elif [[ $(cat ${ANSWER}) == "$_Edit" ]]; then
1714 nano ${MOUNTPOINT}/etc/systemd/coredump.conf
1715 fi
1716 ;;
1717 "3") # Kernel log access
1718 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SecKernTitle " --menu "\nKernel logs may contain information an attacker can use to identify and exploit kernel vulnerabilities, including sensitive memory addresses.\n\nIf systemd-journald logging has not been disabled, it is possible to create a rule in /etc/sysctl.d/ to disable access to these logs unless using root privilages (e.g. via sudo).\n" 0 0 2 \
1719 "$_Disable" "kernel.dmesg_restrict = 1" "$_Edit" "/etc/systemd/coredump.conf.d/custom.conf" 2>${ANSWER}
1720
1721 case $(cat ${ANSWER}) in
1722 "$_Disable") echo "kernel.dmesg_restrict = 1" > ${MOUNTPOINT}/etc/sysctl.d/50-dmesg-restrict.conf
1723 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SecKernTitle " --infobox "\n$_Done!\n\n" 0 0
1724 sleep 2 ;;
1725 "$_Edit") [[ -e ${MOUNTPOINT}/etc/sysctl.d/50-dmesg-restrict.conf ]] && nano ${MOUNTPOINT}/etc/sysctl.d/50-dmesg-restrict.conf \
1726 || dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SeeConfErrTitle " --msgbox "$_SeeConfErrBody1" 0 0 ;;
1727 esac
1728 ;;
1729 *) main_menu
1730 ;;
1731 esac
1732
1733 security_menu
1734}
1735
1736
1737# Greet the user when first starting the installer
1738greeting() {
1739
1740dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_WelTitle $VERSION " --msgbox "$_WelBody" 0 0
1741
1742}
1743
1744# Preparation
1745prep_menu() {
1746
1747 if [[ $SUB_MENU != "prep_menu" ]]; then
1748 SUB_MENU="prep_menu"
1749 HIGHLIGHT_SUB=1
1750 else
1751 if [[ $HIGHLIGHT_SUB != 8 ]]; then
1752 HIGHLIGHT_SUB=$(( HIGHLIGHT_SUB + 1 ))
1753 fi
1754 fi
1755
1756 dialog --default-item ${HIGHLIGHT_SUB} --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_PrepMenuTitle " --menu "$_PrepMenuBody" 0 0 8 \
1757 "1" "$_VCKeymapTitle" \
1758 "2" "$_PrepKBLayout" \
1759 "3" "$_DevShowOpt" \
1760 "4" "$_PrepPartDisk" \
1761 "5" "$_PrepLUKS" \
1762 "6" "$_PrepLVM $_PrepLVM2" \
1763 "7" "$_PrepMntPart" \
1764 "8" "$_Back" 2>${ANSWER}
1765
1766 HIGHLIGHT_SUB=$(cat ${ANSWER})
1767 case $(cat ${ANSWER}) in
1768 "1") set_keymap
1769 ;;
1770 "2") set_xkbmap
1771 ;;
1772 "3") show_devices
1773 ;;
1774 "4") umount_partitions
1775 select_device
1776 create_partitions
1777 ;;
1778 "5") luks_menu
1779 ;;
1780 "6") lvm_menu
1781 ;;
1782 "7") mount_partitions
1783 ;;
1784 *) main_menu
1785 ;;
1786 esac
1787
1788 prep_menu
1789
1790}
1791
1792# Base Installation
1793install_root_menu() {
1794
1795 if [[ $SUB_MENU != "install_base_menu" ]]; then
1796 SUB_MENU="install_base_menu"
1797 HIGHLIGHT_SUB=1
1798 else
1799 if [[ $HIGHLIGHT_SUB != 4 ]]; then
1800 HIGHLIGHT_SUB=$(( HIGHLIGHT_SUB + 1 ))
1801 fi
1802 fi
1803
1804 dialog --default-item ${HIGHLIGHT_SUB} --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_InstBsMenuTitle" --menu "$_InstBseMenuBody" 0 0 4 \
1805 "1" "$_InstBse" \
1806 "2" "$_MMRunMkinit" \
1807 "3" "$_InstBootldr" \
1808 "4" "$_Back" 2>${ANSWER}
1809
1810 HIGHLIGHT_SUB=$(cat ${ANSWER})
1811 case $(cat ${ANSWER}) in
1812 "1") install_root
1813 ;;
1814 "2") run_mkinitcpio
1815 ;;
1816 "3") install_bootloader
1817 ;;
1818 *) main_menu
1819 ;;
1820 esac
1821
1822 install_root_menu
1823}
1824
1825# Base Configuration
1826config_base_menu() {
1827
1828 # Set the default PATH variable
1829 arch_chroot "PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl" 2>/tmp/.errlog
1830 check_for_error
1831
1832 if [[ $SUB_MENU != "config_base_menu" ]]; then
1833 SUB_MENU="config_base_menu"
1834 HIGHLIGHT_SUB=1
1835 else
1836 if [[ $HIGHLIGHT_SUB != 8 ]]; then
1837 HIGHLIGHT_SUB=$(( HIGHLIGHT_SUB + 1 ))
1838 fi
1839 fi
1840
1841 dialog --default-item ${HIGHLIGHT_SUB} --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ConfBseMenuTitle " --menu "$_ConfBseBody" 0 0 8 \
1842 "1" "$_ConfBseFstab" \
1843 "2" "$_ConfBseHost" \
1844 "3" "$_ConfBseSysLoc" \
1845 "4" "$_ConfBseTimeHC" \
1846 "5" "$_ConfUsrRoot" \
1847 "6" "$_ConfUsrNew" \
1848 "7" "$_SecMenuTitle" \
1849 "8" "$_Back" 2>${ANSWER}
1850
1851 HIGHLIGHT_SUB=$(cat ${ANSWER})
1852 case $(cat ${ANSWER}) in
1853 "1") generate_fstab
1854 ;;
1855 "2") set_hostname
1856 ;;
1857 "3") set_locale
1858 ;;
1859 "4") set_timezone
1860 set_hw_clock
1861 ;;
1862 "5") set_root_password
1863 ;;
1864 "6") create_new_user
1865 ;;
1866 "7") security_menu
1867 ;;
1868 *) main_menu
1869 ;;
1870 esac
1871
1872 config_base_menu
1873
1874}
1875
1876# Edit configs of installed system
1877edit_configs() {
1878
1879 # Clear the file variables
1880 FILE=""
1881 user_list=""
1882
1883 if [[ $SUB_MENU != "edit configs" ]]; then
1884 SUB_MENU="edit configs"
1885 HIGHLIGHT_SUB=1
1886 else
1887 if [[ $HIGHLIGHT_SUB != 12 ]]; then
1888 HIGHLIGHT_SUB=$(( HIGHLIGHT_SUB + 1 ))
1889 fi
1890 fi
1891
1892 dialog --default-item ${HIGHLIGHT_SUB} --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_SeeConfOptTitle " --menu "$_SeeConfOptBody" 0 0 12 \
1893 "1" "/etc/vconsole.conf" \
1894 "2" "/etc/locale.conf" \
1895 "3" "/etc/hostname" \
1896 "4" "/etc/hosts" \
1897 "5" "/etc/sudoers" \
1898 "6" "/etc/mkinitcpio.conf" \
1899 "7" "/etc/fstab" \
1900 "8" "/etc/crypttab" \
1901 "9" "grub/syslinux/systemd-boot" \
1902 "10" "/etc/lxdm/lxdm.conf" \
1903 "11" "/etc/pacman.conf" \
1904 "12" "$_Back" 2>${ANSWER}
1905
1906 HIGHLIGHT_SUB=$(cat ${ANSWER})
1907 case $(cat ${ANSWER}) in
1908 "1") [[ -e ${MOUNTPOINT}/etc/vconsole.conf ]] && FILE="${MOUNTPOINT}/etc/vconsole.conf"
1909 ;;
1910 "2") [[ -e ${MOUNTPOINT}/etc/locale.conf ]] && FILE="${MOUNTPOINT}/etc/locale.conf"
1911 ;;
1912 "3") [[ -e ${MOUNTPOINT}/etc/hostname ]] && FILE="${MOUNTPOINT}/etc/hostname"
1913 ;;
1914 "4") [[ -e ${MOUNTPOINT}/etc/hosts ]] && FILE="${MOUNTPOINT}/etc/hosts"
1915 ;;
1916 "5") [[ -e ${MOUNTPOINT}/etc/sudoers ]] && FILE="${MOUNTPOINT}/etc/sudoers"
1917 ;;
1918 "6") [[ -e ${MOUNTPOINT}/etc/mkinitcpio.conf ]] && FILE="${MOUNTPOINT}/etc/mkinitcpio.conf"
1919 ;;
1920 "7") [[ -e ${MOUNTPOINT}/etc/fstab ]] && FILE="${MOUNTPOINT}/etc/fstab"
1921 ;;
1922 "8") [[ -e ${MOUNTPOINT}/etc/crypttab ]] && FILE="${MOUNTPOINT}/etc/crypttab"
1923 ;;
1924 "9") [[ $BOOTLOADER == "grub" ]] && FILE="${MOUNTPOINT}/etc/default/grub"
1925 [[ $BOOTLOADER == "syslinux" ]] && FILE="${MOUNTPOINT}/boot/syslinux/syslinux.cfg"
1926 if [[ $BOOTLOADER == "systemd-boot" ]]; then
1927 FILE="${MOUNTPOINT}${UEFI_MOUNT}/loader/loader.conf"
1928 files=$(ls ${MOUNTPOINT}${UEFI_MOUNT}/loader/entries/*.conf)
1929 for i in ${files}; do
1930 FILE="$FILE ${i}"
1931 done
1932 fi
1933 ;;
1934 "10") [[ -e ${MOUNTPOINT}/etc/lxdm/lxdm.conf ]] && FILE="${MOUNTPOINT}/etc/lxdm/lxdm.conf"
1935 ;;
1936 "11") [[ -e ${MOUNTPOINT}/etc/pacman.conf ]] && FILE="${MOUNTPOINT}/etc/pacman.conf"
1937 ;;
1938 *) main_menu
1939 ;;
1940 esac
1941
1942 [[ $FILE != "" ]] && geany -i $FILE \
1943 || dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_ErrTitle " --msgbox "$_SeeConfErrBody" 0 0
1944
1945 edit_configs
1946}
1947
1948main_menu() {
1949
1950 if [[ $HIGHLIGHT != 5 ]]; then
1951 HIGHLIGHT=$(( HIGHLIGHT + 1 ))
1952 fi
1953
1954 dialog --default-item ${HIGHLIGHT} --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " $_MMTitle " \
1955 --menu "$_MMBody" 0 0 5 \
1956 "1" "$_PrepMenuTitle" \
1957 "2" "$_InstBsMenuTitle" \
1958 "3" "$_ConfBseMenuTitle" \
1959 "4" "$_SeeConfOptTitle" \
1960 "5" "$_Done" 2>${ANSWER}
1961
1962 HIGHLIGHT=$(cat ${ANSWER})
1963
1964 # Depending on the answer, first check whether partition(s) are mounted and whether base has been installed
1965 if [[ $(cat ${ANSWER}) -eq 2 ]]; then
1966 check_mount
1967 fi
1968
1969 if [[ $(cat ${ANSWER}) -ge 3 ]] && [[ $(cat ${ANSWER}) -le 4 ]]; then
1970 check_mount
1971 check_base
1972 fi
1973
1974 case $(cat ${ANSWER}) in
1975 "1") prep_menu
1976 ;;
1977 "2") install_root_menu
1978 ;;
1979 "3") config_base_menu
1980 ;;
1981 "4") edit_configs
1982 ;;
1983 *) dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --yesno "$_CloseInstBody" 0 0
1984
1985 if [[ $? -eq 0 ]]; then
1986 umount_partitions
1987 clear
1988 exit 0
1989 else
1990 main_menu
1991 fi
1992
1993 ;;
1994 esac
1995
1996 main_menu
1997
1998}
1999
2000######################################################################
2001## ##
2002## Execution ##
2003## ##
2004######################################################################
2005id_system
2006select_language
2007check_requirements
2008
2009 while true; do
2010 main_menu
2011 done