#!/bin/bash

if [ $# -ne 1 ]; then
    echo "Usage: $0 <username>"
    exit 1
fi

USERNAME="$1"

if id -u "$USERNAME" >/dev/null 2>&1; then
    echo "Error: User $USERNAME already exists"
    exit 1
fi

if [ -f /etc/debian_version ]; then
    ADMIN_GROUP="sudo"
elif [ -f /etc/redhat-release ]; then
    ADMIN_GROUP="wheel"
else
    echo "Error: Unsupported system type"
    exit 1
fi

echo "Creating user $USERNAME with home directory /home/$USERNAME and adding to group $ADMIN_GROUP..."

useradd -m -s /bin/bash -G "$ADMIN_GROUP" "$USERNAME"

echo "Please set password for user $USERNAME:"
passwd "$USERNAME"

echo "User $USERNAME created successfully with sudo privileges."
echo "Test: su - $USERNAME then run sudo ls /root"


