Use mapfile to read in name and passwords
This commit is contained in:
parent
7633f7f594
commit
7b63ddf59a
@ -5,7 +5,7 @@
|
||||
# Some ideas and code reworked from other resources
|
||||
# AIF, Cnichi, Calamares, Arch Wiki.. Credit where credit is due
|
||||
|
||||
VER=2.0.75
|
||||
VER=2.0.76
|
||||
|
||||
# bulk default values {
|
||||
|
||||
@ -334,40 +334,37 @@ select_config()
|
||||
select_mkuser()
|
||||
{
|
||||
NEWUSER=''
|
||||
local v='' u='' p='' p2='' rp='' rp2=''
|
||||
typeset -a ans
|
||||
|
||||
until [[ $NEWUSER ]]; do
|
||||
i=0
|
||||
tput cnorm
|
||||
dialog --insecure --backtitle "$DIST Installer - $SYS - v$VER" --separator $'\n' --title " User " --mixedform "$_user" 0 0 0 \
|
||||
"Username:" 1 1 "$u" 1 11 "$COLUMNS" 0 0 \
|
||||
"Username:" 1 1 "${ans[0]}" 1 11 "$COLUMNS" 0 0 \
|
||||
"Password:" 2 1 '' 2 11 "$COLUMNS" 0 1 \
|
||||
"Password2:" 3 1 '' 3 12 "$COLUMNS" 0 1 \
|
||||
"--- Root password, if left empty the user password will be used ---" 6 1 '' 6 68 "$COLUMNS" 0 2 \
|
||||
"Password:" 8 1 '' 8 11 "$COLUMNS" 0 1 \
|
||||
"Password2:" 9 1 '' 9 12 "$COLUMNS" 0 1 2>"$ANS" || return 1
|
||||
|
||||
while read -r line; do
|
||||
case $i in 0) u="$line" ;; 1) p="$line" ;; 2) p2="$line" ;; 4) rp="$line" ;; 5) rp2="$line" ;; esac
|
||||
(( i++ ))
|
||||
done < "$ANS"
|
||||
mapfile -t ans <"$ANS"
|
||||
|
||||
# root passwords empty, so use the user passwords
|
||||
[[ -z $rp && -z $rp2 ]] && { rp="$p"; rp2="$p2"; }
|
||||
if [[ -z "${ans[4]}" && -z "${ans[5]}" ]]; then
|
||||
ans[4]="${ans[1]}"
|
||||
ans[5]="${ans[2]}"
|
||||
fi
|
||||
|
||||
# make sure a username was entered and that the passwords match
|
||||
if [[ ${#u} -eq 0 || $u =~ \ |\' || $u =~ [^a-z0-9] ]]; then
|
||||
if [[ -z ${ans[0]} || ${ans[0]} =~ \ |\' || ${ans[0]} =~ [^a-z0-9] ]]; then
|
||||
msg "Invalid Username" "\nInvalid user name.\n\nPlease try again.\n"; u=''
|
||||
elif [[ -z $p ]]; then
|
||||
msg "Empty Password" "\nThe user password cannot be left empty.\n\nPlease try again.\n"
|
||||
elif [[ "$p" != "$p2" ]]; then
|
||||
elif [[ -z "${ans[1]}" || "${ans[1]}" != "${ans[2]}" ]]; then
|
||||
msg "Password Mismatch" "\nThe user passwords do not match.\n\nPlease try again.\n"
|
||||
elif [[ "$rp" != "$rp2" ]]; then
|
||||
elif [[ "${ans[4]}" != "${ans[5]}" ]]; then
|
||||
msg "Password Mismatch" "\nThe root passwords do not match.\n\nPlease try again.\n"
|
||||
else
|
||||
NEWUSER="$u"
|
||||
USER_PASS="$p"
|
||||
ROOT_PASS="$rp"
|
||||
NEWUSER="${ans[0]}"
|
||||
USER_PASS="${ans[1]}"
|
||||
ROOT_PASS="${ans[4]}"
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
@ -1972,32 +1969,26 @@ luks_open()
|
||||
luks_pass()
|
||||
{
|
||||
LUKS_PASS=''
|
||||
local t="$1" n='' p='' p2=''
|
||||
local t="$1"
|
||||
typeset -a ans=(cryptroot) # default name to start
|
||||
|
||||
until [[ $LUKS_PASS ]]; do
|
||||
local i=0
|
||||
tput cnorm
|
||||
dialog --insecure --backtitle "$DIST Installer - $SYS - v$VER" --separator $'\n' --title " $t " --mixedform "$_luksomenu" 0 0 0 \
|
||||
"Name:" 1 1 "${LUKS_NAME:-cryptroot}" 1 7 "$COLUMNS" 0 0 \
|
||||
"Name:" 1 1 "${ans[0]}" 1 7 "$COLUMNS" 0 0 \
|
||||
"Password:" 2 1 '' 2 11 "$COLUMNS" 0 1 \
|
||||
"Password2:" 3 1 '' 3 12 "$COLUMNS" 0 1 2>"$ANS" || return 1
|
||||
|
||||
while read -r line; do
|
||||
case $i in
|
||||
0) n="$line" ;;
|
||||
1) p="$line" ;;
|
||||
2) p2="$line" ;;
|
||||
esac
|
||||
(( i++ ))
|
||||
done < "$ANS"
|
||||
mapfile -t ans <"$ANS"
|
||||
|
||||
if [[ -z $n ]]; then
|
||||
if [[ -z "${ans[0]}" ]]; then
|
||||
msg "Name Empty" "\nEncrypted device name cannot be empty.\n\nPlease try again.\n" 2
|
||||
elif [[ -z $p || "$p" != "$p2" ]]; then
|
||||
LUKS_NAME="$n"
|
||||
elif [[ -z "${ans[1]}" || "${ans[1]}" != "${ans[2]}" ]]; then
|
||||
LUKS_NAME="${ans[0]}"
|
||||
msg "Password Mismatch" "\nThe passwords entered do not match.\n\nPlease try again.\n" 2
|
||||
else
|
||||
LUKS_NAME="$n" LUKS_PASS="$p"
|
||||
LUKS_NAME="${ans[0]}"
|
||||
LUKS_PASS="${ans[1]}"
|
||||
fi
|
||||
done
|
||||
|
||||
|
Reference in New Issue
Block a user