fix: Correct user references throughout codebase to use ADMIN_USER or current user

- Replace all NEW_USER references with ADMIN_USER or current user
- Fix Samba password prompt to use correct user instead of 'nasadmin'
- Update SSH, Docker, and Samba configurations to use proper user variables
- Ensure consistent user handling across all services
- Remove hardcoded 'nasadmin' references
This commit is contained in:
Mărcziem ™
2025-10-03 13:24:47 +02:00
parent 21781166ea
commit c0d6a07cec
3 changed files with 18 additions and 18 deletions

View File

@@ -115,7 +115,7 @@ install_docker() {
log_warning "No suitable non-root user found to add to docker group." log_warning "No suitable non-root user found to add to docker group."
if [[ "${CREATE_NEW_USER_IF_MISSING:-false}" == "true" ]]; then if [[ "${CREATE_NEW_USER_IF_MISSING:-false}" == "true" ]]; then
local create_user local create_user
create_user="${NEW_USER:-nasadmin}" create_user="${ADMIN_USER:-${NEW_USER:-nasadmin}}"
log_info "Creating user '$create_user' and adding to docker group..." log_info "Creating user '$create_user' and adding to docker group..."
handle_error sudo useradd -m -s /bin/bash "$create_user" handle_error sudo useradd -m -s /bin/bash "$create_user"
handle_error sudo usermod -aG docker "$create_user" handle_error sudo usermod -aG docker "$create_user"

View File

@@ -203,16 +203,16 @@ configure_ssh() {
fi fi
# Create new user if not exists # Create new user if not exists
if ! id "${ADMIN_USER:-$NEW_USER}" &>/dev/null; then if ! id "${ADMIN_USER:-$USER}" &>/dev/null; then
log_info "Creating user ${ADMIN_USER:-$NEW_USER}..." log_info "Creating user ${ADMIN_USER:-$USER}..."
sudo useradd -m -s /bin/bash "${ADMIN_USER:-$NEW_USER}" sudo useradd -m -s /bin/bash "${ADMIN_USER:-$USER}"
sudo usermod -aG sudo "${ADMIN_USER:-$NEW_USER}" sudo usermod -aG sudo "${ADMIN_USER:-$USER}"
# Set password # Set password
local password=$(ask_password "Set password for user ${ADMIN_USER:-$NEW_USER}") local password=$(ask_password "Set password for user ${ADMIN_USER:-$USER}")
echo "${ADMIN_USER:-$NEW_USER}:$password" | sudo chpasswd echo "${ADMIN_USER:-$USER}:$password" | sudo chpasswd
add_rollback_action "sudo userdel -r ${ADMIN_USER:-$NEW_USER}" add_rollback_action "sudo userdel -r ${ADMIN_USER:-$USER}"
fi fi
# Configure SSH hardening # Configure SSH hardening
@@ -232,7 +232,7 @@ ClientAliveInterval 300
ClientAliveCountMax 2 ClientAliveCountMax 2
MaxAuthTries 3 MaxAuthTries 3
LoginGraceTime 60 LoginGraceTime 60
AllowUsers ${ADMIN_USER:-$NEW_USER} AllowUsers ${ADMIN_USER:-$USER}
Protocol 2 Protocol 2
EOF EOF
@@ -280,7 +280,7 @@ setup_samba() {
# Create shared directory # Create shared directory
local share_dir="/srv/samba/shared" local share_dir="/srv/samba/shared"
sudo mkdir -p "$share_dir" sudo mkdir -p "$share_dir"
sudo chown "${ADMIN_USER:-$NEW_USER}:${ADMIN_USER:-$NEW_USER}" "$share_dir" sudo chown "${ADMIN_USER:-$USER}:${ADMIN_USER:-$USER}" "$share_dir"
sudo chmod 755 "$share_dir" sudo chmod 755 "$share_dir"
# Configure Samba # Configure Samba
@@ -308,14 +308,14 @@ setup_samba() {
browseable = yes browseable = yes
writable = yes writable = yes
guest ok = no guest ok = no
valid users = ${ADMIN_USER:-$NEW_USER} valid users = ${ADMIN_USER:-$USER}
create mask = 0644 create mask = 0644
directory mask = 0755 directory mask = 0755
EOF EOF
# Add Samba user # Add Samba user
local samba_password=$(ask_password "Set Samba password for user ${ADMIN_USER:-$NEW_USER}") local samba_password=$(ask_password "Set Samba password for user ${ADMIN_USER:-$USER}")
echo -e "$samba_password\n$samba_password" | sudo smbpasswd -a "${ADMIN_USER:-$NEW_USER}" echo -e "$samba_password\n$samba_password" | sudo smbpasswd -a "${ADMIN_USER:-$USER}"
sudo smbpasswd -e "${ADMIN_USER:-$NEW_USER}" sudo smbpasswd -e "${ADMIN_USER:-$NEW_USER}"
# Start and enable Samba services # Start and enable Samba services

View File

@@ -491,7 +491,7 @@ show_installation_summary() {
echo echo
log_info "Installation Summary:" log_info "Installation Summary:"
echo " ✓ System updated and secured" echo " ✓ System updated and secured"
echo " ✓ User '${ADMIN_USER:-$NEW_USER}' created with sudo access" echo " ✓ User '${ADMIN_USER:-$USER}' created with sudo access"
echo " ✓ SSH configured on port ${SSH_PORT:-$DEFAULT_SSH_PORT}" echo " ✓ SSH configured on port ${SSH_PORT:-$DEFAULT_SSH_PORT}"
echo " ✓ Samba file sharing configured" echo " ✓ Samba file sharing configured"
echo " ✓ Firewall configured and enabled" echo " ✓ Firewall configured and enabled"
@@ -531,7 +531,7 @@ show_installation_summary() {
Installation Date: $(date) Installation Date: $(date)
System IP Address: ${ip_address} System IP Address: ${ip_address}
Admin User: ${ADMIN_USER:-$NEW_USER} Admin User: ${ADMIN_USER:-$USER}
SSH Port: ${SSH_PORT:-$DEFAULT_SSH_PORT} SSH Port: ${SSH_PORT:-$DEFAULT_SSH_PORT}
------------------------------------------------------------ ------------------------------------------------------------
@@ -541,8 +541,8 @@ Installed Services and Access Information:
SSH Access: SSH Access:
- Host: ${ip_address} - Host: ${ip_address}
- Port: ${SSH_PORT:-$DEFAULT_SSH_PORT} - Port: ${SSH_PORT:-$DEFAULT_SSH_PORT}
- User: ${ADMIN_USER:-$NEW_USER} - User: ${ADMIN_USER:-$USER}
- Command: ssh -p ${SSH_PORT:-$DEFAULT_SSH_PORT} ${ADMIN_USER:-$NEW_USER}@${ip_address} - Command: ssh -p ${SSH_PORT:-$DEFAULT_SSH_PORT} ${ADMIN_USER:-$USER}@${ip_address}
EOF EOF
@@ -677,7 +677,7 @@ EOF
echo echo
log_warning "Important: Please save the following information:" log_warning "Important: Please save the following information:"
echo " - SSH Port: ${SSH_PORT:-$DEFAULT_SSH_PORT}" echo " - SSH Port: ${SSH_PORT:-$DEFAULT_SSH_PORT}"
echo " - Admin User: ${ADMIN_USER:-$NEW_USER}" echo " - Admin User: ${ADMIN_USER:-$USER}"
echo " - Configuration saved in: ${CONFIG_FILE}" echo " - Configuration saved in: ${CONFIG_FILE}"
echo " - Installation log: ${LOG_FILE}" echo " - Installation log: ${LOG_FILE}"
echo " - Services summary: ${summary_file}" echo " - Services summary: ${summary_file}"