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:
@@ -12,6 +12,14 @@ chmod +x setup.sh
|
|||||||
sudo ./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:
|
Alternative direct download:
|
||||||
```bash
|
```bash
|
||||||
wget -O setup.sh "https://git.del-c.net/Del-c.net/debian-first-boot-setup/raw/branch/main/setup.sh"
|
wget -O setup.sh "https://git.del-c.net/Del-c.net/debian-first-boot-setup/raw/branch/main/setup.sh"
|
||||||
|
|||||||
45
setup.sh
45
setup.sh
@@ -49,18 +49,25 @@ check_debian() {
|
|||||||
|
|
||||||
# Check for required commands
|
# Check for required commands
|
||||||
check_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
|
||||||
for cmd in $required_commands; do
|
error "useradd command not found. Please install the passwd package: apt install -y passwd"
|
||||||
if ! command -v "$cmd" >/dev/null 2>&1 && ! [ -x "/usr/sbin/$cmd" ]; then
|
|
||||||
error "Required command '$cmd' not found. Please install it first."
|
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
# Special check for usermod which we use later
|
# 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
|
||||||
|
|
||||||
|
# Check usermod (in /usr/sbin/)
|
||||||
if ! command -v usermod >/dev/null 2>&1 && ! [ -x /usr/sbin/usermod ]; then
|
if ! command -v usermod >/dev/null 2>&1 && ! [ -x /usr/sbin/usermod ]; then
|
||||||
warn "usermod command not found. Will attempt to use full path."
|
warn "usermod command not found. Will attempt to use full path."
|
||||||
fi
|
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
|
# Ask user about creating an additional user
|
||||||
@@ -180,12 +187,24 @@ create_sysadmin_user() {
|
|||||||
warn "User $SYSADMIN_USER already exists, skipping creation"
|
warn "User $SYSADMIN_USER already exists, skipping creation"
|
||||||
else
|
else
|
||||||
# Create user with home directory
|
# Create user with home directory
|
||||||
|
if command -v useradd >/dev/null 2>&1; then
|
||||||
useradd -m -s /bin/bash "$SYSADMIN_USER"
|
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"
|
log "User $SYSADMIN_USER created successfully"
|
||||||
|
|
||||||
# Set password for sysadmin user
|
# Set password for sysadmin user
|
||||||
echo "Please set a password for user $SYSADMIN_USER:"
|
echo "Please set a password for user $SYSADMIN_USER:"
|
||||||
|
if command -v passwd >/dev/null 2>&1; then
|
||||||
passwd "$SYSADMIN_USER"
|
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
|
fi
|
||||||
|
|
||||||
# Add sysadmin to sudo group
|
# Add sysadmin to sudo group
|
||||||
@@ -207,12 +226,24 @@ create_additional_user() {
|
|||||||
warn "User $ADDITIONAL_USER already exists, skipping creation"
|
warn "User $ADDITIONAL_USER already exists, skipping creation"
|
||||||
else
|
else
|
||||||
# Create user with home directory
|
# Create user with home directory
|
||||||
|
if command -v useradd >/dev/null 2>&1; then
|
||||||
useradd -m -s /bin/bash "$ADDITIONAL_USER"
|
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"
|
log "User $ADDITIONAL_USER created successfully"
|
||||||
|
|
||||||
# Set password for additional user
|
# Set password for additional user
|
||||||
echo "Please set a password for user $ADDITIONAL_USER:"
|
echo "Please set a password for user $ADDITIONAL_USER:"
|
||||||
|
if command -v passwd >/dev/null 2>&1; then
|
||||||
passwd "$ADDITIONAL_USER"
|
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
|
fi
|
||||||
|
|
||||||
# Add additional user to sudo group
|
# Add additional user to sudo group
|
||||||
|
|||||||
Reference in New Issue
Block a user