add basic user functions to get id name and to do basic checks is_uer is_user_group is_user_sudo

master
Kebler Network System Administrator 2023-02-07 09:26:05 -08:00
parent 3be0565a06
commit fa65a9f4a4
1 changed files with 21 additions and 2 deletions

View File

@ -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() {