Skip to content

Instantly share code, notes, and snippets.

@WardsParadox
Created April 21, 2016 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WardsParadox/dbd30cd5aafc9509bf421b9da8f9192a to your computer and use it in GitHub Desktop.
Save WardsParadox/dbd30cd5aafc9509bf421b9da8f9192a to your computer and use it in GitHub Desktop.
Get Current User and if they are admin
#!/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