Created
April 21, 2016 19:56
-
-
Save WardsParadox/dbd30cd5aafc9509bf421b9da8f9192a to your computer and use it in GitHub Desktop.
Get Current User and if they are admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Grabs the current logged in user and detects if they are admin | |
# Per MacMule's better dection of the logged in user: | |
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");'` | |
# Per munkireport-php's localadmin module | |
admin_users='' | |
for user in $(dscl . -list /Users | grep -v "^_\|^root$") ; do | |
ismember=$(dsmemberutil checkmembership -U $user -G admin) | |
case $ismember in | |
*'user is a member of the group'*) admin_users+=( $user );; | |
esac | |
done | |
echo "All admin users:${admin_users[@]}" | |
echo "Current User: $loggedInUser" | |
for admins in ${admin_users[@]} ; do | |
if [ "$admins" == "$loggedInUser" ]; then | |
echo "$admins is an admin and is logged in"; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment