ifms-zentyal-scripts/pdc-del-user.sh

33 lines
684 B
Bash
Raw Normal View History

2022-05-24 19:10:18 +00:00
#!/bin/bash
2023-06-07 14:53:15 +00:00
# Check if is running as root
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
2022-05-24 19:10:18 +00:00
USERNAME=$1
# Check if arguments are not empty
if [ -z "$USERNAME" ]; then
echo "Usage: $0 <username>"
exit 1
fi
2023-03-07 18:22:56 +00:00
# Check if $USERNAME starts with a number
if [[ $USERNAME =~ ^[0-9] ]]; then
echo "Username cannot start with a number. Appending 'u' to the beginning of the username..."
USERNAME="u$USERNAME"
fi
2022-05-24 19:10:18 +00:00
# Check if user exists
if ! samba-tool user show $USERNAME >/dev/null 2>&1; then
echo "User $USERNAME does not exist"
exit 1
fi
samba-tool user delete $USERNAME
rm -rf /home/$USERNAME
echo "/home/$USERNAME directory deleted"