58 lines
1.6 KiB
Bash
Executable File
58 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Usage: ./remove_samba_user.sh <username>
|
|
|
|
# Check for root
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "This script must be run as root."
|
|
exit 1
|
|
fi
|
|
|
|
|
|
####################################################################
|
|
# Parse username
|
|
####################################################################
|
|
|
|
USERNAME="$1"
|
|
|
|
if [[ -z "$USERNAME" ]]; then
|
|
read -p "Enter username to remove: " USERNAME
|
|
fi
|
|
|
|
####################################################################
|
|
# Remove shares
|
|
# All the shares associated to the user are removed
|
|
####################################################################
|
|
|
|
bash $SMB_TOOLS_PATH/functions/list_smb_shares.sh $USERNAME | while IFS= read -r line; do
|
|
# Skip empty lines
|
|
[ -z "$line" ] && continue
|
|
|
|
bash $SMB_TOOLS_PATH/functions/remove_share.sh "$line"
|
|
done
|
|
|
|
# ####################################################################
|
|
# # Remove samba user
|
|
# ####################################################################
|
|
|
|
if pdbedit -L | grep -q "^$USERNAME:"; then
|
|
smbpasswd -x "$USERNAME"
|
|
echo "Samba user $USERNAME removed."
|
|
else
|
|
echo "Samba user $USERNAME does not exist."
|
|
fi
|
|
|
|
# ####################################################################
|
|
# # Remove system user
|
|
# ####################################################################
|
|
|
|
if id "$USERNAME" &>/dev/null; then
|
|
userdel -r "$USERNAME"
|
|
echo "System user $USERNAME removed (including home directory)."
|
|
else
|
|
echo "System user $USERNAME does not exist."
|
|
fi
|
|
|
|
# ####################################################################
|
|
# # Remove filebrowser
|
|
# #################################################################### |