feat(bypass): allow --username/--password/--full-name for unattended runs
This commit is contained in:
+6
-6
@@ -170,11 +170,11 @@ admin_only_mode() {
|
||||
echo ""
|
||||
step "Creating local admin account"
|
||||
|
||||
prompt_default realName "Full name" "Apple"
|
||||
acquire_realname realName
|
||||
|
||||
local username
|
||||
while true; do
|
||||
prompt_username username
|
||||
acquire_username username
|
||||
if check_user_exists "$node" "$username"; then
|
||||
warn "User '$username' already exists."
|
||||
if confirm "Delete and recreate?"; then
|
||||
@@ -189,7 +189,7 @@ admin_only_mode() {
|
||||
done
|
||||
|
||||
local passw
|
||||
prompt_password passw
|
||||
acquire_password passw
|
||||
|
||||
local uid
|
||||
uid=$(find_available_uid "$node")
|
||||
@@ -227,11 +227,11 @@ full_bypass_mode() {
|
||||
step "Creating temporary admin account"
|
||||
|
||||
local realName
|
||||
prompt_default realName "Full name" "Apple"
|
||||
acquire_realname realName
|
||||
|
||||
local username
|
||||
while true; do
|
||||
prompt_username username
|
||||
acquire_username username
|
||||
if check_user_exists "$node" "$username"; then
|
||||
warn "User '$username' already exists."
|
||||
if confirm "Delete and recreate?"; then
|
||||
@@ -246,7 +246,7 @@ full_bypass_mode() {
|
||||
done
|
||||
|
||||
local passw
|
||||
prompt_password passw
|
||||
acquire_password passw
|
||||
|
||||
local uid
|
||||
uid=$(find_available_uid "$node")
|
||||
|
||||
@@ -45,3 +45,60 @@ prompt_password() {
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Account credentials: CLI flags (--username/--password/--full-name) win over
|
||||
# interactive prompts so bypass/admin/dualboot can run unattended.
|
||||
OPT_USERNAME="${OPT_USERNAME:-}"
|
||||
OPT_PASSWORD="${OPT_PASSWORD:-}"
|
||||
OPT_REALNAME="${OPT_REALNAME:-}"
|
||||
|
||||
parse_account_opts() {
|
||||
ACCOUNT_ARGS=()
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--username|--password|--full-name)
|
||||
local key="$1"
|
||||
if [ $# -lt 2 ] || [ -z "$2" ] || [[ "$2" == --* ]]; then
|
||||
error_exit "$key requires a value"
|
||||
fi
|
||||
case "$key" in
|
||||
--username) OPT_USERNAME="$2" ;;
|
||||
--password) OPT_PASSWORD="$2" ;;
|
||||
--full-name) OPT_REALNAME="$2" ;;
|
||||
esac
|
||||
shift 2 ;;
|
||||
*) ACCOUNT_ARGS+=("$1"); shift ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
acquire_username() {
|
||||
local var_name="$1"
|
||||
if [ -n "$OPT_USERNAME" ]; then
|
||||
local msg
|
||||
msg=$(validate_username "$OPT_USERNAME" 2>&1) || error_exit "Invalid --username: $msg"
|
||||
eval "$var_name=\"\$OPT_USERNAME\""
|
||||
else
|
||||
prompt_username "$var_name"
|
||||
fi
|
||||
}
|
||||
|
||||
acquire_password() {
|
||||
local var_name="$1"
|
||||
if [ -n "$OPT_PASSWORD" ]; then
|
||||
local msg
|
||||
msg=$(validate_password "$OPT_PASSWORD" 2>&1) || error_exit "Invalid --password: $msg"
|
||||
eval "$var_name=\"\$OPT_PASSWORD\""
|
||||
else
|
||||
prompt_password "$var_name"
|
||||
fi
|
||||
}
|
||||
|
||||
acquire_realname() {
|
||||
local var_name="$1"
|
||||
if [ -n "$OPT_REALNAME" ]; then
|
||||
eval "$var_name=\"\$OPT_REALNAME\""
|
||||
else
|
||||
prompt_default "$var_name" "Full name" "Apple"
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user