128 lines
5.0 KiB
Bash
128 lines
5.0 KiB
Bash
#!/bin/bash
|
|
|
|
##########################################################################
|
|
# Shellscript : Ändern des Schlüsselbund-Passwortes
|
|
# Autor : Andreas Vogel, macenterprise gmbh, 31.10.2019
|
|
##########################################################################
|
|
|
|
## User is
|
|
user=$(stat -f '%u %Su' /dev/console | cut -d ' ' -f 2)
|
|
|
|
## Check default-keychain
|
|
keychain=$(security default-keychain | tr -d '[:space:]' | sed 's/"//g')
|
|
|
|
# echo $keychain
|
|
|
|
## If Keychain run close
|
|
if ( pgrep "Keychain Access" > /dev/null ); then
|
|
echo "Killing Keychain Access"
|
|
killall "Keychain Access"
|
|
else
|
|
echo "Keychain Access is not running"
|
|
fi
|
|
|
|
|
|
## Variablen
|
|
askPass () {
|
|
osascript <<EOF - 2>/dev/null
|
|
tell application "SystemUIServer"
|
|
activate
|
|
text returned of (display dialog "$1" default answer "" with hidden answer)
|
|
end tell
|
|
EOF
|
|
}
|
|
|
|
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
|
|
jamf="/usr/local/bin/jamf"
|
|
|
|
|
|
|
|
## INGIcon
|
|
KeychainIcon="/System/Applications/Utilities/Keychain Access.app/Contents/Resources/AppIcon.icns"
|
|
ErrorIcon="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns"
|
|
SuccessfulIcon="/Library/Application Support/JAMF/ING/ok-1976099_640.png"
|
|
|
|
######################################################################################################################################
|
|
|
|
## Messages
|
|
Message="Mit diesem Programm wird das Windows-Passwort und das Schlüsselbund-Passwort synchronisiert.
|
|
|
|
Nur fortfahren, wenn das Schlüsselbund-Passwort nicht dem aktuellen Windows-Passwort entspricht.
|
|
|
|
This program synchronizes the Windows password and keychain password.
|
|
Only proceed if the keychain password does not match the current Windows password.
|
|
"
|
|
|
|
FailedPwMessage="Die Eingabe stimmt nicht überein, bitte das neue Passwort erneut eingeben.
|
|
|
|
The entry does not match, please reenter the new password.
|
|
"
|
|
|
|
FailedPwMessageAgain="Die Eingabe stimmt erneut nicht überein. Das Programm wird beendet.
|
|
|
|
The input does not match again. The program is ended.
|
|
"
|
|
|
|
FailedChange="Das Passwort konnte nicht geändert werden. Versuche es erneut. Falls das Problem weiterhin besteht, wende dich an dem Client_Service_Mac.
|
|
|
|
The password could not be changed. Try again. If the problem persists, contact the Client_Service_Mac.
|
|
"
|
|
|
|
SuccessfulChange="Das Passwort wurde erfolgreich geändert.
|
|
The password was changed successfully.
|
|
"
|
|
|
|
######################################################################################################################################
|
|
|
|
## Abfrage, ob der User das Passwort wirklich ändern möchte.
|
|
HELPER=$("$jamfHelper" -windowType utility -icon "$KeychainIcon" -title "Change Keychain password" -description "$Message" -button1 "OK" -button2 "Cancel" -cancelButton "2" -defaultButton 2)
|
|
echo "Jamf Helper Exit Code: $HELPER"
|
|
|
|
## Wenn der User den zustimmt, wird das alte Passwort und das neue Passwort abgefragt.
|
|
|
|
if [ "$HELPER" == "0" ]
|
|
then
|
|
oldPassphrase=$(askPass 'Bitte gebe das alte Passwort ein. Please enter the old password.') || exit
|
|
newPassphrase=$(askPass 'Bitte gebe das aktuelle Windows-Passwort ein. Please enter the current Windows password.') || exit
|
|
newPassphrase2=$(askPass 'Bitte gebe das aktuelle Windows-Passwort erneut ein. Please enter the current Windows password again.') || exit
|
|
|
|
|
|
## Prüfen ob das neue Passwort übereinstimmt.
|
|
if [[ $newPassphrase != $newPassphrase2 ]]
|
|
then
|
|
|
|
HELPER=$("$jamfHelper" -windowType utility -icon "$ErrorIcon" -title "Wrong Entry" -description "$FailedPwMessage" -button1 "OK" -defaultButton 1)
|
|
echo "Exit Code: Die Eingabe stimmte nicht überein"
|
|
|
|
newPassphrase=$(askPass 'Bitte gebe das aktuelle Windows-Passwort ein. Please enter the current Windows password.') || exit
|
|
newPassphrase2=$(askPass 'Bitte gebe das aktuelle Windows-Passwort erneut ein. Please enter the current Windows password again.') || exit
|
|
fi
|
|
|
|
## Erneute Prüfung. Ist die erneute Prüfung fehlerhaft, so wird das Tool beendet.
|
|
if [[ $newPassphrase != $newPassphrase2 ]]
|
|
then
|
|
|
|
HELPER=$("$jamfHelper" -windowType utility -icon "$ErrorIcon" -title "Renewed wrong entry" -description "$FailedPwMessageAgain" -button1 "OK" -defaultButton 1)
|
|
echo "Exit Code: Die Eingabe war erneut falsch."
|
|
|
|
exit 1
|
|
fi
|
|
|
|
## Wurde das Tool nicht beendet, so wird das Passwort geändert.
|
|
|
|
# security set-keychain-password -o $oldPassphrase -p $newPassphrase $keychain
|
|
if security set-keychain-password -o $oldPassphrase -p $newPassphrase $keychain
|
|
then
|
|
|
|
printf HELPER=$("$jamfHelper" -windowType utility -icon "$SuccessfulIcon" -title "Successful Change" -description "$SuccessfulChange" -button1 "OK" -defaultButton 1)
|
|
echo "Exit Code: Passwort wurde erfolgreich geändert."
|
|
|
|
else
|
|
|
|
printf HELPER=$("$jamfHelper" -windowType utility -icon "$ErrorIcon" -title "Error" -description "$FailedChange" -button1 "OK" -defaultButton 1)
|
|
echo "Exit Code: Passwort konnte nicht geändert werden. Ist das alte Passwort richtig?"
|
|
fi
|
|
|
|
fi
|
|
|
|
exit 0 |