feat: enhance debros user creation in installation script for non-interactive mode

- Added support for non-interactive mode to automatically create the 'debros' user without user prompts.
- Implemented passwordless login for the 'debros' user in non-interactive mode.
- Retained interactive prompts for user creation when not in non-interactive mode, improving user experience and flexibility.
This commit is contained in:
anonpenguin23 2025-10-25 16:01:44 +03:00
parent e5a71ba295
commit 38e77c79c6
No known key found for this signature in database
GPG Key ID: 1CBB1FE35AFBEE30

View File

@ -35,6 +35,12 @@ error() { echo -e "${RED}[ERROR]${NOCOLOR} $1"; }
success() { echo -e "${GREEN}[SUCCESS]${NOCOLOR} $1"; } success() { echo -e "${GREEN}[SUCCESS]${NOCOLOR} $1"; }
warning() { echo -e "${YELLOW}[WARNING]${NOCOLOR} $1"; } warning() { echo -e "${YELLOW}[WARNING]${NOCOLOR} $1"; }
# Detect non-interactive mode EARLY (before any function calls that require user input)
if [ ! -t 0 ]; then
NON_INTERACTIVE=true
log "Running in non-interactive mode"
fi
# Check if we need to create debros user first (requires root) # Check if we need to create debros user first (requires root)
check_and_setup_debros_user() { check_and_setup_debros_user() {
CURRENT_USER=$(whoami) CURRENT_USER=$(whoami)
@ -68,68 +74,85 @@ check_and_setup_debros_user() {
echo -e "${YELLOW}DeBros requires a '$DEBROS_USER' system user to run services.${NOCOLOR}" echo -e "${YELLOW}DeBros requires a '$DEBROS_USER' system user to run services.${NOCOLOR}"
echo -e "" echo -e ""
# Ask for permission to create the user # In non-interactive mode, automatically create the user
while true; do if [ "$NON_INTERACTIVE" = true ]; then
read -rp "Would you like to create the '$DEBROS_USER' user? (yes/no): " CREATE_USER_CHOICE log "Non-interactive mode: automatically creating '$DEBROS_USER' user..."
case "$CREATE_USER_CHOICE" in useradd -r -m -s /bin/bash -d "$INSTALL_DIR" "$DEBROS_USER" 2>/dev/null || true
[Yy][Ee][Ss]|[Yy]) if id "$DEBROS_USER" &>/dev/null; then
log "Creating system user '$DEBROS_USER'..." success "System user '$DEBROS_USER' created"
useradd -r -m -s /bin/bash -d "$INSTALL_DIR" "$DEBROS_USER" 2>/dev/null || true # Enable passwordless login in non-interactive mode
if id "$DEBROS_USER" &>/dev/null; then TEMP_PASS="temp123"
success "System user '$DEBROS_USER' created" echo "$DEBROS_USER:$TEMP_PASS" | chpasswd
passwd -d "$DEBROS_USER" 2>/dev/null || true
# Prompt for password success "Passwordless login enabled for '$DEBROS_USER' user"
echo -e "" else
log "Setting password for '$DEBROS_USER' user..." error "Failed to create user '$DEBROS_USER'"
echo -e "${YELLOW}Note: You can leave the password empty for passwordless login${NOCOLOR}" exit 1
echo -e "" fi
echo -n "Enter password for '$DEBROS_USER' user (or press Enter for no password): " else
read -s DEBROS_PASSWORD # Ask for permission to create the user
echo "" while true; do
echo -n "Confirm password: " read -rp "Would you like to create the '$DEBROS_USER' user? (yes/no): " CREATE_USER_CHOICE
read -s DEBROS_PASSWORD_CONFIRM case "$CREATE_USER_CHOICE" in
echo "" [Yy][Ee][Ss]|[Yy])
log "Creating system user '$DEBROS_USER'..."
# Verify passwords match useradd -r -m -s /bin/bash -d "$INSTALL_DIR" "$DEBROS_USER" 2>/dev/null || true
if [ "$DEBROS_PASSWORD" != "$DEBROS_PASSWORD_CONFIRM" ]; then if id "$DEBROS_USER" &>/dev/null; then
error "Passwords do not match!" success "System user '$DEBROS_USER' created"
exit 1
fi # Prompt for password
echo -e ""
# Set password or enable passwordless login log "Setting password for '$DEBROS_USER' user..."
if [ -z "$DEBROS_PASSWORD" ]; then echo -e "${YELLOW}Note: You can leave the password empty for passwordless login${NOCOLOR}"
# For passwordless login, we need to use a special approach echo -e ""
# First, set a temporary password, then remove it echo -n "Enter password for '$DEBROS_USER' user (or press Enter for no password): "
TEMP_PASS="temp123" read -s DEBROS_PASSWORD
echo "$DEBROS_USER:$TEMP_PASS" | chpasswd echo ""
# Now remove the password to make it passwordless echo -n "Confirm password: "
passwd -d "$DEBROS_USER" 2>/dev/null || true read -s DEBROS_PASSWORD_CONFIRM
success "Passwordless login enabled for '$DEBROS_USER' user" echo ""
else
# Set password using chpasswd # Verify passwords match
echo "$DEBROS_USER:$DEBROS_PASSWORD" | chpasswd if [ "$DEBROS_PASSWORD" != "$DEBROS_PASSWORD_CONFIRM" ]; then
if [ $? -eq 0 ]; then error "Passwords do not match!"
success "Password set successfully for '$DEBROS_USER' user"
else
error "Failed to set password for '$DEBROS_USER' user"
exit 1 exit 1
fi fi
# Set password or enable passwordless login
if [ -z "$DEBROS_PASSWORD" ]; then
# For passwordless login, we need to use a special approach
# First, set a temporary password, then remove it
TEMP_PASS="temp123"
echo "$DEBROS_USER:$TEMP_PASS" | chpasswd
# Now remove the password to make it passwordless
passwd -d "$DEBROS_USER" 2>/dev/null || true
success "Passwordless login enabled for '$DEBROS_USER' user"
else
# Set password using chpasswd
echo "$DEBROS_USER:$DEBROS_PASSWORD" | chpasswd
if [ $? -eq 0 ]; then
success "Password set successfully for '$DEBROS_USER' user"
else
error "Failed to set password for '$DEBROS_USER' user"
exit 1
fi
fi
else
error "Failed to create user '$DEBROS_USER'"
exit 1
fi fi
else break
error "Failed to create user '$DEBROS_USER'" ;;
[Nn][Oo]|[Nn])
error "Cannot continue without '$DEBROS_USER' user. Exiting."
exit 1 exit 1
fi ;;
break *)
;; error "Invalid choice. Please enter 'yes' or 'no'."
[Nn][Oo]|[Nn]) ;;
error "Cannot continue without '$DEBROS_USER' user. Exiting." esac
exit 1 done
;; fi
*)
error "Invalid choice. Please enter 'yes' or 'no'."
;;
esac
done
else else
log "User '$DEBROS_USER' already exists" log "User '$DEBROS_USER' already exists"
fi fi
@ -163,18 +186,12 @@ check_and_setup_debros_user() {
# Check and setup debros user (called before other checks) # Check and setup debros user (called before other checks)
check_and_setup_debros_user check_and_setup_debros_user
# Detect non-interactive mode
if [ ! -t 0 ]; then
NON_INTERACTIVE=true
log "Running in non-interactive mode"
fi
# Root/sudo checks # Root/sudo checks
if [[ $EUID -eq 0 ]]; then if [[ $EUID -eq 0 ]]; then
warning "Running as root is not recommended for security reasons." warning "Running as root is not recommended for security reasons."
if [ "$NON_INTERACTIVE" != true ]; then if [ "$NON_INTERACTIVE" != true ]; then
echo -n "Are you sure you want to continue? (yes/no): " echo -n "Are you sure you want to continue? (yes/no): "
read ROOT_CONFIRM read -r ROOT_CONFIRM
if [[ "$ROOT_CONFIRM" != "yes" ]]; then if [[ "$ROOT_CONFIRM" != "yes" ]]; then
error "Installation cancelled for security reasons." error "Installation cancelled for security reasons."
exit 1 exit 1