Skip to content

Instantly share code, notes, and snippets.

@rtrouton
Created November 13, 2017 00:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtrouton/786f69d5d180b4ba2e9cf51a269ffa48 to your computer and use it in GitHub Desktop.
Save rtrouton/786f69d5d180b4ba2e9cf51a269ffa48 to your computer and use it in GitHub Desktop.
Script which is designed to check and report the status of encrypted Apple File System (APFS) drives.
#!/bin/bash
osvers_major=$(sw_vers -productVersion | awk -F. '{print $1}')
osvers_minor=$(sw_vers -productVersion | awk -F. '{print $2}')
ERROR=0
# Checks to see if the OS on the Mac is 10.x.x. If it is not, the
# following message is displayed without quotes:
#
# "Unknown Version Of macOS"
if [[ ${osvers_major} -ne 10 ]]; then
echo "Unknown Version Of macOS"
fi
# Checks to see if the OS on the Mac is 10.13 or higher.
# If it is not, the following message is displayed without quotes:
#
# "APFS Encryption Not Available For This Version Of macOS"
if [[ ${osvers_major} -eq 10 ]] && [[ ${osvers_minor} -lt 13 ]]; then
echo "APFS Encryption Not Available For This Version Of macOS"
fi
if [[ ${osvers_major} -eq 10 ]] && [[ ${osvers_minor} -ge 13 ]]; then
# If the OS on the Mac is 10.13 or higher, check to see if the
# boot drive is formatted with APFS or HFS+
boot_filesystem_check=$(/usr/sbin/diskutil info / | awk '/Type \(Bundle\)/ {print $3}')
# If the drive is formatted with APFS, the fdesetup tool will
# be available and is able to display the encryption status.
if [[ "$boot_filesystem_check" = "apfs" ]]; then
# If encrypted, the following message is
# displayed without quotes:
# "FileVault is On."
#
# If encrypting, the following message is
# displayed without quotes:
# "Encryption in progress:"
# How much has been encrypted of of the total
# amount of space is also displayed.
#
# If decrypting, the following message is
# displayed without quotes:
# "Decryption in progress:"
# How much has been decrypted of of the total
# amount of space is also displayed
#
# If not encrypted, the following message is
# displayed without quotes:
# "FileVault is Off."
ENCRYPTSTATUS=$(fdesetup status | xargs)
if [[ -z $(echo "$ENCRYPTSTATUS" | awk '/Encryption | Decryption/') ]]; then
ENCRYPTSTATUS=$(fdesetup status | head -1)
echo "$ENCRYPTSTATUS"
else
ENCRYPTSTATUS=$(fdesetup status | tail -1)
echo "$ENCRYPTSTATUS"
fi
else
echo "Unable to display encryption status for filesystems other than APFS."
fi
fi
exit $ERROR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment