i have 2 user profiles (fred, fredmoo) with filevault 2 enabled.
i have the following bash:
## Get the logged in user's name
userName=$(/usr/bin/stat -f%Su /dev/console)
## This first user check sees if the logged in account is already authorized with FileVault 2
userCheck=`fdesetup list | awk -v usrN="$userName" -F, 'index($0, usrN) {print $1}'`
if [ "${userCheck}" != "${userName}" ]; then
echo "This user is not a FileVault 2 enabled user."
exit 3
fi
----------------
if i do echo userName , i get -----> fred
if i do echo userCheck , i get -----> fred fredmoo
------------------
the conditional statement above works well if there's only 1 profile.
however since my mac has more than 1 user profiles, the statement will echo "This user is not a FileVault 2 enabled user." and exit.
userCheck has both profiles.
how do i modify the if statement to say if userName does NOT equal to the 1st userCheck or 2nd userCheck, then echo "This user is not a FileVault 2 enabled user." and exit?
i would appreciate any assistance. thanks so much!
Also, did you check the alternative awk suggestion? How did that work out?
-- @RudiC, fdsetup list produces a comma-separated record on every line, so when you put the whole command in a string, the first field of a record could be preceded by either a ^ or a newline...