#!/bin/bash

config_locale() {
	local LOCALE
	LOCALE=$(whiptail --title "Language selection" --menu "Choose your language:" 20 90 10 \
	"aa_DJ.UTF-8 UTF-8" "Afar" \
	"aa_ER UTF-8" "Afar" \
	"aa_ET UTF-8" "Afar" \
	"af_ZA.UTF-8 UTF-8" "Afrikaans" \
	"agr_PE UTF-8" "Aguaruna" \
	"ak_GH UTF-8" "Akan" \
	"am_ET UTF-8" "Amharic" \
	"an_ES.UTF-8 UTF-8" "Aragonese" \
	"anp_IN UTF-8" "Angika" \
	"ar_AE.UTF-8 UTF-8" "Arabic" \
	"ar_BH.UTF-8 UTF-8" "Arabic" \
	"ar_DZ.UTF-8 UTF-8" "Arabic" \
	"ar_EG.UTF-8 UTF-8" "Arabic" \
	"ar_IN UTF-8" "Arabic" \
	"ar_IQ.UTF-8 UTF-8" "Arabic" \
	"ar_JO.UTF-8 UTF-8" "Arabic" \
	"ar_KW.UTF-8 UTF-8" "Arabic" \
	"ar_LB.UTF-8 UTF-8" "Arabic" \
	"ar_LY.UTF-8 UTF-8" "Arabic" \
	"ar_MA.UTF-8 UTF-8" "Arabic" \
	"ar_OM.UTF-8 UTF-8" "Arabic" \
	"ar_QA.UTF-8 UTF-8" "Arabic" \
	"ar_SA.UTF-8 UTF-8" "Arabic" \
	"ar_SD.UTF-8 UTF-8" "Arabic" \
	"ar_SS UTF-8" "Arabic" \
	"ar_SY.UTF-8 UTF-8" "Arabic" \
	"ar_TN.UTF-8 UTF-8" "Arabic" \
	"ar_YE.UTF-8 UTF-8" "Arabic" \
	"ayc_PE UTF-8" "Southern Aymara" \
	"az_AZ UTF-8" "Azerbaijani" \
	"az_IR UTF-8" "Azerbaijani" \
	"as_IN UTF-8" "Assamese" \
	"ast_ES.UTF-8 UTF-8" "Asturian" \
	"be_BY.UTF-8 UTF-8" "Belarusian" \
	"be_BY@latin UTF-8" "Belarusian" \
	"bem_ZM UTF-8" "Bemba (Zambia)" \
	"ber_DZ UTF-8" "Berber languages" \
	"ber_MA UTF-8" "Berber languages" \
	"bg_BG.UTF-8 UTF-8" "Bulgarian" \
	"bhb_IN.UTF-8 UTF-8" "Bhili" \
	"bho_IN UTF-8" "Bhojpuri" \
	"bho_NP UTF-8" "Bhojpuri" \
	"bi_VU UTF-8" "Bislama" \
	"bn_BD UTF-8" "Bengali" \
	"bn_IN UTF-8" "Bengali" \
	"bo_CN UTF-8" "Tibetan" \
	"bo_IN UTF-8" "Tibetan" \
	"br_FR.UTF-8 UTF-8" "Breton" \
	"br_FR@euro ISO-8859-15" "Breton" \
	"brx_IN UTF-8" "Bodo (India)" \
	"bs_BA.UTF-8 UTF-8" "Bosnian" \
	"byn_ER UTF-8" "Bilin" \
	"ca_AD.UTF-8 UTF-8" "Catalan" \
	"ca_ES.UTF-8 UTF-8" "Catalan" \
	"ca_ES@euro ISO-8859-15" "Catalan" \
	"ca_ES@valencia UTF-8" "Catalan" \
	"ca_FR.UTF-8 UTF-8" "Catalan" \
	"ca_IT.UTF-8 UTF-8" "Catalan" \
	"ce_RU UTF-8" "Chechen" \
	"chr_US UTF-8" "Cherokee" \
	"ckb_IQ UTF-8" "Central Kurdish" \
	"cmn_TW UTF-8" "Mandarin Chinese" \
	"crh_RU UTF-8" "Crimean Tatar" \
	"crh_UA UTF-8" "Crimean Tatar" \
	"csb_PL UTF-8" "Kashubian" \
	"cs_CZ.UTF-8 UTF-8" "Czech" \
	"cv_RU UTF-8" "Chuvash" \
	"cy_GB.UTF-8 UTF-8" "Welsh" \
	"da_DK.UTF-8 UTF-8" "Danish" \
	"de_AT.UTF-8 UTF-8" "German" \
	"de_AT@euro ISO-8859-15" "German" \
	"de_BE.UTF-8 UTF-8" "German" \
	"de_BE@euro ISO-8859-15" "German" \
	"de_CH.UTF-8 UTF-8" "German" \
	"de_DE.UTF-8 UTF-8" "German" \
	"de_DE@euro ISO-8859-15" "German" \
	"de_IT.UTF-8 UTF-8" "German" \
	"de_LI.UTF-8 UTF-8" "German" \
	"de_LU.UTF-8 UTF-8" "German" \
	"de_LU@euro ISO-8859-15" "German" \
	"doi_IN UTF-8" "Dogri (macrolanguage)" \
	"dsb_DE UTF-8" "Lower Sorbian" \
	"dv_MV UTF-8" "Dhivehi" \
	"dz_BT UTF-8" "Dzongkha" \
	"el_CY.UTF-8 UTF-8" "Modern Greek" \
	"el_GR.UTF-8 UTF-8" "Modern Greek" \
	"el_GR@euro ISO-8859-7" "Modern Greek" \
	"en_AG UTF-8" "English" \
	"en_AU.UTF-8 UTF-8" "English" \
	"en_BW.UTF-8 UTF-8" "English" \
	"en_CA.UTF-8 UTF-8" "English" \
	"en_DK.UTF-8 UTF-8" "English" \
	"en_GB.UTF-8 UTF-8" "English" \
	"en_HK.UTF-8 UTF-8" "English" \
	"en_IE.UTF-8 UTF-8" "English" \
	"en_IE@euro ISO-8859-15" "English" \
	"en_IL UTF-8" "English" \
	"en_IN UTF-8" "English" \
	"en_NG UTF-8" "English" \
	"en_NZ.UTF-8 UTF-8" "English" \
	"en_PH.UTF-8 UTF-8" "English" \
	"en_SC.UTF-8 UTF-8" "English" \
	"en_SG.UTF-8 UTF-8" "English" \
	"en_US.UTF-8 UTF-8" "English" \
	"en_ZA.UTF-8 UTF-8" "English" \
	"en_ZM UTF-8" "English" \
	"en_ZW.UTF-8 UTF-8" "English" \
	"eo UTF-8" "Esperanto" \
	"es_AR.UTF-8 UTF-8" "Spanish" \
	"es_BO.UTF-8 UTF-8" "Spanish" \
	"es_CL.UTF-8 UTF-8" "Spanish" \
	"es_CO.UTF-8 UTF-8" "Spanish" \
	"es_CR.UTF-8 UTF-8" "Spanish" \
	"es_CU UTF-8" "Spanish" \
	"es_DO.UTF-8 UTF-8" "Spanish" \
	"es_EC.UTF-8 UTF-8" "Spanish" \
	"es_ES.UTF-8 UTF-8" "Spanish" \
	"es_ES@euro ISO-8859-15" "Spanish" \
	"es_GT.UTF-8 UTF-8" "Spanish" \
	"es_HN.UTF-8 UTF-8" "Spanish" \
	"es_MX.UTF-8 UTF-8" "Spanish" \
	"es_NI.UTF-8 UTF-8" "Spanish" \
	"es_PA.UTF-8 UTF-8" "Spanish" \
	"es_PE.UTF-8 UTF-8" "Spanish" \
	"es_PR.UTF-8 UTF-8" "Spanish" \
	"es_PY.UTF-8 UTF-8" "Spanish" \
	"es_SV.UTF-8 UTF-8" "Spanish" \
	"es_US.UTF-8 UTF-8" "Spanish" \
	"es_UY.UTF-8 UTF-8" "Spanish" \
	"es_VE.UTF-8 UTF-8" "Spanish" \
	"et_EE.UTF-8 UTF-8" "Estonian" \
	"eu_ES.UTF-8 UTF-8" "Basque" \
	"eu_ES@euro ISO-8859-15" "Basque" \
	"fa_IR UTF-8" "Persian" \
	"ff_SN UTF-8" "Fulah" \
	"fi_FI.UTF-8 UTF-8" "Finnish" \
	"fi_FI@euro ISO-8859-15" "Finnish" \
	"fil_PH UTF-8" "Filipino" \
	"fo_FO.UTF-8 UTF-8" "Faroese" \
	"fr_BE.UTF-8 UTF-8" "French" \
	"fr_BE@euro ISO-8859-15" "French" \
	"fr_CA.UTF-8 UTF-8" "French" \
	"fr_CH.UTF-8 UTF-8" "French" \
	"fr_FR.UTF-8 UTF-8" "French" \
	"fr_FR@euro ISO-8859-15" "French" \
	"fr_LU.UTF-8 UTF-8" "French" \
	"fr_LU@euro ISO-8859-15" "French" \
	"fur_IT UTF-8" "Friulian" \
	"fy_DE UTF-8" "Western Frisian" \
	"fy_NL UTF-8" "Western Frisian" \
	"ga_IE UTF-8" "Irish" \
	"ga_IE@euro ISO-8859-15" "Irish" \
	"gbm_IN UTF-8" "Garhwali" \
	"gd_GB UTF-8" "Scottish Gaelic" \
	"gez_ER UTF-8" "Geez" \
	"gez_ER@abegede UTF-8" "Geez" \
	"gez_ET UTF-8" "Geez" \
	"gez_ET@abegede UTF-8" "Geez" \
	"gl_ES UTF-8" "Galician" \
	"gl_ES@euro ISO-8859-15" "Galician" \
	"gu_IN UTF-8" "Gujarati" \
	"gv_GB.UTF-8 UTF-8" "Manx" \
	"hak_TW UTF-8" "Hakka Chinese" \
	"ha_NG UTF-8" "Hausa" \
	"he_IL.UTF-8 UTF-8" "Hebrew" \
	"hif_FJ UTF-8" "Fiji Hindi" \
	"hi_IN UTF-8" "Hindi" \
	"hne_IN UTF-8" "Chhattisgarhi" \
	"hr_HR.UTF-8 UTF-8" "Croatian" \
	"hsb_DE.UTF-8 UTF-8" "Upper Sorbian" \
	"ht_HT UTF-8" "Haitian" \
	"hu_HU.UTF-8 UTF-8" "Hungarian" \
	"hy_AM UTF-8" "Armenian" \
	"ia_FR UTF-8" "Interlingua (International Auxiliary Language Association)" \
	"id_ID.UTF-8 UTF-8" "Indonesian" \
	"ig_NG UTF-8" "Igbo" \
	"ik_CA UTF-8" "Inupiaq" \
	"is_IS.UTF-8 UTF-8" "Icelandic" \
	"it_CH.UTF-8 UTF-8" "Italian" \
	"it_IT.UTF-8 UTF-8" "Italian" \
	"it_IT@euro ISO-8859-15" "Italian" \
	"iu_CA UTF-8" "Inuktitut" \
	"ja_JP.UTF-8 UTF-8" "Japanese" \
	"kab_DZ UTF-8" "Kabyle" \
	"ka_GE.UTF-8 UTF-8" "Georgian" \
	"kk_KZ.UTF-8 UTF-8" "Kazakh" \
	"kl_GL.UTF-8 UTF-8" "Kalaallisut" \
	"km_KH UTF-8" "Central Khmer" \
	"kn_IN UTF-8" "Kannada" \
	"kok_IN UTF-8" "Konkani (macrolanguage)" \
	"ko_KR.UTF-8 UTF-8" "Korean" \
	"ks_IN UTF-8" "Kashmiri" \
	"ks_IN@devanagari UTF-8" "Kashmiri" \
	"ku_TR.UTF-8 UTF-8" "Kurdish" \
	"kw_GB.UTF-8 UTF-8" "Cornish" \
	"ky_KG UTF-8" "Kirghiz" \
	"lb_LU UTF-8" "Luxembourgish" \
	"lg_UG.UTF-8 UTF-8" "Ganda" \
	"li_BE UTF-8" "Limburgan" \
	"lij_IT UTF-8" "Ligurian" \
	"li_NL UTF-8" "Limburgan" \
	"ln_CD UTF-8" "Lingala" \
	"lo_LA UTF-8" "Lao" \
	"lt_LT.UTF-8 UTF-8" "Lithuanian" \
	"ltg_LV.UTF-8 UTF-8" "Latgalian" \
	"lv_LV.UTF-8 UTF-8" "Latvian" \
	"lzh_TW UTF-8" "Literary Chinese" \
	"mag_IN UTF-8" "Magahi" \
	"mai_IN UTF-8" "Maithili" \
	"mai_NP UTF-8" "Maithili" \
	"mdf_RU UTF-8" "Moksha" \
	"mfe_MU UTF-8" "Morisyen" \
	"mg_MG.UTF-8 UTF-8" "Malagasy" \
	"mhr_RU UTF-8" "Eastern Mari" \
	"mi_NZ.UTF-8 UTF-8" "Maori" \
	"miq_NI UTF-8" "Mískito" \
	"mjw_IN UTF-8" "Karbi" \
	"mk_MK.UTF-8 UTF-8" "Macedonian" \
	"ml_IN UTF-8" "Malayalam" \
	"mni_IN UTF-8" "Manipuri" \
	"mn_MN UTF-8" "Mongolian" \
	"mnw_MM UTF-8" "Mon" \
	"mr_IN UTF-8" "Marathi" \
	"ms_MY.UTF-8 UTF-8" "Malay (macrolanguage)" \
	"mt_MT.UTF-8 UTF-8" "Maltese" \
	"my_MM UTF-8" "Burmese" \
	"nan_TW UTF-8" "Min Nan Chinese" \
	"nan_TW@latin UTF-8" "Min Nan Chinese" \
	"nb_NO.UTF-8 UTF-8" "Norwegian Bokmål" \
	"nds_DE UTF-8" "Low German" \
	"nds_NL UTF-8" "Low German" \
	"ne_NP UTF-8" "Nepali" \
	"nhn_MX UTF-8" "Central Nahuatl" \
	"niu_NU UTF-8" "Niuean" \
	"niu_NZ UTF-8" "Niuean" \
	"nl_AW UTF-8" "Dutch" \
	"nl_BE.UTF-8 UTF-8" "Dutch" \
	"nl_BE@euro ISO-8859-15" "Dutch" \
	"nl_NL.UTF-8 UTF-8" "Dutch" \
	"nl_NL@euro ISO-8859-15" "Dutch" \
	"nn_NO.UTF-8 UTF-8" "Norwegian Nynorsk" \
	"nr_ZA UTF-8" "South Ndebele" \
	"nso_ZA UTF-8" "Pedi" \
	"oc_FR.UTF-8 UTF-8" "Occitan (post 1500)" \
	"om_ET UTF-8" "Oromo" \
	"om_KE.UTF-8 UTF-8" "Oromo" \
	"or_IN UTF-8" "Oriya" \
	"os_RU UTF-8" "Ossetian" \
	"pa_IN UTF-8" "Panjabi" \
	"pap_AW UTF-8" "Papiamento" \
	"pap_CW UTF-8" "Papiamento" \
	"pa_PK UTF-8" "Panjabi" \
	"pl_PL.UTF-8 UTF-8" "Polish" \
	"ps_AF UTF-8" "Pushto" \
	"pt_BR.UTF-8 UTF-8" "Portuguese" \
	"pt_PT.UTF-8 UTF-8" "Portuguese" \
	"pt_PT@euro ISO-8859-15" "Portuguese" \
	"quz_PE UTF-8" "Cusco Quechua" \
	"raj_IN UTF-8" "Rajasthani" \
	"rif_MA UTF-8" "Tarifit" \
	"ro_RO.UTF-8 UTF-8" "Romanian" \
	"ru_RU.UTF-8 UTF-8" "Russian" \
	"ru_UA.UTF-8 UTF-8" "Russian" \
	"rw_RW UTF-8" "Kinyarwanda" \
	"sah_RU UTF-8" "Yakut" \
	"sa_IN UTF-8" "Sanskrit" \
	"sat_IN UTF-8" "Santali" \
	"sc_IT UTF-8" "Sardinian" \
	"scn_IT UTF-8" "Sicilian" \
	"sd_IN UTF-8" "Sindhi" \
	"sd_IN@devanagari UTF-8" "Sindhi" \
	"se_NO UTF-8" "Northern Sami" \
	"sgs_LT UTF-8" "Samogitian" \
	"shn_MM UTF-8" "Shan" \
	"shs_CA UTF-8" "Shuswap" \
	"sid_ET UTF-8" "Sidamo" \
	"si_LK UTF-8" "Sinhala" \
	"sk_SK.UTF-8 UTF-8" "Slovak" \
	"sl_SI.UTF-8 UTF-8" "Slovenian" \
	"sm_WS UTF-8" "Samoan" \
	"so_DJ.UTF-8 UTF-8" "Somali" \
	"so_ET UTF-8" "Somali" \
	"so_KE.UTF-8 UTF-8" "Somali" \
	"so_SO.UTF-8 UTF-8" "Somali" \
	"sq_AL.UTF-8 UTF-8" "Albanian" \
	"sq_MK UTF-8" "Albanian" \
	"sr_ME UTF-8" "Serbian" \
	"sr_RS UTF-8" "Serbian" \
	"sr_RS@latin UTF-8" "Serbian" \
	"ss_ZA.UTF-8 UTF-8" "Swati" \
	"st_ZA.UTF-8 UTF-8" "Southern Sotho" \
	"sv_FI.UTF-8 UTF-8" "Swedish" \
	"sv_FI@euro ISO-8859-15" "Swedish" \
	"sv_SE.UTF-8 UTF-8" "Swedish" \
	"sw_KE UTF-8" "Swahili (macrolanguage)" \
	"sw_TZ UTF-8" "Swahili (macrolanguage)" \
	"syr UTF-8" "Syriac" \
	"szl_PL UTF-8" "Silesian" \
	"ta_IN UTF-8" "Tamil" \
	"ta_LK UTF-8" "Tamil" \
	"tcy_IN.UTF-8 UTF-8" "Tulu" \
	"te_IN UTF-8" "Telugu" \
	"tg_TJ.UTF-8 UTF-8" "Tajik" \
	"the_NP UTF-8" "Chitwania Tharu" \
	"th_TH.UTF-8 UTF-8" "Thai" \
	"ti_ER UTF-8" "Tigrinya" \
	"ti_ET UTF-8" "Tigrinya" \
	"tig_ER UTF-8" "Tigre" \
	"tk_TM UTF-8" "Turkmen" \
	"tl_PH.UTF-8 UTF-8" "Tagalog" \
	"tn_ZA UTF-8" "Tswana" \
	"to_TO UTF-8" "Tonga (Tonga Islands)" \
	"tpi_PG UTF-8" "Tok Pisin" \
	"tr_CY.UTF-8 UTF-8" "Turkish" \
	"tr_TR.UTF-8 UTF-8" "Turkish" \
	"ts_ZA UTF-8" "Tsonga" \
	"tt_RU UTF-8" "Tatar" \
	"tt_RU@iqtelif UTF-8" "Tatar" \
	"ug_CN UTF-8" "Uighur" \
	"uk_UA.UTF-8 UTF-8" "Ukrainian" \
	"unm_US UTF-8" "Unami" \
	"ur_IN UTF-8" "Urdu" \
	"ur_PK UTF-8" "Urdu" \
	"uz_UZ.UTF-8 UTF-8" "Uzbek" \
	"uz_UZ@cyrillic UTF-8" "Uzbek" \
	"ve_ZA UTF-8" "Venda" \
	"vi_VN UTF-8" "Vietnamese" \
	"wa_BE.UTF-8 UTF-8" "Walloon" \
	"wa_BE@euro ISO-8859-15" "Walloon" \
	"wae_CH UTF-8" "Walser" \
	"wal_ET UTF-8" "Wolaytta" \
	"wo_SN UTF-8" "Wolof" \
	"xh_ZA.UTF-8 UTF-8" "Xhosa" \
	"yi_US.UTF-8 UTF-8" "Yiddish" \
	"yo_NG UTF-8" "Yoruba" \
	"yue_HK UTF-8" "Yue Chinese" \
	"yuw_PG UTF-8" "Yau (Morobe Province)" \
	"zgh_MA UTF-8" "Standard Moroccan Tamazight (Morocco)" \
	"zh_CN.UTF-8 UTF-8" "Chinese" \
	"zh_HK.UTF-8 UTF-8" "Chinese" \
	"zh_SG.UTF-8 UTF-8" "Chinese" \
	"zh_TW.UTF-8 UTF-8" "Chinese" \
	"zu_ZA.UTF-8 UTF-8" "Zulu" 3>&1 1>&2 2>&3)
	if [[ "$?" == "1" ]]; then
		config_menu
	fi
	echo "$LOCALE"
}

#-------------------------------------------------------------------------

config_vconsole_keymap() {
	local KEYMAPS
	local KEYMAP

	#KEYMAPS=$(localectl list-keymaps | cat -n)
	KEYMAPS=$(localectl list-keymaps | awk '{print $0 " KeyMap"}')
	KEYMAP=$(whiptail --title "Vconsole keymap selection" --menu "Choose keyboard map:" --noitem 20 60 10 ${KEYMAPS} 3>&1 1>&2 2>&3)
	if [[ "$?" == "1" ]]; then
		config_menu
	fi
	echo "$KEYMAP"
}

#-------------------------------------------------------------------------

config_timezone() {
	local TIMEZONES
	local TIMEZONE

	#TIMEZONES=$(timedatectl list-timezones | cat -n)
	TIMEZONES=$(timedatectl list-timezones | awk '{print $0 " Locale"}')
	TIMEZONE=$(whiptail --title "Timezone selection" --menu "Choose your timezone:" --noitem 20 60 10 ${TIMEZONES} 3>&1 1>&2 2>&3)
	if [[ "$?" == "1" ]]; then
		config_menu
	fi
	echo "$TIMEZONE"
}

#-------------------------------------------------------------------------

config_disk() {
	local DISKS
	local DISK

	DISKS=$(lsblk --nodeps --noheadings --paths --raw --output NAME,SIZE)
	DISK=$(whiptail --title "Drive selection" --menu "Choose a disk to install Arch Linux to:" 20 60 10 ${DISKS} 3>&1 1>&2 2>&3)
	if [[ "$?" == "1" ]]; then
		config_menu
	fi
	echo "$DISK"
}

#-------------------------------------------------------------------------

config_partition() {
	local DISK
	local TYPE
	local PARTITIONS
	local PARTITION

	DISK="$1"
	TYPE="$2"
	PARTITIONS=$(lsblk --noheadings  --path --raw --output NAME,SIZE,TYPE "$DISK" | grep part | sed 's/\part//g')
	PARTITION=$(whiptail --title "Partition selection" --menu "Select the $TYPE partition:" 20 60 10 ${PARTITIONS} 3>&1 1>&2 2>&3)
	if [[ "$?" == "1" ]]; then
		config_menu
	fi
	echo "$PARTITION"
}

#-------------------------------------------------------------------------

config_password() {
	local TITLE
	local MESSAGE
	local PASSWORD
	local REENTER_PASSWORD

	TITLE="$1"
	MESSAGE="$2"
	PASSWORD=$(whiptail --title "$TITLE" --passwordbox "Enter a password for $MESSAGE" --nocancel 8 78 3>&1 1>&2 2>&3)
	REENTER_PASSWORD=$(whiptail --title "$TITLE" --passwordbox "Re-enter the password for $MESSAGE" --nocancel 8 78 3>&1 1>&2 2>&3)

	if [[ "$PASSWORD" == "$REENTER_PASSWORD" ]]; then
		echo "$PASSWORD"
	else
		echo "passwords-not-matched"
	fi
}

#-------------------------------------------------------------------------

#Create the luks partition
install_luks() {
	local DRIVE
	local LUKS_DEVICE
	local LUKS_KEY
	local LUKS_NAME

	DRIVE="$1"
	LUKS_DEVICE="$2"
	LUKS_KEY="$3"
	LUKS_NAME="$4"
	{
		echo "5" #Whiptail percentage
		if [ -d "/sys/firmware/efi/efivars" ]; then
			echo -en "$LUKS_KEY\n" | cryptsetup -q -v luksFormat --type luks2 "$LUKS_DEVICE" #Create encrypted partition
		else
			echo -en "$LUKS_KEY\n" | cryptsetup -q -v luksFormat --type luks1 "$LUKS_DEVICE" #Create encrypted partition
		fi
			echo "45" #Whiptail percentage

		if [[ "$(lsblk --noheadings  --path --raw --output ROTA "$DRIVE")" == "0" ]]; then
			echo -en "$LUKS_KEY\n" | cryptsetup --allow-discards --perf-no_read_workqueue --perf-no_write_workqueue --persistent luksOpen "$LUKS_DEVICE" "$LUKS_NAME" #Open encrypted partition
		else
			echo -en "$LUKS_KEY\n" | cryptsetup --perf-no_read_workqueue --perf-no_write_workqueue --persistent luksOpen "$LUKS_DEVICE" "$LUKS_NAME" #Open encrypted partition
		fi
		echo "100" #Whiptail percentage
		sleep 0.5
	} | whiptail --gauge "Configuring disk encryption..." 8 78 0
}

#-------------------------------------------------------------------------

#Create logical volumes with lvm
install_lvm() {
	local LUKS_DEVICE
	local SWAP

	LUKS_DEVICE="$1"
	SWAP="$2"
	{
		echo "10" #Whiptail percentage
		pvcreate "$LUKS_DEVICE" #Create lvm partition
		echo "25" #Whiptail percentage
		vgcreate vg_root0 "$LUKS_DEVICE" #Create lvm group
		echo "50" #Whiptail percentage
		if [ ! -d "/sys/firmware/efi/efivars" ]; then
			lvcreate -L 1G vg_root0 -n boot-arch #Create lvm logical volume with 1GB
		fi
		echo "65" #Whiptail percentage
		if [[ "$SWAP" != "disabled" ]]; then
			lvcreate -L"${SWAP}"G vg_root0 -n swap-arch #Create lvm logical volume
		fi
		echo "75" #Whiptail percentage
		lvcreate -l 50%FREE vg_root0 -n root-arch #Create lvm logical volume with half of the free space available
		echo "90" #Whiptail percentage
		lvcreate -l 100%FREE vg_root0 -n home-arch #Create lvm logical volume with all free space available
		echo "100" #Whiptail percentage
	} | whiptail --gauge "Configuring LVM volumes..." 8 78 0
}

#-------------------------------------------------------------------------

#Prepare the btrfs filesystem for UEFI
install_btrfs() {
	local DRIVE
	local BOOT
	local ROOT
	local SWAP

	DRIVE="$1"
	BOOT="$2"
	ROOT="$3"
	SWAP="$4"
	{
		echo "5" #Whiptail percentage

		#Format the partitions
		if [ -d "/sys/firmware/efi/efivars" ]; then
			mkfs.fat -F32 "$BOOT"
		fi
		mkfs.btrfs -f -L "Root" "$ROOT"
		echo "35" #Whiptail percentage

		mount "$ROOT" /mnt
		cd /mnt || exit

		#Create subvolumes root-arch and home-arch
		btrfs subvolume create _active
		btrfs subvolume create _active/root-arch
		btrfs subvolume create _active/home-arch
		btrfs subvolume create _snapshots
		echo "45" #Whiptail percentage

		if [[ "$SWAP" != "disabled" ]]; then
			btrfs subvolume create _swap
		fi
		echo "65" #Whiptail percentage

		#Unmount
		cd / || exit
		umount /mnt

		#Mount file systems for install
		if [[ "$(lsblk --noheadings  --path --raw --output ROTA "$DRIVE")" == "0" ]]; then
			mount -o rw,relatime,ssd,discard=async,space_cache=v2,subvol=/_active/root-arch "$ROOT" /mnt
			mkdir /mnt/{boot,efi,home,tmp}
			mount -o rw,relatime,ssd,discard=async,space_cache=v2,subvol=/_active/home-arch "$ROOT" /mnt/home
		else
			mount -o rw,relatime,autodefrag,space_cache=v2,subvol=/_active/root-arch "$ROOT" /mnt
			mkdir /mnt/{boot,efi,home,tmp}
			mount -o rw,relatime,autodefrag,space_cache=v2,subvol=/_active/home-arch "$ROOT" /mnt/home
		fi
		echo "75" #Whiptail percentage

		#Prepare swap
		if [[ "$SWAP" != "disabled" ]]; then
			mkdir /mnt/swap
			if [[ "$(lsblk --noheadings  --path --raw --output ROTA "$DRIVE")" == "0" ]]; then
				mount -o rw,noatime,ssd,discard=async,space_cache=v2,subvol=/_swap "$ROOT" /mnt/swap
			else
				mount -o rw,noatime,autodefrag,space_cache=v2,subvol=/_swap "$ROOT" /mnt/swap
			fi
			btrfs filesystem mkswapfile --size "${SWAP}"g --uuid clear /mnt/swap/swapfile
			swapon /mnt/swap/swapfile
		fi
		echo "85" #Whiptail percentage

		if [ -d "/sys/firmware/efi/efivars" ]; then
			mount -o rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro "$BOOT" /mnt/efi
		fi
		echo "100" #Whiptail percentage
		} | whiptail --gauge "Configuring btrfs filesystem..." 8 78 0
}

#-------------------------------------------------------------------------

#Prepare the ext4 filesystem for UEFI
install_ext4() {
	local BOOT
	local ROOT
	local HOME
	local SWAP
	local SWAP_SIZE

	BOOT="$1"
	ROOT="$2"
	HOME="$3"
	SWAP="$4"
	SWAP_SIZE="$5"
	{
		echo "5" #Whiptail percentage

		#Format the partitions
		if [ -d "/sys/firmware/efi/efivars" ]; then
			mkfs.fat -F32 "$BOOT"
		fi
		echo "25" #Whiptail percentage
		mkfs.ext4 -F "$ROOT"
		echo "50" #Whiptail percentage
		mkfs.ext4 -F "$HOME"
		echo "75" #Whiptail percentage

		#Prepare swap
		if [[ "$SWAP_SIZE" != "disabled" ]]; then
			mkswap "$SWAP"
			swapon "$SWAP"
		fi
		echo "95" #Whiptail percentage

		#Mount file systems for install
		mount "$ROOT" /mnt
		mkdir /mnt/{boot,efi,home,tmp}
		if [ -d "/sys/firmware/efi/efivars" ]; then
			mount "$BOOT" /mnt/efi
		fi
		mount "$HOME" /mnt/home
		echo "100" #Whiptail percentage
	} | whiptail --gauge "Configuring ext4 filesystem..." 8 78 0
}

#-------------------------------------------------------------------------

message_welcome() {
	whiptail --title "Arch Linux" --msgbox "Arch Linux installation script\n\nWritten by 7thCore\n\nWelcome to the Arch Linux installation script. Before we begin you will have to enter some basic information.\n\nNote: This script was written and torn appart over the years while I messed with Arch Linux. I still do. It started when I decided to switch to linux and I wanted to be the so called cool guy and just jump straight into Arch. I had the installation media booted up in VirtualBox and Notepad++ on a second monitor, writing down everything I typed in the install media console while pouring over the Arch Linux Wiki. Then I made a basic script out of it and it somewhat evolved over the years.\n\nYou can use this but if it's your first time, I strongly recommend you do it manually at least once. I did and because of it, I gained a lot of bash scripting knowledge and a general idea where everything is and how linux works. And maybe a small sense of accomplishment. I recommend you do the same just for the learning experience." 26 78
}

#-------------------------------------------------------------------------

message_warning() {
	whiptail --title "WARNING" --msgbox "I wrote this script because installing Arch Linux manually is time consuming. This script was written with my preferences in mind and I do not intend to maintain it on a grand scale. It's a tool for me to use when I need to. If you're using it, you are doing so at your own risk. I will not be responsible for any data loss or hardware issues.\n\nYou have been warned." 13 78
}

#-------------------------------------------------------------------------

message_installation_complete() {
	if whiptail --title "Installation complete" --yesno "Congratz! The script completed without frying the CPU. Well we'll see what happens after a reboot. Brace for the fireworks buddy and hold on to your panty hoes!\n\nKDE Wallet: create a new wallet named 'kdewallet' with blowfish encryption and an empty password to enable automatic unlock of the wallet.\n\nDo you want to reboot?" --yes-button "Reboot" --no-button "Exit" 14 78; then
		shutdown -r now
	else
		exit 1
	fi
}

#-------------------------------------------------------------------------

#Select language
config_menu_locale() {
	local INSTALL_CONFIG_DUAL_LOCALE

	#Dual languages
	if whiptail --title "Language selection" --yesno "Do you wish enable a second language? The first selected language is going to be the operating system language and the second is going to be time, measurments, paper formats, etc. This is usefull if for example you want an english language but formats in  your native language." --yes-button "Single" --no-button "Dual" 8 78; then
		INSTALL_CONFIG_DUAL_LOCALE=NO
	else
		INSTALL_CONFIG_DUAL_LOCALE=YES
	fi

	#Get primary language
	INSTALL_CONFIG_PRIMARY_LOCALE=$(config_locale)

	#Get secondary language
	if [[ "$INSTALL_CONFIG_DUAL_LOCALE" == "YES" ]]; then
		INSTALL_CONFIG_SECONDARY_LOCALE=$(config_locale)
	else
		INSTALL_CONFIG_SECONDARY_LOCALE="$INSTALL_CONFIG_PRIMARY_LOCALE"
	fi

	#Get keyboard layout for console
	INSTALL_CONFIG_KEYMAP=$(config_vconsole_keymap)
	#INSTALL_CONFIG_KEYMAP_TEXT=$(localectl list-keymaps | cat -n | grep -w " $INSTALL_CONFIG_KEYMAP_NUMBER" | awk '{print $2}')

	#Select timezone
	INSTALL_CONFIG_TIMEZONE=$(config_timezone)
	#INSTALL_CONFIG_TIMEZONE_TEXT=$(timedatectl list-timezones | cat -n | grep -w " $INSTALL_CONFIG_TIMEZONE_NUMBER" | awk '{print $2}')
}

#-------------------------------------------------------------------------

#Configure the disk
config_menu_disk() {
	#Select disk to install arch linux to
	INSTALL_CONFIG_DISK=$(config_disk)

	#Wipe the disk
	if whiptail --title "Wipe selected drive" --yesno "Do you wish to wipe the selected drive of any partition tables?" 8 78; then
		{
			sleep 0.5
			echo "5"
			wipefs --all --quiet "$INSTALL_CONFIG_DISK"
			echo "100"
			sleep 0.5
		} | whiptail --gauge "Please wait while the script wipes the disk..." 8 78 0
	fi

	#Partition the disk
	if whiptail --title "Partitioning" --yesno "Do you wish to manually partition the disk?" --yes-button "Automatic" --no-button "Manual" 8 78; then
		{
			sleep 0.5
			echo "5"
			sgdisk -n 1::+10G -t 1:ef00 -c 1:"EFI System" "$INSTALL_CONFIG_DISK"
			echo "50"
			sgdisk -n 2:: -t 2:8300 -c 2:"Root Filesystem" "$INSTALL_CONFIG_DISK"
			echo "100"
			sleep 0.5
		} | whiptail --gauge "Please wait while the script partitions the disk..." 8 78 0
	else
		cfdisk "$INSTALL_CONFIG_DISK"
	fi

	#Enable encryption on the disk
	if whiptail --title "Encryption" --yesno "Enable encryption on the selected drive?" 8 78; then
		INSTALL_CONFIG_ENCRYPTION="YES"
	else
		INSTALL_CONFIG_ENCRYPTION="NO"
	fi

	#Get the encryption password
	if [[ "$INSTALL_CONFIG_ENCRYPTION" == "YES" ]]; then
		INSTALL_CONFIG_ENCRYPTION_PASSWORD="passwords-not-matched"
		until [[ "$INSTALL_CONFIG_ENCRYPTION_PASSWORD" != "passwords-not-matched" ]]; do
			INSTALL_CONFIG_ENCRYPTION_PASSWORD=$(config_password "Luks password" "the luks partition:")
		done
	fi

	#Get boot and root partitions
	INSTALL_CONFIG_BOOT_PARTITION=$(config_partition "$INSTALL_CONFIG_DISK" "boot")
	INSTALL_CONFIG_ROOT_PARTITION=$(config_partition "$INSTALL_CONFIG_DISK" "root")

	#Select filesystem
	INSTALL_CONFIG_FILESYSTEM=$(whiptail --title "Filesystem" --menu "Select your desired filesystem" 20 60 10 "btrfs" "B-Tree filesystem." "ext4" "Fourth extended filesystem." 3>&1 1>&2 2>&3)
	if [[ "$?" == "1" ]]; then
		config_menu
	fi

	#Do you want to enable swap
	if whiptail --title "Swap" --yesno "Enable swap for os instance?" 8 78; then
		INSTALL_CONFIG_SWAP_SIZE=$(whiptail --title "Swap" --inputbox "Enter your desired swap size in gigabytes" 10 39 8 3>&1 1>&2 2>&3)
		if [[ "$?" == "1" ]]; then
			config_menu
		fi
	else
		INSTALL_CONFIG_SWAP_SIZE="disabled"
	fi

	#Prepare luks partition and filesystems
	if [[ "$INSTALL_CONFIG_ENCRYPTION" == "YES" ]]; then
		install_luks "$INSTALL_CONFIG_DISK" "$INSTALL_CONFIG_ROOT_PARTITION" "$INSTALL_CONFIG_ENCRYPTION_PASSWORD" "crypt_luks_root_install"
		if [[ "$INSTALL_CONFIG_FILESYSTEM" == "btrfs" ]]; then
			install_btrfs "$INSTALL_CONFIG_DISK" "$INSTALL_CONFIG_BOOT_PARTITION" "/dev/mapper/crypt_luks_root_install" "$INSTALL_CONFIG_SWAP_SIZE"
		elif [[ "$INSTALL_CONFIG_FILESYSTEM" == "ext4" ]]; then
			install_lvm "/dev/mapper/crypt_luks_root_install" "$INSTALL_CONFIG_SWAP_SIZE"
			install_ext4 "$INSTALL_CONFIG_BOOT_PARTITION" "vg_root0/root-arch" "vg_root0/home-arch" "vg_root0/swap-arch" "$INSTALL_CONFIG_SWAP_SIZE"
		fi
	else
		if [[ "$INSTALL_CONFIG_FILESYSTEM" == "btrfs" ]]; then
			install_btrfs "$INSTALL_CONFIG_DISK" "$INSTALL_CONFIG_BOOT_PARTITION" "$INSTALL_CONFIG_ROOT_PARTITION" "$INSTALL_CONFIG_SWAP_SIZE"
		elif [[ "$INSTALL_CONFIG_FILESYSTEM" == "ext4" ]]; then
			install_ext4 "$INSTALL_CONFIG_BOOT_PARTITION" "$CONFIG_ROOT_PART" "$CONFIG_HOME_PART" "$CONFIG_SWAP_PART"
			install_ext4 "$INSTALL_CONFIG_BOOT_PARTITION" "vg_root0/root-arch" "vg_root0/home-arch" "vg_root0/swap-arch" "$INSTALL_CONFIG_SWAP_SIZE"
		fi
	fi
}

#-------------------------------------------------------------------------

#Enable secure boot
config_menu_secure_boot() {
	if whiptail --title "Secure boot" --yesno "Enable secure boot?" 8 78; then
		INSTALL_CONFIG_SECURE_BOOT=YES
		INSTALL_PACKAGES=("systemd-ukify" "sbctl" "${INSTALL_PACKAGES[@]}")
	else
		INSTALL_CONFIG_SECURE_BOOT=NO
	fi
}

#-------------------------------------------------------------------------

#Get username
config_menu_hostname() {
	INSTALL_CONFIG_HOSTNAME=$(whiptail --title "Enter hostname" --inputbox "Enter your desired hostname" 8 39 ArchLinux-PC 3>&1 1>&2 2>&3)
	if [[ "$?" == "1" ]]; then
		config_menu
	fi
}

#-------------------------------------------------------------------------

#Get username
config_menu_username() {
	INSTALL_CONFIG_USER=$(whiptail --title "Enter username" --inputbox "Enter your desired username" 8 39 archlinux 3>&1 1>&2 2>&3)
	if [[ "$?" == "1" ]]; then
		config_menu
	fi
}

#-------------------------------------------------------------------------

#Get user password
config_menu_user_password() {
	INSTALL_CONFIG_USER_PASSWORD="passwords-not-matched"
	until [[ "$INSTALL_CONFIG_USER_PASSWORD" != "passwords-not-matched" ]]; do
		INSTALL_CONFIG_USER_PASSWORD=$(config_password "User password" "your username:")
	done
}

#-------------------------------------------------------------------------

#Get root password
config_menu_root_password() {
	INSTALL_CONFIG_ROOT_PASSWORD="passwords-not-matched"
	until [[ "$INSTALL_CONFIG_ROOT_PASSWORD" != "passwords-not-matched" ]]; do
		INSTALL_CONFIG_ROOT_PASSWORD=$(config_password "Root password" "root:")
	done
}

#-------------------------------------------------------------------------

#Select prefered shell
config_menu_shell() {
	if whiptail --title "Shell" --yesno "Select your prefered shell:" --yes-button "Zsh" --no-button "Bash" 8 78; then
		INSTALL_CONFIG_USER_SHELL=ZSH_SHELL
		INSTALL_PACKAGES=("zsh" "zsh-completions" "zsh-autosuggestions" "zsh-syntax-highlighting" "zsh-history-substring-search" "${INSTALL_PACKAGES[@]}")
	else
		INSTALL_CONFIG_USER_SHELL=BASH_SHELL
	fi
}

#-------------------------------------------------------------------------

#Use 7thCore's local repository
config_menu_core_repo() {
	if whiptail --title "7thCore's local repository" --yesno "Use 7thCore's local repository for installation?" 8 78; then
		INSTALL_CONFIG_SEVENTHCORE_LOCAL_REPO=YES
	else
		INSTALL_CONFIG_SEVENTHCORE_LOCAL_REPO=NO
	fi
}

#-------------------------------------------------------------------------

#Enable 7thCore's aur-prebuilt repositories
config_menu_aur_prebuilt() {
	INSTALL_CONFIG_AUR_PREBUILT=NO
	INSTALL_CONFIG_AUR_PREBUILT_CORE=NO
	INSTALL_CONFIG_AUR_PREBUILT_CORE_ESSENTIALS=NO
	INSTALL_CONFIG_AUR_PREBUILT_DOTNET=NO
	INSTALL_CONFIG_AUR_PREBUILT_FFMPEG=NO
	INSTALL_CONFIG_AUR_PREBUILT_LIBREWOLF=NO
	INSTALL_CONFIG_AUR_PREBUILT_NVIDIA390=NO
	INSTALL_CONFIG_AUR_PREBUILT_NVIDIA470=NO
	INSTALL_CONFIG_AUR_PREBUILT_NVIDIA550=NO

	if whiptail --title "7thCore's repositories" --yesno "Enable 7thCore's personal aur-prebuilt repositories?" 8 78; then
		INSTALL_CONFIG_AUR_REPOSITORIES=("$(whiptail --title "7thCore's repositories" --checklist --separate-output "Select repositories to enable" 15 81 8 \
		"aur-prebuilt" "Various prebuilt packages from the AUR." ON \
		"aur-prebuilt-core" "7thCore's personal packages." ON \
		"aur-prebuilt-dotnet" "Prebuilt .Net Framework packages." OFF \
		"aur-prebuilt-ffmpeg" "Prebuilt FFMpeg packages and it's dependancies." OFF \
		"aur-prebuilt-librewolf" "Prebuilt LibreWolf packages and it's extensions." OFF \
		"aur-prebuilt-nvidia390" "Prebuilt Nvidia version 390 drivers." OFF \
		"aur-prebuilt-nvidia470" "Prebuilt Nvidia version 470 drivers." OFF \
		"aur-prebuilt-nvidia550" "Prebuilt Nvidia version 550 drivers." OFF 3>&1 1>&2 2>&3)")
		if [[ "$?" == "1" ]]; then
			config_menu
		fi
		for AUR_REPOSITORY in ${INSTALL_CONFIG_AUR_REPOSITORIES[@]}; do
			if [[ "$AUR_REPOSITORY" == "aur-prebuilt" ]]; then
				INSTALL_CONFIG_AUR_PREBUILT=YES
			elif [[ "$AUR_REPOSITORY" == "aur-prebuilt-core" ]]; then
				INSTALL_CONFIG_AUR_PREBUILT_CORE=YES
				if whiptail --title "7thCore's repositories" --yesno "Install 7thcore-essentials package?" 8 78; then
					INSTALL_CONFIG_AUR_PREBUILT_CORE_ESSENTIALS=YES
					INSTALL_PACKAGES=("7thcore-essentials" "${INSTALL_PACKAGES[@]}")
				fi
			elif [[ "$AUR_REPOSITORY" == "aur-prebuilt-dotnet" ]]; then
				INSTALL_CONFIG_AUR_PREBUILT_DOTNET=YES
			elif [[ "$AUR_REPOSITORY" == "aur-prebuilt-ffmpeg" ]]; then
				INSTALL_CONFIG_AUR_PREBUILT_FFMPEG=YES
			elif [[ "$AUR_REPOSITORY" == "aur-prebuilt-librewolf" ]]; then
				INSTALL_CONFIG_AUR_PREBUILT_LIBREWOLF=YES
			elif [[ "$AUR_REPOSITORY" == "aur-prebuilt-nvidia390" ]]; then
				INSTALL_CONFIG_AUR_PREBUILT_NVIDIA390=YES
			elif [[ "$AUR_REPOSITORY" == "aur-prebuilt-nvidia470" ]]; then
				INSTALL_CONFIG_AUR_PREBUILT_NVIDIA470=YES
			elif [[ "$AUR_REPOSITORY" == "aur-prebuilt-nvidia550" ]]; then
				INSTALL_CONFIG_AUR_PREBUILT_NVIDIA550=YES
			fi
		done
	fi
}

#-------------------------------------------------------------------------

#Install common cli applications
config_menu_cli_applications() {
	INSTALL_CONFIG_SSH=NO
	INSTALL_CONFIG_SSH_PORT=NONE
	INSTALL_CONFIG_UFW=NO
	INSTALL_CONFIG_NTP=NO
	INSTALL_CONFIG_SAMBA=NO
	INSTALL_CONFIG_SAMBA_PASSWORD=NONE
	INSTALL_CONFIG_POSTFIX=NO
	INSTALL_CONFIG_POSTFIX_USER=NONE
	INSTALL_CONFIG_POSTFIX_PASSWORD=NONE
	INSTALL_CONFIG_PRINT=NO
	INSTALL_CONFIG_AMD=NO
	INSTALL_CONFIG_INTEL=NO
	INSTALL_CONFIG_NVIDIA=NO
	INSTALL_CONFIG_WINE=NO
	INSTALL_CONFIG_LIBVIRT=NO
	INSTALL_CONFIG_V4L2_LOOPBACK=NO

	INSTALL_CONFIG_COMMON_CLI_APPLICATIONS=("$(whiptail --title "Common CLI applications and drivers" --checklist --separate-output "Select applications you want to install:" 19 90 12 \
	"Ssh" "Install secure shell protocol" ON \
	"Ufw" "Install uncomplicated firewall" ON \
	"Ntp" "Install network time protocol" ON \
	"Samba" "Install SMB/CIFS for file sharing" OFF \
	"Postfix" "Install postfix for automatic email sending on user configured events" OFF \
	"Cups" "Enable printer support" OFF \
	"Amd" "Install AMD gpu drivers" OFF \
	"Intel" "Install Intel gpu drivers" OFF \
	"Nvidia" "Install Nvidia gpu drivers" OFF \
	"Wine" "Install Wine" OFF \
	"LibVirt" "Install LibVirt virtual machine manager" OFF \
	"V4l2loopback" "Kernel module for video loopkack devices. Optional for example OBS" ON 3>&1 1>&2 2>&3)")
	if [[ "$?" == "1" ]]; then
		config_menu
	fi
	for CLI_APPLICATION in ${INSTALL_CONFIG_COMMON_CLI_APPLICATIONS[@]}; do
		if [[ "$CLI_APPLICATION" == "Ssh" ]]; then
			INSTALL_CONFIG_SSH=YES
			INSTALL_CONFIG_SSH_PORT=$(whiptail --title "SSH port" --inputbox "Enter your desired ssh port:" --nocancel 8 39 22 3>&1 1>&2 2>&3)
			INSTALL_PACKAGES=("openssh" "keychain" "${INSTALL_PACKAGES[@]}")
		elif [[ "$CLI_APPLICATION" == "Ufw" ]]; then
			INSTALL_CONFIG_UFW=YES
			INSTALL_PACKAGES=("ufw" "${INSTALL_PACKAGES[@]}")
		elif [[ "$CLI_APPLICATION" == "Ntp" ]]; then
			INSTALL_CONFIG_NTP=YES
			INSTALL_PACKAGES=("ntp" "${INSTALL_PACKAGES[@]}")
		elif [[ "$CLI_APPLICATION" == "Samba" ]]; then
			INSTALL_CONFIG_SAMBA=YES
			INSTALL_CONFIG_SAMBA_WORKGROUP=$(whiptail --title "Samba workgroup" --inputbox "Enter your workgroup:" 8 39 WORKGROUP 3>&1 1>&2 2>&3)
			INSTALL_CONFIG_SAMBA_PASSWORD="passwords-not-matched"
			INSTALL_PACKAGES=("samba" "smbclient" "${INSTALL_PACKAGES[@]}")
			until [[ "$INSTALL_CONFIG_SAMBA_PASSWORD" != "passwords-not-matched" ]]; do
				INSTALL_CONFIG_SAMBA_PASSWORD=$(config_password "Samba password" "your user's samba entry:")
			done
		elif [[ "$CLI_APPLICATION" == "Postfix" ]]; then
			INSTALL_CONFIG_POSTFIX=YES
			INSTALL_CONFIG_POSTFIX_USER=$(whiptail --title "Postfix user" --inputbox "Enter your email username:" 8 39 example@mail.com 3>&1 1>&2 2>&3)
			INSTALL_CONFIG_POSTFIX_PASSWORD="passwords-not-matched"
			until [[ "$INSTALL_CONFIG_POSTFIX_PASSWORD" != "passwords-not-matched" ]]; do
				INSTALL_CONFIG_POSTFIX_PASSWORD=$(config_password "Postfix password" "your email account:")
			done
			INSTALL_PACKAGES=("postfix" "s-nail" "${INSTALL_PACKAGES[@]}")
		elif [[ "$CLI_APPLICATION" == "Cups" ]]; then
			INSTALL_CONFIG_PRINT=YES
			INSTALL_PACKAGES=("cups" "hplip" "system-config-printer" "${INSTALL_PACKAGES[@]}")
		elif [[ "$CLI_APPLICATION" == "Amd" ]]; then
			INSTALL_CONFIG_AMD=YES
			INSTALL_PACKAGES=("mesa" "xf86-video-amdgpu" "vulkan-radeon" "libva-mesa-driver" "opencl-mesa" "${INSTALL_PACKAGES[@]}")
		elif [[ "$CLI_APPLICATION" == "Intel" ]]; then
			INSTALL_CONFIG_INTEL=YES
			INSTALL_PACKAGES=("mesa" "xf86-video-intel" "vulkan-intel" "intel-media-driver" "${INSTALL_PACKAGES[@]}")
		elif [[ "$CLI_APPLICATION" == "Nvidia" ]]; then
			INSTALL_CONFIG_NVIDIA=YES
			INSTALL_PACKAGES=("nvidia-open" "nvidia-settings" "nvidia-utils" "virtualgl" "${INSTALL_PACKAGES[@]}")
		elif [[ "$CLI_APPLICATION" == "Wine" ]]; then
			INSTALL_CONFIG_WINE=YES
			INSTALL_PACKAGES=("wine" "winetricks" "wine-mono" "wine_gecko" "libpulse" "libxml2" "mpg123" "lcms2" "giflib" "libpng" "gnutls" "gst-plugins-base" "gst-plugins-good" "${INSTALL_PACKAGES[@]}")
			INSTALL_PACKAGES_LIB32=("lib32-libpulse" "lib32-libxml2" "lib32-mpg123" "lib32-lcms2" "lib32-giflib" "lib32-libpng" "lib32-gnutls" "lib32-gst-plugins-base" "lib32-gst-plugins-good" "${INSTALL_PACKAGES_LIB32[@]}")
		elif [[ "$CLI_APPLICATION" == "LibVirt" ]]; then
			INSTALL_CONFIG_LIBVIRT=YES
			INSTALL_PACKAGES=("qemu-full" "qemu-block-gluster" "qemu-block-iscsi" "libvirt" "virt-install" "virt-manager" "ebtables" "dnsmasq" "bridge-utils" "openbsd-netcat" "edk2-ovmf" "${INSTALL_PACKAGES[@]}")
		elif [[ "$CLI_APPLICATION" == "V4l2loopback" ]]; then
			INSTALL_CONFIG_V4L2_LOOPBACK=YES
			INSTALL_PACKAGES=("v4l2loopback-dkms" "v4l2loopback-utils" "${INSTALL_PACKAGES[@]}")
		fi
	done
}

#-------------------------------------------------------------------------

#Desktop environment selection
config_menu_desktop() {
	INSTALL_CONFIG_DESKTOP_ENVIRONMENT=NONE
	INSTALL_CONFIG_KDE_TYPE=NONE
	INSTALL_CONFIG_KDE_AUTOLOGIN=NO
	INSTALL_CONFIG_KDE_GAMES=NO
	INSTALL_CONFIG_STEAM=NO
	INSTALL_CONFIG_LUTRIS=NO
	INSTALL_CONFIG_LIBREOFFICE=NO
	INSTALL_CONFIG_OBS=NO
	INSTALL_CONFIG_VLC=NO
	INSTALL_CONFIG_GIMP=NO
	INSTALL_CONFIG_OPENRGB=NO
	INSTALL_CONFIG_THUNDERBIRD=NO
	INSTALL_CONFIG_LIB32=NO
	INSTALL_CONFIG_NEXTCLOUD=NO
	INSTALL_CONFIG_LIBREWOLF=NO
	INSTALL_CONFIG_BRAVE=NO
	INSTALL_CONFIG_TEAMVIEWER=NO
	INSTALL_CONFIG_VESKTOP=NO

	if whiptail --title "Desktop environment" --yesno "Install a desktop environment?" 8 78; then
		INSTALL_PACKAGES=("pipewire" \
		"pipewire-jack" \
		"pipewire-v4l2" \
		"pipewire-pulse" \
		"pipewire-zeroconf" \
		"fprintd" \
		"switcheroo-control" \
		"power-profiles-daemon" \
		"networkmanager" \
		"networkmanager-vpn-plugin-l2tp" \
		"networkmanager-vpn-plugin-openconnect" \
		"networkmanager-vpn-plugin-openvpn" \
		"networkmanager-vpn-plugin-pptp" \
		"networkmanager-vpn-plugin-sstp" \
		"networkmanager-vpn-plugin-vpnc" \
		"sof-firmware" "${INSTALL_PACKAGES[@]}")
		INSTALL_PACKAGES_LIB32=("lib32-pipewire" "lib32-pipewire-jack" "lib32-pipewire-v4l2" "${INSTALL_PACKAGES_LIB32[@]}")
		INSTALL_CONFIG_DESKTOP_ENVIRONMENT=$(whiptail --title "Desktop environment" --radiolist "Select your desktop environment:" 18 70 11 \
		"CINNAMON_DE" "Cinnamon desktop environment" OFF \
		"COSMIC_DE" "Cosmic desktop environment (System76/PopOS)" OFF \
		"GNOME_DE" "Gnome desktop environment" OFF \
		"KDE_DE" "KDE Plasma desktop environment" ON 3>&1 1>&2 2>&3)
		if [[ "$?" == "1" ]]; then
			config_menu
		fi
		if [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" == "CINNAMON_DE" ]]; then
			echo "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT"
		elif [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" == "COSMIC_DE" ]]; then
			INSTALL_PACKAGES=("cosmic-app-library" \
			"cosmic-applets" \
			"cosmic-bg" \
			"cosmic-comp" \
			"cosmic-files" \
			"cosmic-greeter" \
			"cosmic-idle" \
			"cosmic-initial-setup" \
			"cosmic-launcher" \
			"cosmic-notifications" \
			"cosmic-osd" \
			"cosmic-panel" \
			"cosmic-player" \
			"cosmic-randr" \
			"cosmic-screenshot" \
			"cosmic-session" \
			"cosmic-settings" \
			"cosmic-settings-daemon" \
			"cosmic-store" \
			"cosmic-terminal" \
			"cosmic-text-editor" \
			"cosmic-wallpapers" \
			"cosmic-workspaces" \
			"firefox" \
			"gnome-keyring" \
			"gvfs" \
			"gvfs-nfs" \
			"gvfs-smv" \
			"gvfs-dnssd" \
			"xdg-desktop-portal-cosmic" "${INSTALL_PACKAGES[@]}")
		elif [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" == "GNOME_DE" ]]; then
			INSTALL_PACKAGES=("audio-sharing" \
			"baobab" \
			"dconf-editor" \
			"decibels" \
			"epiphany" \
			"extension-manager" \
			"decoder" \
			"gdm" \
			"gnome-backgrounds" \
			"gnome-boxes" \
			"gnome-calculator" \
			"gnome-calendar" \
			"gnome-characters" \
			"gnome-clocks" \
			"gnome-color-manager" \
			"gnome-connections" \
			"gnome-console" \
			"gnome-contacts" \
			"gnome-control-center" \
			"gnome-disk-utility" \
			"gnome-font-viewer" \
			"gnome-keyring" \
			"gnome-logs" \
			"gnome-maps" \
			"gnome-menus" \
			"gnome-music" \
			"gnome-remote-desktop" \
			"gnome-session" \
			"gnome-settings-daemon" \
			"gnome-shell" \
			"gnome-shell-extensions" \
			"gnome-software" \
			"gnome-sound-recorder" \
			"gnome-system-monitor" \
			"gnome-text-editor" \
			"gnome-tour" \
			"gnome-tweaks" \
			"gnome-user-docs" \
			"gnome-user-share" \
			"gnome-weather" \
			"grilo-plugins" \
			"gvfs" \
			"gvfs-afc" \
			"gvfs-dnssd" \
			"gvfs-goa" \
			"gvfs-google" \
			"gvfs-gphoto2" \
			"gvfs-mtp" \
			"gvfs-nfs" \
			"gvfs-onedrive" \
			"gvfs-smb" \
			"gvfs-wsdd" \
			"gst-plugin-pipewire" \
			"impression" \
			"loupe" \
			"malcontent" \
			"nautilus" \
			"orca" \
			"paper-clip" \
			"papers" \
			"power-profiles-daemon" \
			"raider" \
			"resources" \
			"file-roller" \
			"rygel" \
			"showtime" \
			"simple-scan" \
			"snapshot" \
			"sushi" \
			"tecla" \
			"xdg-desktop-portal-gnome" \
			"xdg-user-dirs-gtk" \
			"yelp" "${INSTALL_PACKAGES[@]}")

			INSTALL_CONFIG_COMMON_GNOME_APPLICATIONS=("$(whiptail --title "Additional GNOME applications" --checklist --separate-output "Select GNOME applications you want to install:" --nocancel 12 82 5 \
			"Chatty" "Simple to use SMS and Matrix messaging application" OFF \
			"EarTag" "Simple audio file tag editor" ON \
			"Endeavour" "Personal task manager" OFF \
			"Fragments" "BitTorrent client for GNOME" ON \
			"Polari" "An IRC Client for GNOME" OFF 3>&1 1>&2 2>&3)")
			for GNOME_APPLICATION in ${INSTALL_CONFIG_COMMON_GNOME_APPLICATIONS[@]}; do
				if [[ "$GNOME_APPLICATION" == "Chatty" ]]; then
					INSTALL_PACKAGES=("chatty" "${INSTALL_PACKAGES[@]}")
				elif [[ "$GNOME_APPLICATION" == "EarTag" ]]; then
					INSTALL_PACKAGES=("eartag" "${INSTALL_PACKAGES[@]}")
				elif [[ "$GNOME_APPLICATION" == "Fragments" ]]; then
					INSTALL_PACKAGES=("fragments" "${INSTALL_PACKAGES[@]}")
				elif [[ "$GNOME_APPLICATION" == "Polari" ]]; then
					INSTALL_PACKAGES=("polari" "${INSTALL_PACKAGES[@]}")
				fi
			done

			if whiptail --title "GNOME" --yesno "Do you wish to install some of the GNOME games?" 8 78; then
				INSTALL_CONFIG_COMMON_GNOME_GAMES=("$(whiptail --title "GNOME" --checklist --separate-output "Select the games you want to install:" --nocancel 21 117 14 \
				"Boxes" "Simple GNOME application to access virtual systems" ON \
				"Chess" "Play the classic two-player boardgame of chess" ON \
				"Mahjongg" "Disassemble a pile of tiles by removing matching pairs" ON \
				"Mines" "Clear hidden mines from a minefield" ON \
				"Nibbles" "Guide a worm around a maze" ON \
				"Robots" "Avoid the robots and make them crash into each other" ON \
				"Lights Off" "Turn off all the lights" ON \
				"Sudoku" "Test your logic skills in this number grid puzzle" ON \
				"Quadrapassel" "Fit falling blocks together (Tetris-like game for GNOME)" ON \
				"Swell Foop" "Clear the screen by removing groups of colored and shaped tiles" ON \
				"0 A.D." "Cross-platform, 3D and historically-based real-time strategy game" ON \
				"Hedgewars" "Turn-based strategy artillery game similiar to Worms" ON \
				"SuperTux" "A classic 2D jump'n'run sidescroller game in a style similar to the original SuperMario games" ON \
				"SuperTuxKart" "Kart racing game featuring Tux and his friends" ON 3>&1 1>&2 2>&3)")
				for GNOME_GAME in ${INSTALL_CONFIG_COMMON_GNOME_GAMES[@]}; do
					if [[ "$GNOME_GAME" == "Boxes" ]]; then
						INSTALL_PACKAGES=("gnome-boxes" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "Chess" ]]; then
						INSTALL_PACKAGES=("gnome-chess" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "Mahjongg" ]]; then
						INSTALL_PACKAGES=("gnome-mahjongg" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "Mines" ]]; then
						INSTALL_PACKAGES=("gnome-mines" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "Nibbles" ]]; then
						INSTALL_PACKAGES=("gnome-nibbles" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "Robots" ]]; then
						INSTALL_PACKAGES=("gnome-robots" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "Lights Off" ]]; then
						INSTALL_PACKAGES=("lightsoff" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "Sudoku" ]]; then
						INSTALL_PACKAGES=("gnome-sudoku" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "Quadrapassel" ]]; then
						INSTALL_PACKAGES=("quadrapassel" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "Swell Foop" ]]; then
						INSTALL_PACKAGES=("swell-foop" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "0 A.D." ]]; then
						INSTALL_PACKAGES=("0ad" "0ad-data" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "Hedgewars" ]]; then
						INSTALL_PACKAGES=("hedgewars" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "SuperTux" ]]; then
						INSTALL_PACKAGES=("supertux" "${INSTALL_PACKAGES[@]}")
					elif [[ "$GNOME_GAME" == "SuperTuxKart" ]]; then
						INSTALL_PACKAGES=("supertuxkart" "${INSTALL_PACKAGES[@]}")
					fi
				done
			fi
		elif [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" == "KDE_DE" ]]; then
			INSTALL_PACKAGES=("ark" \
			"aurorae" \
			"baloo" \
			"baloo-widgets" \
			"bluedevil" \
			"breeze" \
			"breeze-gtk" \
			"drkonqi" \
			"dolphin" \
			"dolphin-plugins" \
			"elisa" \
			"ffmpegthumbs" \
			"filelight" \
			"firefox" \
			"flatpak-kcm" \
			"ghostwriter" \
			"gwenview" \
			"haruna" \
			"kactivitymanagerd" \
			"kate" \
			"kcalc" \
			"kcharselect" \
			"kcolorchooser" \
			"kde-cli-tools" \
			"kde-gtk-config" \
			"kde-inotify-survey" \
			"kdegraphics-thumbnailers" \
			"kdenetwork-filesharing" \
			"kdeplasma-addons" \
			"keysmith" \
			"kfind" \
			"kglobalacceld" \
			"kgpg" \
			"khelpcenter" \
			"kile" \
			"kimageformats" \
			"kinfocenter" \
			"kio" \
			"kio-admin" \
			"kio-extras" \
			"kio-fuse" \
			"kio-gdrive" \
			"kmenuedit" \
			"knighttime" \
			"kpipewire" \
			"krdc" \
			"krdp" \
			"kolourpaint" \
			"kompare" \
			"konsole" \
			"kscreen" \
			"kscreenlocker" \
			"ksshaskpass" \
			"ksystemstats" \
			"ksystemlog" \
			"kwallet" \
			"kwallet-pam" \
			"kwalletmanager" \
			"kwayland" \
			"kwin" \
			"kwrited" \
			"layer-shell-qt" \
			"libkscreen" \
			"libksysguard" \
			"libplasma" \
			"networkmanager-qt" \
			"ocean-sound-theme" \
			"okular" \
			"oxygen" \
			"oxygen-sounds" \
			"partitionmanager" \
			"plasma-activities" \
			"plasma-activities-stats" \
			"plasma-browser-integration" \
			"plasma-desktop" \
			"plasma-disks" \
			"plasma-firewall" \
			"plasma-integration" \
			"plasma-nm" \
			"plasma-pa" \
			"plasma-systemmonitor" \
			"plasma-thunderbolt" \
			"plasma-vault" \
			"plasma-workspace" \
			"plasma-workspace-wallpapers" \
			"print-manager" \
			"polkit-kde-agent" \
			"powerdevil" \
			"qrca" \
			"sddm" \
			"sddm-kcm" \
			"skanpage" \
			"spectacle" \
			"sweeper" \
			"systemsettings" \
			"xdg-desktop-portal-kde" "${INSTALL_PACKAGES[@]}")
			if whiptail --title "KDE Plasma" --yesno "Do you wish to enable automatic login for user $INSTALL_CONFIG_USER?" 8 78; then
				if whiptail --title "KDE Plasma" --yesno "Do you wish to enable automatic lock after login for user $INSTALL_CONFIG_USER?\n(Usefull for servers with remote desktop access)" 8 78; then
					INSTALL_CONFIG_KDE_AUTOLOGIN=YES-LOCK
				else
					INSTALL_CONFIG_KDE_AUTOLOGIN=YES
				fi
			fi

			INSTALL_CONFIG_COMMON_KDE_APPLICATIONS=("$(whiptail --title "Additional KDE applications" --checklist --separate-output "Select KDE applications you want to install:" --nocancel 16 82 9 \
			"KDE Connect" "Adds communication between KDE and your smartphone" ON \
			"Kdevelop" "C++ IDE using KDE technologies" OFF \
			"Ktimer" "Countdown Launcher" OFF \
			"Neochat" "A client for matrix, the decentralized communication protocol" OFF \
			"Kamoso" "A webcam recorder from KDE community" ON \
			"Krita" "Edit and paint images" OFF \
			"Kid3" "Music tag editor" OFF \
			"K3b" "CD burning application" OFF 3>&1 1>&2 2>&3)")
			for KDE_APPLICATION in ${INSTALL_CONFIG_COMMON_KDE_APPLICATIONS[@]}; do
				if [[ "$KDE_APPLICATION" == "KDE Connect" ]]; then
					INSTALL_PACKAGES=("kdeconnect" "${INSTALL_PACKAGES[@]}")
				elif [[ "$KDE_APPLICATION" == "Kdevelop" ]]; then
					INSTALL_PACKAGES=("kdevelop" "${INSTALL_PACKAGES[@]}")
				elif [[ "$KDE_APPLICATION" == "Ktimer" ]]; then
					INSTALL_PACKAGES=("ktimer" "${INSTALL_PACKAGES[@]}")
				elif [[ "$KDE_APPLICATION" == "Neochat" ]]; then
					INSTALL_PACKAGES=("neochat" "${INSTALL_PACKAGES[@]}")
				elif [[ "$KDE_APPLICATION" == "Kamoso" ]]; then
					INSTALL_PACKAGES=("kamoso" "${INSTALL_PACKAGES[@]}")
				elif [[ "$KDE_APPLICATION" == "Krita" ]]; then
					INSTALL_PACKAGES=("krita" "${INSTALL_PACKAGES[@]}")
				elif [[ "$KDE_APPLICATION" == "Kid3" ]]; then
					INSTALL_PACKAGES=("kid3" "${INSTALL_PACKAGES[@]}")
				elif [[ "$KDE_APPLICATION" == "K3b" ]]; then
					INSTALL_PACKAGES=("k3b" "${INSTALL_PACKAGES[@]}")
				fi
			done

			if whiptail --title "KDE Plasma" --yesno "Do you wish to install some of KDE plasma games?" 8 78; then
				INSTALL_CONFIG_COMMON_KDE_GAMES=("$(whiptail --title "KDE Plasma" --checklist --separate-output "Select the games you want to install:" --nocancel 24 117 17 \
				"Kapman" "A clone of the well known game Pac-Man" ON \
				"KBlocks" "The classic falling blocks game like Tetris" ON \
				"KBounce" "A single player arcade game with the elements of puzzle" ON \
				"KBreakOut" "The objective is to destroy as many bricks as possible without losing the ball" ON \
				"KDiamond" "Single player puzzle game. The object of the game is to build lines of three similar diamonds" ON \
				"KFourInLine" "A four-in-a-row game" ON \
				"Kiriki" "An addictive and fun dice game" ON \
				"KMahjongg" "A tile matching game for one or two players" ON \
				"KMines" "The classic Minesweeper game" ON \
				"Naval Battle" "A ship sinking game" ON \
				"KNights" "Chess board by KDE with XBoard protocol support" ON \
				"KPatience" "Offers a selection of solitaire card games" ON \
				"KSudoku" "A logic-based symbol placement puzzle" ON \
				"0 A.D." "Cross-platform, 3D and historically-based real-time strategy game" ON \
				"Hedgewars" "Turn-based strategy artillery game similiar to Worms" ON \
				"SuperTux" "A classic 2D jump'n'run sidescroller game in a style similar to the original SuperMario games" ON \
				"SuperTuxKart" "Kart racing game featuring Tux and his friends" ON 3>&1 1>&2 2>&3)")
				for KDE_GAME in ${INSTALL_CONFIG_COMMON_KDE_GAMES[@]}; do
					if [[ "$KDE_GAME" == "Kapman" ]]; then
						INSTALL_PACKAGES=("kapman" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "KBlocks" ]]; then
						INSTALL_PACKAGES=("kblocks" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "KBounce" ]]; then
						INSTALL_PACKAGES=("kbounce" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "KBreakOut" ]]; then
						INSTALL_PACKAGES=("kbreakout" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "KDiamond" ]]; then
						INSTALL_PACKAGES=("kdiamond" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "KFourInLine" ]]; then
						INSTALL_PACKAGES=("kfourinline" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "Kiriki" ]]; then
						INSTALL_PACKAGES=("kiriki" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "KMahjongg" ]]; then
						INSTALL_PACKAGES=("kmahjongg" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "KMines" ]]; then
						INSTALL_PACKAGES=("kmines" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "Naval Battle" ]]; then
						INSTALL_PACKAGES=("knavalbattle" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "KNights" ]]; then
						INSTALL_PACKAGES=("knights" "gnuchess" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "KPatience" ]]; then
						INSTALL_PACKAGES=("kpat" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "KSudoku" ]]; then
						INSTALL_PACKAGES=("ksudoku" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "0 A.D." ]]; then
						INSTALL_PACKAGES=("0ad" "0ad-data" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "Hedgewars" ]]; then
						INSTALL_PACKAGES=("hedgewars" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "SuperTux" ]]; then
						INSTALL_PACKAGES=("supertux" "${INSTALL_PACKAGES[@]}")
					elif [[ "$KDE_GAME" == "SuperTuxKart" ]]; then
						INSTALL_PACKAGES=("supertuxkart" "${INSTALL_PACKAGES[@]}")
					fi
				done
			fi
		fi

		#Additional applications
		local INSTALL_CONFIG_COMMON_GUI_APPLICATIONS
		INSTALL_CONFIG_COMMON_GUI_APPLICATIONS=("$(whiptail --title "Common GUI applications" --checklist --separate-output "Select applications you want to install:" --nocancel 16 82 9 \
		"Steam" "Steam game distribution platform by Valve" ON \
		"Lutris" "Lutris open gaming platform for Linux." OFF \
		"Nextcloud" "Nextcloud desktop client" OFF \
		"LibreOffice" "Private, free and open source office suite" ON \
		"OBS Studio" "Free, open source software for live streaming and recording" ON \
		"Vlc" "Free and open source multimedia player and framework" ON \
		"Gimp" "GNU Image Manipulation Program" ON \
		"OpenRGB" "Open source RGB lighting control" ON \
		"Thunderbird" "Standalone mail and news reader from Mozilla" ON 3>&1 1>&2 2>&3)")
		for GUI_APPLICATION in ${INSTALL_CONFIG_COMMON_GUI_APPLICATIONS[@]}; do
			if [[ "$GUI_APPLICATION" == "Steam" ]]; then
				INSTALL_CONFIG_STEAM=YES
				INSTALL_CONFIG_LIB32=YES
				INSTALL_PACKAGES=("steam" "ttf-liberation" "${INSTALL_PACKAGES[@]}")
			elif [[ "$GUI_APPLICATION" == "Lutris" ]]; then
				INSTALL_CONFIG_LUTRIS=YES
				INSTALL_CONFIG_LIB32=YES
				INSTALL_PACKAGES=("lutris" "${INSTALL_PACKAGES[@]}")
			elif [[ "$GUI_APPLICATION" == "Nextcloud" ]]; then
				INSTALL_CONFIG_NEXTCLOUD=YES
				INSTALL_PACKAGES=("nextcloud-client" "${INSTALL_PACKAGES[@]}")
			elif [[ "$GUI_APPLICATION" == "LibreOffice" ]]; then
				INSTALL_CONFIG_LIBREOFFICE=YES
				INSTALL_PACKAGES=("libreoffice-fresh" "hunspell" "${INSTALL_PACKAGES[@]}")
			elif [[ "$GUI_APPLICATION" == "OBS Studio" ]]; then
				INSTALL_CONFIG_OBS=YES
				INSTALL_PACKAGES=("obs-studio" "${INSTALL_PACKAGES[@]}")
			elif [[ "$GUI_APPLICATION" == "Vlc" ]]; then
				INSTALL_CONFIG_VLC=YES
				INSTALL_PACKAGES=("vlc" "vlc-plugins-all" "${INSTALL_PACKAGES[@]}")
			elif [[ "$GUI_APPLICATION" == "Gimp" ]]; then
				INSTALL_CONFIG_GIMP=YES
				INSTALL_PACKAGES=("gimp" "${INSTALL_PACKAGES[@]}")
			elif [[ "$GUI_APPLICATION" == "OpenRGB" ]]; then
				INSTALL_CONFIG_OPENRGB=YES
				INSTALL_PACKAGES=("openrgb" "${INSTALL_PACKAGES[@]}")
			elif [[ "$GUI_APPLICATION" == "Thunderbird" ]]; then
				INSTALL_CONFIG_THUNDERBIRD=YES
				INSTALL_PACKAGES=("thunderbird" "${INSTALL_PACKAGES[@]}")
			fi
		done

		#Additional applications from 7thCore's aur-prebuilt repositories
		if [[ "$INSTALL_CONFIG_AUR_PREBUILT" == "YES" && "$INSTALL_CONFIG_AUR_PREBUILT_LIBREWOLF" == "YES" ]]; then
			local INSTALL_CONFIG_AUR_PREBUILT_GUI_APPLICATIONS
			INSTALL_CONFIG_AUR_PREBUILT_GUI_APPLICATIONS=("$(whiptail --title "Common GUI applications from aur-prebuilt" --checklist --separate-output "Select applications you want to install:" --nocancel 15 112 8 \
			"LibreWolf" "Community-maintained fork of Firefox, focused on privacy, security and freedom" OFF \
			"Brave" "Web browser that blocks ads and trackers by default" OFF \
			"Heroic Game Launcher" "An Open source launcher for Epic, Amazon and GOG games" OFF \
			"Jellyfin Desktop" "Jellyfin desktop client" OFF \
			"TeamViewer" "All-In-One software for remote support and online meetings" OFF \
			"Vesktop" "A cross platform desktop app aiming to give you a snappier Discord experience with Vencord" OFF \
			"WinBox" "Mikrotik RouterOS GUI Configurator" OFF \
			"XIV Launcher" "Custom launcher for Final Fantasy XIV Online" OFF 3>&1 1>&2 2>&3)")
			for AUR_PREBUILT_GUI_APPLICATION in ${INSTALL_CONFIG_AUR_PREBUILT_GUI_APPLICATIONS[@]}; do
				if [[ "$AUR_PREBUILT_GUI_APPLICATION" == "LibreWolf" ]]; then
					INSTALL_PACKAGES=("librewolf-bin" "librewolf-extension-darkreader-bin" "librewolf-extension-istilldontcareaboutcookies-bin" "librewolf-extension-localcdn-bin" "librewolf-extension-reverse-image-search" "librewolf-extension-sponsorblock-bin" "librewolf-extension-ublock-origin-bin" "${INSTALL_PACKAGES[@]}")
				elif [[ "$AUR_PREBUILT_GUI_APPLICATION" == "Brave" ]]; then
					INSTALL_PACKAGES=("brave-bin" "${INSTALL_PACKAGES[@]}")
				elif [[ "$AUR_PREBUILT_GUI_APPLICATION" == "Heroic Game Launcher" ]]; then
					INSTALL_PACKAGES=("heroic-games-launcher-bin" "${INSTALL_PACKAGES[@]}")
				elif [[ "$AUR_PREBUILT_GUI_APPLICATION" == "Jellyfin Desktop" ]]; then
					INSTALL_PACKAGES=("jellyfin-desktop" "${INSTALL_PACKAGES[@]}")
				elif [[ "$AUR_PREBUILT_GUI_APPLICATION" == "TeamViewer" ]]; then
					INSTALL_PACKAGES=("teamviewer" "${INSTALL_PACKAGES[@]}")
				elif [[ "$AUR_PREBUILT_GUI_APPLICATION" == "Vesktop" ]]; then
					INSTALL_PACKAGES=("vesktop" "${INSTALL_PACKAGES[@]}")
				elif [[ "$AUR_PREBUILT_GUI_APPLICATION" == "WinBox" ]]; then
					INSTALL_PACKAGES=("winbox" "${INSTALL_PACKAGES[@]}")
				elif [[ "$AUR_PREBUILT_GUI_APPLICATION" == "XIV Launcher" ]]; then
					INSTALL_PACKAGES=("xivlauncher-bin" "${INSTALL_PACKAGES[@]}")
				fi
			done
		fi
	fi
}

#-------------------------------------------------------------------------

config_systemd_networkd_interfaces() {
	for INTERFACE in $(ip address | grep -oP '(^[\d]+:\s)\K[\d\w]+'); do
		MAC=$(ip address show "${INTERFACE}" | grep -oP '(?<=link/ether\s)\K[\da-f:]+|(?<=link/loopback\s)\K[\da-f:]+')
		printf '%17s %10s\n' "${MAC}" "${INTERFACE}"
	done
}

#-------------------------------------------------------------------------

config_systemd_networkd() {
	INSTALL_CONFIG_SYSTEMD_NETWORKD=NONE
	INSTALL_CONFIG_IP=NONE
	INSTALL_CONFIG_MASK=NONE
	INSTALL_CONFIG_GATEWAY=NONE
	INSTALL_CONFIG_PRIMARY_DNS=NONE
	INSTALL_CONFIG_SECONDARY_DNS=NONE
	INSTALL_CONFIG_MASK_CDIF=NONE
	INSTALL_CONFIG_IP_ADDRESS=NONE
	INSTALL_CONFIG_NETWORK_TYPE=NONE
	INSTALL_CONFIG_NETWORK_MAC_ADDRESS_LIST=NONE
	INSTALL_CONFIG_NETWORK_MAC_ADDRESS_PRIMARY=NONE
	INSTALL_CONFIG_NETWORK_MAC_ADDRESS_SECONDARY=NONE

	INSTALL_CONFIG_SYSTEMD_NETWORKD=$(whiptail --title "Systemd-networkd" --menu "Select your desired network connection" --noitem --nocancel 10 60 2 "dhcp" "" "static" "" 3>&1 1>&2 2>&3)
	if [[ "$INSTALL_CONFIG_SYSTEMD_NETWORKD" == "static" ]]; then
		INSTALL_CONFIG_IP=$(whiptail --title "Systemd-networkd" --inputbox "IP address:" 8 39 192.168.1.10 3>&1 1>&2 2>&3)
		INSTALL_CONFIG_MASK=$(whiptail --title "Systemd-networkd" --inputbox "Netmask:" 8 39 255.255.255.0 3>&1 1>&2 2>&3)
		INSTALL_CONFIG_GATEWAY=$(whiptail --title "Systemd-networkd" --inputbox "Gateway:" 8 39 192.168.1.1 3>&1 1>&2 2>&3)
		INSTALL_CONFIG_PRIMARY_DNS=$(whiptail --title "Systemd-networkd" --inputbox "Primary DNS:" 8 39 1.1.1.1 3>&1 1>&2 2>&3)
		INSTALL_CONFIG_SECONDARY_DNS=$(whiptail --title "Systemd-networkd" --inputbox "Secondary DNS:" 8 39 1.0.0.1 3>&1 1>&2 2>&3)
		INSTALL_CONFIG_MASK_CDIF=$(echo "$INSTALL_CONFIG_MASK" | tr '.' '\n' | awk '{print and($1,255)}' | while read octet; do printf "%08d\n" $(echo "obase=2; $octet" | bc); done | grep -o "1" | wc -l)
		INSTALL_CONFIG_IP_ADDRESS=$(echo "$INSTALL_CONFIG_IP/$INSTALL_CONFIG_MASK_CDIF")
	fi
	INSTALL_CONFIG_NETWORK_TYPE=$(whiptail --title "Systemd-networkd" --menu "Select your desired network type. Select the normal option if you don't know what this list means." --nocancel 12 80 3 "NORMAL" "Normal connection type" "BRIDGE" "Networking with a bridge for virtual machines" "BRIDGE_BOND" "Bonded networking for multiple connections with a bridge" 3>&1 1>&2 2>&3)
	INSTALL_CONFIG_NETWORK_MAC_ADDRESS_LIST=$(config_systemd_networkd_interfaces)
	INSTALL_CONFIG_NETWORK_MAC_ADDRESS_PRIMARY=$(whiptail --title "Systemd-networkd" --menu "Select the network interface for systemd-networkd to use:" --nocancel 20 60 10 ${INSTALL_CONFIG_NETWORK_MAC_ADDRESS_LIST} 3>&1 1>&2 2>&3)
	if [[ "$INSTALL_CONFIG_NETWORK_TYPE" == "BRIDGE_BOND" ]]; then
		INSTALL_CONFIG_NETWORK_MAC_ADDRESS_SECONDARY=$(whiptail --title "Systemd-networkd" --menu "Select the second network interface for systemd-networkd to use for the bond:" --nocancel 20 60 10 ${INSTALL_CONFIG_NETWORK_MAC_ADDRESS_LIST} 3>&1 1>&2 2>&3)
	fi
}

#-------------------------------------------------------------------------

config_menu_network() {
	INSTALL_CONFIG_NETWORK=NONE
	if [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" != "NONE" ]]; then
		INSTALL_CONFIG_NETWORK=$(whiptail --title "Network configuration" --menu "Select your desired network manager. Select NetworkManager if you want to have a graphical user interface in your desktop manager." 12 80 2 "NetworkManager" "GUI - Network connection manager and user applications" "Systemd-networkd" "CLI - System daemon that manages network configurations" 3>&1 1>&2 2>&3)
		if [[ "$?" == "1" ]]; then
			config_menu
		fi
		if [[ "$INSTALL_CONFIG_NETWORK" == "Systemd-networkd" ]]; then
			config_systemd_networkd
		fi
	else
		INSTALL_CONFIG_NETWORK="Systemd-networkd"
		config_systemd_networkd
	fi
}

#-------------------------------------------------------------------------

#Install guest additions
config_menu_vm() {
	if [[ $(systemd-detect-virt) == "qemu" || $(systemd-detect-virt) == "kvm" ]]; then
		if whiptail --title "Virtual machine" --yesno "Virtual machine detected. Install guest additions?" 8 78; then
			if whiptail --title "Guest additions" --yesno "Select guest additions for your virtual machine:" --yes-button "LibVirt/Qemu" --no-button "VirtualBox" 8 78; then
				INSTALL_CONFIG_VM_GUEST_ADDITIONS=QEMU
				INSTALL_PACKAGES=("qemu-guest-agent" "${INSTALL_PACKAGES[@]}")
				if [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" != "NONE" ]]; then
					INSTALL_PACKAGES=("xf86-video-qxl" "spice-vdagent" "${INSTALL_PACKAGES[@]}")
				fi
			else
				INSTALL_CONFIG_VM_GUEST_ADDITIONS=VBOX
				if [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" != "NONE" ]]; then
					INSTALL_PACKAGES=("virtualbox-guest-utils" "${INSTALL_PACKAGES[@]}")
				elif [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" == "NONE" ]]; then
					INSTALL_PACKAGES=("virtualbox-guest-utils-nox" "${INSTALL_PACKAGES[@]}")
				fi
			fi
		fi
	fi
}

#-------------------------------------------------------------------------

#Generate mirrorlist
install_prep_mirrors() {
	local REFLECTOR_COUNTRY_CODE
	REFLECTOR_COUNTRY_CODE=$(curl -4 ifconfig.co/country-iso)
	timedatectl set-ntp true
	pacman -Sy --noconfirm pacman-contrib reflector rsync
	sed -i 's/^#Para/Para/' /etc/pacman.conf
	cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup

	echo "# Generated on $(date +"%Y-%m-%d %H:%M:%S")" > /etc/pacman.d/mirrorlist
	echo '' >> /etc/pacman.d/mirrorlist
	if [[ "$INSTALL_CONFIG_SEVENTHCORE_LOCAL_REPO" == "YES" ]]; then
		{
		echo '# Local mirror'
		echo 'Server = https://repository.7thcore.eu/archlinux/$repo/os/$arch'
		echo ''
		} >> /etc/pacman.d/mirrorlist
	fi
	echo "# $REFLECTOR_COUNTRY_CODE mirrors" >> /etc/pacman.d/mirrorlist
	reflector --protocol https --protocol rsync --country "$REFLECTOR_COUNTRY_CODE" --latest 10 | grep Server >> /etc/pacman.d/mirrorlist
}

#-------------------------------------------------------------------------

#Install Arch Linux and generate fstab
install_base() {
	pacstrap /mnt base base-devel linux linux-lts linux-firmware
	genfstab -U /mnt >> /mnt/etc/fstab
}

#-------------------------------------------------------------------------

#Set language and time zone
install_locale() {
	#Set primary language
	echo "C.UTF-8 UTF-8" > /mnt/etc/locale.gen
	echo "$INSTALL_CONFIG_PRIMARY_LOCALE" >> /mnt/etc/locale.gen

	#Set secondary language
	if [[ "$INSTALL_CONFIG_PRIMARY_LOCALE" != "$INSTALL_CONFIG_SECONDARY_LOCALE" ]]; then
		echo "$INSTALL_CONFIG_SECONDARY_LOCALE" >> /mnt/etc/locale.gen
	fi

	{
	echo "LANG=$INSTALL_CONFIG_PRIMARY_LOCALE"
	echo "LANGUAGE=$INSTALL_CONFIG_PRIMARY_LOCALE"
	echo "LC_ADDRESS=$INSTALL_CONFIG_SECONDARY_LOCALE"
	echo "LC_COLLATE=$INSTALL_CONFIG_SECONDARY_LOCALE"
	echo "LC_CTYPE=$INSTALL_CONFIG_PRIMARY_LOCALE"
	echo "LC_IDENTIFICATION=$INSTALL_CONFIG_SECONDARY_LOCALE"
	echo "LC_MEASUREMENT=$INSTALL_CONFIG_SECONDARY_LOCALE"
	echo "LC_MESSAGES=$INSTALL_CONFIG_PRIMARY_LOCALE"
	echo "LC_MONETARY=$INSTALL_CONFIG_SECONDARY_LOCALE"
	echo "LC_NAME=$INSTALL_CONFIG_SECONDARY_LOCALE"
	echo "LC_NUMERIC=$INSTALL_CONFIG_SECONDARY_LOCALE"
	echo "LC_PAPER=$INSTALL_CONFIG_SECONDARY_LOCALE"
	echo "LC_TELEPHONE=$INSTALL_CONFIG_SECONDARY_LOCALE"
	echo "LC_TIME=$INSTALL_CONFIG_SECONDARY_LOCALE"
	} > /mnt/etc/locale.conf

	echo "KEYMAP=$INSTALL_CONFIG_KEYMAP" > /mnt/etc/vconsole.conf
	rm -rf /mnt/etc/localtime

	arch-chroot /mnt /bin/bash <<- EOF
	locale-gen
	ln -s /usr/share/zoneinfo/$INSTALL_CONFIG_TIMEZONE /etc/localtime
	EOF
}

#-------------------------------------------------------------------------

install_hooks() {
	if [[ "$INSTALL_CONFIG_ENCRYPTION" == "YES" ]]; then
		if [[ "$INSTALL_CONFIG_FILESYSTEM" == "ext4" ]]; then
			arch-chroot /mnt /bin/bash <<- EOF
			sed -i "s+^#\?\(HOOKS\)=.*$+\1=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt lvm2 filesystems resume fsck)+" /etc/mkinitcpio.conf
			EOF
		elif [[ "$INSTALL_CONFIG_FILESYSTEM" == "btrfs" ]]; then
			arch-chroot /mnt /bin/bash <<- EOF
			sed -i "s+^#\?\(BINARIES\)=.*$+\1=(btrfs)+" /etc/mkinitcpio.conf
			sed -i "s+^#\?\(HOOKS\)=.*$+\1=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt filesystems btrfs resume fsck)+" /etc/mkinitcpio.conf
			EOF
		fi
	else
		if [[ "$INSTALL_CONFIG_FILESYSTEM" == "ext4" ]]; then
			arch-chroot /mnt /bin/bash <<- EOF
			sed -i "s+^#\?\(BINARIES\)=.*$+\1=(btrfs)+" /etc/mkinitcpio.conf
			sed -i "s+^#\?\(HOOKS\)=.*$+\1=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block filesystems fsck resume)+" /etc/mkinitcpio.conf
			EOF
		elif [[ "$INSTALL_CONFIG_FILESYSTEM" == "btrfs" ]]; then
			arch-chroot /mnt /bin/bash <<- EOF
			sed -i "s+^#\?\(BINARIES\)=.*$+\1=(btrfs)+" /etc/mkinitcpio.conf
			sed -i "s+^#\?\(HOOKS\)=.*$+\1=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block filesystems btrfs fsck resume)+" /etc/mkinitcpio.conf
			EOF
		fi
	fi
}

#-------------------------------------------------------------------------

install_package_array() {
	if [[ $(cat /proc/cpuinfo | grep vendor | uniq | awk '{print $3}') == *"Intel"* ]]; then
		INSTALL_PACKAGES=("intel-ucode" "${INSTALL_PACKAGES[@]}")
	else
		INSTALL_PACKAGES=("amd-ucode" "${INSTALL_PACKAGES[@]}")
	fi
	INSTALL_PACKAGES=("7zip" \
	"acpid" \
	"apparmor" \
	"bash-completion" \
	"btrfs-progs" \
	"cifs-utils" \
	"cryfs" \
	"dhcpcd" \
	"dosfstools" \
	"e2fsprogs" \
	"encfs" \
	"exfat-utils" \
	"f2fs-tools" \
	"fwupd" \
	"git" \
	"glances" \
	"gnupg" \
	"haveged" \
	"htop" \
	"inetutils" \
	"jfsutils" \
	"linux-firmware" \
	"linux-firmware-qlogic" \
	"linux-headers" \
	"linux-lts" \
	"linux-lts-headers" \
	"lm_sensors" \
	"lshw" \
	"nano" \
	"nilfs-utils" \
	"ntfs-3g" \
	"openvpn" \
	"polkit" \
	"procps-ng" \
	"python-notify2" \
	"python-psutil" \
	"rsync" \
	"smartmontools" \
	"socat" \
	"sshfs" \
	"tk" \
	"tmux" \
	"udftools" \
	"unrar" \
	"usbutils" \
	"util-linux" \
	"wget" \
	"xfsprogs" "${INSTALL_PACKAGES[@]}")

	arch-chroot /mnt /bin/bash <<- EOF
	pacman -Sy --noconfirm ${INSTALL_PACKAGES[@]}
	systemctl enable acpid.service
	systemctl enable smartd.service
	systemctl enable haveged.service
	EOF
}

#-------------------------------------------------------------------------

#Install systemd-boot
install_systemd-boot() {
	local ENCRYPTION
	local FILESYSTEM
	local ROOT_PARTITION
	local SWAP_ENABLED
	local SECURE_BOOT

	ENCRYPTION="$1"
	FILESYSTEM="$2"
	ROOT_PARTITION="$3"
	SWAP_ENABLED="$4"
	SECURE_BOOT="$5"

	arch-chroot /mnt /bin/bash <<- EOF
	bootctl --esp-path=/efi install
	EOF

	mkdir -p /mnt/efi/loader/entries
	mkdir -p /mnt/efi/uki/arch-linux

	cat > /mnt/efi/loader/loader.conf <<- EOF
	default arch-linux.conf
	timeout 4
	console-mode max
	editor no
	EOF

	cat > /mnt/efi/loader/entries/arch-linux.conf <<- EOF
	title Arch Linux
	sort-key archlinux-10
	efi /uki/arch-linux/arch-linux.efi
	EOF

	cat > /mnt/efi/loader/entries/arch-linux-fallback.conf <<- EOF
	title Arch Linux Fallback
	sort-key archlinux-10
	efi /uki/arch-linux/arch-linux-fallback.efi
	EOF

	cat > /mnt/efi/loader/entries/arch-linux-lts.conf <<- EOF
	title Arch Linux LTS
	sort-key archlinux-20
	efi /uki/arch-linux/arch-linux-lts.efi
	EOF

	cat > /mnt/efi/loader/entries/arch-linux-lts-fallback.conf <<- EOF
	title Arch Linux LTS Fallback
	sort-key archlinux-20
	efi /uki/arch-linux/arch-linux-lts-fallback.efi
	EOF

	cat > /mnt/etc/mkinitcpio.d/linux.preset <<- 'EOF'
	# mkinitcpio preset file for the 'linux' package

	#ALL_config="/etc/mkinitcpio.conf"
	ALL_kver="$(pacman -Qql linux | grep 'vmlinuz$')"
	#ALL_kerneldest="/boot/vmlinuz-linux"

	#PRESETS=('default')
	PRESETS=('default' 'fallback')

	#default_config="/etc/mkinitcpio.conf"
	#default_image="/boot/initramfs-linux.img"
	default_uki="/efi/uki/arch-linux/arch-linux.efi"
	default_options="--splash /usr/share/systemd/bootctl/splash-arch.bmp"

	#fallback_config="/etc/mkinitcpio.conf"
	#fallback_image="/boot/initramfs-linux-fallback.img"
	fallback_uki="/efi/uki/arch-linux/arch-linux-fallback.efi"
	fallback_options="--skiphooks autodetect --splash /usr/share/systemd/bootctl/splash-arch.bmp"
	EOF

	cat > /mnt/etc/mkinitcpio.d/linux-lts.preset <<- 'EOF'
	# mkinitcpio preset file for the 'linux-lts' package

	#ALL_config="/etc/mkinitcpio.conf"
	ALL_kver="$(pacman -Qql linux-lts | grep 'vmlinuz$')"
	#ALL_kerneldest="/boot/vmlinuz-linux-lts"

	#PRESETS=('default')
	PRESETS=('default' 'fallback')

	#default_config="/etc/mkinitcpio.conf"
	#default_image="/boot/initramfs-linux-lts.img"
	default_uki="/efi/uki/arch-linux/arch-linux-lts.efi"
	default_options="--splash /usr/share/systemd/bootctl/splash-arch.bmp"

	#fallback_config="/etc/mkinitcpio.conf"
	#fallback_image="/boot/initramfs-linux-lts-fallback.img"
	fallback_uki="/efi/uki/arch-linux/arch-linux-lts-fallback.efi"
	fallback_options="--skiphooks autodetect --splash /usr/share/systemd/bootctl/splash-arch.bmp"
	EOF

	if [ ! -d "/mnt/etc/cmdline.d" ]; then
		mkdir /mnt/etc/cmdline.d
	fi

	if [[ "$ENCRYPTION" == "YES" ]]; then
		ROOT_UUID=$(blkid -s UUID -o value /dev/mapper/crypt_luks_root_install)
	else
		ROOT_UUID=$(blkid -s UUID -o value "$ROOT_PARTITION")
	fi

	if [[ "$FILESYSTEM" == "btrfs" ]]; then
		if [[ "$SWAP_ENABLED" != "disabled" ]]; then
			SWAP_OFFSET=$(btrfs inspect-internal map-swapfile -r /mnt/swap/swapfile | awk '{print $NF}')
			cat > /mnt/etc/cmdline.d/root.conf <<- EOF
			root=UUID=$ROOT_UUID rootfstype=btrfs rootflags=subvol=_active/root-arch resume=UUID=$ROOT_UUID resume_offset=$SWAP_OFFSET rw lsm=landlock,lockdown,yama,integrity,apparmor,bpf audit=1 audit_backlog_limit=4096
			EOF
		else
			cat > /mnt/etc/cmdline.d/root.conf <<- EOF
			root=UUID=$ROOT_UUID rootfstype=btrfs rootflags=subvol=_active/root-arch rw lsm=landlock,lockdown,yama,integrity,apparmor,bpf audit=1 audit_backlog_limit=4096
			EOF
		fi
	elif [[ "$FILESYSTEM" == "ext4" ]]; then
		ROOT_UUID=$(blkid -s UUID -o value "$ROOT_PARTITION")
		if [[ "$SWAP_ENABLED" != "disabled" ]]; then
			cat > /mnt/etc/cmdline.d/root.conf <<- EOF
			root=UUID=$ROOT_UUID resume=UUID=$ROOT_UUID rw
			EOF
		else
			cat > /mnt/etc/cmdline.d/root.conf <<- EOF
			root=UUID=$ROOT_UUID rw
			EOF
		fi
	fi

	if [[ "$ENCRYPTION" == "YES" ]]; then
		LUKS_ROOT_UUID=$(blkid -s UUID -o value "$ROOT_PARTITION")
		LUKS_ROOT_CYPHER=$(cryptsetup -v status crypt_luks_root_install | grep cipher | awk '{print $2}')

		cat >> /mnt/etc/crypttab <<- EOF
		crypt_luks_root0 UUID=$LUKS_ROOT_UUID none cipher=$LUKS_ROOT_CYPHER,timeout=180,tries=3
		EOF
		cp /mnt/etc/crypttab /mnt/etc/crypttab.initramfs
	fi

	mkdir -p /mnt/etc/pacman.d/hooks

	#Create systemd-boot update hook for pacman
	cat > /mnt/etc/pacman.d/hooks/systemd-boot.hook <<- EOF
	[Trigger]
	Type = Package
	Operation = Upgrade
	Target = systemd

	[Action]
	Description = Updating systemd-boot
	When = PostTransaction
	Exec = /usr/bin/bootctl --esp-path=/efi update
	EOF

	if [[ "$SECURE_BOOT" == "YES" ]]; then
		arch-chroot /mnt /bin/bash <<- EOF
		sbctl create-keys
		sbctl enroll-keys -m
		sbctl sign -s /efi/EFI/BOOT/BOOTX64.EFI
		sbctl sign -s /efi/EFI/systemd/systemd-bootx64.efi
		EOF
	fi

	arch-chroot /mnt /bin/bash <<- EOF
	mkinitcpio -p linux
	mkinitcpio -p linux-lts
	EOF
}

#-------------------------------------------------------------------------

#Install grub
install_grub() {
	local ENCRYPTION
	local ROOT_DRIVE
	local LUKS_ROOT_PARTITION
	local LUKS_KEY

	ENCRYPTION="$1"
	ROOT_DRIVE="$2"
	LUKS_ROOT_PARTITION="$3"
	LUKS_KEY="$4"

	mkdir /mnt/hostlvm
	mount --bind /run/lvm /mnt/hostlvm

	arch-chroot /mnt /bin/bash <<- EOF
	pacman -Sy --noconfirm grub
	EOF

	if [[ "$ENCRYPTION" == "YES" ]]; then
		#Write grub boot configuration
		LUKS_ROOT_UUID=$(blkid -s UUID -o value "/dev/$LUKS_ROOT_PARTITION")
		arch-chroot /mnt /bin/bash <<- EOF
		sed -i 's+^#\?\(GRUB_CMDLINE_LINUX_DEFAULT\)=.*$+\1=""+' /etc/default/grub
		sed -i 's+^#\?\(GRUB_CMDLINE_LINUX\)=.*$+\1="rd.luks.name='$LUKS_ROOT_UUID'=crypt_luks_root0 rd.luks.key='$LUKS_ROOT_UUID'=/root/crypt_luks_root0.keyfile"+' /etc/default/grub
		sed -i 's/#GRUB_ENABLE_CRYPTODISK/GRUB_ENABLE_CRYPTODISK/' /etc/default/grub
		sed -i 's+^#\?\(GRUB_PRELOAD_MODULES\)=.*$+\1="part_gpt part_msdos cryptodisk crypto luks lvm"+' /etc/default/grub
		sed -i "s+^#\?\(FILES\)=.*$+\1=(/root/crypt_luks_root0.keyfile)+" /mnt/etc/mkinitcpio.conf
		dd bs=512 count=4 if=/dev/urandom of=/root/crypt_luks_root0.keyfile iflag=fullblock
		chmod 000 /root/crypt_luks_root0.keyfile
		echo -en "$LUKS_KEY\n" | cryptsetup -v luksAddKey /dev/$LUKS_ROOT_UUID /root/crypt_luks_root0.keyfile
		EOF
	else
		#Write grub boot configuration
		arch-chroot /mnt /bin/bash <<- EOF
		sed -i 's+^#\?\(GRUB_CMDLINE_LINUX_DEFAULT\)=.*$+\1=""+' /etc/default/grub
		EOF
	fi

	#Install grub bootloader
	arch-chroot /mnt /bin/bash <<- EOF
	ln -s /hostlvm /run/lvm
	grub-install --target=i386-pc --recheck $ROOT_DRIVE
	EOF

	#Generate grub configuration
	arch-chroot /mnt /bin/bash <<- EOF
	ln -s /hostlvm /run/lvm
	grub-mkconfig -o /boot/grub/grub.cfg
	EOF
}

#-------------------------------------------------------------------------

#Add user, change passwords, add user to sudoers and set hostname
install_user() {
	install_user_shell() {
		if [ -f "/mnt/root/$1" ]; then
			rm "/mnt/root/$1"
		fi
		if [ -f "/mnt/root/$3" ]; then
			rm "/mnt/root/$3"
		fi
		if [ -f "/mnt/root/.tmux.conf" ]; then
			rm "/mnt/root/.tmux.conf"
		fi
		cp "/etc/7thcore/conf/$2" "/mnt/root/$1"
		cp "/etc/7thcore/conf/$4" "/mnt/root/$3"
		cp "/etc/7thcore/conf/$5" "/mnt/root/.tmux.conf"
		if [ -n "$(ls -A /mnt/home/)" ]; then
			for USER_SHELL_INSTALL in /mnt/home/*; do
				if [ -f "$USER_SHELL_INSTALL/$1" ]; then
					rm "$USER_SHELL_INSTALL/$1"
				fi
				if [ -f "$USER_SHELL_INSTALL/$3" ]; then
					rm "$USER_SHELL_INSTALL/$3"
				fi
				if [ -f "$USER_SHELL_INSTALL/.tmux.conf" ]; then
					rm "$USER_SHELL_INSTALL/.tmux.conf"
				fi
				cp "/etc/7thcore/conf/$2" "$USER_SHELL_INSTALL/$1"
				cp "/etc/7thcore/conf/$4" "$USER_SHELL_INSTALL/$3"
				cp "/etc/7thcore/conf/$5" "$USER_SHELL_INSTALL/.tmux.conf"
				chown "$(stat -c "%u" "$USER_SHELL_INSTALL")":"$(stat -c "%g" "$USER_SHELL_INSTALL")" "$USER_SHELL_INSTALL/$1" "$USER_SHELL_INSTALL/$3" "$USER_SHELL_INSTALL/.tmux.conf"
			done
		fi

		if [ -f "/mnt/etc/nanorc" ]; then
			rm "/mnt/etc/nanorc"
		fi
		cp /etc/7thcore/conf/nanorc /mnt/etc/nanorc
	}

	local INSTALL_USER
	local INSTALL_USER_PASS
	local INSTALL_ROOT_PASS
	local INSTALL_HOSTNAME
	local INSTALL_SHELL

	INSTALL_USER="$1"
	INSTALL_USER_PASS="$2"
	INSTALL_ROOT_PASS="$3"
	INSTALL_HOSTNAME="$4"
	INSTALL_SHELL="$5"

	arch-chroot /mnt /bin/bash <<- EOF
	groupadd --system audit
	systemctl enable auditd
	EOF

	if [[ "$INSTALL_SHELL" == "ZSH_SHELL" ]]; then
		arch-chroot /mnt /bin/bash <<- EOF
		useradd -m -g users -G wheel,storage,power,audit,systemd-journal -s /bin/zsh $INSTALL_USER
		chsh --shell /bin/zsh root
		EOF
		install_user_shell ".zshrc" "zshrc" ".zshenv" "zshenv" "tmux_zsh"
	elif [[ "$INSTALL_SHELL" == "BASH_SHELL" ]]; then
		arch-chroot /mnt /bin/bash <<- EOF
		useradd -m -g users -G wheel,storage,power,audit,systemd-journal -s /bin/bash $INSTALL_USER
		EOF
		install_user_shell ".bashrc" "bashrc" ".bash_profile" "bash_profile" "tmux_bash"
	fi

	arch-chroot /mnt /bin/bash <<- EOF
	echo -en "$INSTALL_USER_PASS\n$INSTALL_USER_PASS\n" | passwd $INSTALL_USER
	echo -en "$INSTALL_ROOT_PASS\n$INSTALL_ROOT_PASS\n" | passwd root

	echo "$INSTALL_HOSTNAME" > /etc/hostname
	sed -i 's/localhost/$INSTALL_HOSTNAME/g' /etc/hosts
	sed -i 's/$INSTALL_HOSTNAME.localdomain/localhost.localdomain/g' /etc/hosts
	sed -i 's/log_group = root/log_group = audit/g' /etc/audit/auditd.conf
	chmod 750 /var/log/audit
	EOF

	if [ ! -d /mnt/etc/sudoers.d ]; then
		mkdir /mnt/etc/sudoers.d
	fi

	if [ ! -d /mnt/etc/tmpfiles.d ]; then
		mkdir /mnt/etc/tmpfiles.d
	fi
	cat > /mnt/etc/tmpfiles.d/audit.conf <<- EOF
	z /var/log/audit 750 root audit - -
	EOF

	cat > "/mnt/etc/sudoers.d/user-$INSTALL_USER" <<- EOF
	$INSTALL_USER ALL=(ALL) ALL
	EOF
}

#-------------------------------------------------------------------------

#Enable multilib repository
install_lib32() {
	echo "[multilib]" >> /mnt/etc/pacman.conf
	echo "Include = /etc/pacman.d/mirrorlist" >> /mnt/etc/pacman.conf
	arch-chroot /mnt /bin/bash <<- EOF
	pacman -Sy --noconfirm
	EOF
}

#-------------------------------------------------------------------------

#Install arch user repository pre-built repositories
install_aur() {
	local INSTALL_AUR_PREBUILT
	local INSTALL_AUR_PREBUILT_CORE
	local INSTALL_AUR_PREBUILT_DOTNET
	local INSTALL_AUR_PREBUILT_FFMPEG
	local INSTALL_AUR_PREBUILT_LIBREWOLF
	local INSTALL_AUR_PREBUILT_NVIDIA390
	local INSTALL_AUR_PREBUILT_NVIDIA470
	local INSTALL_AUR_PREBUILT_NVIDIA550

	INSTALL_AUR_PREBUILT="$1"
	INSTALL_AUR_PREBUILT_CORE="$2"
	INSTALL_AUR_PREBUILT_DOTNET="$3"
	INSTALL_AUR_PREBUILT_FFMPEG="$4"
	INSTALL_AUR_PREBUILT_LIBREWOLF="$5"
	INSTALL_AUR_PREBUILT_NVIDIA390="$6"
	INSTALL_AUR_PREBUILT_NVIDIA470="$7"
	INSTALL_AUR_PREBUILT_NVIDIA550="$8"

	if [[ "$INSTALL_AUR_PREBUILT" == "YES" ]]; then
		cat >> /mnt/etc/pacman.conf <<- EOF
		Include = /etc/pacman.d/aur-prebuilt
		EOF

		cat > /mnt/etc/pacman.d/aur-prebuilt <<- 'EOF'
		[aur-prebuilt]
		SigLevel = Optional TrustAll
		Server = https://repository.7thcore.eu/archlinux/$repo/os/$arch
		EOF
	fi

	if [[ "$INSTALL_AUR_PREBUILT_CORE" == "YES" ]]; then
		cat >> /mnt/etc/pacman.conf <<- EOF
		Include = /etc/pacman.d/aur-prebuilt-core
		EOF

		cat > /mnt/etc/pacman.d/aur-prebuilt-core <<- 'EOF'
		[aur-prebuilt-core]
		SigLevel = Optional TrustAll
		Server = https://repository.7thcore.eu/archlinux/$repo/os/$arch
		EOF
	fi

	if [[ "$INSTALL_AUR_PREBUILT_DOTNET" == "YES" ]]; then
		cat >> /mnt/etc/pacman.conf <<- EOF
		Include = /etc/pacman.d/aur-prebuilt-dotnet
		EOF

		cat > /mnt/etc/pacman.d/aur-prebuilt-dotnet <<- 'EOF'
		[aur-prebuilt-dotnet]
		SigLevel = Optional TrustAll
		Server = https://repository.7thcore.eu/archlinux/$repo/os/$arch
		EOF
	fi

	if [[ "$INSTALL_AUR_PREBUILT_FFMPEG" == "YES" ]]; then
		cat >> /mnt/etc/pacman.conf <<- EOF
		Include = /etc/pacman.d/aur-prebuilt-ffmpeg
		EOF

		cat > /mnt/etc/pacman.d/aur-prebuilt-ffmpeg <<- 'EOF'
		[aur-prebuilt-ffmpeg]
		SigLevel = Optional TrustAll
		Server = https://repository.7thcore.eu/archlinux/$repo/os/$arch
		EOF
	fi

	if [[ "$INSTALL_AUR_PREBUILT_LIBREWOLF" == "YES" ]]; then
		cat >> /mnt/etc/pacman.conf <<- EOF
		Include = /etc/pacman.d/aur-prebuilt-librewolf
		EOF

		cat > /mnt/etc/pacman.d/aur-prebuilt-librewolf <<- 'EOF'
		[aur-prebuilt-librewolf]
		SigLevel = Optional TrustAll
		Server = https://repository.7thcore.eu/archlinux/$repo/os/$arch
		EOF
	fi

	if [[ "$INSTALL_AUR_PREBUILT_NVIDIA390" == "YES" ]]; then
		cat >> /mnt/etc/pacman.conf <<- EOF
		Include = /etc/pacman.d/aur-prebuilt-nvidia390
		EOF

		cat > /mnt/etc/pacman.d/aur-prebuilt-nvidia390 <<- 'EOF'
		[aur-prebuilt-nvidia390]
		SigLevel = Optional TrustAll
		Server = https://repository.7thcore.eu/archlinux/$repo/os/$arch
		EOF
	fi

	if [[ "$INSTALL_AUR_PREBUILT_NVIDIA470" == "YES" ]]; then
		cat >> /mnt/etc/pacman.conf <<- EOF
		Include = /etc/pacman.d/aur-prebuilt-nvidia470
		EOF

		cat > /mnt/etc/pacman.d/aur-prebuilt-nvidia470 <<- 'EOF'
		[aur-prebuilt-nvidia470]
		SigLevel = Optional TrustAll
		Server = https://repository.7thcore.eu/archlinux/$repo/os/$arch
		EOF
	fi

	if [[ "$INSTALL_AUR_PREBUILT_NVIDIA550" == "YES" ]]; then
		cat >> /mnt/etc/pacman.conf <<- EOF
		Include = /etc/pacman.d/aur-prebuilt-nvidia550
		EOF

		cat > /mnt/etc/pacman.d/aur-prebuilt-nvidia550 <<- 'EOF'
		[aur-prebuilt-nvidia550]
		SigLevel = Optional TrustAll
		Server = https://repository.7thcore.eu/archlinux/$repo/os/$arch
		EOF
	fi
	arch-chroot /mnt /bin/bash <<- EOF
	pacman -Sy --noconfirm
	EOF
}

#-------------------------------------------------------------------------

#Install OpenSSH
install_ssh() {
	local INSTALL_USER
	local INSTALL_SSH_PORT

	INSTALL_USER="$1"
	INSTALL_SSH_PORT="$2"

	cat > /mnt/etc/ssh/sshd_config <<- EOF
	# Include drop-in configurations
	Include /etc/ssh/sshd_config.d/*.conf

	# This is the sshd server system-wide configuration file. See
	# sshd_config(5) for more information.

	# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/bin

	# The strategy used for options in the default sshd_config shipped with
	# OpenSSH is to specify options with their default value where
	# possible, but leave them commented. Uncommented options override the
	# default value.

	Port $INSTALL_SSH_PORT
	#AddressFamily any
	#ListenAddress 0.0.0.0
	#ListenAddress ::

	#HostKey /etc/ssh/ssh_host_rsa_key
	#HostKey /etc/ssh/ssh_host_ecdsa_key
	#HostKey /etc/ssh/ssh_host_ed25519_key

	# Ciphers and keying
	#RekeyLimit default none

	# Logging
	#SyslogFacility AUTH
	#LogLevel INFO

	# Authentication:

	AllowUsers $INSTALL_USER
	#LoginGraceTime 2m
	#PermitRootLogin prohibit-password
	#StrictModes yes
	#MaxAuthTries 6
	#MaxSessions 10

	#PubkeyAuthentication yes

	# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
	# but this is overridden so installations will only check .ssh/authorized_keys
	AuthorizedKeysFile	.ssh/authorized_keys

	#AuthorizedPrincipalsFile none

	#AuthorizedKeysCommand none
	#AuthorizedKeysCommandUser nobody

	# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
	#HostbasedAuthentication no
	# Change to yes if you don't trust ~/.ssh/known_hosts for
	# HostbasedAuthentication
	#IgnoreUserKnownHosts no
	# Don't read the user's ~/.rhosts and ~/.shosts files
	#IgnoreRhosts yes

	# To disable tunneled clear text passwords, change to "no" here!
	#PasswordAuthentication no
	PasswordAuthentication yes
	PermitEmptyPasswords no

	# Change to "no" to disable keyboard-interactive authentication. Depending on
	# the system's configuration, this may involve passwords, challenge-response,
	# one-time passwords or some combination of these and other methods.
	#KbdInteractiveAuthentication yes

	# Kerberos options
	#KerberosAuthentication no
	#KerberosOrLocalPasswd yes
	#KerberosTicketCleanup yes
	#KerberosGetAFSToken no

	# GSSAPI options
	#GSSAPIAuthentication no
	#GSSAPICleanupCredentials yes

	# Set this to 'yes' to enable PAM authentication, account processing,
	# and session processing. If this is enabled, PAM authentication will
	# be allowed through the KbdInteractiveAuthentication and
	# PasswordAuthentication. Depending on your PAM configuration,
	# PAM authentication via KbdInteractiveAuthentication may bypass
	# the setting of "PermitRootLogin prohibit-password".
	# If you just want the PAM account and session checks to run without
	# PAM authentication, then enable this but set PasswordAuthentication
	# and KbdInteractiveAuthentication to 'no'.
	UsePAM yes

	#AllowAgentForwarding yes
	#AllowTcpForwarding yes
	#GatewayPorts no
	#X11Forwarding no
	#X11DisplayOffset 10
	#X11UseLocalhost yes
	#PermitTTY yes
	PrintMotd no
	#PrintLastLog yes
	#TCPKeepAlive yes
	#PermitUserEnvironment no
	#Compression delayed
	#ClientAliveInterval 0
	#ClientAliveCountMax 3
	#UseDNS no
	#PidFile /run/sshd.pid
	#MaxStartups 10:30:100
	#PermitTunnel no
	#ChrootDirectory none
	#VersionAddendum none

	# no default banner path
	#Banner none

	# override default of no subsystems
	Subsystem	sftp	/usr/lib/ssh/sftp-server

	# Example of overriding settings on a per-user basis
	#Match User anoncvs
	#	X11Forwarding no
	#	AllowTcpForwarding no
	#	PermitTTY no
	#	ForceCommand cvs server
	EOF

	if [ ! -d "/mnt/home/$INSTALL_USER/.config/systemd/user/" ]; then
		mkdir -p "/mnt/home/$INSTALL_USER/.config/systemd/user/"
	fi

	cat > "/mnt/home/$INSTALL_USER/.config/systemd/user/ssh-agent.service" <<- 'EOF'
	[Unit]
	Description=SSH key agent

	[Service]
	Type=simple
	Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket
	Environment=DISPLAY=:0
	ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK

	[Install]
	WantedBy=default.target
	EOF

	arch-chroot /mnt /bin/bash <<- EOF
	systemctl enable sshd.service
	EOF

	arch-chroot /mnt /bin/bash <<- EOF
	chown -R $INSTALL_USER:users /home/$INSTALL_USER/.config
	EOF
}

#-------------------------------------------------------------------------

#Install ufw firewall
install_ufw() {
	local INSTALL_SSH
	local INSTALL_SSH_PORT
	local INSTALL_SMB
	local INSTALL_STEAM

	INSTALL_SSH="$1"
	INSTALL_SSH_PORT="$2"
	INSTALL_SMB="$3"
	INSTALL_STEAM="$4"

	arch-chroot /mnt /bin/bash <<- EOF
	systemctl enable ufw.service
	EOF

	if [[ "$INSTALL_SSH" == "YES" ]]; then
		cat > /mnt/etc/ufw/applications.d/ufw-openssh-custom <<- EOF
		[OpenSSH-Custom]
		title=OpenSSH-Custom
		description=OpenSSH is the premier connectivity tool for remote login with the SSH protocol. It encrypts all traffic to eliminate eavesdropping, connection hijacking, and other attacks. In addition, OpenSSH provides a large suite of secure tunneling capabilities, several authentication methods, and sophisticated configuration options.
		ports=$INSTALL_SSH_PORT/tcp
		EOF
	fi

	cat > /mnt/etc/ufw/applications.d/ufw-steam <<- EOF
	[Steam]
	title=Steam
	description=Steam is a popular game distribution platform by Valve
	ports=3478/udp|4379/udp|4380/udp|27015:27030/udp|27015:27030/tcp|27000:27030/udp|27032:27035/udp|27037:27100/udp

	[Steam In-Home Streaming]
	title=Steam In-Home Streaming
	description=Steam's in-home streaming solution
	ports=27031/udp|27036/udp|27036/tcp|27037/tcp
	EOF

	cat > /mnt/etc/ufw/applications.d/ufw-kdeconnect <<- EOF
	[KDEConnect]
	title=KDEConnect
	description=KDE's phone integration tool
	ports=1714:1764/udp|1714:1764/tcp
	EOF

	arch-chroot /mnt /bin/bash <<- EOF
	ufw app update Steam
	ufw app update KDEConnect
	ufw allow KDEConnect
	ufw default deny incoming
	ufw default allow outgoing
	EOF

	if [[ "$INSTALL_SSH" == "YES" ]]; then
		arch-chroot /mnt /bin/bash <<- EOF
		ufw app update OpenSSH-Custom
		ufw allow OpenSSH-Custom
		EOF
	fi

	if [[ "$INSTALL_SMB" == "YES" ]]; then
		arch-chroot /mnt /bin/bash <<- EOF
		ufw allow CIFS
	EOF
	fi

	if [[ "$INSTALL_STEAM" == "YES" ]]; then
		arch-chroot /mnt /bin/bash <<- EOF
		ufw allow Steam
	EOF
	fi

	arch-chroot /mnt /bin/bash <<- EOF
	ufw enable
	EOF
}

#-------------------------------------------------------------------------

#Install samba file sharing
install_smb() {
	local INSTALL_USER
	local INSTALL_HOSTNAME
	local INSTALL_SMBPSW
	local INSTALL_SMBWG

	INSTALL_USER="$1"
	INSTALL_HOSTNAME="$2"
	INSTALL_SMBPSW="$3"
	INSTALL_SMBWG="$4"

	cat > /mnt/etc/samba/smb.conf <<- EOF
	#======================= Global Settings =====================================
	[global]

	# network socket options
	;  socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536

	# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
	workgroup = $INSTALL_SMBWG

	# server string is the equivalent of the NT Description field
	server string = Arch Linux

	# server netbios name
	netbios name = $INSTALL_HOSTNAME

	# Server role
	server role = standalone server

	# Allow hosts
	;   hosts allow = 192.168.1. 192.168.2. 127.

	# Logs
	logging = systemd

	# Put a capping on the size of the log files (in Kb).
	max log size = 50

	# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
	# via DNS nslookups. The default is NO.
	dns proxy = no

	# SMB1 protocol is considered a security risk and most clients at least support SMB2.
	# So it makes sense to deny connection attempts to the server via SMB1 protocol:
	server min protocol = SMB3

	#============================ Share Definitions ==============================
	[private]
		comment = PRIVATE
		path = /home/$INSTALL_USER/Shares/Local/Private
		valid users = $INSTALL_USER
		public = no
		writable = yes
		printable = no
		vfs objects = recycle
		recycle:repository = .recycle
		recycle:keeptree = yes
		recycle:versions = yes

	[public]
		comment = PUBLIC
		path = /home/$INSTALL_USER/Shares/Local/Public
		public = yes
		writable = yes
		printable = no
		vfs objects = recycle
		recycle:repository = .recycle
		recycle:keeptree = yes
		recycle:versions = yes
	EOF

	#Generate shares for user
	mkdir -p "/mnt/home/$INSTALL_USER/Shares/Local/Private"
	mkdir -p "/mnt/home/$INSTALL_USER/Shares/Local/Public"

	#Test samba conf, add samba user and give samba acces to it's logs
	arch-chroot /mnt /bin/bash <<- EOF
	chown -R $INSTALL_USER:samba /home/$INSTALL_USER/Shares/Local/Private
	chown -R $INSTALL_USER:samba /home/$INSTALL_USER/Shares/Local/Public
	testparm
	echo -en "$INSTALL_SMBPSW\n$INSTALL_SMBPSW\n" | smbpasswd -a $INSTALL_USER
	chown $INSTALL_USER -R /home/$INSTALL_USER/Shares
	systemctl enable smb.service
	systemctl enable nmb.service
	systemctl enable winbind.service
	EOF
}

#-------------------------------------------------------------------------

#Install psotfix relay
install_postfix() {
	local INSTALL_POSTFIXUSER
	local INSTALL_POSTFIXPSW

	INSTALL_POSTFIXUSER="$1"
	INSTALL_POSTFIXPSW="$2"

	cat >> /mnt/etc/postfix/main.cf <<- EOF
	relayhost = [smtp.gmail.com]:587
	smtp_sasl_auth_enable = yes
	smtp_sasl_password_maps = lmdb:/etc/postfix/sasl_passwd
	smtp_sasl_security_options = noanonymous
	smtp_tls_CApath = /etc/ssl/certs
	smtpd_tls_CApath = /etc/ssl/certs
	smtp_use_tls = yes
	EOF

	cat > /mnt/etc/postfix/sasl_passwd <<- EOF
	[smtp.gmail.com]:587 $INSTALL_POSTFIXUSER:$INSTALL_POSTFIXPSW
	EOF

	arch-chroot /mnt /bin/bash <<- EOF
	chmod 400 /etc/postfix/sasl_passwd
	postmap /etc/postfix/sasl_passwd
	systemctl enable postfix
	EOF
}

#-------------------------------------------------------------------------


#Install the wine compatibility layer
install_wine() {
	cat > /mnt/etc/pacman.d/hooks/stop-wine-associations.hook <<- 'EOF'
	[Trigger]
	Type = File
	Operation = Install
	Operation = Upgrade
	Target = usr/share/wine/wine.inf

	[Action]
	Description = Stopping Wine from hijacking file associations...
	When = PostTransaction
	Exec = /bin/sh -c '/usr/bin/grep -q "HKCU,\"Software\\\Wine\\\FileOpenAssociations\",\"Enable\",2,\"N\"" /usr/share/wine/wine.inf || /usr/bin/sed -i "s/\[Services\]/\[Services\]\nHKCU,\"Software\\\Wine\\\FileOpenAssociations\",\"Enable\",2,\"N\"/g" /usr/share/wine/wine.inf'
	EOF
}

#-------------------------------------------------------------------------

#Install libvirt
install_libvirt() {
	local INSTALL_USER
	INSTALL_USER="$1"
	arch-chroot /mnt /bin/bash <<- EOF
	systemctl enable libvirtd.service
	systemctl enable virtlogd.service
	systemctl enable libvirt-guests.service
	usermod -a -G kvm $INSTALL_USER
	usermod -a -G libvirt $INSTALL_USER
	EOF

	rm /mnt/etc/conf.d/libvirt-guests

	cat > /mnt/etc/conf.d/libvirt-guests <<- EOF
	BYPASS_CACHE=0
	CONNECT_RETRIES=10
	ON_BOOT=start
	ON_SHUTDOWN=shutdown
	PARALLEL_SHUTDOWN=0
	RETRIES_SLEEP=1
	SHUTDOWN_TIMEOUT=300
	START_DELAY=0
	URIS=default
	EOF

	{
	echo '/* Allow users in kvm group to manage the libvirt daemon without authentication */'
	echo 'polkit.addRule(function(action, subject) {'
	echo '	if (action.id == "org.libvirt.unix.manage" &&'
	echo '		subject.isInGroup("kvm")) {'
	echo '			return polkit.Result.YES;'
	echo '	}'
	echo '});'
	} > /mnt/etc/polkit-1/rules.d/50-libvirt.rules

	{
	echo ''
	echo 'nvram = ['
	echo '	"/usr/share/edk2-ovmf/x64/OVMF_CODE.fd:/usr/share/edk2-ovmf/x64/OVMF_VARS.fd"'
	echo '	"/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd:/usr/share/edk2-ovmf/x64/OVMF_VARS.fd"'
	echo ']'
	echo ''
	echo 'spice_tls = 0'
	echo ''
	} >> /mnt/etc/libvirt/qemu.conf
}

#-------------------------------------------------------------------------

#Install gnome desktop environment
#install_gnome() {

#network-manager-applet
#}

#-------------------------------------------------------------------------

#Install kde plasma desktop environment
install_kde() {
	local INSTALL_USER
	local INSTALL_KDE_AUTOLOGIN

	INSTALL_USER="$1"
	INSTALL_KDE_AUTOLOGIN="$2"

	arch-chroot /mnt /bin/bash <<- EOF
	systemctl enable sddm.service
	EOF

	cat > /mnt/etc/profile.d/sshaskpass.sh <<- EOF
	export SSH_ASKPASS="/usr/bin/ksshaskpass"
	EOF

	if [ ! -d "/mnt/etc/systemd/system/sddm.service.d" ]; then
		mkdir -p /mnt/etc/systemd/system/sddm.service.d/
	fi

	cat > /mnt/etc/systemd/system/sddm.service.d/keyringmode.conf <<- EOF
	[Service]
	KeyringMode=inherit
	EOF

	if [ ! -d "/mnt/etc/sddm.conf.d" ]; then
		mkdir /mnt/etc/sddm.conf.d
	fi

	if [[ "$INSTALL_KDE_AUTOLOGIN" == "YES" ]] || [[ "$INSTALL_KDE_AUTOLOGIN" == "YES-LOCK" ]]; then
		cat > /mnt/etc/sddm.conf.d/kde_settings.conf <<- EOF
		[Autologin]
		Relogin=false
		Session=plasma
		User=$INSTALL_USER
		EOF
	fi

	if [ ! -d "/mnt/home/$INSTALL_USER/.config" ]; then
		mkdir -p "/mnt/home/$INSTALL_USER/.config"
	fi

	if [ ! -d "/mnt/home/$INSTALL_USER/.config/autostart" ]; then
		mkdir -p "/mnt/home/$INSTALL_USER/.config/autostart"
	fi

	cat > "/mnt/home/$INSTALL_USER/.config/autostart/apparmor-notify.desktop" <<- EOF
	[Desktop Entry]
	Type=Application
	Name=AppArmor Notify
	Comment=Receive on screen notifications of AppArmor denials
	TryExec=aa-notify
	Exec=aa-notify -p -s 1 -w 60 -f /var/log/audit/audit.log
	StartupNotify=false
	NoDisplay=true
	EOF

	if [[ "$INSTALL_KDE_AUTOLOGIN" == "YES-LOCK" ]]; then
		cat > "/mnt/home/$INSTALL_USER/.config/kscreenlockerrc" <<- EOF
		[Daemon]
		LockOnStart=true
		EOF

		arch-chroot /mnt /bin/bash <<- EOF
		chown -R $INSTALL_USER:users /home/$INSTALL_USER/.config
		EOF
	fi

	cat >> "/mnt/etc/sddm.conf.d/kde_settings.conf" <<- EOF
	[General]
	HaltCommand=/usr/bin/systemctl poweroff
	RebootCommand=/usr/bin/systemctl reboot

	[Theme]
	Current=

	[Users]
	MaximumUid=60513
	MinimumUid=1000
	EOF
}

#-------------------------------------------------------------------------

#Install systemd-networkd static configuration for a single network interface
install_systemdnetworkd_static_single() {
	cat > /mnt/etc/systemd/network/network-eth0.network <<- EOF
	[Match]
	MACAddress=$INSTALL_CONFIG_NETWORK_MAC_ADDRESS_PRIMARY

	[Link]
	Description=LAN Controller
	Name=network-eth0

	[Network]
	Address=$INSTALL_CONFIG_IP_ADDRESS
	Gateway=$INSTALL_CONFIG_GATEWAY
	DNS=$INSTALL_CONFIG_PRIMARY_DNS
	DNS=$INSTALL_CONFIG_SECONDARY_DNS
	EOF
}

#-------------------------------------------------------------------------

#Install systemd-networkd static configuration for a single network interface with a bridge
install_systemdnetworkd_static_bridge() {
	cat > /mnt/etc/systemd/network/nic0-bridge.netdev <<- EOF
	NetDev]
	Name=nic0-bridge
	Kind=bridge
	EOF

	cat > /mnt/etc/systemd/network/nic0-bridge.network <<- EOF
	[Match]
	Name=nic0-bridge

	[Network]
	Address=$INSTALL_CONFIG_IP_ADDRESS
	Gateway=$INSTALL_CONFIG_GATEWAY
	DNS=$INSTALL_CONFIG_PRIMARY_DNS
	DNS=$INSTALL_CONFIG_SECONDARY_DNS
	EOF

	cat > /mnt/etc/systemd/network/nic0.network <<- EOF
	[Match]
	MACAddress=$INSTALL_CONFIG_NETWORK_MAC_ADDRESS_PRIMARY

	[Network]
	Bridge=nic0-bridge
	EOF
}

#-------------------------------------------------------------------------

#Install systemd-networkd static configuration for two network interface with a bridge
install_systemdnetworkd_static_bridge_bond() {
	cat > /mnt/etc/systemd/network/bridge-bond0.netdev <<- EOF
	[NetDev]
	Name=bridge-bond0
	Kind=bridge
	EOF

	cat > /mnt/etc/systemd/network/bridge-bond0.network <<- EOF
	[Match]
	Name=nic-bond0

	[Network]
	Bridge=bridge-bond0
	EOF

	cat > /mnt/etc/systemd/network/net-bond0.network <<- EOF
	[Match]
	Name=bridge-bond0

	[Network]
	Address=$INSTALL_CONFIG_IP_ADDRESS
	Gateway=$INSTALL_CONFIG_GATEWAY
	DNS=$INSTALL_CONFIG_PRIMARY_DNS
	DNS=$INSTALL_CONFIG_SECONDARY_DNS
	EOF

	cat > /mnt/etc/systemd/network/nic-bond0.netdev <<- EOF
	[NetDev]
	Name=nic-bond0
	Description=LAG/Bond to a switch
	Kind=bond

	[Bond]
	Mode=802.3ad
	EOF

	cat >> /mnt/etc/systemd/network/nic-bond0.network <<- EOF
	[Match]
	Mame=nic0
	Mame=nic1

	[Network]
	Bond=nic-bond0
	EOF

	cat >> /mnt/etc/udev/rules.d/10-network.rules <<- EOF
	SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="${INSTALL_CONFIG_NETWORK_MAC_ADDRESS_PRIMARY}", NAME="nic0"
	SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="${INSTALL_CONFIG_NETWORK_MAC_ADDRESS_SECONDARY}", NAME="nic1"
	EOF
}

#-------------------------------------------------------------------------

#Install systemd-networkd dhcp configuration for a single network interface
install_systemdnetworkd_dhcp_single() {
	cat > /mnt/etc/systemd/network/network-eth0.network <<- EOF
	[Match]
	MACAddress=$INSTALL_CONFIG_NETWORK_MAC_ADDRESS_PRIMARY

	[Link]
	RequiredForOnline=routable

	[Network]
	DHCP=yes

	[DHCPv4]
	RouteMetric=100

	[IPv6AcceptRA]
	RouteMetric=100
	EOF
}

#-------------------------------------------------------------------------

#Install systemd-networkd dhcp configuration for a single network interface with a bridge
install_systemdnetworkd_dhcp_bridge() {
	cat > /mnt/etc/systemd/network/nic0-bridge.netdev <<- EOF
	[NetDev]
	Name=nic0-bridge
	Kind=bridge
	EOF

	cat > /mnt/etc/systemd/network/nic0-bridge.network <<- EOF
	[Match]
	Name=nic0-bridge

	[Link]
	RequiredForOnline=routable

	[Network]
	DHCP=yes

	[DHCPv4]
	RouteMetric=100

	[IPv6AcceptRA]
	RouteMetric=100
	EOF

	cat > /mnt/etc/systemd/network/nic0.network <<- EOF
	[Match]
	MACAddress=$INSTALL_CONFIG_NETWORK_MAC_ADDRESS_PRIMARY

	[Network]
	Bridge=nic0-bridge
	EOF
}

#-------------------------------------------------------------------------

#Install systemd-networkd dhcp configuration for two network interface with a bridge
install_systemdnetworkd_dhcp_bridge_bond() {
	cat > /mnt/etc/systemd/network/bridge-bond0.netdev <<- EOF
	[NetDev]
	Name=bridge-bond0
	Kind=bridge
	EOF

	cat > /mnt/etc/systemd/network/bridge-bond0.network <<- EOF
	[Match]
	Name=nic-bond0

	[Network]
	Bridge=bridge-bond0
	EOF

	cat > /mnt/etc/systemd/network/net-bond0.network <<- EOF
	[Match]
	Name=bridge-bond0

	[Link]
	RequiredForOnline=routable

	[Network]
	DHCP=yes

	[DHCPv4]
	RouteMetric=100

	[IPv6AcceptRA]
	RouteMetric=100
	EOF

	cat > /mnt/etc/systemd/network/nic-bond0.netdev <<- EOF
	[NetDev]
	Name=nic-bond0
	Description=LAG/Bond to a switch
	Kind=bond

	[Bond]
	Mode=802.3ad
	EOF

	cat >> /mnt/etc/systemd/network/nic-bond0.network <<- EOF
	[Match]
	Mame=nic0
	Mame=nic1

	[Network]
	Bond=nic-bond0
	EOF

	cat >> /mnt/etc/udev/rules.d/10-network.rules <<- EOF
	SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="${INSTALL_CONFIG_NETWORK_MAC_ADDRESS_PRIMARY}", NAME="nic0"
	SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="${INSTALL_CONFIG_NETWORK_MAC_ADDRESS_SECONDARY}", NAME="nic1"
	EOF
}

#-------------------------------------------------------------------------

#Main installation
install_main() {
	install_prep_mirrors "$INSTALL_CONFIG_SEVENTHCORE_LOCAL_REPO"
	install_base
	install_locale
	install_hooks
	if [[ "$INSTALL_CONFIG_LIB32" == "YES" ]]; then
		install_lib32
		INSTALL_PACKAGES_LIB32=("lib32-procps-ng" "${INSTALL_PACKAGES_LIB32[@]}")
		INSTALL_PACKAGES+=(${INSTALL_PACKAGES_LIB32[@]})
	fi
	install_aur "$INSTALL_CONFIG_AUR_PREBUILT" "$INSTALL_CONFIG_AUR_PREBUILT_CORE" "$INSTALL_CONFIG_AUR_PREBUILT_DOTNET" "$INSTALL_CONFIG_AUR_PREBUILT_FFMPEG" "$INSTALL_CONFIG_AUR_PREBUILT_LIBREWOLF" "$INSTALL_CONFIG_AUR_PREBUILT_NVIDIA390" "$INSTALL_CONFIG_AUR_PREBUILT_NVIDIA470" "$INSTALL_CONFIG_AUR_PREBUILT_NVIDIA550"
	install_package_array
	if [ -d "/sys/firmware/efi/efivars" ]; then
		install_systemd-boot "$INSTALL_CONFIG_ENCRYPTION" "$INSTALL_CONFIG_FILESYSTEM" "$INSTALL_CONFIG_ROOT_PARTITION" "$INSTALL_CONFIG_SWAP_SIZE" "$INSTALL_CONFIG_SECURE_BOOT"
	else
		install_grub "$INSTALL_CONFIG_ENCRYPTION" "$INSTALL_CONFIG_DISK" "$INSTALL_CONFIG_ROOT_PARTITION" "$INSTALL_CONFIG_ENCRYPTION_PASSWORD"
	fi
	install_user "$INSTALL_CONFIG_USER" "$INSTALL_CONFIG_USER_PASSWORD" "$INSTALL_CONFIG_ROOT_PASSWORD" "$INSTALL_CONFIG_HOSTNAME" "$INSTALL_CONFIG_USER_SHELL"
	if [[ "$INSTALL_CONFIG_SSH" == "YES" ]]; then
		install_ssh "$INSTALL_CONFIG_USER" "$INSTALL_CONFIG_SSH_PORT"
	fi
	if [[ "$INSTALL_CONFIG_UFW" == "YES" ]]; then
		install_ufw "$CONFIG_SSH" "$INSTALL_CONFIG_SSH_PORT" "$INSTALL_CONFIG_SAMBA" "$INSTALL_CONFIG_STEAM"
	fi
	if [[ "$INSTALL_CONFIG_NTP" == "YES" ]]; then
		arch-chroot /mnt /bin/bash <<- EOF
		systemctl enable ntpd.service
		ntpdate time.nist.gov
		hwclock --systohc --utc
		EOF
	fi
	if [[ "$INSTALL_CONFIG_SAMBA" == "YES" ]]; then
		install_smb "$INSTALL_CONFIG_USER" "$INSTALL_CONFIG_HOSTNAME" "$INSTALL_CONFIG_SAMBA_PASSWORD" "$INSTALL_CONFIG_SAMBA_WORKGROUP"
	fi
	if [[ "$INSTALL_CONFIG_POSTFIX" == "YES" ]]; then
		install_postfix "$INSTALL_CONFIG_POSTFIX_USER" "$INSTALL_CONFIG_POSTFIX_PASSWORD"
	fi
	if [[ "$INSTALL_CONFIG_PRINT" == "YES" ]]; then
		arch-chroot /mnt /bin/bash <<- EOF
		systemctl enable cups.service
		EOF
	fi
	if [[ "$INSTALL_CONFIG_WINE" == "YES" ]]; then
		install_wine
	fi
	if [[ "$INSTALL_CONFIG_LIBVIRT" == "YES" ]]; then
		install_libvirt "$INSTALL_CONFIG_USER"
	fi
	if [[ "$INSTALL_CONFIG_V4L2_LOOPBACK" == "YES" ]]; then
		arch-chroot /mnt /bin/bash <<- EOF
		modprobe v4l2loopback
		EOF
	fi
	if [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" != "NONE" ]]; then
		if [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" == "CINNAMON_DE" ]]; then
			install_cinnamon
		elif [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" == "COSMIC_DE" ]]; then
			arch-chroot /mnt /bin/bash <<- EOF
			systemctl enable cosmic-greeter.service
			EOF
		elif [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" == "GNOME_DE" ]]; then
			arch-chroot /mnt /bin/bash <<- EOF
			systemctl enable gdm.service
			EOF
		elif [[ "$INSTALL_CONFIG_DESKTOP_ENVIRONMENT" == "KDE_DE" ]]; then
			install_kde "$INSTALL_CONFIG_USER" "$INSTALL_CONFIG_KDE_AUTOLOGIN"
		fi
		if [[ "$INSTALL_CONFIG_TEAMVIEWER" == "YES" && "$INSTALL_CONFIG_AUR_PREBUILT" == "YES" ]]; then
			arch-chroot /mnt /bin/bash <<- EOF
			systemctl enable teamviewerd.service
			EOF
		fi
		arch-chroot /mnt /bin/bash <<- EOF
		systemctl enable switcheroo-control.service
		EOF
	fi
	if [[ "$INSTALL_CONFIG_NETWORK" == "Systemd-networkd" ]]; then
		if [[ "$INSTALL_CONFIG_SYSTEMD_NETWORKD" == "static" ]]; then
			if [[ "$INSTALL_CONFIG_NETWORK_TYPE" == "NORMAL" ]]; then
				install_systemdnetworkd_static_single
			elif [[ "$INSTALL_CONFIG_NETWORK_TYPE" == "BRIDGE" ]]; then
				install_systemdnetworkd_static_bridge
			elif [[ "$INSTALL_CONFIG_NETWORK_TYPE" == "BRIDGE_BOND" ]]; then
				install_systemdnetworkd_static_bridge_bond
			fi
		elif [[ "$INSTALL_CONFIG_SYSTEMD_NETWORKD" == "dhcp" ]]; then
			if [[ "$INSTALL_CONFIG_NETWORK_TYPE" == "NORMAL" ]]; then
				install_systemdnetworkd_dhcp_single
			elif [[ "$INSTALL_CONFIG_NETWORK_TYPE" == "BRIDGE" ]]; then
				install_systemdnetworkd_dhcp_bridge
			elif [[ "$INSTALL_CONFIG_NETWORK_TYPE" == "BRIDGE_BOND" ]]; then
				install_systemdnetworkd_dhcp_bridge_bond
			fi
		fi
		arch-chroot /mnt /bin/bash <<- EOF
		systemctl enable systemd-networkd.service
		systemctl enable systemd-networkd-wait-online.service
		systemctl enable systemd-resolved.service
		EOF
	else
		arch-chroot /mnt /bin/bash <<- EOF
		systemctl enable bluetooth.service
		systemctl enable NetworkManager.service
		systemctl enable NetworkManager-wait-online.service
		EOF
	fi
	if [[ "$INSTALL_CONFIG_VM_GUEST_ADDITIONS" != "NO" ]]; then
		if [[ "$INSTALL_CONFIG_VM_GUEST_ADDITIONS" == "QEMU" ]]; then
			arch-chroot /mnt /bin/bash <<- EOF
			systemctl enable qemu-guest-agent.service
			EOF
		elif [[ "$INSTALL_CONFIG_VM_GUEST_ADDITIONS" == "VBOX" ]]; then
			arch-chroot /mnt /bin/bash <<- EOF
			systemctl enable vboxservice.service
			EOF
		fi
	fi
	if [[ "$INSTALL_CONFIG_AUR_PREBUILT_CORE_ESSENTIALS" == "YES" ]]; then
		if [[ "$INSTALL_CONFIG_ENCRYPTION" == "YES" ]]; then
			INSTALL_ROOT_UUID=$(blkid -s UUID -o value /dev/mapper/crypt_luks_root_install)
		else
			INSTALL_ROOT_UUID=$(blkid -s UUID -o value "$INSTALL_CONFIG_ROOT_PARTITION")
		fi
		sed -i "s/system_snapshot_enabled=0/system_snapshot_enabled=1/g" /mnt/etc/7thcore/7thcore-essentials.conf
		sed -i "s/00000000-0000-000000000-000000000000/${INSTALL_ROOT_UUID}/g" /mnt/etc/7thcore/7thcore-essentials.conf
	fi
	message_installation_complete
}

#-------------------------------------------------------------------------

config_menu() {
	local INSTALL_CONFIG_MENU
	while true; do
		INSTALL_CONFIG_MENU=$(whiptail --title "Arch Linux" --menu "Select configuration" --nocancel 24 60 16 \
		"locale" "Configure your language and timezone" \
		"disk" "Configure your disk" \
		"secure-boot" "Enable or disable secure boot" \
		"hostname" "Enter your hostname" \
		"username" "Enter your username" \
		"user-password" "Enter your user password" \
		"root-password" "Enter your root password" \
		"shell" "Select your prefered shell" \
		"7thcore-repo" "Use 7thCore's repository for installation" \
		"aur-prebuilt" "Configure 7thCore's repositories" \
		"cli-apps" "Configure common CLI applications" \
		"desktop" "Configure desktop environment" \
		"network" "Configure network" \
		"begin-install" "Begin installation" \
		"" "" \
		"exit" "Exit the installation" 3>&1 1>&2 2>&3)
		if [[ "$INSTALL_CONFIG_MENU" == "locale" ]]; then
			config_menu_locale
		elif [[ "$INSTALL_CONFIG_MENU" == "disk" ]]; then
			config_menu_disk
		elif [[ "$INSTALL_CONFIG_MENU" == "secure-boot" ]]; then
			config_menu_secure_boot
		elif [[ "$INSTALL_CONFIG_MENU" == "hostname" ]]; then
			config_menu_hostname
		elif [[ "$INSTALL_CONFIG_MENU" == "username" ]]; then
			config_menu_username
		elif [[ "$INSTALL_CONFIG_MENU" == "user-password" ]]; then
			config_menu_user_password
		elif [[ "$INSTALL_CONFIG_MENU" == "root-password" ]]; then
			config_menu_root_password
		elif [[ "$INSTALL_CONFIG_MENU" == "shell" ]]; then
			config_menu_shell
		elif [[ "$INSTALL_CONFIG_MENU" == "7thcore-repo" ]]; then
			config_menu_core_repo
		elif [[ "$INSTALL_CONFIG_MENU" == "aur-prebuilt" ]]; then
			config_menu_aur_prebuilt
		elif [[ "$INSTALL_CONFIG_MENU" == "cli-apps" ]]; then
			config_menu_cli_applications
		elif [[ "$INSTALL_CONFIG_MENU" == "desktop" ]]; then
			config_menu_desktop
		elif [[ "$INSTALL_CONFIG_MENU" == "network" ]]; then
			config_menu_network
		elif [[ "$INSTALL_CONFIG_MENU" == "begin-install" ]]; then
			config_menu_vm
			install_main
		elif [[ "$INSTALL_CONFIG_MENU" == "exit" ]]; then
			exit 1
		fi
	done
}

#-------------------------------------------------------------------------

#Guided configuration and installation
config_installation() {
	config_menu_locale
	config_menu_disk
	config_menu_secure_boot
	config_menu_hostname
	config_menu_username
	config_menu_user_password
	config_menu_root_password
	config_menu_shell
	config_menu_core_repo
	config_menu_aur_prebuilt
	config_menu_cli_applications
	config_menu_desktop
	config_menu_network
	config_menu_vm
	install_main
}

#-------------------------------------------------------------------------

#Script beginning
message_welcome
message_warning
while true; do
	INSTALL_CONFIG_TYPE=$(whiptail --title "Arch Linux" --menu "Choose to install or reconsider your life choices:" --noitem --nocancel 10 60 2 \
	"Begin installation" "" \
	"Exit" "" 3>&1 1>&2 2>&3)
	if [[ "$INSTALL_CONFIG_TYPE" == "Begin installation" ]]; then
		config_installation
	elif [[ "$INSTALL_CONFIG_TYPE" == "Exit" ]]; then
		exit 1
	fi
done

#Also diffrent desktop environments
