feat(bypass): allow --username/--password/--full-name for unattended runs
CI / Bash Syntax Check (push) Successful in 3s
CI / Markdown Lint (push) Successful in 6s
CI / ShellCheck (push) Successful in 2m8s

This commit is contained in:
2026-11-09 11:07:10 +08:00
parent 59487b693e
commit d43c23135f
8 changed files with 183 additions and 34 deletions
+81 -15
View File
@@ -358,6 +358,63 @@ prompt_password() {
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
}
dscl_node() {
local data_mount="$1"
@@ -620,11 +677,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
@@ -639,7 +696,7 @@ admin_only_mode() {
done
local passw
prompt_password passw
acquire_password passw
local uid
uid=$(find_available_uid "$node")
@@ -677,11 +734,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
@@ -696,7 +753,7 @@ full_bypass_mode() {
done
local passw
prompt_password passw
acquire_password passw
local uid
uid=$(find_available_uid "$node")
@@ -2844,9 +2901,9 @@ vpn_kill_status() {
show_cmd_help() {
case "$1" in
bypass) echo "Bypass MDM from Recovery. Creates admin user." ;;
bypass) echo "Bypass MDM from Recovery. Creates admin user (accepts --username/--password/--full-name)." ;;
suppress) echo "Suppress enrollment without creating a user." ;;
admin) echo "Create an admin user without suppressing enrollment." ;;
admin) echo "Create an admin user without suppressing enrollment (accepts --username/--password/--full-name)." ;;
heal) echo "Re-apply suppression after macOS updates." ;;
persist) echo "Install auto-heal LaunchDaemon." ;;
unpersist) echo "Remove auto-heal LaunchDaemon." ;;
@@ -2857,7 +2914,7 @@ show_cmd_help() {
whitelist) echo "Block only MDM domains, keep iCloud/App Store." ;;
backup) echo "Save current state." ;;
restore) echo "Restore from backup." ;;
dualboot) echo "Target an external macOS install." ;;
dualboot) echo "Target an external macOS install (accepts --username/--password/--full-name)." ;;
status) echo "Show MDM enrollment status (Recovery only)." ;;
check) echo "Pre-format / pre-upgrade safety report." ;;
history) echo "Show event log from monitor/heal runs." ;;
@@ -2991,6 +3048,12 @@ OPTIONS
--dry-run Simulate without making changes
--log-file <f> Write logs to file (appended)
Account options (bypass / admin / dualboot):
--username <u> Pre-set the admin username (skips the prompt)
--password <p> Pre-set the admin password (skips the prompt)
--full-name <n> Pre-set the display name
Note: --password is visible in shell history and process lists.
Run without arguments for interactive menu.
HELP
}
@@ -3001,6 +3064,7 @@ cmd_version() {
}
cmd_bypass() {
parse_account_opts "$@"
if is_recovery; then
if [ "$DRY_RUN" = true ]; then
full_bypass_mode "the selected Data volume"
@@ -3034,6 +3098,7 @@ cmd_backup() {
}
cmd_admin() {
parse_account_opts "$@"
if ! is_recovery; then
error_exit "Admin creation must run from Recovery mode."
fi
@@ -3062,6 +3127,7 @@ cmd_dualboot() {
error_exit "Dual-boot needs sudo: sudo ./runaway dualboot"
fi
parse_account_opts "$@"
header "Dual-Boot Mode"
local volumes
@@ -3079,11 +3145,11 @@ cmd_dualboot() {
step "Creating admin account on target"
local realName
prompt_default realName "Full name" "Apple"
acquire_realname realName
local username
prompt_username username
acquire_username username
local passw
prompt_password passw
acquire_password passw
local uid
uid=$(find_available_uid "$node")
@@ -3426,9 +3492,9 @@ main() {
fi
case "${1:-}" in
bypass|by) cmd_bypass ;;
bypass|by) cmd_bypass "$@" ;;
suppress|sv) cmd_suppress ;;
admin|adm) cmd_admin ;;
admin|adm) cmd_admin "$@" ;;
heal) cmd_heal ;;
persist) cmd_persist ;;
unpersist) cmd_unpersist ;;
@@ -3439,7 +3505,7 @@ main() {
whitelist|wl) cmd_whitelist ;;
backup) cmd_backup ;;
restore) cmd_restore ;;
dualboot) cmd_dualboot ;;
dualboot) cmd_dualboot "$@" ;;
status|st|ls) cmd_status ;;
check) cmd_check ;;
history) cmd_history ;;