Skip to content

Commit

Permalink
cleaning __sm.user.exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Dec 18, 2011
1 parent e79f8c4 commit 78b85d7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
34 changes: 17 additions & 17 deletions core/internal/shell/user/functions
Original file line number Diff line number Diff line change
Expand Up @@ -80,38 +80,39 @@ __sm.user.set.home()

__sm.user.exists()
{
typeset _filter _user _flags
typeset _user _flags

_user="$1"
_flags="$2"

if __sm.os.type.is darwin && __sm.string.contains "system" "${_flags}"
then _user="_${_user}" ; fi

if __sm.string.contains "system" "${_flags}"
then _filter="< ${__sm_user_id_users}"
else _filter=">= ${__sm_user_id_users}"
fi
if __sm.string.is.empty "${_user}"
then

# TODO: Figure out the filtering of system users... although I am not
# convinced that filter is necessary at all.
return 1

# At this point _user is expected to be UID numeric or USER string.
if [[ "${_user}" == "0" ]] || (( _user ))
# At this point _user is expected to be UID numeric or USER login string.
elif __sm.string.is.number "${_user}"
then # UID

if __sm.os.type.is darwin
then
dscl . -list /Users UniqueID | \awk '{if ($2 == '${_user}') print $1;}'
dscl . -list /Users UniqueID | \awk '{print $2;}'
else
\awk -F: '{if ($3 == '${_user}') print $1;}' /etc/passwd
\awk -F: '{print $3;}' /etc/passwd
fi | \grep "^${_user}$" >/dev/null || return $?

else # Name

if __sm.os.type.is darwin && __sm.string.contains "system" "${_flags}"
then _user="_${_user#_}" ; fi

if __sm.os.type.is darwin
then
dscl . -list /Users UniqueID | awk '{print $1}'
dscl . -list /Users UniqueID | \awk '{print $1;}'
else
awk -F: '/^'${_user}':/{print $1}' /etc/passwd
\awk -F: '{print $1;}' /etc/passwd
fi | \grep "^${_user}$" >/dev/null || return $?

fi
}

Expand Down Expand Up @@ -287,4 +288,3 @@ __sm.user.is()
[[ "$USER" == "${_identifier}" ]]
fi
}

15 changes: 15 additions & 0 deletions core/sm/shell/string/functions
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,18 @@ __sm.string.ematch()
;;
esac
}

__sm.string.is.number()
{
if [[ -n "$1" ]]
then
[[ "$1" == "0" ]] || (( $1 ))
else
return 1
fi
}

__sm.string.is.empty()
{
[[ -z "$1" ]]
}

0 comments on commit 78b85d7

Please sign in to comment.