Last active
June 29, 2017 13:12
-
-
Save Freccia/8f7c1a41b9e17812ce81f83b0d55c773 to your computer and use it in GitHub Desktop.
This script enables filevault (deferred) and set ask for password immediately
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
######################## | |
# written by freccia # | |
# 22.06.2017 # | |
######################## | |
# Make sure only root can run our script | |
if [ "$(id -u)" != "0" ]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
# Get username and user Home # | |
# variante: | |
#echo "I am `who | cut -f 1 -d ' '`" | |
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'` | |
loggedInUserHome=`dscl . -read /Users/$loggedInUser | grep NFSHomeDirectory: | /usr/bin/awk '{print $2}'` | |
# Enable FileVault at next login # | |
shopt -s nocasematch | |
fileVaultStatus="`fdesetup status`" | |
numberOfSkips="0" | |
if [[ $fileVaultStatus == "FileVault is Off." ]] || [[ $fileVaultStatus == "FileVault is Off."* ]] ; then | |
echo $fileVaultStatus | |
echo "Filevault will be enabled at next login." | |
fdesetup enable -defer "$loggedInUserHome"/Desktop/fde_recovery.plist -forceatlogin $numberOfSkips –dontaskatlogout | |
else | |
echo $fileVaultStatus | |
fi | |
shopt -u nocasematch | |
# Set Ask for password immediately # | |
echo "Set Ask for password for user: "$loggedInUser"..." | |
requirePassword="1" # Integer (1 = true, 0 = false) | |
timeBeforeRequiringPassword="0" # Integer: Seconds | |
rm -rf "$loggedInUserHome"/Library/Preferences/com.apple.screensaver.plist | |
touch "$loggedInUserHome"/Library/Preferences/com.apple.screensaver.plist | |
if [[ -n $requirePassword ]]; then | |
/usr/libexec/PlistBuddy -c "Add :askForPassword integer $requirePassword" "$loggedInUserHome"/Library/Preferences/com.apple.screensaver.plist | |
fi | |
if [[ -n $timeBeforeRequiringPassword ]]; then | |
/usr/libexec/PlistBuddy -c "Add :askForPasswordDelay integer $timeBeforeRequiringPassword" "$loggedInUserHome"/Library/Preferences/com.apple.screensaver.plist | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment