Just executing the code, I'd receive 4 different inputs like this:
DB user password:
DB user password again:
DB user password:
DB user password again:
which would make me think that some thing went wrong in the first time, and I'd input the same password again. You are not making it obvious for the user to input root password first.
echo "Enter root user credentials"
read -sp "root user password:" dbrootp_1 && echo
read -sp "root user password again:" dbrootp_2 && echo
echo "Enter new user credentials"
read -sp "new user password:" dbuserp_1 && echo
read -sp "new user password again:" dbuserp_2 && echo
makes it slightly better.
if [ "$dbrootp_1" != "$dbrootp_2" ]; then echo "Values unmatched" && exit 1 fi
if [ "$dbuserp_1" != "$dbuserp_2" ]; then echo "Values unmatched" && exit 1 fi
You may wish to convey exactly which set of password was mismatched. It is more a UX debate though. You might not want to do that as it might cause some security vulnerability! However, look at
function error_quit() {
local EXITCODE=$1
local MESSAGE="$2"
>&2 echo $MESSAGE
exit $EXITCODE
}
[[ "$dbrootp_1" != "$dbrootp_2" ]] && { error_quit 1 "Values unmatched" }
[[ "$dbuserp_1" != "$dbuserp_2" ]] && { error_quit 1 "Values unmatched" }
Splitting into a function gives you an added benefit so that in future you might expand the script, and use the same minimal exit setup instead of copying it everywhere.
The >&2
directs the error to stderr
stream.