· 9 years ago · Jun 25, 2017, 06:48 AM
1# !/bin/bash
2#
3# Arch Base Installation Framework (version 1.3 - 08-Oct-2015)
4#
5# Written by Carl Duff for ArchBang 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# ISO Specific Variables
19ISO_HOST="mantos" # ISO Host Name
20ISO_USER="live" # Live user account
21VERSION="MantOS Installation Framework 1.0" # Installer Name / Version
22TRANS_SRC="/abif-master" # Dir where translation files are stored
23
24# Create a temporary file to store menu selections
25ANSWER="/tmp/.abif"
26
27# Installation
28BOOTLOADER="n/a" # Which bootloader has been installed?
29KEYMAP="us" # Virtual console keymap. Default is "us"
30XKBMAP="us" # X11 keyboard layout. Default is "us"
31ZONE="" # For time
32SUBZONE="" # For time
33LOCALE="en_US.UTF-8" # System locale. Default is "en_US.UTF-8"
34
35# Architecture
36ARCHI=`uname -m` # Display whether 32 or 64 bit system
37SYSTEM="Unknown" # Display whether system is BIOS or UEFI. Default is "unknown"
38ROOT_PART="" # ROOT partition
39UEFI_PART="" # UEFI partition
40UEFI_MOUNT="" # UEFI mountpoint
41INST_DEV="" # Device where system has been installed
42HIGHLIGHT=0 # Highlight items for Main Menu
43HIGHLIGHT_SUB=0 # Highlight items for submenus
44SUB_MENU="" # Submenu to be highlighted
45
46# Logical Volume Management
47LVM=0 # Logical Volume Management Detected?
48LUKS=0 # Luks Detected?
49LVM_ROOT=0 # LVM used for Root?
50LVM_SEP_BOOT=0 # 1 = Seperate /boot, 2 = seperate /boot & LVM
51LVM_DISABLE=0 # Option to allow user to deactive existing LVM
52LVM_VG="" # Name of volume group to create
53LVM_VG_MB=0 # MB remaining of VG
54LVM_LV_NAME="" # Name of LV to create
55LV_SIZE_INVALID=0 # Is LVM LV size entered valid?
56VG_SIZE_TYPE="" # Is VG in Gigabytes or Megabytes?
57
58# Installation
59MOUNTPOINT="/mnt" # Installation
60MOUNT_TYPE="" # "/dev/" for standard partitions, "/dev/mapper" for LVM
61AIROOTIMG="" # Root image to install
62BYPASS="$MOUNTPOINT/bypass/" # Root image mountpoint
63BTRFS=0 # BTRFS used? "1" = btrfs alone, "2" = btrfs + subvolume(s)
64BTRFS_OPTS="/tmp/.btrfs_opts" #BTRFS Mount options
65BTRFS_MNT="" # used for syslinux where /mnt is a btrfs subvolume
66
67# Language Support
68CURR_LOCALE="en_US.UTF-8" # Default Locale
69FONT="" # Set new font if necessary
70
71# Edit Files
72FILE="" # Which file is to be opened?
73FILE2="" # Which second file is to be opened?
74
75######################################################################
76## ##
77## Core Functions ##
78## ##
79######################################################################
80
81# Add locale on-the-fly and sets source translation file for installer
82select_language() {
83
84 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " Select Language " --menu "\nLanguage / sprache / taal / sprÃ¥k / lingua / idioma / nyelv / lÃngua" 0 0 11 \
85 "1" $"English (en)" \
86 "2" $"Italian (it)" \
87 "3" $"Russian (ru)" \
88 "4" $"Turkish (tr)" \
89 "5" $"Dutch (nl)" \
90 "6" $"Greek (el)" \
91 "7" $"Danish (da)" \
92 "8" $"Hungarian (hu)" \
93 "9" $"Portuguese (pt)" \
94 "10" $"German (de)" \
95 "11" $"French (fr)" 2>${ANSWER}
96
97 case $(cat ${ANSWER}) in
98 "1") source ${TRANS_SRC}/english.trans
99 CURR_LOCALE="en_US.UTF-8"
100 ;;
101 "2") source ${TRANS_SRC}/italian.trans
102 CURR_LOCALE="it_IT.UTF-8"
103 ;;
104 "3") source ${TRANS_SRC}/russian.trans
105 CURR_LOCALE="ru_RU.UTF-8"
106 FONT="LatKaCyrHeb-14.psfu"
107 ;;
108 "4") source ${TRANS_SRC}/turkish.trans
109 CURR_LOCALE="tr_TR.UTF-8"
110 FONT="LatKaCyrHeb-14.psfu"
111 ;;
112 "5") source ${TRANS_SRC}/dutch.trans
113 CURR_LOCALE="nl_NL.UTF-8"
114 ;;
115 "6") source ${TRANS_SRC}/greek.trans
116 CURR_LOCALE="el_GR.UTF-8"
117 FONT="iso07u-16.psfu"
118 ;;
119 "7") source ${TRANS_SRC}/danish.trans
120 CURR_LOCALE="da_DK.UTF-8"
121 ;;
122 "8") source ${TRANS_SRC}/hungarian.trans
123 CURR_LOCALE="hu_HU.UTF-8"
124 FONT="lat2-16.psfu"
125 ;;
126 "9") source ${TRANS_SRC}/portuguese.trans
127 CURR_LOCALE="pt_BR.UTF-8"
128 ;;
129 "10") source ${TRANS_SRC}/german.trans
130 CURR_LOCALE="de_DE.UTF-8"
131 ;;
132 "11") source ${TRANS_SRC}/french.trans
133 CURR_LOCALE="fr_FR.UTF-8"
134 ;;
135 *) exit 0
136 ;;
137 esac
138
139 # Generate the chosen locale and set the language
140 sed -i "s/#${CURR_LOCALE}/${CURR_LOCALE}/" /etc/locale.gen
141 locale-gen >/dev/null 2>&1
142 export LANG=${CURR_LOCALE}
143}
144
145# Check user is root, then id system parameters
146check_system() {
147
148 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ChkTitle" --infobox "$_ChkBody" 0 0
149 sleep 2
150
151 # Ensure script is run as root. If not, terminate.
152 if [[ `whoami` != "root" ]]; then
153 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_RtFailTitle" --infobox "$_RtFailBody" 0 0
154 sleep 2
155 exit 1
156 fi
157
158 # Clear error log and detect system
159 echo "" > /tmp/.errlog
160
161 # Apple System Detection
162 if [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Inc.' ]] || [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Computer, Inc.' ]]; then
163 modprobe -r -q efivars || true # if MAC
164 else
165 modprobe -q efivarfs # all others
166 fi
167
168 # BIOS or UEFI Detection
169 if [[ -d "/sys/firmware/efi/" ]]; then
170 # Mount efivarfs if it is not already mounted
171 if [[ -z $(mount | grep /sys/firmware/efi/efivars) ]]; then
172 mount -t efivarfs efivarfs /sys/firmware/efi/efivars
173 fi
174 SYSTEM="UEFI"
175 else
176 SYSTEM="BIOS"
177 fi
178
179 # Encryption (LUKS) Detection
180 [[ $(lsblk -o TYPE | grep "crypt") == "" ]] && LUKS=0 || LUKS=1
181
182}
183
184# Chroot without terminating the script
185arch_chroot() {
186 arch-chroot $MOUNTPOINT /bin/bash -c "${1}"
187}
188
189# If there is an error, display it, clear the log and then go back to the main menu.
190check_for_error() {
191
192 if [[ $? -eq 1 ]] && [[ $(cat /tmp/.errlog | grep -i "error") != "" ]]; then
193 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ErrTitle" --msgbox "$(cat /tmp/.errlog)" 0 0
194 echo "" > /tmp/.errlog
195 main_menu
196 fi
197
198}
199
200# Ensure that a partition is mounted
201check_mount() {
202
203 if [[ $(lsblk -o MOUNTPOINT | grep ${MOUNTPOINT}) == "" ]]; then
204 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ErrTitle" --msgbox "$_ErrNoMount" 0 0
205 main_menu
206 fi
207
208}
209
210# Ensure that Arch has been installed
211check_base() {
212
213 if [[ ! -e ${MOUNTPOINT}/etc ]]; then
214 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ErrTitle" --msgbox "$_ErrNoBase" 0 0
215 main_menu_online
216 fi
217
218}
219
220# Show devices / partitions.
221show_devices() {
222 lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT | grep -v "loop" | grep -v "rom" | grep -v "arch_airootfs" > /tmp/.devlist
223 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_DevShowTitle" --textbox /tmp/.devlist 0 0
224}
225
226######################################################################
227## ##
228## Configuration Functions ##
229## ##
230######################################################################
231
232# virtual console keymap
233set_keymap() {
234
235 KEYMAPS=""
236 for i in $(ls -R /usr/share/kbd/keymaps | grep "map.gz" | sed 's/\.map.gz//g' | sort); do
237 KEYMAPS="${KEYMAPS} ${i} -"
238 done
239
240 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_KeymapTitle" \
241 --menu "$_KeymapBody" 20 40 16 ${KEYMAPS} 2>${ANSWER} || prep_menu
242 KEYMAP=$(cat ${ANSWER})
243 check_for_error
244 echo -e "KEYMAP=$KEYMAP\nFONT=$FONT" > /tmp/vconsole.conf
245 }
246
247# Set keymap for X11
248 set_xkbmap() {
249
250 XKBMAP_LIST=""
251 keymaps_xkb=("af_Afghani al_Albanian am_Armenian ara_Arabic at_German-Austria az_Azerbaijani ba_Bosnian bd_Bangla be_Belgian bg_Bulgarian br_Portuguese-Brazil bt_Dzongkha bw_Tswana by_Belarusian ca_French-Canada cd_French-DR-Congo ch_German-Switzerland cm_English-Cameroon cn_Chinese cz_Czech de_German dk_Danishee_Estonian epo_Esperanto es_Spanish et_Amharic fo_Faroese fi_Finnish fr_French gb_English-UK ge_Georgian gh_English-Ghana gn_French-Guinea gr_Greek hr_Croatian hu_Hungarian ie_Irish il_Hebrew iq_Iraqi ir_Persian is_Icelandic it_Italian jp_Japanese ke_Swahili-Kenya kg_Kyrgyz kh_Khmer-Cambodia kr_Korean kz_Kazakh la_Lao latam_Spanish-Lat-American lk_Sinhala-phonetic lt_Lithuanian lv_Latvian ma_Arabic-Morocco mao_Maori md_Moldavian me_Montenegrin mk_Macedonian ml_Bambara mm_Burmese mn_Mongolian mt_Maltese mv_Dhivehi ng_English-Nigeria nl_Dutch no_Norwegian np_Nepali ph_Filipino pk_Urdu-Pakistan pl_Polish pt_Portuguese ro_Romanian rs_Serbian ru_Russian se_Swedish si_Slovenian sk_Slovak sn_Wolof sy_Arabic-Syria th_Thai tj_Tajik tm_Turkmen tr_Turkish tw_Taiwanese tz_Swahili-Tanzania ua_Ukrainian us_English-US uz_Uzbek vn_Vietnamese za_English-S-Africa")
252
253 for i in ${keymaps_xkb}; do
254 XKBMAP_LIST="${XKBMAP_LIST} ${i} -"
255 done
256
257 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_XkbmapTitle" --menu "$_KeymapBody" 0 0 16 ${XKBMAP_LIST} 2>${ANSWER} || prep_menu
258 XKBMAP=$(cat ${ANSWER} |sed 's/_.*//')
259 echo -e "Section "\"InputClass"\"\nIdentifier "\"system-keyboard"\"\nMatchIsKeyboard "\"on"\"\nOption "\"XkbLayout"\" "\"${XKBMAP}"\"\nEndSection" > /tmp/01-keyboard-layout.conf
260 setxkbmap $XKBMAP 2>/tmp/.errlog
261 check_for_error
262}
263
264# Set the installed system's locale
265set_locale() {
266
267 LOCALES=""
268 for i in $(cat /etc/locale.gen | grep -v "# " | sed 's/#//g' | sed 's/ UTF-8//g' | grep .UTF-8); do
269 LOCALES="${LOCALES} ${i} -"
270 done
271
272 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LocateTitle" --menu "$_localeBody" 0 0 16 ${LOCALES} 2>${ANSWER} || config_base_menu
273 LOCALE=$(cat ${ANSWER})
274
275 echo "LANG=\"${LOCALE}\"" > ${MOUNTPOINT}/etc/locale.conf
276 sed -i "s/#${LOCALE}/${LOCALE}/" ${MOUNTPOINT}/etc/locale.gen 2>/tmp/.errlog
277 arch_chroot "locale-gen" >/dev/null 2>>/tmp/.errlog
278 check_for_error
279}
280
281# Set Zone and Sub-Zone
282set_timezone() {
283
284 ZONE=""
285 for i in $(cat /usr/share/zoneinfo/zone.tab | awk '{print $3}' | grep "/" | sed "s/\/.*//g" | sort -ud); do
286 ZONE="$ZONE ${i} -"
287 done
288
289 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_TimeZTitle" --menu "$_TimeZBody" 0 0 10 ${ZONE} 2>${ANSWER} || config_base_menu
290 ZONE=$(cat ${ANSWER})
291
292 SUBZONE=""
293 for i in $(cat /usr/share/zoneinfo/zone.tab | awk '{print $3}' | grep "${ZONE}/" | sed "s/${ZONE}\///g" | sort -ud); do
294 SUBZONE="$SUBZONE ${i} -"
295 done
296
297 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_TimeSubZTitle" --menu "$_TimeSubZBody" 0 0 11 ${SUBZONE} 2>${ANSWER} || config_base_menu
298 SUBZONE=$(cat ${ANSWER})
299
300 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --yesno "$_TimeZQ ${ZONE}/${SUBZONE} ?" 0 0
301
302 if [[ $? -eq 0 ]]; then
303 arch_chroot "ln -sf /usr/share/zoneinfo/${ZONE}/${SUBZONE} /etc/localtime" 2>/tmp/.errlog
304 check_for_error
305 else
306 config_base_menu
307 fi
308}
309
310set_hw_clock() {
311
312 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_HwCTitle" \
313 --menu "$_HwCBody" 0 0 2 \
314 "1" "$_HwCUTC" \
315 "2" "$_HwLocal" 2>${ANSWER}
316
317 case $(cat ${ANSWER}) in
318 "1") arch_chroot "hwclock --systohc --utc" 2>/tmp/.errlog
319 ;;
320 "2") arch_chroot "hwclock --systohc --localtime" 2>/tmp/.errlog
321 ;;
322 *) config_base_menu
323 ;;
324 esac
325
326 check_for_error
327}
328
329# Generate the installed system's FSTAB
330generate_fstab() {
331
332 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_FstabTitle" \
333 --menu "$_FstabBody" 0 0 3 \
334 "1" "$_FstabDev" \
335 "2" "$_FstabLabel" \
336 "3" "$_FstabUUID" 2>${ANSWER}
337
338 case $(cat ${ANSWER}) in
339 "1") genfstab -p ${MOUNTPOINT} >> ${MOUNTPOINT}/etc/fstab 2>/tmp/.errlog
340 ;;
341 "2") genfstab -L -p ${MOUNTPOINT} >> ${MOUNTPOINT}/etc/fstab 2>/tmp/.errlog
342 ;;
343 "3") if [[ $SYSTEM == "UEFI" ]]; then
344 genfstab -t PARTUUID -p ${MOUNTPOINT} >> ${MOUNTPOINT}/etc/fstab 2>/tmp/.errlog
345 else
346 genfstab -U -p ${MOUNTPOINT} >> ${MOUNTPOINT}/etc/fstab 2>/tmp/.errlog
347 fi
348 ;;
349 *) config_base_menu
350 ;;
351 esac
352
353 check_for_error
354
355 [[ -f ${MOUNTPOINT}/swapfile ]] && sed -i "s/\\${MOUNTPOINT}//" ${MOUNTPOINT}/etc/fstab
356
357
358 # Determine if there is a swapfile before copying over appropriate OB menu
359 if [[ $(cat $MOUNTPOINT/etc/fstab | grep "swap") != "" ]]; then
360 cp -f /inst/menu2.xml $MOUNTPOINT/etc/skel/.config/openbox/menu.xml 2>/tmp/.errlog
361 cp -f /inst/menu2.xml $MOUNTPOINT/home/$ISO_USER/.config/openbox/menu.xml 2>/tmp/.errlog
362 else
363 cp -f /inst/menu.xml $MOUNTPOINT/etc/skel/.config/openbox/menu.xml 2>/tmp/.errlog
364 cp -f /inst/menu.xml $MOUNTPOINT/home/$ISO_USER/.config/openbox/menu.xml 2>/tmp/.errlog
365 fi
366 check_for_error
367
368}
369
370# Set the installed system's hostname
371set_hostname() {
372
373 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_HostNameTitle" --inputbox "$_HostNameBody" 0 0 "MantOS" 2>${ANSWER} || config_base_menu
374 HOST_NAME=$(cat ${ANSWER})
375
376 echo "$HOST_NAME" > ${MOUNTPOINT}/etc/hostname
377 sed -i "s/$ISO_HOST/$HOST_NAME/g" ${MOUNTPOINT}/etc/hosts
378}
379
380# Set the installed system's root password
381set_root_password() {
382
383 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_PassRtTitle" --clear --insecure --passwordbox "$_PassRtBody" 0 0 2> ${ANSWER} || config_base_menu
384 PASSWD=$(cat ${ANSWER})
385
386 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_PassRtTitle" --clear --insecure --passwordbox "$_PassRtBody2" 0 0 2> ${ANSWER} || config_base_menu
387 PASSWD2=$(cat ${ANSWER})
388
389 if [[ $PASSWD == $PASSWD2 ]]; then
390 echo -e "${PASSWD}\n${PASSWD}" > /tmp/.passwd
391 arch_chroot "passwd root" < /tmp/.passwd >/dev/null 2>/tmp/.errlog
392 rm /tmp/.passwd
393 check_for_error
394 else
395 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_PassRtErrTitle" --msgbox "$_PassRtErrBody" 0 0
396 set_root_password
397 fi
398
399}
400
401# Create new user(s) for installed system. First user is created by renaming the live account.
402# All others are brand new.
403create_new_user() {
404
405 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_NUsrTitle" --inputbox "$_NUsrBody" 0 0 "" 2>${ANSWER} || config_user_menu
406 USER=$(cat ${ANSWER})
407
408 # Loop while user name is blank, has spaces, or has capital letters in it.
409 while [[ ${#USER} -eq 0 ]] || [[ $USER =~ \ |\' ]] || [[ $USER =~ [^a-z0-9\ ] ]]; do
410 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_NUsrTitle" --inputbox "$_NUsrErrBody" 0 0 "" 2>${ANSWER} || config_user_menu
411 USER=$(cat ${ANSWER})
412 done
413
414 # Enter password. This step will only be reached where the loop has been skipped or broken.
415 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_PassNUsrTitle" --clear --insecure --passwordbox "$_PassNUsrBody $USER\n\n" 0 0 2> ${ANSWER} || config_base_menu
416 PASSWD=$(cat ${ANSWER})
417
418 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_PassNUsrTitle" --clear --insecure --passwordbox "$_PassNUsrBody2 $USER\n\n" 0 0 2> ${ANSWER} || config_base_menu
419 PASSWD2=$(cat ${ANSWER})
420
421 # loop while passwords entered do not match.
422 while [[ $PASSWD != $PASSWD2 ]]; do
423 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_PassNUsrErrTitle" --msgbox "$_PassNUsrErrBody" 0 0
424
425 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_PassNUsrTitle" --clear --insecure --passwordbox "$_PassNUsrBody $USER\n\n" 0 0 2> ${ANSWER} || config_base_menu
426 PASSWD=$(cat ${ANSWER})
427
428 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_PassNUsrTitle" --clear --insecure --passwordbox "$_PassNUsrBody2 $USER\n\n" 0 0 2> ${ANSWER} || config_base_menu
429 PASSWD2=$(cat ${ANSWER})
430 done
431
432 # State new new user is being created
433 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_NUsrSetTitle" --infobox "$_NUsrSetBody" 0 0
434 sleep 2
435 echo -e "${PASSWD}\n${PASSWD}" > /tmp/.passwd
436
437 # If the first (or only) user account, then change the live account
438 arch_chroot "passwd $ISO_USER" < /tmp/.passwd >/dev/null 2>>/tmp/.errlog
439 check_for_error
440
441 # Distro-specific configuration for entered username
442 sed -i "s/$ISO_USER/$USER/g" ${MOUNTPOINT}/home/$ISO_USER/.gtkrc-2.0 2>/tmp/.errlog
443
444 # Convert live account to entered username - group, password, folder, and ownership
445 sed -i "s/$ISO_USER/$USER/g" ${MOUNTPOINT}/etc/group 2>>/tmp/.errlog
446 sed -i "s/$ISO_USER/$USER/g" ${MOUNTPOINT}/etc/gshadow 2>>/tmp/.errlog
447 sed -i "s/$ISO_USER/$USER/g" ${MOUNTPOINT}/etc/passwd 2>>/tmp/.errlog
448 sed -i "s/$ISO_USER/$USER/g" ${MOUNTPOINT}/etc/shadow 2>>/tmp/.errlog
449 mv ${MOUNTPOINT}/home/$ISO_USER ${MOUNTPOINT}/home/$USER 2>>/tmp/.errlog
450 chown -R $USER:users ${MOUNTPOINT}/home/$USER 2>>/tmp/.errlog
451
452 # Change sudoers file to require passwords for sudo commands
453 sed -i '/%wheel ALL=(ALL) ALL/s/^#//' ${MOUNTPOINT}/etc/sudoers 2>>/tmp/.errlog
454 sed -i '/%wheel ALL=(ALL) ALL NOPASSWD: ALL/s/#%wheel ALL=(ALL) ALL NOPASSWD: ALL//' ${MOUNTPOINT}/etc/sudoers 2>>/tmp/.errlog
455 check_for_error
456
457 cp -rf /etc/skel/.config ~/$USER/
458
459
460 rm /tmp/.passwd
461}
462
463run_mkinitcpio() {
464
465 clear
466
467 # If $LVM is being used, add the lvm2 hook
468 [[ $LVM -eq 1 ]] && sed -i 's/block filesystems/block lvm2 filesystems/g' ${MOUNTPOINT}/etc/mkinitcpio.conf
469
470 # Amend command depending on whether LTS kernel was installed or not
471 [[ $LTS -eq 1 ]] && arch_chroot "mkinitcpio -p linux-lts" 2>/tmp/.errlog || arch_chroot "mkinitcpio -p linux" 2>/tmp/.errlog
472 check_for_error
473
474}
475
476######################################################################
477## ##
478## System and Partitioning Functions ##
479## ##
480######################################################################
481
482
483
484# Unmount partitions.
485umount_partitions(){
486
487 MOUNTED=""
488 MOUNTED=$(mount | grep "${MOUNTPOINT}" | awk '{print $3}' | sort -r)
489 swapoff -a
490
491 for i in ${MOUNTED[@]}; do
492 umount $i >/dev/null 2>>/tmp/.errlog
493 done
494
495 check_for_error
496
497}
498
499# Adapted from AIS
500confirm_mount() {
501 if [[ $(mount | grep $1) ]]; then
502 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_MntStatusTitle" --infobox "$_MntStatusSucc" 0 0
503 sleep 2
504 PARTITIONS="$(echo $PARTITIONS | sed s/${PARTITION}$' -'//)"
505 NUMBER_PARTITIONS=$(( NUMBER_PARTITIONS - 1 ))
506 else
507 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_MntStatusTitle" --infobox "$_MntStatusFail" 0 0
508 sleep 2
509 prep_menu
510 fi
511}
512
513# btrfs specific for subvolumes
514confirm_mount_btrfs() {
515 if [[ $(mount | grep $1) ]]; then
516 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_MntStatusTitle" --infobox "$_MntStatusSucc\n$(cat ${BTRFS_OPTS})",subvol="${BTRFS_MSUB_VOL}\n\n" 0 0
517 sleep 2
518 else
519 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_MntStatusTitle" --infobox "$_MntStatusFail" 0 0
520 sleep 2
521 prep_menu
522 fi
523}
524
525# Adapted from AIS. However, this does not assume that the formatted device is the Root
526# installation device; more than one device may be formatted. This is now set in the
527# mount_partitions function, when the Root is chosen.
528select_device() {
529
530 DEVICE=""
531 devices_list=$(lsblk -d | awk '{print "/dev/" $1}' | grep 'sd\|hd\|vd');
532
533 for i in ${devices_list[@]}; do
534 DEVICE="${DEVICE} ${i} -"
535 done
536
537 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_DevSelTitle" --menu "$_DevSelBody" 0 0 4 ${DEVICE} 2>${ANSWER} || prep_menu
538 DEVICE=$(cat ${ANSWER})
539
540 }
541
542# Same as above, but goes to install_base_menu instead where cancelling, and otherwise installs Grub.
543select_grub_device() {
544
545 GRUB_DEVICE=""
546 grub_devices_list=$(lsblk -d | awk '{print "/dev/" $1}' | grep 'sd\|hd\|vd');
547
548 for i in ${grub_devices_list[@]}; do
549 GRUB_DEVICE="${GRUB_DEVICE} ${i} -"
550 done
551
552 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_DevSelGrubTitle" --menu "$_DevSelBody" 0 0 4 ${GRUB_DEVICE} 2>${ANSWER} || install_base_menu
553 GRUB_DEVICE=$(cat ${ANSWER})
554 clear
555 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " Grub-install " --infobox "$_PlsWaitBody" 0 0
556 sleep 1
557 arch_chroot "grub-install --target=i386-pc --recheck ${GRUB_DEVICE}" 2>/tmp/.errlog
558 check_for_error
559
560 }
561
562# Create partitions.
563create_partitions(){
564
565# This only creates the minimum number of partition(s) necessary. Users wishing for other schemes will
566# have to learn to use a partitioning application.
567auto_partition(){
568
569# Deleting partitions in reverse order deals with logical partitions easily.
570delete_partitions(){
571
572 parted -s ${DEVICE} print | awk '/^ / {print $1}' > /tmp/.del_parts
573
574 for del_part in $(tac /tmp/.del_parts); do
575 parted -s ${DEVICE} rm ${del_part} 2>/tmp/.errlog
576 check_for_error
577 done
578
579
580}
581
582 # Identify the partition table
583 part_table=$(parted -s ${DEVICE} print | grep -i 'partition table' | awk '{print $3}')
584
585 # Autopartition for BIOS systems
586 if [[ $SYSTEM == "BIOS" ]]; then
587 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " Auto-Partition (BIOS/MBR) " --yesno "$_AutoPartBody1 $DEVICE $_AutoPartBIOSBody2" 0 0
588
589 if [[ $? -eq 0 ]]; then
590 delete_partitions
591 if [[ $part_table != "msdos" ]]; then
592 parted -s ${DEVICE} mklabel msdos 2>/tmp/.errlog
593 check_for_error
594 fi
595 parted -s ${DEVICE} mkpart primary ext3 1MiB 100% 2>/tmp/.errlog
596 parted -s ${DEVICE} set 1 boot on 2>>/tmp/.errlog
597 check_for_error
598 echo -e "Partition Scheme:\n" > /tmp/.devlist
599 lsblk ${DEVICE} -o NAME,TYPE,FSTYPE,SIZE > /tmp/.devlist
600 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "" --textbox /tmp/.devlist 0 0
601 else
602 create_partitions
603 fi
604
605 # Autopartition for UEFI systems
606 else
607 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " Auto-Partition (UEFI/GPT) " --yesno "$_AutoPartBody1 $DEVICE $_AutoPartUEFIBody2" 0 0
608
609 if [[ $? -eq 0 ]]; then
610 delete_partitions
611 if [[ $part_table != "gpt" ]]; then
612 parted -s ${DEVICE} mklabel gpt 2>/tmp/.errlog
613 check_for_error
614 fi
615 parted -s ${DEVICE} mkpart ESP fat32 1MiB 513MiB 2>/tmp/.errlog
616 parted -s ${DEVICE} set 1 boot on 2>>/tmp/.errlog
617 parted -s ${DEVICE} mkpart primary ext3 513MiB 100% 2>>/tmp/.errlog
618 echo -e "Partition Scheme:\n" > /tmp/.devlist
619 lsblk ${DEVICE} -o NAME,TYPE,FSTYPE,SIZE >> /tmp/.devlist
620 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "" --textbox /tmp/.devlist 0 0
621 else
622 create_partitions
623 fi
624
625 fi
626
627}
628
629 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_PartToolTitle" \
630 --menu "$_PartToolBody" 0 0 7 \
631 "1" $"Auto Partition" \
632 "2" $"GParted" \
633 "3" $"Parted (BIOS & UEFI)" \
634 "4" $"CFDisk (BIOS/MBR)" \
635 "5" $"CGDisk (UEFI/GPT)" \
636 "6" $"FDisk (BIOS & UEFI)" \
637 "7" $"GDisk (UEFI/GPT)" 2>${ANSWER}
638
639 case $(cat ${ANSWER}) in
640 "1") auto_partition
641 ;;
642 "2") gparted ${DEVICE} >/dev/null 2>&1
643 ;;
644 "3") clear
645 parted ${DEVICE}
646 ;;
647 "4") cfdisk ${DEVICE}
648 ;;
649 "5") cgdisk ${DEVICE}
650 ;;
651 "6") clear
652 fdisk ${DEVICE}
653 ;;
654 "7") clear
655 gdisk ${DEVICE}
656 ;;
657 *) prep_menu
658 ;;
659 esac
660}
661
662# find all available partitions and generate a list of them
663# This also includes partitions on different devices.
664find_partitions() {
665
666 PARTITIONS=""
667 NUMBER_PARTITIONS=0
668 partition_list=$(lsblk -l | grep 'part\|lvm' | sed 's/[\t ].*//' | sort -u)
669
670 for i in ${partition_list[@]}; do
671 PARTITIONS="${PARTITIONS} ${i} -"
672 NUMBER_PARTITIONS=$(( NUMBER_PARTITIONS + 1 ))
673 done
674
675 # Deal with incorrect partitioning
676 if [[ $NUMBER_PARTITIONS -lt 2 ]] && [[ $SYSTEM == "UEFI" ]]; then
677 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_UefiPartErrTitle" --msgbox "$_UefiPartErrBody" 0 0
678 create_partitions
679 fi
680
681 if [[ $NUMBER_PARTITIONS -eq 0 ]] && [[ $SYSTEM == "BIOS" ]]; then
682 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_BiosPartErrTitle" --msgbox "$_BiosPartErrBody" 0 0
683 create_partitions
684 fi
685}
686
687# Set static list of filesystems rather than on-the-fly. Partially as most require additional flags, and
688# partially because some don't seem to be viable.
689select_filesystem(){
690
691# Clear special FS type flags
692BTRFS=0
693
694dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_FSTitle" \
695 --menu "$_FSBody" 0 0 12 \
696 "1" "$_FSSkip" \
697 "2" $"btrfs" \
698 "3" $"ext2" \
699 "4" $"ext3" \
700 "5" $"ext4" \
701 "6" $"f2fs" \
702 "7" $"jfs" \
703 "8" $"nilfs2" \
704 "9" $"ntfs" \
705 "10" $"reiserfs" \
706 "11" $"vfat" \
707 "12" $"xfs" 2>${ANSWER}
708
709 case $(cat ${ANSWER}) in
710 "1") FILESYSTEM="skip"
711 ;;
712 "2") FILESYSTEM="mkfs.btrfs -f"
713 modprobe btrfs
714
715 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_btrfsSVTitle" --yesno "$_btrfsSVBody" 0 0
716 if [[ $? -eq 0 ]];then
717 BTRFS=2
718 else
719 BTRFS=1
720 fi
721
722 ;;
723 "3") FILESYSTEM="mkfs.ext2 -F"
724 ;;
725 "4") FILESYSTEM="mkfs.ext3 -F"
726 ;;
727 "5") FILESYSTEM="mkfs.ext4 -F"
728 ;;
729 "6") FILESYSTEM="mkfs.f2fs"
730 modprobe f2fs
731 ;;
732 "7") FILESYSTEM="mkfs.jfs -q"
733 ;;
734 "8") FILESYSTEM="mkfs.nilfs2 -f"
735 ;;
736 "9") FILESYSTEM="mkfs.ntfs -q"
737 ;;
738 "10") FILESYSTEM="mkfs.reiserfs -f -f"
739 ;;
740 "11") FILESYSTEM="mkfs.vfat -F32"
741 ;;
742 "12") FILESYSTEM="mkfs.xfs -f"
743 ;;
744 *) prep_menu
745 ;;
746 esac
747
748 }
749
750mount_partitions() {
751
752# function created to save repetition of code. Checks and determines if standard partition or LVM LV,
753# and sets the prefix accordingly.
754set_mount_type() {
755
756[[ $(echo ${PARTITION} | grep 'sd\|hd\|vd[a-z][1-99]') != "" ]] && MOUNT_TYPE="/dev/" || MOUNT_TYPE="/dev/mapper/"
757
758}
759
760btrfs_subvols() {
761
762 BTRFS_MSUB_VOL=""
763 BTRFS_OSUB_VOL=""
764 BTRFS_MNT=""
765 BTRFS_VOL_LIST="/tmp/.vols"
766 echo "" > ${BTRFS_VOL_LIST}
767 BTRFS_OSUB_NUM=1
768
769 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_btrfsSVTitle" --inputbox "$_btrfsMSubBody1 ${MOUNTPOINT}${MOUNT} $_btrfsMSubBody2" 0 0 "" 2>${ANSWER} || select_filesystem
770 BTRFS_MSUB_VOL=$(cat ${ANSWER})
771 # if root, then create boot flag for syslinux, systemd-boot and rEFInd bootloaders
772 [[ ${MOUNT} == "" ]] && BTRFS_MNT="rootflags=subvol="$BTRFS_MSUB_VOL
773
774 # Loop while subvolume is blank or has spaces.
775 while [[ ${#BTRFS_MSUB_VOL} -eq 0 ]] || [[ $BTRFS_MSUB_VOL =~ \ |\' ]]; do
776 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_btrfsSVErrTitle" --inputbox "$_btrfsSVErrBody" 0 0 "" 2>${ANSWER} || select_filesystem
777 BTRFS_MSUB_VOL=$(cat ${ANSWER})
778 # if root, then create flag for syslinux, systemd-boot and rEFInd bootloaders
779 [[ ${MOUNT} == "" ]] && BTRFS_MNT="rootflags=subvol="$BTRFS_MSUB_VOL
780 done
781
782 # change dir depending on whether root partition or not
783 [[ ${MOUNT} == "" ]] && cd ${MOUNTPOINT} || cd ${MOUNTPOINT}${MOUNT} 2>/tmp/.errlog
784 btrfs subvolume create ${BTRFS_MSUB_VOL} 2>>/tmp/.errlog
785 cd
786 umount ${MOUNT_TYPE}${PARTITION} 2>>/tmp/.errlog
787 check_for_error
788
789 # Get any mount options and mount
790 btrfs_mount_opts
791 if [[ $(cat ${BTRFS_OPTS}) != "" ]]; then
792 [[ ${MOUNT} == "" ]] && mount -o $(cat ${BTRFS_OPTS})",subvol="${BTRFS_MSUB_VOL} ${MOUNT_TYPE}${PARTITION} ${MOUNTPOINT} 2>/tmp/.errlog || mount -o $(cat ${BTRFS_OPTS})",subvol="${BTRFS_MSUB_VOL} ${MOUNT_TYPE}${PARTITION} ${MOUNTPOINT}${MOUNT} 2>/tmp/.errlog
793 else
794 [[ ${MOUNT} == "" ]] && mount -o "subvol="${BTRFS_MSUB_VOL} ${MOUNT_TYPE}${PARTITION} ${MOUNTPOINT} 2>/tmp/.errlog || mount -o "subvol="${BTRFS_MSUB_VOL} ${MOUNT_TYPE}${PARTITION} ${MOUNTPOINT}${MOUNT} 2>/tmp/.errlog
795 fi
796
797 # Check for error and confirm successful mount
798 check_for_error
799 [[ ${MOUNT} == "" ]] && confirm_mount_btrfs ${MOUNTPOINT} || confirm_mount_btrfs ${MOUNTPOINT}${MOUNT}
800
801 # Now create the subvolumes
802 [[ ${MOUNT} == "" ]] && cd ${MOUNTPOINT} || cd ${MOUNTPOINT}${MOUNT} 2>/tmp/.errlog
803 check_for_error
804
805 # Loop while the termination character has not been entered
806 while [[ $BTRFS_OSUB_VOL != "*" ]]; do
807 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_btrfsSVTitle ($BTRFS_MSUB_VOL) " --inputbox "$_btrfsSVBody1 $BTRFS_OSUB_NUM $_btrfsSVBody2 $BTRFS_MSUB_VOL.$_btrfsSVBody3 $(cat ${BTRFS_VOL_LIST})" 0 0 "" 2>${ANSWER} || select_filesystem
808 BTRFS_OSUB_VOL=$(cat ${ANSWER})
809
810 # Loop while subvolume is blank or has spaces.
811 while [[ ${#BTRFS_OSUB_VOL} -eq 0 ]] || [[ $BTRFS_SUB_VOL =~ \ |\' ]]; do
812 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_btrfsSVErrTitle ($BTRFS_MSUB_VOL) " --inputbox "$_btrfsSVErrBody ($BTRFS_OSUB_NUM)." 0 0 "" 2>${ANSWER} || select_filesystem
813 BTRFS_OSUB_VOL=$(cat ${ANSWER})
814 done
815
816 btrfs subvolume create ${BTRFS_OSUB_VOL} 2>/tmp/.errlog
817 check_for_error
818 BTRFS_OSUB_NUM=$(( BTRFS_OSUB_NUM + 1 ))
819 echo $BTRFS_OSUB_VOL" " >> ${BTRFS_VOL_LIST}
820 done
821
822 # Show the subvolumes created
823 echo -e "btrfs subvols:\n" > /tmp/.subvols
824 ls >> /tmp/.subvols
825 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --textbox /tmp/.subvols 0 0
826 cd
827}
828
829# This function allows for btrfs-specific mounting options to be applied. Written as a seperate function
830# for neatness.
831btrfs_mount_opts() {
832
833 echo "" > ${BTRFS_OPTS}
834
835 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_btrfsMntTitle" --checklist "$_btrfsMntBody" 0 0 16 \
836 "1" "autodefrag" off \
837 "2" "compress=zlib" off \
838 "3" "compress=lzo" off \
839 "4" "compress=no" off \
840 "5" "compress-force=zlib" off \
841 "6" "compress-force=lzo" off \
842 "7" "discard" off \
843 "8" "noacl" off \
844 "9" "noatime" off \
845 "10" "nodatasum" off \
846 "11" "nospace_cache" off \
847 "12" "recovery" off \
848 "13" "skip_balance" off \
849 "14" "space_cache" off \
850 "15" "ssd" off \
851 "16" "ssd_spread" off 2>${BTRFS_OPTS}
852
853 # Double-digits first
854 sed -i 's/10/nodatasum,/' ${BTRFS_OPTS}
855 sed -i 's/11/nospace_cache,/' ${BTRFS_OPTS}
856 sed -i 's/12/recovery,/' ${BTRFS_OPTS}
857 sed -i 's/13/skip_balance,/' ${BTRFS_OPTS}
858 sed -i 's/14/space_cache,/' ${BTRFS_OPTS}
859 sed -i 's/15/ssd,/' ${BTRFS_OPTS}
860 sed -i 's/16/ssd_spread,/' ${BTRFS_OPTS}
861 # then single digits
862 sed -i 's/1/autodefrag,/' ${BTRFS_OPTS}
863 sed -i 's/2/compress=zlib,/' ${BTRFS_OPTS}
864 sed -i 's/3/compress=lzo,/' ${BTRFS_OPTS}
865 sed -i 's/4/compress=no,/' ${BTRFS_OPTS}
866 sed -i 's/5/compress-force=zlib,/' ${BTRFS_OPTS}
867 sed -i 's/6/compress-force=lzo,/' ${BTRFS_OPTS}
868 sed -i 's/7/noatime,/' ${BTRFS_OPTS}
869 sed -i 's/8/noacl,/' ${BTRFS_OPTS}
870 sed -i 's/9/noatime,/' ${BTRFS_OPTS}
871 # Now clean up the file
872 sed -i 's/ //g' ${BTRFS_OPTS}
873 sed -i '$s/,$//' ${BTRFS_OPTS}
874
875
876 if [[ $(cat ${BTRFS_OPTS}) != "" ]]; then
877 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_btrfsMntTitle" --yesno "$_btrfsMntConfBody $(cat $BTRFS_OPTS)\n" 0 0
878 [[ $? -eq 1 ]] && btrfs_mount_opts
879 fi
880
881}
882
883 # LVM Detection. If detected, activate.
884 detect_lvm
885 if [[ $LVM -eq 1 ]]; then
886 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmDetTitle" --infobox "$_LvmDetBody2" 0 0
887 sleep 2
888 modprobe dm-mod 2>/tmp/.errlog
889 check_for_error
890 vgscan >/dev/null 2>&1
891 vgchange -ay >/dev/null 2>&1
892 fi
893
894 # Ensure partitions are unmounted (i.e. where mounted previously), and then list available partitions
895 umount_partitions
896 find_partitions
897
898 # Identify and mount root
899 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_SelRootTitle" --menu "$_SelRootBody" 0 0 4 ${PARTITIONS} 2>${ANSWER} || prep_menu
900 PARTITION=$(cat ${ANSWER})
901 ROOT_PART=${PARTITION}
902 set_mount_type
903
904 # This is to identify the device for Grub installations.
905 if [[ $MOUNT_TYPE == "/dev/" ]]; then
906 LVM_ROOT=0
907 INST_DEV=${MOUNT_TYPE}$(cat ${ANSWER} | sed 's/[0-9]*//g')
908 else
909 LVM_ROOT=1
910 fi
911
912 select_filesystem
913 [[ $FILESYSTEM != "skip" ]] && ${FILESYSTEM} ${MOUNT_TYPE}${PARTITION} >/dev/null 2>/tmp/.errlog
914 check_for_error
915
916 # Make the root directory
917 mkdir -p ${MOUNTPOINT} 2>/tmp/.errlog
918
919 # If btrfs without subvolumes has been selected, get the mount options
920 [[ $BTRFS -eq 1 ]] && btrfs_mount_opts
921
922 # If btrfs has been selected without subvolumes - and at least one btrfs mount option selected - then
923 # mount with options. Otherwise, basic mount.
924 if [[ $BTRFS -eq 1 ]] && [[ $(cat ${BTRFS_OPTS}) != "" ]]; then
925 mount -o $(cat ${BTRFS_OPTS}) ${MOUNT_TYPE}${PARTITION} ${MOUNTPOINT} 2>>/tmp/.errlog
926 else
927 mount ${MOUNT_TYPE}${PARTITION} ${MOUNTPOINT} 2>>/tmp/.errlog
928 fi
929
930 # Check for error, confirm mount, and deal with BTRFS with subvolumes if applicable
931 check_for_error
932 confirm_mount ${MOUNTPOINT}
933 [[ $BTRFS -eq 2 ]] && btrfs_subvols
934
935 # Identify and create swap, if applicable
936 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_SelSwpTitle" --menu "$_SelSwpBody" 0 0 4 "$_SelSwpNone" $"-" "$_SelSwpFile" $"-" ${PARTITIONS} 2>${ANSWER} || prep_menu
937 if [[ $(cat ${ANSWER}) != "$_SelSwpNone" ]]; then
938 PARTITION=$(cat ${ANSWER})
939
940 if [[ $PARTITION == "$_SelSwpFile" ]]; then
941 total_memory=`grep MemTotal /proc/meminfo | awk '{print $2/1024}' | sed 's/\..*//'`
942 fallocate -l ${total_memory}M ${MOUNTPOINT}/swapfile >/dev/null 2>/tmp/.errlog
943 check_for_error
944 chmod 600 ${MOUNTPOINT}/swapfile >/dev/null 2>&1
945 mkswap ${MOUNTPOINT}/swapfile >/dev/null 2>&1
946 swapon ${MOUNTPOINT}/swapfile >/dev/null 2>&1
947 else
948 set_mount_type
949 mkswap ${MOUNT_TYPE}${PARTITION} >/dev/null 2>/tmp/.errlog
950 swapon ${MOUNT_TYPE}${PARTITION} >/dev/null 2>>/tmp/.errlog
951 check_for_error
952 # Since a partition was used, remove that partition from the list
953 PARTITIONS="$(echo $PARTITIONS | sed s/${PARTITION}$' -'//)"
954 NUMBER_PARTITIONS=$(( NUMBER_PARTITIONS - 1 ))
955 fi
956 fi
957
958 # Extra Step for VFAT UEFI Partition. This cannot be in an LVM container.
959 if [[ $SYSTEM == "UEFI" ]]; then
960
961 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_SelUefiTitle" --menu "$_SelUefiBody" 0 0 4 ${PARTITIONS} 2>${ANSWER} || config_base_menu
962 PARTITION=$(cat ${ANSWER})
963 UEFI_PART=$"/dev/"${PARTITION}
964
965 # If it is already a fat/vfat partition...
966 if [[ $(fsck -N /dev/$PARTITION | grep fat) ]]; then
967 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_FormUefiTitle" --yesno "$_FormUefiBody $PARTITION $_FormUefiBody2" 0 0 && mkfs.vfat -F32 $"/dev/"${PARTITION} >/dev/null 2>/tmp/.errlog
968 else
969 mkfs.vfat -F32 $"/dev/"${PARTITION} >/dev/null 2>/tmp/.errlog
970 fi
971 check_for_error
972
973 # Inform users of the mountpoint options and consequences
974 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_MntUefiTitle" --menu "$_MntUefiBody" 0 0 2 \
975 "1" $"/boot" \
976 "2" $"/boot/efi" 2>${ANSWER}
977
978 case $(cat ${ANSWER}) in
979 "1") UEFI_MOUNT="/boot"
980 ;;
981 "2") UEFI_MOUNT="/boot/efi"
982 ;;
983 *) config_base_menu
984 ;;
985 esac
986
987 mkdir -p ${MOUNTPOINT}${UEFI_MOUNT} 2>/tmp/.errlog
988 mount $"/dev/"${PARTITION} ${MOUNTPOINT}${UEFI_MOUNT} 2>>/tmp/.errlog
989 check_for_error
990 confirm_mount ${MOUNTPOINT}${UEFI_MOUNT}
991
992 fi
993
994 # All other partitions
995 while [[ $NUMBER_PARTITIONS > 0 ]]; do
996 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ExtPartTitle" --menu "$_ExtPartBody" 0 0 4 "$_Done" $"-" ${PARTITIONS} 2>${ANSWER} || config_base_menu
997 PARTITION=$(cat ${ANSWER})
998 set_mount_type
999
1000 if [[ $PARTITION == ${_Done} ]]; then
1001 break;
1002 else
1003 MOUNT=""
1004
1005 select_filesystem
1006 [[ $FILESYSTEM != "skip" ]] && ${FILESYSTEM} ${MOUNT_TYPE}${PARTITION} >/dev/null 2>/tmp/.errlog
1007 check_for_error
1008
1009 # Don't give /boot as an example for UEFI systems!
1010 if [[ $SYSTEM == "UEFI" ]]; then
1011 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ExtNameTitle $PARTITON " --inputbox "$_ExtNameBodyUefi" 0 0 "/" 2>${ANSWER} || config_base_menu
1012 else
1013 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ExtNameTitle $PARTITON " --inputbox "$_ExtNameBodyBios" 0 0 "/" 2>${ANSWER} || config_base_menu
1014 fi
1015 MOUNT=$(cat ${ANSWER})
1016
1017 # loop if the mountpoint specified is incorrect (is only '/', is blank, or has spaces).
1018 while [[ ${MOUNT:0:1} != "/" ]] || [[ ${#MOUNT} -le 1 ]] || [[ $MOUNT =~ \ |\' ]]; do
1019 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ExtErrTitle" --msgbox "$_ExtErrBody" 0 0
1020
1021 # Don't give /boot as an example for UEFI systems!
1022 if [[ $SYSTEM == "UEFI" ]]; then
1023 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ExtNameTitle $PARTITON " --inputbox "$_ExtNameBodyUefi" 0 0 "/" 2>${ANSWER} || config_base_menu
1024 else
1025 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ExtNameTitle $PARTITON " --inputbox "$_ExtNameBodyBios" 0 0 "/" 2>${ANSWER} || config_base_menu
1026 fi
1027 MOUNT=$(cat ${ANSWER})
1028 done
1029
1030 # Create directory and mount. This step will only be reached where the loop has been skipped or broken.
1031 mkdir -p ${MOUNTPOINT}${MOUNT} 2>/tmp/.errlog
1032
1033 # If btrfs without subvolumes has been selected, get the mount options
1034 [[ $BTRFS -eq 1 ]] && btrfs_mount_opts
1035
1036 # If btrfs has been selected without subvolumes - and at least one btrfs mount option selected - then
1037 # mount with options. Otherwise, basic mount.
1038 if [[ $BTRFS -eq 1 ]] && [[ $(cat ${BTRFS_OPTS}) != "" ]]; then
1039 mount -o $(cat ${BTRFS_OPTS}) ${MOUNT_TYPE}${PARTITION} ${MOUNTPOINT}${MOUNT} 2>>/tmp/.errlog
1040 else
1041 mount ${MOUNT_TYPE}${PARTITION} ${MOUNTPOINT}${MOUNT} 2>>/tmp/.errlog
1042 fi
1043
1044 # Check for error, confirm mount, and deal with BTRFS with subvolumes if applicable
1045 check_for_error
1046 confirm_mount ${MOUNTPOINT}${MOUNT}
1047 [[ $BTRFS -eq 2 ]] && btrfs_subvols
1048
1049 # Determine if a seperate /boot is used, and if it is LVM or not
1050 LVM_SEP_BOOT=0
1051 if [[ $MOUNT == "/boot" ]]; then
1052 [[ $MOUNT_TYPE == "/dev/" ]] && LVM_SEP_BOOT=1 || LVM_SEP_BOOT=2
1053 fi
1054 fi
1055 done
1056}
1057
1058######################################################################
1059## ##
1060## Logical Volume Management Functions ##
1061## ##
1062######################################################################
1063
1064
1065# LVM Detection.
1066detect_lvm() {
1067
1068 LVM_PV=$(pvs -o pv_name --noheading 2>/dev/null)
1069 LVM_VG=$(vgs -o vg_name --noheading 2>/dev/null)
1070 LVM_LV=$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)
1071
1072 if [[ $LVM_LV = "" ]] && [[ $LVM_VG = "" ]] && [[ $LVM_PV = "" ]]; then
1073 LVM=0
1074 else
1075 LVM=1
1076 fi
1077
1078}
1079
1080# Where existing LVM is found, offer to deactivate it. Code adapted from the Manjaro installer.
1081# NEED TO ADD COMMAND TO REMOVE LVM2 FSTYPE.
1082deactivate_lvm() {
1083
1084 LVM_DISABLE=0
1085
1086 if [[ $LVM -eq 1 ]]; then
1087 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmDetTitle" --yesno "$_LvmDetBody1" 0 0 \
1088 && LVM_DISABLE=1 || LVM_DISABLE=0
1089 fi
1090
1091 if [[ $LVM_DISABLE -eq 1 ]]; then
1092 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmRmTitle" --infobox "$_LvmRmBody" 0 0
1093 sleep 2
1094
1095 for i in ${LVM_LV}; do
1096 lvremove -f /dev/mapper/${i} >/dev/null 2>&1
1097 done
1098
1099 for i in ${LVM_VG}; do
1100 vgremove -f ${i} >/dev/null 2>&1
1101 done
1102
1103 for i in ${LV_PV}; do
1104 pvremove -f ${i} >/dev/null 2>&1
1105 done
1106
1107 # This step will remove old lvm metadata on partitions where identified.
1108 LVM_PT=$(lvmdiskscan | grep 'LVM physical volume' | grep 'sd[a-z]' | sed 's/\/dev\///' | awk '{print $1}')
1109 for i in ${LVM_PT}; do
1110 dd if=/dev/zero bs=512 count=512 of=/dev/${i} >/dev/null 2>&1
1111 done
1112 fi
1113
1114}
1115
1116# Find and create a list of partitions that can be used for LVM. Partitions already used are excluded.
1117find_lvm_partitions() {
1118
1119 LVM_PARTITIONS=""
1120 NUMBER_LVM_PARTITIONS=0
1121 lvm_partition_list=$(lvmdiskscan | grep -v 'LVM physical volume' | grep 'sd[a-z][1-99]' | sed 's/\/dev\///' | awk '{print $1}')
1122
1123 for i in ${lvm_partition_list[@]}; do
1124 LVM_PARTITIONS="${LVM_PARTITIONS} ${i} -"
1125 NUMBER_LVM_PARTITIONS=$(( NUMBER_LVM_PARTITIONS + 1 ))
1126 done
1127
1128}
1129
1130# This simplifies the creation of the PV and VG into a single step.
1131create_lvm() {
1132
1133# subroutine to save a lot of repetition.
1134check_lv_size() {
1135
1136 LV_SIZE_INVALID=0
1137 LV_SIZE_TYPE=$(echo ${LVM_LV_SIZE:$(( ${#LVM_LV_SIZE} - 1 )):1})
1138 chars=0
1139
1140 # Check to see if anything was actually entered
1141 [[ ${#LVM_LV_SIZE} -eq 0 ]] && LV_SIZE_INVALID=1
1142
1143 # Check if there are any non-numeric characters prior to the last one
1144 while [[ $chars -lt $(( ${#LVM_LV_SIZE} - 1 )) ]]; do
1145 if [[ ${LVM_LV_SIZE:chars:1} != [0-9] ]]; then
1146 LV_SIZE_INVALID=1
1147 break;
1148 fi
1149 chars=$(( chars + 1 ))
1150 done
1151
1152 # Check to see if first character is '0'
1153 [[ ${LVM_LV_SIZE:0:1} -eq "0" ]] && LV_SIZE_INVALID=1
1154
1155 # Check to see if last character is "G" or "M", and if so, whether the value is greater than
1156 # or equal to the LV remaining Size. If not, convert into MB for VG space remaining.
1157 if [[ ${LV_SIZE_INVALID} -eq 0 ]]; then
1158 case ${LV_SIZE_TYPE} in
1159 "G") if [[ $(( $(echo ${LVM_LV_SIZE:0:$(( ${#LVM_LV_SIZE} - 1 ))}) * 1000 )) -ge ${LVM_VG_MB} ]]; then
1160 LV_SIZE_INVALID=1
1161 else
1162 LVM_VG_MB=$(( LVM_VG_MB - $(( $(echo ${LVM_LV_SIZE:0:$(( ${#LVM_LV_SIZE} - 1 ))}) * 1000 )) ))
1163 fi
1164 ;;
1165 "M") if [[ $(echo ${LVM_LV_SIZE:0:$(( ${#LVM_LV_SIZE} - 1 ))}) -ge ${LVM_VG_MB} ]]; then
1166 LV_SIZE_INVALID=1
1167 else
1168 LVM_VG_MB=$(( LVM_VG_MB - $(echo ${LVM_LV_SIZE:0:$(( ${#LVM_LV_SIZE} - 1 ))}) ))
1169 fi
1170 ;;
1171 *) LV_SIZE_INVALID=1
1172 ;;
1173 esac
1174 fi
1175
1176}
1177
1178 # Check that there is at least one partition available for LVM
1179 if [[ $NUMBER_LVM_PARTITIONS -lt 1 ]]; then
1180 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmPartErrTitle" --msgbox "$_LvmPartErrBody" 0 0
1181 prep_menu
1182 fi
1183
1184 # Create a temporary file to store the partition(s) selected. This is later used for the vgcreate command. 'x' is used as a marker.
1185 echo "x" > /tmp/.vgcreate
1186
1187 # Name the Volume Group
1188 LVM_VG=""
1189 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmNameVgTitle" --inputbox "$_LvmNameVgBody" 0 0 "" 2>${ANSWER} || prep_menu
1190 LVM_VG=$(cat ${ANSWER})
1191
1192 # Loop while the Volume Group name starts with a "/", is blank, has spaces, or is already being used
1193 while [[ ${LVM_VG:0:1} == "/" ]] || [[ ${#LVM_VG} -eq 0 ]] || [[ $LVM_VG =~ \ |\' ]] || [[ $(lsblk | grep ${LVM_VG}) != "" ]]; do
1194 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmNameVgErrTitle" --msgbox "$_LvmNameVgErr" 0 0
1195
1196 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmNameVgTitle" --inputbox "$_LvmNameVgBody" 0 0 "" 2>${ANSWER} || prep_menu
1197 LVM_VG=$(cat ${ANSWER})
1198 done
1199
1200 # Select the first or only partition for the Volume Group
1201 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmPvSelTitle" --menu "$_LvmPvSelBody" 0 0 4 ${LVM_PARTITIONS} 2>${ANSWER} || prep_menu
1202 LVM_PARTITION=$(cat ${ANSWER})
1203
1204 # add the partition to the temporary file for the vgcreate command
1205 # Remove selected partition from the list and deduct number of LVM viable partitions remaining
1206 sed -i "s/x/\/dev\/${LVM_PARTITION} x/" /tmp/.vgcreate
1207 LVM_PARTITIONS="$(echo $LVM_PARTITIONS | sed s/${LVM_PARTITION}$' -'//)"
1208 NUMBER_LVM_PARTITIONS=$(( NUMBER_LVM_PARTITIONS - 1 ))
1209 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmPvCreateTitle" --infobox "\n$_Done\n\n" 0 0
1210 sleep 1
1211
1212 # Where there are viable partitions still remaining, run loop
1213 while [[ $NUMBER_LVM_PARTITIONS -gt 0 ]]; do
1214
1215 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmPvSelTitle" --menu "$_LvmPvSelBody" 0 0 4 $"Done" $"-" ${LVM_PARTITIONS} 2>${ANSWER} || prep_menu
1216 LVM_PARTITION=$(cat ${ANSWER})
1217
1218 if [[ $LVM_PARTITION == "Done" ]]; then
1219 break;
1220 else
1221 sed -i "s/x/\/dev\/${LVM_PARTITION} x/" /tmp/.vgcreate
1222 LVM_PARTITIONS="$(echo $LVM_PARTITIONS | sed s/${LVM_PARTITION}$' -'//)"
1223 NUMBER_LVM_PARTITIONS=$(( NUMBER_LVM_PARTITIONS - 1 ))
1224 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmPvCreateTitle" --infobox "\n$_Done\n\n" 0 0
1225 sleep 1
1226 fi
1227
1228 done
1229
1230 # Once all the partitions have been selected, remove 'x' from the .vgcreate file, then use it in 'vgcreate' command.
1231 # Also determine the size of the VG, to use for creating LVs for it.
1232 VG_PARTS=$(cat /tmp/.vgcreate | sed 's/x//')
1233 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmPvConfTitle" --yesno "$_LvmPvConfBody1${LVM_VG} $_LvmPvConfBody2${VG_PARTS}" 0 0
1234
1235 if [[ $? -eq 0 ]]; then
1236 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmPvActTitle" --infobox "$_LvmPvActBody1${LVM_VG}.$_LvmPvActBody2" 0 0
1237 sleep 2
1238 vgcreate -f ${LVM_VG} ${VG_PARTS} >/dev/null 2>/tmp/.errlog
1239 check_for_error
1240 VG_SIZE=$(vgdisplay | grep 'VG Size' | awk '{print $3}' | sed 's/\..*//')
1241 VG_SIZE_TYPE=$(vgdisplay | grep 'VG Size' | awk '{print $4}' | sed 's/\..*//')
1242 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmPvDoneTitle" --msgbox "$_LvmPvDoneBody1 '${LVM_VG}' $_LvmPvDoneBody2 (${VG_SIZE} ${VG_SIZE_TYPE}).\n\n" 0 0
1243 sleep 2
1244 else
1245 prep_menu
1246 fi
1247
1248 # Convert the VG size into GB and MB. These variables are used to keep tabs on space available and remaining
1249 [[ ${VG_SIZE_TYPE:0:1} == "G" ]] && LVM_VG_MB=$(( VG_SIZE * 1000 )) || LVM_VG_MB=$VG_SIZE
1250
1251 # Specify number of Logical volumes to create.
1252 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvNumTitle" --inputbox "$_LvmLvNumBody1 ${LVM_VG}.$_LvmLvNumBody2" 0 0 "" 2>${ANSWER} || prep_menu
1253 NUMBER_LOGICAL_VOLUMES=$(cat ${ANSWER})
1254
1255 # Loop if the number of LVs is no 1-9 (including non-valid characters)
1256 while [[ $NUMBER_LOGICAL_VOLUMES != [1-9] ]]; do
1257 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvNumErrTitle" --msgbox "$_LvmLvNumErrBody" 0 0
1258
1259 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvNumTitle" --inputbox "$_LvmLvNumBody1 ${LVM_VG}.$_LvmLvNumBody2" 0 0 "" 2>${ANSWER} || prep_menu
1260 NUMBER_LOGICAL_VOLUMES=$(cat ${ANSWER})
1261 done
1262
1263 # Loop while the number of LVs is greater than 1. This is because the size of the last LV is automatic.
1264 while [[ $NUMBER_LOGICAL_VOLUMES -gt 1 ]]; do
1265 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvNameTitle" --inputbox "$_LvmLvNameBody1" 0 0 "lvol" 2>${ANSWER} || prep_menu
1266 LVM_LV_NAME=$(cat ${ANSWER})
1267
1268 # Loop if preceeded with a "/", if nothing is entered, if there is a space, or if that name already exists.
1269 while [[ ${LVM_LV_NAME:0:1} == "/" ]] || [[ ${#LVM_LV_NAME} -eq 0 ]] || [[ ${LVM_LV_NAME} =~ \ |\' ]] || [[ $(lsblk | grep ${LVM_LV_NAME}) != "" ]]; do
1270 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvNameErrTitle" --msgbox "$_LvmLvNameErrBody" 0 0
1271
1272 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvNameTitle" --inputbox "$_LvmLvNameBody1" 0 0 "lvol" 2>${ANSWER} || prep_menu
1273 LVM_LV_NAME=$(cat ${ANSWER})
1274 done
1275
1276 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvSizeTitle" --inputbox "\n${LVM_VG}: ${VG_SIZE}${VG_SIZE_TYPE} (${LVM_VG_MB}MB $_LvmLvSizeBody1).$_LvmLvSizeBody2" 0 0 "" 2>${ANSWER} || prep_menu
1277 LVM_LV_SIZE=$(cat ${ANSWER})
1278 check_lv_size
1279
1280 # Loop while an invalid value is entered.
1281 while [[ $LV_SIZE_INVALID -eq 1 ]]; do
1282 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvSizeErrTitle" --msgbox "$_LvmLvSizeErrBody" 0 0
1283
1284 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvSizeTitle" --inputbox "\n${LVM_VG}: ${VG_SIZE}${VG_SIZE_TYPE} (${LVM_VG_MB}MB $_LvmLvSizeBody1).$_LvmLvSizeBody2" 0 0 "" 2>${ANSWER} || prep_menu
1285 LVM_LV_SIZE=$(cat ${ANSWER})
1286 check_lv_size
1287 done
1288
1289 # Create the LV
1290 lvcreate -L ${LVM_LV_SIZE} ${LVM_VG} -n ${LVM_LV_NAME} 2>/tmp/.errlog
1291 check_for_error
1292 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvDoneTitle" --msgbox "\n$_Done\n\nLV ${LVM_LV_NAME} (${LVM_LV_SIZE}) $_LvmPvDoneBody2.\n\n" 0 0
1293 NUMBER_LOGICAL_VOLUMES=$(( NUMBER_LOGICAL_VOLUMES - 1 ))
1294 done
1295
1296 # Now the final LV. Size is automatic.
1297 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvNameTitle" --inputbox "$_LvmLvNameBody1 $_LvmLvNameBody2 (${LVM_VG_MB}MB)." 0 0 "lvol" 2>${ANSWER} || prep_menu
1298 LVM_LV_NAME=$(cat ${ANSWER})
1299
1300 # Loop if preceeded with a "/", if nothing is entered, if there is a space, or if that name already exists.
1301 while [[ ${LVM_LV_NAME:0:1} == "/" ]] || [[ ${#LVM_LV_NAME} -eq 0 ]] || [[ ${LVM_LV_NAME} =~ \ |\' ]] || [[ $(lsblk | grep ${LVM_LV_NAME}) != "" ]]; do
1302 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvNameErrTitle" --msgbox "$_LvmLvNameErrBody" 0 0
1303
1304 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmLvNameTitle" --inputbox "$_LvmLvNameBody1 $_LvmLvNameBody2 (${LVM_VG_MB}MB)." 0 0 "lvol" 2>${ANSWER} || prep_menu
1305 LVM_LV_NAME=$(cat ${ANSWER})
1306 done
1307
1308 # Create the final LV
1309 lvcreate -l +100%FREE ${LVM_VG} -n ${LVM_LV_NAME} 2>/tmp/.errlog
1310 check_for_error
1311 NUMBER_LVM_PARTITIONS=$(( NUMBER_LVM_PARTITIONS - 1 ))
1312 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_LvmCompTitle" --yesno "$_LvmCompBody" 0 0 \
1313 && show_devices || prep_menu
1314}
1315
1316######################################################################
1317## ##
1318## Installation Functions ##
1319## ##
1320######################################################################
1321
1322install_root(){
1323
1324 clear
1325
1326 # Change installation method depending on use of img or sfs
1327 if [[ -e /run/archiso/sfs/airootfs/airootfs.img ]]; then
1328 AIROOTIMG="/run/archiso/sfs/airootfs/airootfs.img"
1329 mkdir -p ${BYPASS} 2>/tmp/.errlog
1330 mount ${AIROOTIMG} ${BYPASS} 2>>/tmp/.errlog
1331 rsync -a --progress ${BYPASS} ${MOUNTPOINT}/ 2>>/tmp/.errlog
1332 umount -l ${BYPASS}
1333 else
1334 AIROOTIMG="/run/archiso/sfs/airootfs/"
1335 rsync -a --progress ${AIROOTIMG} ${MOUNTPOINT}/ 2>/tmp/.errlog
1336 fi
1337
1338 check_for_error
1339
1340 # Keyboard config for vc and x11
1341 [[ -e /tmp/vconsole.conf ]] && cp /tmp/vconsole.conf ${MOUNTPOINT}/etc/vconsole.conf 2>>/tmp/.errlog
1342 [[ -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
1343
1344 # set up kernel for mkiniticpio
1345 cp /run/archiso/bootmnt/arch/boot/${ARCHI}/vmlinuz ${MOUNTPOINT}/boot/vmlinuz-linux 2>>/tmp/.errlog
1346
1347 # copy over new mirrorlist
1348 cp /etc/pacman.d/mirrorlist ${MOUNTPOINT}/etc/pacman.d/mirrorlist 2>>/tmp/.errlog
1349
1350 # Clean up installation
1351 [[ -d ${MOUNTPOINT}/abif-master ]] && rm -R ${MOUNTPOINT}/abif-master 2>>/tmp/.errlog
1352 [[ -d ${MOUNTPOINT}/aif-master ]] && rm -R ${MOUNTPOINT}/abif-master 2>>/tmp/.errlog
1353 [[ -d ${MOUNTPOINT}/inst ]] && rm -R ${MOUNTPOINT}/inst &> /dev/null 2>>/tmp/.errlog
1354 rm -f ${MOUNTPOINT}/usr/bin/lastmin 2>>/tmp/.errlog
1355 rm -rf ${MOUNTPOINT}/vomi 2>>/tmp/.errlog
1356 rm -rf ${BYPASS} 2>>/tmp/.errlog
1357 rm -rf ${MOUNTPOINT}/source 2>>/tmp/.errlog
1358 rm -rf ${MOUNTPOINT}/src 2>>/tmp/.errlog
1359 rmdir ${MOUNTPOINT}/bypass 2>>/tmp/.errlog
1360 rmdir ${MOUNTPOINT}/src 2>>/tmp/.errlog
1361 rmdir ${MOUNTPOINT}/source 2>>/tmp/.errlog
1362 rm -f ${MOUNTPOINT}/etc/sudoers.d/g_wheel 2>>/tmp/.errlog
1363 rm -f ${MOUNTPOINT}/var/lib/NetworkManager/NetworkManager.state 2>>/tmp/.errlog
1364 rm -f ${MOUNTPOINT}/update-abif 2>>/tmp/.errlog
1365 sed -i 's/.*pam_wheel\.so/#&/' ${MOUNTPOINT}/etc/pam.d/su 2>>/tmp/.errlog
1366
1367 # clean out archiso files from install
1368 find ${MOUNTPOINT}/usr/lib/initcpio -name archiso* -type f -exec rm '{}' \;
1369
1370 # systemd
1371 rm -R ${MOUNTPOINT}/etc/systemd/system/getty@tty1.service.d 2>>/tmp/.errlog
1372 rm ${MOUNTPOINT}/etc/systemd/system/default.target 2>>/tmp/.errlog
1373
1374
1375 # Journal
1376 sed -i 's/volatile/auto/g' ${MOUNTPOINT}/etc/systemd/journald.conf 2>>/tmp/.errlog
1377
1378 # Stop pacman complaining
1379 arch_chroot "mkdir -p /var/lib/pacman/sync" 2>>/tmp/.errlog
1380 arch_chroot "touch /var/lib/pacman/sync/{core.db,extra.db,community.db}" 2>>/tmp/.errlog
1381
1382 # Fix NetworkManager
1383 arch_chroot "systemctl enable NetworkManager -f" 2>>/tmp/.errlog
1384
1385 # Keyboard config for vc and x11
1386 [[ -e /tmp/vconsole.conf ]] && cp /tmp/vconsole.conf ${MOUNTPOINT}/etc/vconsole.conf 2>>/tmp/.errlog
1387 [[ -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
1388 check_for_error
1389}
1390
1391# Install Bootloader
1392install_bootloader() {
1393
1394bios_bootloader() {
1395
1396 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_InstBiosBtTitle" \
1397 --menu "$_InstBiosBtBody" 0 0 2 \
1398 "1" $"Grub2" \
1399 "2" $"Syslinux" 2>${ANSWER}
1400
1401 case $(cat ${ANSWER}) in
1402 "1") # GRUB
1403 if [[ $LVM_ROOT -eq 1 ]]; then
1404 select_grub_device
1405 else
1406 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_InstGrubDevTitle" --yesno "$_InstGrubDevBody ($INST_DEV)?$_InstGrubDevBody2" 0 0
1407
1408 if [[ $? -eq 0 ]]; then
1409 clear
1410 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " Grub-install " --infobox "$_PlsWaitBody" 0 0
1411 sleep 1
1412 arch_chroot "grub-install --target=i386-pc --recheck ${INST_DEV}" 2>/tmp/.errlog
1413 check_for_error
1414 else
1415 select_grub_device
1416 fi
1417
1418 fi
1419
1420 arch_chroot "grub-mkconfig -o /boot/grub/grub.cfg" 2>/tmp/.errlog
1421 check_for_error
1422
1423 # if /boot is LVM then amend /boot/grub/grub.cfg accordingly
1424 if ( [[ $LVM_ROOT -eq 1 ]] && [[ $LVM_SEP_BOOT -eq 0 ]] ) || [[ $LVM_SEP_BOOT -eq 2 ]]; then
1425 sed -i '/### BEGIN \/etc\/grub.d\/00_header ###/a insmod lvm' ${MOUNTPOINT}/boot/grub/grub.cfg
1426 fi
1427 BOOTLOADER="Grub"
1428 ;;
1429 "2") # Syslinux
1430 arch_chroot "syslinux-install_update -iam" 2>/tmp/.errlog
1431 check_for_error
1432
1433 # Amend configuration file depending on whether lvm used or not for root.
1434 if [[ $LVM_ROOT -eq 0 ]]; then
1435 sed -i "s/sda[0-9]/${ROOT_PART}/g" ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1436 else
1437 sed -i "s/APPEND.*/APPEND root=\/dev\/mapper\/${ROOT_PART} rw/g" ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1438 fi
1439
1440 # Amend configuration file for LTS kernel and/or btrfs subvolume as root
1441 [[ $LTS -eq 1 ]] && sed -i 's/linux/linux-lts/g' ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1442 [[ $BTRFS_MNT != "" ]] && sed -i "s/rw/rw $BTRFS_MNT/g" ${MOUNTPOINT}/boot/syslinux/syslinux.cfg
1443
1444 BOOTLOADER="Syslinux"
1445 ;;
1446 *) install_base_menu
1447 ;;
1448 esac
1449}
1450
1451uefi_bootloader() {
1452
1453 #Ensure again that efivarfs is mounted
1454 [[ -z $(mount | grep /sys/firmware/efi/efivars) ]] && mount -t efivarfs efivarfs /sys/firmware/efi/efivars
1455
1456 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_InstUefiBtTitle" \
1457 --menu "$_InstUefiBtBody" 0 0 3 \
1458 "1" $"Grub2" \
1459 "2" $"rEFInd" \
1460 "3" $"systemd-boot" 2>${ANSWER}
1461
1462 case $(cat ${ANSWER}) in
1463 "1") # GRUB
1464 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title " Grub-install " --infobox "$_PlsWaitBody" 0 0
1465 sleep 1
1466 arch_chroot "grub-install --target=x86_64-efi --efi-directory=${UEFI_MOUNT} --bootloader-id=arch_grub --recheck" 2>/tmp/.errlog
1467 arch_chroot "grub-mkconfig -o /boot/grub/grub.cfg" 2>>/tmp/.errlog
1468 check_for_error
1469
1470 # Ask if user wishes to set Grub as the default bootloader and act accordingly
1471 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_SetGrubDefTitle" --yesno "$_SetGrubDefBody ${UEFI_MOUNT}/EFI/boot $_SetGrubDefBody2" 0 0
1472
1473 if [[ $? -eq 0 ]]; then
1474 arch_chroot "mkdir ${UEFI_MOUNT}/EFI/boot" 2>/tmp/.errlog
1475 arch_chroot "cp -r ${UEFI_MOUNT}/EFI/arch_grub/grubx64.efi ${UEFI_MOUNT}/EFI/boot/bootx64.efi" 2>>/tmp/.errlog
1476 check_for_error
1477 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_SetDefDoneTitle" --infobox "\nGrub $_SetDefDoneBody" 0 0
1478 sleep 2
1479 fi
1480
1481 BOOTLOADER="Grub"
1482 ;;
1483
1484 "2") # rEFInd
1485 if [[ $UEFI_MOUNT == "/boot/efi" ]]; then
1486 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_SetRefiDefTitle" --yesno "$_SetRefiDefBody ${UEFI_MOUNT}/EFI/boot $_SetRefiDefBody2" 0 0
1487
1488 if [[ $? -eq 0 ]]; then
1489 clear
1490 arch_chroot "refind-install --usedefault ${UEFI_PART} --alldrivers" 2>/tmp/.errlog
1491 else
1492 clear
1493 arch_chroot "refind-install" 2>/tmp/.errlog
1494 fi
1495
1496 check_for_error
1497
1498 # Now generate config file to pass kernel parameters. Default read only (ro) changed to read-write (rw),
1499 # and amend where using btfs subvol root
1500 arch_chroot "refind-mkrlconf" 2>/tmp/.errlog
1501 check_for_error
1502 sed -i 's/ro /rw /g' ${MOUNTPOINT}/boot/refind_linux.conf
1503 [[ $BTRFS_MNT != "" ]] && sed -i "s/rw/rw $BTRFS_MNT/g" ${MOUNTPOINT}/boot/refind_linux.conf
1504
1505 BOOTLOADER="rEFInd"
1506 else
1507 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_RefiErrTitle" --msgbox "$_RefiErrBody" 0 0
1508 uefi_bootloader
1509 fi
1510 ;;
1511
1512 "3") # systemd-boot
1513 arch_chroot "bootctl --path=${UEFI_MOUNT} install" 2>>/tmp/.errlog
1514 check_for_error
1515
1516 # Deal with LVM Root
1517 if [[ $LVM_ROOT -eq 0 ]]; then
1518 sysdb_root=$(blkid -s PARTUUID $"/dev/"${ROOT_PART} | sed 's/.*=//g' | sed 's/"//g')
1519 else
1520 sysdb_root="/dev/mapper/${ROOT_PART}"
1521 fi
1522
1523 # Deal with LTS Kernel
1524 if [[ $LTS -eq 1 ]]; then
1525 echo -e "title\tMantOS Linux\nlinux\t/vmlinuz-linux-lts\ninitrd\t/initramfs-linux-lts.img\noptions\troot=PARTUUID=${sysdb_root} rw" > ${MOUNTPOINT}${UEFI_MOUNT}/loader/entries/MantOS.conf
1526 else
1527 echo -e "title\tMantOS Linux\nlinux\t/vmlinuz-linux\ninitrd\t/initramfs-linux.img\noptions\troot=PARTUUID=${sysdb_root} rw" > ${MOUNTPOINT}${UEFI_MOUNT}/loader/entries/MantOS.conf
1528 fi
1529
1530 # Fix LVM Root installations, and deal with btrfs root subvolume mounting
1531 [[ $LVM_ROOT -eq 1 ]] && sed -i "s/PARTUUID=//g" ${MOUNTPOINT}${UEFI_MOUNT}/loader/entries/MantOS.conf
1532 [[ $BTRFS_MNT != "" ]] && sed -i "s/rw/rw $BTRFS_MNT/g" ${MOUNTPOINT}${UEFI_MOUNT}/loader/entries/MantOS.conf
1533
1534 BOOTLOADER="systemd-boot"
1535 # Set the loader file
1536 echo -e "default MantOS\ntimeout 5" > ${MOUNTPOINT}${UEFI_MOUNT}/loader/loader.conf 2>/tmp/.errlog
1537 check_for_error
1538 ;;
1539
1540 *) install_base_menu
1541 ;;
1542 esac
1543
1544}
1545 check_mount
1546 # Set the default PATH variable
1547 arch_chroot "PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl" 2>/tmp/.errlog
1548 check_for_error
1549
1550 if [[ $SYSTEM == "BIOS" ]]; then
1551 bios_bootloader
1552 else
1553 uefi_bootloader
1554 fi
1555}
1556
1557######################################################################
1558## ##
1559## Main Interfaces ##
1560## ##
1561######################################################################
1562
1563# Greet the user when first starting the installer
1564greeting() {
1565
1566dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_WelTitle $VERSION " --msgbox "$_WelBody" 0 0
1567
1568}
1569
1570# Preparation
1571prep_menu() {
1572
1573 if [[ $SUB_MENU != "prep_menu" ]]; then
1574 SUB_MENU="prep_menu"
1575 HIGHLIGHT_SUB=1
1576 else
1577 if [[ $HIGHLIGHT_SUB != 7 ]]; then
1578 HIGHLIGHT_SUB=$(( HIGHLIGHT_SUB + 1 ))
1579 fi
1580 fi
1581
1582 dialog --default-item ${HIGHLIGHT_SUB} --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_PrepTitle" \
1583 --menu "$_PrepBody" 0 0 7 \
1584 "1" "$_ConfBseVirtCon" \
1585 "2" "$_PrepKBLayout" \
1586 "3" "$_DevShowOpt" \
1587 "4" "$_PrepPartDisk" \
1588 "5" "$_PrepLVM" \
1589 "6" "$_PrepMntPart" \
1590 "7" "$_Back" 2>${ANSWER}
1591
1592 HIGHLIGHT_SUB=$(cat ${ANSWER})
1593 case $(cat ${ANSWER}) in
1594 "1") set_keymap
1595 ;;
1596 "2") set_xkbmap
1597 ;;
1598 "3") show_devices
1599 ;;
1600 "4") umount_partitions
1601 select_device
1602 create_partitions
1603 ;;
1604 "5") detect_lvm
1605 deactivate_lvm
1606 find_lvm_partitions
1607 create_lvm
1608 ;;
1609 "6") mount_partitions
1610 ;;
1611 *) main_menu
1612 ;;
1613 esac
1614
1615 prep_menu
1616
1617}
1618
1619# Base Installation
1620install_root_menu() {
1621
1622 if [[ $SUB_MENU != "install_base_menu" ]]; then
1623 SUB_MENU="install_base_menu"
1624 HIGHLIGHT_SUB=1
1625 else
1626 if [[ $HIGHLIGHT_SUB != 4 ]]; then
1627 HIGHLIGHT_SUB=$(( HIGHLIGHT_SUB + 1 ))
1628 fi
1629 fi
1630
1631 dialog --default-item ${HIGHLIGHT_SUB} --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_InstBsMenuTitle" --menu "$_InstBseMenuBody" 0 0 4 \
1632 "1" "$_InstBse" \
1633 "2" "$_MMRunMkinit" \
1634 "3" "$_InstBootldr" \
1635 "4" "$_Back" 2>${ANSWER}
1636
1637 HIGHLIGHT_SUB=$(cat ${ANSWER})
1638 case $(cat ${ANSWER}) in
1639 "1") install_root
1640 ;;
1641 "2") run_mkinitcpio
1642 ;;
1643 "3") install_bootloader
1644 ;;
1645 *) main_menu
1646 ;;
1647 esac
1648
1649 install_root_menu
1650}
1651
1652# Base Configuration
1653config_base_menu() {
1654
1655 # Set the default PATH variable
1656 arch_chroot "PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl" 2>/tmp/.errlog
1657 check_for_error
1658
1659 if [[ $SUB_MENU != "config_base_menu" ]]; then
1660 SUB_MENU="config_base_menu"
1661 HIGHLIGHT_SUB=1
1662 else
1663 if [[ $HIGHLIGHT_SUB != 8 ]]; then
1664 HIGHLIGHT_SUB=$(( HIGHLIGHT_SUB + 1 ))
1665 fi
1666 fi
1667
1668 dialog --default-item ${HIGHLIGHT_SUB} --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_ConfBseTitle" --menu "$_ConfBseBody" 0 0 8 \
1669 "1" "$_ConfBseFstab" \
1670 "2" "$_ConfBseHost" \
1671 "3" "$_ConfBseTime" \
1672 "4" "$_ConfBseHWC" \
1673 "5" "$_ConfBseSysLoc" \
1674 "6" "$_ConfUsrRoot" \
1675 "7" "$_ConfUsrNew" \
1676 "8" "$_Back" 2>${ANSWER}
1677
1678 HIGHLIGHT_SUB=$(cat ${ANSWER})
1679 case $(cat ${ANSWER}) in
1680 "1") generate_fstab
1681 ;;
1682 "2") set_hostname
1683 ;;
1684 "3") set_timezone
1685 ;;
1686 "4") set_hw_clock
1687 ;;
1688 "5") set_locale
1689 ;;
1690 "6") set_root_password
1691 ;;
1692 "7") create_new_user
1693 ;;
1694 *) main_menu
1695 ;;
1696 esac
1697
1698 config_base_menu
1699
1700}
1701
1702# Edit configs of installed system
1703edit_configs() {
1704
1705 # Clear the file variables
1706 FILE=""
1707 FILE2=""
1708
1709 if [[ $SUB_MENU != "edit configs" ]]; then
1710 SUB_MENU="edit configs"
1711 HIGHLIGHT_SUB=1
1712 else
1713 if [[ $HIGHLIGHT_SUB != 10 ]]; then
1714 HIGHLIGHT_SUB=$(( HIGHLIGHT_SUB + 1 ))
1715 fi
1716 fi
1717
1718 dialog --default-item ${HIGHLIGHT_SUB} --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_SeeConfOptTitle" --menu "$_SeeConfOptBody" 0 0 11 \
1719 "1" "/etc/vconsole.conf" \
1720 "2" "/etc/locale.conf" \
1721 "3" "/etc/hostname" \
1722 "4" "/etc/hosts" \
1723 "5" "/etc/sudoers" \
1724 "6" "/etc/mkinitcpio.conf" \
1725 "7" "/etc/fstab" \
1726 "8" "$BOOTLOADER" \
1727 "9" "/etc/pacman.conf" \
1728 "10" "/etc/pacman.d/mirrorlist" \
1729 "11" "$_Back" 2>${ANSWER}
1730
1731 HIGHLIGHT_SUB=$(cat ${ANSWER})
1732 case $(cat ${ANSWER}) in
1733 "1") FILE="${MOUNTPOINT}/etc/vconsole.conf"
1734 ;;
1735 "2") FILE="${MOUNTPOINT}/etc/locale.conf"
1736 ;;
1737 "3") FILE="${MOUNTPOINT}/etc/hostname"
1738 ;;
1739 "4") FILE="${MOUNTPOINT}/etc/hosts"
1740 ;;
1741 "5") FILE="${MOUNTPOINT}/etc/sudoers"
1742 ;;
1743 "6") FILE="${MOUNTPOINT}/etc/mkinitcpio.conf"
1744 ;;
1745 "7") FILE="${MOUNTPOINT}/etc/fstab"
1746 ;;
1747 "8") case $BOOTLOADER in
1748 "Grub") FILE="${MOUNTPOINT}/etc/default/grub"
1749 ;;
1750 "Syslinux") FILE="${MOUNTPOINT}/boot/syslinux/syslinux.cfg"
1751 ;;
1752 "systemd-boot") FILE="${MOUNTPOINT}${UEFI_MOUNT}/loader/entries/MantOS.conf"
1753 FILE2="${MOUNTPOINT}${UEFI_MOUNT}/loader/loader.conf"
1754 ;;
1755 "rEFInd") [[ -e ${MOUNTPOINT}${UEFI_MOUNT}/EFI/refind/refind.conf ]] \
1756 && FILE="${MOUNTPOINT}${UEFI_MOUNT}/EFI/refind/refind.conf" || FILE="${MOUNTPOINT}${UEFI_MOUNT}/EFI/BOOT/refind.conf"
1757 FILE2="${MOUNTPOINT}/boot/refind_linux.conf"
1758 ;;
1759 esac
1760 ;;
1761 "9") FILE="${MOUNTPOINT}/etc/pacman.conf"
1762 ;;
1763 "10") FILE="${MOUNTPOINT}/etc/pacman.d/mirrorlist"
1764 ;;
1765 *) main_menu
1766 ;;
1767 esac
1768
1769 # open file(s) with nano
1770 if [[ -e $FILE ]] && [[ $FILE2 != "" ]]; then
1771 nano $FILE $FILE2
1772 elif [[ -e $FILE ]]; then
1773 nano $FILE
1774 else
1775 dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_SeeConfErrTitle" --msgbox "$_SeeConfErrBody1" 0 0
1776 fi
1777
1778 edit_configs
1779}
1780
1781main_menu() {
1782
1783 if [[ $HIGHLIGHT != 5 ]]; then
1784 HIGHLIGHT=$(( HIGHLIGHT + 1 ))
1785 fi
1786
1787 dialog --default-item ${HIGHLIGHT} --backtitle "$VERSION - $SYSTEM ($ARCHI)" --title "$_MMTitle" \
1788 --menu "$_MMBody" 0 0 5 \
1789 "1" "$_MMPrep" \
1790 "2" "$_MMInstBse" \
1791 "3" "$_MMConfBse" \
1792 "4" "$_SeeConfOpt" \
1793 "5" "$_Done" 2>${ANSWER}
1794
1795 HIGHLIGHT=$(cat ${ANSWER})
1796
1797 # Depending on the answer, first check whether partition(s) are mounted and whether base has been installed
1798 if [[ $(cat ${ANSWER}) -eq 2 ]]; then
1799 check_mount
1800 fi
1801
1802 if [[ $(cat ${ANSWER}) -ge 3 ]] && [[ $(cat ${ANSWER}) -le 4 ]]; then
1803 check_mount
1804 check_base
1805 fi
1806
1807 case $(cat ${ANSWER}) in
1808 "1") prep_menu
1809 ;;
1810 "2") install_root_menu
1811 ;;
1812 "3") config_base_menu
1813 ;;
1814 "4") edit_configs
1815 ;;
1816 *) dialog --backtitle "$VERSION - $SYSTEM ($ARCHI)" --yesno "$_CloseInstBody" 0 0
1817
1818 if [[ $? -eq 0 ]]; then
1819 umount_partitions
1820 clear
1821 exit 0
1822 else
1823 main_menu
1824 fi
1825
1826 ;;
1827 esac
1828
1829 main_menu
1830
1831}
1832
1833######################################################################
1834## ##
1835## Execution ##
1836## ##
1837######################################################################
1838select_language
1839check_system
1840
1841 while true; do
1842 main_menu
1843 done