72 lines
2.6 KiB
Bash
72 lines
2.6 KiB
Bash
#!/bin/bash
|
|
|
|
##########################################################################
|
|
# Shellscript : temp. Berechtigung Konsole zu nutzen
|
|
# Adaption von MakeMeanAdmin.sh
|
|
# Autor : Jobst Heinermann, macenterprise gmbh
|
|
##########################################################################
|
|
|
|
|
|
currentUser=$(who | awk '/console/{print $1}')
|
|
echo $currentUser
|
|
|
|
osascript -e 'display dialog "Du kannst Konsole für die Analyse von Absturzberichten nutzen. Die Berechtigung wird nach 30 Minuten entfernt. Die Anforderung der Rechte wird protokolliert!" buttons {"Recht zuweisen"} default button 1'
|
|
|
|
|
|
#Create the plist
|
|
sudo defaults write /Library/LaunchDaemons/removeConsoleAccess.plist Label -string "removeConsoleAccess"
|
|
|
|
#Add program argument to have it run the update script
|
|
sudo defaults write /Library/LaunchDaemons/removeConsoleAccess.plist ProgramArguments -array -string /bin/sh -string "/Library/Application Support/JAMF/removeConsoleAccessRights.sh"
|
|
|
|
#Set the run inverval to run every 7 days
|
|
sudo defaults write /Library/LaunchDaemons/removeConsoleAccess.plist StartInterval -integer 1800
|
|
|
|
#Set run at load
|
|
sudo defaults write /Library/LaunchDaemons/removeConsoleAccess.plist RunAtLoad -boolean yes
|
|
|
|
#Set ownership
|
|
sudo chown root:wheel /Library/LaunchDaemons/removeConsoleAccess.plist
|
|
sudo chmod 644 /Library/LaunchDaemons/removeConsoleAccess.plist
|
|
|
|
#Load the daemon
|
|
launchctl load /Library/LaunchDaemons/removeConsoleAccess.plist
|
|
sleep 10
|
|
|
|
#########################
|
|
# make file for removal #
|
|
#########################
|
|
|
|
if [ ! -d /private/var/userToRemove ]; then
|
|
mkdir /private/var/userToRemove
|
|
echo $currentUser >> /private/var/userToRemove/user
|
|
else
|
|
echo $currentUser >> /private/var/userToRemove/user
|
|
fi
|
|
|
|
##################################
|
|
# give the user console privileges #
|
|
##################################
|
|
|
|
/usr/sbin/dseditgroup -o edit -a $currentUser -t user _analyticsusers
|
|
|
|
########################################
|
|
# write a script for the launch daemon #
|
|
# to run to demote the user back and #
|
|
# then pull logs of what the user did. #
|
|
########################################
|
|
|
|
cat << 'EOF' > /Library/Application\ Support/JAMF/removeConsoleAccessRights.sh
|
|
if [[ -f /private/var/userToRemove/user ]]; then
|
|
userToRemove=$(cat /private/var/userToRemove/user)
|
|
echo "Removing $userToRemove's console privileges"
|
|
killall Console
|
|
/usr/sbin/dseditgroup -o edit -d $userToRemove -t user _analyticsusers
|
|
rm -f /private/var/userToRemove/user
|
|
launchctl unload /Library/LaunchDaemons/removeConsoleAccess.plist
|
|
rm /Library/LaunchDaemons/removeConsoleAccess.plist
|
|
log collect --last 30m --output /private/var/userToRemove/$userToRemove.logarchive
|
|
fi
|
|
EOF
|
|
|
|
exit 0 |