112 lines
3.4 KiB
Bash
112 lines
3.4 KiB
Bash
#!/bin/bash
|
|
|
|
##########################################################################
|
|
# Shellscript : Startup Script und LaunchAgent erstellen
|
|
# Quelle :
|
|
# Autor : Jobst Heinermann, macenterprise gmbh
|
|
# Copyright : macenterprise 2019
|
|
##########################################################################
|
|
|
|
# Variabel
|
|
user=$(stat -f '%u %Su' /dev/console | cut -d ' ' -f 2)
|
|
|
|
# Ordner neu erstellen
|
|
mkdir -p "/Library/User Template/German.lproj/Library/LaunchAgents"
|
|
|
|
# Erstellung XML
|
|
read -d '' launchAgent <<"EOF"
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>Label</key>
|
|
<string>de.ing.startup.plist</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>/usr/local/scripte/de.ing.startup.sh</string>
|
|
</array>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
</dict>
|
|
</plist>
|
|
EOF
|
|
|
|
# XML schreiben
|
|
echo "$launchAgent" > "/Library/User Template/German.lproj/Library/LaunchAgents/de.ing.startup.plist"
|
|
|
|
# Rechte setzen
|
|
/bin/chmod 644 "/Library/User Template/German.lproj/Library/LaunchAgents/de.ing.startup.plist"
|
|
|
|
|
|
# Erstellung startup script
|
|
read -d '' startupscript<<"EOF"
|
|
|
|
#!/bin/bash
|
|
|
|
##########################################################################
|
|
# Shellscript : First Startup ING Mac
|
|
# : Login absichern (Yubikey)
|
|
# Autor : Jobst Heinermann, macenterprise gmbh
|
|
# Copyright : macenterprise 2019
|
|
##########################################################################
|
|
|
|
##########################################################################
|
|
# Shellscript : Update Username in Jamf Record
|
|
# Autor : Jobst Heinermann, macenterprise gmbh
|
|
# Quelle : https://www.jamf.com/jamf-nation/discussions/17139/assign-users-to-computers-via-api
|
|
# Copyright : macenterprise 2019
|
|
##########################################################################
|
|
|
|
# Variabeln
|
|
aduser=$(dscl . list /Users | grep -v '_' | sort -ug | tail -n1)
|
|
user=$(stat -f '%u %Su' /dev/console | cut -d ' ' -f 2)
|
|
|
|
# Userinfo auslesen
|
|
if [ $aduser -gt 10000 ]
|
|
then
|
|
# -endUsername The user name of the primary user
|
|
endUsername=$(dscl . read /Users/$aduser RecordName | awk {'print $2'})
|
|
# -realname The real name of the primary user
|
|
realname=$(dscl . read /Users/$aduser RealName | tr -d ' ' | tail -n1)
|
|
# -email The email address of the primary user
|
|
email=$(dscl . read /Users/$aduser EMailAddress | awk {'print $2'})
|
|
# -position The position (job title) of the primary user
|
|
position=$(dscl . read /Users/$aduser JobTitle | tr -d ' ' | tail -n1)
|
|
# -phone The phone number of the primary user
|
|
phone=$(dscl . read /Users/$aduser PhoneNumber | tr -d ' ' | tail -n1)
|
|
# -building The text representation of a building in the jSS
|
|
building=enrolled
|
|
|
|
jamf recon -endUsername "$endUsername" -realname "$realname" -email "$email" -position "$position" -phone "$phone" -building "$building"
|
|
|
|
else
|
|
echo "kein AD User vorhanden"
|
|
exit 1
|
|
fi
|
|
|
|
sleep 20
|
|
|
|
# Profile durch geänderten Scope abfragen
|
|
|
|
jamf recon
|
|
|
|
# self destroy
|
|
rm /usr/local/scripte/de.ing.startup.sh
|
|
rm /Users/$user/Library/LaunchAgents/de.ing.startup.plist
|
|
rm "/Library/User Template/German.lproj/Library/LaunchAgents/de.ing.startup.plist"
|
|
|
|
# User ausloggen
|
|
pkill loginwindow
|
|
|
|
EOF
|
|
|
|
# script schreiben
|
|
mkdir -p /usr/local/scripte
|
|
echo "$startupscript" > /usr/local/scripte/de.ing.startup.sh
|
|
|
|
# Rechte setzen
|
|
/bin/chmod a+x /usr/local/scripte/de.ing.startup.sh
|
|
|
|
exit 0
|
|
|