[fix] Delete properly group as well as user

This commit is contained in:
Maniack Crudelis 2019-03-13 18:42:07 +01:00 committed by GitHub
parent 4ed6392680
commit 485cb4b5c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -63,6 +63,21 @@ ynh_system_user_exists() {
getent passwd "$username" &>/dev/null
}
# Check if a group exists on the system
#
# usage: ynh_system_group_exists --group=group
# | arg: -g, --group - the group to check
ynh_system_group_exists() {
# Declare an array to define the options of this helper.
local legacy_args=g
declare -Ar args_array=( [g]=group= )
local group
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
getent group "$group" &>/dev/null
}
# Create a system user
#
# examples:
@ -116,11 +131,21 @@ ynh_system_user_delete () {
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
if ynh_system_user_exists "$username" # Check if the user exists on the system
# Check if the user exists on the system
if ynh_system_user_exists "$username"
then
echo "Remove the user $username" >&2
sudo userdel $username
deluser $username
else
echo "The user $username was not found" >&2
fi
# Check if the group exists on the system
if ynh_system_group_exists "$username"
then
echo "Remove the group $username" >&2
delgroup $username
else
echo "The group $username was not found" >&2
fi
}