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.

This commit is contained in:
2025-09-05 12:40:42 +01:00
parent fd2be2393e
commit 9ce963b1b7
2 changed files with 50 additions and 11 deletions

View File

@@ -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"

View File

@@ -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