|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +currentUser=$(who | awk '/console/{print $1}') |
| 4 | +echo $currentUser |
| 5 | + |
| 6 | +osascript -e 'set T to text returned of (display dialog "Please enter a one line business justification for the admin-level action(s) to be taken." buttons {"Cancel", "OK"} default button "OK" default answer "")' |
| 7 | + |
| 8 | + |
| 9 | +osascript -e 'display dialog "Your local computer user account has been elevated to admin privileges for 30 minutes. Activity is logged." buttons {"Cancel", "OK"} default button 2' |
| 10 | + |
| 11 | +sudo defaults write /Library/LaunchDaemons/removeAdmin.plist Label -string "removeAdmin" |
| 12 | + |
| 13 | +sudo defaults write /Library/LaunchDaemons/removeAdmin.plist ProgramArguments -array -string /bin/sh -string "/Library/Application Support/JAMF/removeAdminRights.sh" |
| 14 | + |
| 15 | +sudo defaults write /Library/LaunchDaemons/removeAdmin.plist StartInterval -integer 1800 |
| 16 | + |
| 17 | +sudo defaults write /Library/LaunchDaemons/removeAdmin.plist RunAtLoad -boolean yes |
| 18 | + |
| 19 | +sudo chown root:wheel /Library/LaunchDaemons/removeAdmin.plist |
| 20 | +sudo chmod 644 /Library/LaunchDaemons/removeAdmin.plist |
| 21 | + |
| 22 | +launchctl load /Library/LaunchDaemons/removeAdmin.plist |
| 23 | +sleep 10 |
| 24 | + |
| 25 | +if [ ! -d /private/var/userToRemove ]; then |
| 26 | + mkdir /private/var/userToRemove |
| 27 | + echo $currentUser >> /private/var/userToRemove/user |
| 28 | + else |
| 29 | + echo $currentUser >> /private/var/userToRemove/user |
| 30 | +fi |
| 31 | + |
| 32 | +/usr/sbin/dseditgroup -o edit -a $currentUser -t user admin |
| 33 | + |
| 34 | +cat << 'EOF' > /Library/Application\ Support/JAMF/removeAdminRights.sh |
| 35 | +if [[ -f /private/var/userToRemove/user ]]; then |
| 36 | + userToRemove=$(cat /private/var/userToRemove/user) |
| 37 | + echo "Removing $userToRemove admin privileges" |
| 38 | + /usr/sbin/dseditgroup -o edit -d $userToRemove -t user admin |
| 39 | + rm -f /private/var/userToRemove/user |
| 40 | + launchctl unload /Library/LaunchDaemons/removeAdmin.plist |
| 41 | + rm /Library/LaunchDaemons/removeAdmin.plist |
| 42 | + log collect --last 30m --output /private/var/userToRemove/$userToRemove.logarchive |
| 43 | +fi |
| 44 | +
|
| 45 | +EOF |
| 46 | +exit 0 |
0 commit comments