diff --git a/usr.sbin/bsdinstall/scripts/rootpass b/usr.sbin/bsdinstall/scripts/rootpass --- a/usr.sbin/bsdinstall/scripts/rootpass +++ b/usr.sbin/bsdinstall/scripts/rootpass @@ -1,6 +1,7 @@ #!/bin/sh #- # Copyright (c) 2011 Nathan Whitehorn +# Copyright (c) 2024 The FreeBSD Foundation # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -27,18 +28,83 @@ BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 -clear -echo "$OSNAME Installer" -echo "========================" -echo if [ -n "$ROOTPASS_ENC" ]; then printf '%s\n' "$ROOTPASS_ENC" | pw -R $BSDINSTALL_CHROOT usermod root -H 0 + exit $? elif [ -n "$ROOTPASS_PLAIN" ]; then printf '%s\n' "$ROOTPASS_PLAIN" | pw -R $BSDINSTALL_CHROOT usermod root -h 0 -else - echo "Please select a password for the system management account (root):" - echo "Typed characters will not be visible." - - chroot $BSDINSTALL_CHROOT passwd root 2>&1 + exit $? fi + +: ${BSDDIALOG:=bsddialog} +: ${BSDDIALOG_OK:=0} + +error_get_message() +{ + case $1 in + 63) + echo "The passwords do not match" + ;; + 64) #EX_USAGE + echo "Command used incorrectly" + ;; + 65) #EX_DATAERR + echo "Incorrect input data" + ;; + 67) #EX_NOUSER + echo "User not found" + ;; + 70) #EX_SOFTWARE + echo "Internal software error" + ;; + 71) #EX_OSERR + echo "Operating System error detected" + ;; + 72) #EX_OSFILE + echo "Error in a system file" + ;; + 74) #EX_IOERR + echo "I/O error" + ;; + 77) #EX_NOPERM + echo "Insufficient permissions" + ;; + 78) #EX_CONFIG + echo "Configuration error" + ;; + 0) + ;; + *) + echo "An unknown error occurred (code $1)" + ;; + esac +} + +errormsg= +username="root" +while true; do + exec 5>&1 + output=$($BSDDIALOG --backtitle "$OSNAME Installer" \ + --title "Set $username password" \ + --cancel-label "Skip" \ + --passwordform --insecure \ + "Please select a password for the system management account ($username) +$errormsg" \ + 0 0 2 \ + "Password" 0 0 '' 0 17 32 32 \ + "Repeat password" 1 0 '' 1 17 32 32 \ + 2>&1 1>&5) + res=$? + exec 5>&- + [ $res -eq $BSDDIALOG_OK ] || exit 0 + + echo -n "$output" | (read password1 + read password2 + [ "$password1" = "$password2" ] || exit 63 + echo "$password1" | chroot $BSDINSTALL_CHROOT \ + /usr/sbin/pw usermod "$username" -h 0 + ) + errormsg=$(error_get_message $?) + [ -n "$errormsg" ] || exit 0 +done