Skip to content

Instantly share code, notes, and snippets.

@triti
Created November 14, 2011 15:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triti/1364265 to your computer and use it in GitHub Desktop.
Save triti/1364265 to your computer and use it in GitHub Desktop.
Bash: Absolute Manage FileVault 2 status script
#!/bin/bash
# Based on the FileVault 2 Encryption Check script by rtrouton
# https://github.com/rtrouton/rtrouton_scripts/blob/master/rtrouton_scripts/filevault_2_encryption_check/regular_script/filevault_2_encryption_check.sh
PATH='/usr/bin:/usr/sbin'
ST_NOTENABLED='Not Enabled'
ST_ENCRYPTING='Encrypting (%s%%)'
ST_ENCRYPTED='Encrypted'
ST_DECRYPTING='Decrypting (%s%%)'
ST_DECRYPTED='Decrypted'
ST_UNKNOWN='Unknown'
OS_VERSION="$(sw_vers | awk '/ProductVersion/ {print $2}')"
IFS=. read _ OS_MAJOR_POINT _ <<< "$OS_VERSION"
if ((OS_MAJOR_POINT >= 7)); then
CORE_STORAGE_STATUS="$(diskutil cs list)"
case "$CORE_STORAGE_STATUS" in
*'No CoreStorage'* ) printf "$ST_NOTENABLED\n" ;;
*'Logical Volume Family'* )
ENCRYPTION_CONTEXT="$(awk '/Encryption Context/ {print $3}' <<< "$CORE_STORAGE_STATUS")"
if [[ "$ENCRYPTION_CONTEXT" = Present ]]; then
ENCRYPTION_TYPE="$(awk '/Encryption Type/ {print $3}' <<< "$CORE_STORAGE_STATUS")"
case "$ENCRYPTION_TYPE" in
AES-XTS )
CONVERSION_STATUS="$(awk '/Conversion Status/ {print $3}' <<< "$CORE_STORAGE_STATUS")"
case "$CONVERSION_STATUS" in
*Complete* ) printf "$ST_ENCRYPTED\n" ;;
*Converting* )
CONVERSION_DIRECTION="$(awk '/Conversion Direction/ {print $3}' <<< "$CORE_STORAGE_STATUS")"
if [[ "$CONVERSION_DIRECTION" = *forward* ]]; then
SIZE_CONVERTED="$(awk '/Size \(Converted\)/ {print $3}' <<< "$CORE_STORAGE_STATUS")"
SIZE_TOTAL="$(awk '/Size \(Total\)/ {print $3}' <<< "$CORE_STORAGE_STATUS")"
CONVERTED_PERCENT="$(bc <<< "scale=1; $SIZE_CONVERTED * 100 / $SIZE_TOTAL")"
printf "$ST_ENCRYPTING\n" "$CONVERTED_PERCENT"
else
printf "$ST_UNKNOWN\n"
fi
;;
esac
;;
None )
CONVERSION_DIRECTION="$(awk '/Conversion Direction/ {print $3}' <<< "$CORE_STORAGE_STATUS")"
case "$CONVERSION_DIRECTION" in
*backward* )
SIZE_CONVERTED="$(awk '/Size \(Converted\)/ {print $3}' <<< "$CORE_STORAGE_STATUS")"
SIZE_TOTAL="$(awk '/Size \(Total\)/ {print $3}' <<< "$CORE_STORAGE_STATUS")"
CONVERTED_PERCENT="$(bc <<< "scale=1; $SIZE_CONVERTED * 100 / $SIZE_TOTAL")"
printf "$ST_DECRYPTING\n" "$CONVERTED_PERCENT"
;;
*-none-* ) printf "$ST_DECRYPTED\n" ;;
* ) printf "$ST_UNKNOWN\n" ;;
esac
;;
esac
fi
esac
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment