installer/scripts/lib/helpers
2024-12-12 20:16:13 -08:00

51 lines
1.1 KiB
Bash
Executable file

#!/bin/bash
error_dialog(){
DIALOGRC="${HOME}/.dialogerrrc" dialog --ok-label 'Continue' --nocancel \
--title 'Error' \
--msgbox "${1}" 0 0
}
run_in_chroot(){
chroot '/target/' /bin/bash -c "${1}"
}
validate_pass(){
#sanitize password too
if [[ "${1}" == "${2}" ]];then
return 0
else
error_dialog "Passwords do not match"
return 1
fi
}
validate_install_size(){
#provide option to have no home part
#automatically detect max rootfs partition size
disk_size=$(echo '( '`lsblk -b --output SIZE -n -d "${dest_dev}"`' / 1048576 ) - 1024' | bc)
if [[ "${disk_size}" -gt "${root_end}" ]];then
return 0
else
error_dialog "Requested installation too large for target device"
return 1
fi
}
validate_username(){
if [[ "${1}" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]];then
return 0
else
error_dialog "Bad username format"
return 1
fi
}
sanitize_hostname(){
printf "%s" "${1}" | tr -dc '\-[:alnum:]\n\r' | tr '[:upper:]' '[:lower:]'
}
encrypt_partition(){
echo -n "${3}" | cryptsetup luksFormat "${1}" -
echo -n "${3}" | cryptsetup luksOpen "${1}" "${2}_crypt" -
}