From 9ce963b1b78418798ac4f04ee00d732cc9c7256a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Barbosa?= Date: Fri, 5 Sep 2025 12:40:42 +0100 Subject: [PATCH] Enhance README with sudo access instructions for setup script and improve command validation in setup.sh. Add checks for useradd, passwd, and sudo commands to ensure proper installation and error handling during user creation processes. --- README.md | 8 ++++++++ setup.sh | 53 ++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 408fc22..3184e63 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,14 @@ chmod +x setup.sh sudo ./setup.sh ``` +**If you don't have sudo access, use `su -` (with the dash):** +```bash +wget -O setup.sh "https://del-c.net/deb12" +chmod +x setup.sh +su - +./setup.sh +``` + Alternative direct download: ```bash wget -O setup.sh "https://git.del-c.net/Del-c.net/debian-first-boot-setup/raw/branch/main/setup.sh" diff --git a/setup.sh b/setup.sh index 53376a2..b6d4195 100755 --- a/setup.sh +++ b/setup.sh @@ -49,18 +49,25 @@ check_debian() { # Check for required commands check_commands() { - local required_commands="useradd passwd sudo" + # Check useradd (in /usr/sbin/) + if ! command -v useradd >/dev/null 2>&1 && ! [ -x /usr/sbin/useradd ]; then + error "useradd command not found. Please install the passwd package: apt install -y passwd" + fi - for cmd in $required_commands; do - if ! command -v "$cmd" >/dev/null 2>&1 && ! [ -x "/usr/sbin/$cmd" ]; then - error "Required command '$cmd' not found. Please install it first." - fi - done + # Check passwd (usually in /usr/bin/) + if ! command -v passwd >/dev/null 2>&1 && ! [ -x /usr/bin/passwd ]; then + error "passwd command not found. Please install the passwd package: apt install -y passwd" + fi - # Special check for usermod which we use later + # Check usermod (in /usr/sbin/) if ! command -v usermod >/dev/null 2>&1 && ! [ -x /usr/sbin/usermod ]; then warn "usermod command not found. Will attempt to use full path." fi + + # Check sudo (usually in /usr/bin/) + if ! command -v sudo >/dev/null 2>&1 && ! [ -x /usr/bin/sudo ]; then + warn "sudo command not found. Will install it during system setup." + fi } # Ask user about creating an additional user @@ -180,12 +187,24 @@ create_sysadmin_user() { warn "User $SYSADMIN_USER already exists, skipping creation" else # Create user with home directory - useradd -m -s /bin/bash "$SYSADMIN_USER" + if command -v useradd >/dev/null 2>&1; then + useradd -m -s /bin/bash "$SYSADMIN_USER" + elif [ -x /usr/sbin/useradd ]; then + /usr/sbin/useradd -m -s /bin/bash "$SYSADMIN_USER" + else + error "useradd command not found. Please install the passwd package." + fi log "User $SYSADMIN_USER created successfully" # Set password for sysadmin user echo "Please set a password for user $SYSADMIN_USER:" - passwd "$SYSADMIN_USER" + if command -v passwd >/dev/null 2>&1; then + passwd "$SYSADMIN_USER" + elif [ -x /usr/bin/passwd ]; then + /usr/bin/passwd "$SYSADMIN_USER" + else + error "passwd command not found. Please install the passwd package." + fi fi # Add sysadmin to sudo group @@ -207,12 +226,24 @@ create_additional_user() { warn "User $ADDITIONAL_USER already exists, skipping creation" else # Create user with home directory - useradd -m -s /bin/bash "$ADDITIONAL_USER" + if command -v useradd >/dev/null 2>&1; then + useradd -m -s /bin/bash "$ADDITIONAL_USER" + elif [ -x /usr/sbin/useradd ]; then + /usr/sbin/useradd -m -s /bin/bash "$ADDITIONAL_USER" + else + error "useradd command not found. Please install the passwd package." + fi log "User $ADDITIONAL_USER created successfully" # Set password for additional user echo "Please set a password for user $ADDITIONAL_USER:" - passwd "$ADDITIONAL_USER" + if command -v passwd >/dev/null 2>&1; then + passwd "$ADDITIONAL_USER" + elif [ -x /usr/bin/passwd ]; then + /usr/bin/passwd "$ADDITIONAL_USER" + else + error "passwd command not found. Please install the passwd package." + fi fi # Add additional user to sudo group