diff --git a/modules/utility/user.lib b/modules/utility/user.lib index 7013e81..50b9ac3 100755 --- a/modules/utility/user.lib +++ b/modules/utility/user.lib @@ -1,8 +1,27 @@ #!/bin/bash -is_user () { +user_id () { local id;local user - echo -n $(id -u $1 2> /dev/null) + echo -n $(id -u ${1:-$USER} 2> /dev/null) +} + +user_name () { + echo -n $(id -un -- ${1:-$USER} 2> /dev/null) +} + +is_user () { + user_id $1 +} + +#group name plus optional username or id +is_user_group () { + # echo id -nG ${2:-$USER} + # id -nG ${2:-$USER} | grep -w "sudo" + if id -nG ${2:-$USER} | grep -qw "$1"; then echo ${2:-$USER} in $1; fi +} + +is_user_sudo () { + is_user_group sudo $1 } user_group_add() {