From bd64a0c661b8a1715d8b52defb3465e6e9888b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sun, 3 Jan 2016 17:20:32 +0100 Subject: [PATCH] [enh] Add a helper to check if a user exists on the system --- data/apps/helpers.d/user | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/data/apps/helpers.d/user b/data/apps/helpers.d/user index fc58d0027..bfd044070 100644 --- a/data/apps/helpers.d/user +++ b/data/apps/helpers.d/user @@ -1,15 +1,14 @@ -# Check if a user exists +# Check if a YunoHost user exists # # example: ynh_user_exists 'toto' || exit 1 # # usage: ynh_user_exists username # | arg: username - the username to check -# | ret: retcode - 0 if user exists, 1 otherwise ynh_user_exists() { sudo yunohost user list --output-as json | grep -q "\"username\": \"${1}\"" } -# Retrieve a user information +# Retrieve a YunoHost user information # # example: mail=$(ynh_user_get_info 'toto' 'mail') # @@ -18,5 +17,13 @@ ynh_user_exists() { # | arg: key - the key to retrieve # | ret: string - the key's value ynh_user_get_info() { - sudo yunohost user info "${1}" --output-as plain | ynh_get_plain_key "${2}" + sudo yunohost user info "$1" --output-as plain | ynh_get_plain_key "$2" +} + +# Check if a user exists on the system +# +# usage: ynh_system_user_exists username +# | arg: username - the username to check +ynh_system_user_exists() { + getent passwd "$1" &>/dev/null }