101 lines
4.5 KiB
Bash
Executable File
101 lines
4.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
##########################################################################
|
|
# Shellscript : Script
|
|
# Autor : Jobst Heinermann, macenterprise gmbh
|
|
# Copyright : macenterprise 2019
|
|
##########################################################################
|
|
############################################## Check der austehenden Policies ###############################################
|
|
jamf policy
|
|
############################################## Jamf Helper ##################################################################
|
|
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
|
|
jamf="/usr/local/bin/jamf"
|
|
|
|
ErrorIcon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarDeleteIcon.icns"
|
|
SuccessfulIcon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/HomeFolderIcon.icns"
|
|
|
|
ErrorBindingIcon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ConnectToIcon.icns"
|
|
SuccessfulBindingIcon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
|
|
|
|
BindingOkMassage="AD ist erreichbar und konfiguriert"
|
|
NoBindMassage="AD ist nicht konfiguriert.
|
|
Bitte das Gerät an das AD binden."
|
|
|
|
ErrorMassage="Account konnte nicht angelegt werden. Bitte prüfen:
|
|
|
|
- Ist der Account aktiv?
|
|
- Ist der Account gesperrt?
|
|
- Ist das Passwort aktuell?
|
|
|
|
"
|
|
|
|
SuccessfulMassage="Account wurde erfolgreich angelegt."
|
|
|
|
############################################## Function #####################################################################
|
|
ask () {
|
|
osascript <<EOF - 2>/dev/null
|
|
tell application "SystemUIServer"
|
|
activate
|
|
text returned of (display dialog "$1" default answer "")
|
|
end tell
|
|
EOF
|
|
}
|
|
|
|
askhidden () {
|
|
osascript <<EOF - 2>/dev/null
|
|
tell application "SystemUIServer"
|
|
activate
|
|
text returned of (display dialog "$1" default answer "" with hidden answer)
|
|
end tell
|
|
EOF
|
|
}
|
|
|
|
DecryptString() {
|
|
# Usage: ~$ DecryptString "Encrypted String" "Salt" "Passphrase"
|
|
echo "${1}" | /usr/bin/openssl enc -aes256 -d -a -A -S "${2}" -k "${3}"
|
|
}
|
|
|
|
############################################## Prüfung diba.corp.int erreichbar ################################################
|
|
AD_ING="diba.corp.int" #AD Domaine
|
|
AD_STAT=$(dsconfigad -show | awk '/Active Directory Domain/{print $NF}') #AD Domain auf System
|
|
|
|
ping -c1 $AD_ING 1>/dev/null 2>/dev/null
|
|
SUCCESS=$?
|
|
|
|
if [[ "$AD_STAT" = "$AD_ING" && $SUCCESS -eq 0 ]]
|
|
then
|
|
HELPER=$("$jamfHelper" -windowType utility -icon "$SuccessfulBindingIcon" -title "Binding OK" -description "$BindingOkMassage" -button1 "OK" -defaultButton 1)
|
|
echo "Exit Code: Gerät ist nicht gebunden."
|
|
|
|
else
|
|
HELPER=$("$jamfHelper" -windowType utility -icon "$ErrorBindingIcon" -title "No Binding" -description "$NoBindMassage" -button1 "OK" -defaultButton 1)
|
|
echo "Exit Code: Gerät ist nicht gebunden. Prüfen ob die Policy [021] gelaufen ist."
|
|
exit 1
|
|
fi
|
|
|
|
############################################## Variabeln #########################################################################
|
|
PNUM=$(ask 'Bitte Personalnummer eingeben') || exit #Personalnummer
|
|
ADMIN="$4" #lokaler Admin
|
|
PASS=$(askhidden 'Bitte das Passwort des User eingeben') || exit #User Passwort
|
|
APASS=$(DecryptString "$5" "$6" "$7") #Admin Passwort
|
|
AGRP="DOMDIBACORP\Domain Users" #User Gruppe im AD
|
|
|
|
############################################## Anlegen des Users aus dem AD (inkl. SercureToken) ###################################
|
|
if /System/Library/CoreServices/ManagedClient.app/Contents/Resources/createmobileaccount -n "$PNUM" -p "$PASS" -a "$ADMIN" -U "$APASS"
|
|
then
|
|
HELPER=$("$jamfHelper" -windowType utility -icon "$SuccessfulIcon" -title "Accocunt Fertig" -description "$SuccessfulMassage" -button1 "OK" -defaultButton 1)
|
|
echo "Exit Code: Account wurde erfolgreich angelegt."
|
|
|
|
endUsername=$(dscl . read /Users/$PNUM RecordName | awk {'print $2'})
|
|
realname=$(dscl . read /Users/$PNUM RealName | tr -d ' ' | tail -n1)
|
|
email=$(dscl . read /Users/$PNUM EMailAddress | awk {'print $2'})
|
|
position=$(dscl . read /Users/$PNUM JobTitle | tr -d ' ' | tail -n1)
|
|
phone=$(dscl . read /Users/$PNUM PhoneNumber | tr -d ' ' | tail -n1)
|
|
room=$(dscl . read /Users/$PNUM City | awk {'print $2'})
|
|
|
|
jamf recon -endUsername "$endUsername" -realname "$realname" -email "$email" -position "$position" -phone "$phone" -building "$building" -Room "room"
|
|
else
|
|
HELPER=$("$jamfHelper" -windowType utility -icon "$ErrorIcon" -title "Error" -description "$ErrorMassage" -button1 "OK" -defaultButton 1)
|
|
echo "Exit Code: Account konnte nicht angelegt werden."
|
|
fi
|
|
exit 0 |