Posted on 07-31-2018 03:07 PM
Can anyone shed some light on why my code below is not working? It's not very complicated... but I believe it's because the firmwarepasswd -check is returning a result with a carriage return, but despite using tr and sed to strip the return or new line, the if statement always returns false. any help would be appreciated!
result= /usr/sbin/firmwarepasswd -check
echo $result
if [[ $result = "Password Enabled: No" ]] ; then
/usr/local/bin/jamf policy -trigger setefi
sudo shutdown -r +1
else
echo "EFI already set"
fi
exit 0
Posted on 07-31-2018 03:53 PM
This won't help you today but maybe if Jamf implemented this:
Posted on 07-31-2018 06:02 PM
Try
result=$(/usr/sbin/firmwarepasswd -check)
You could also use awk to pull out the “No”
You should also have a double equal sign in your if statement.
Posted on 07-31-2018 09:18 PM
I think the missing = sign in the if/then statement might be the problem, and you should also surround $result in double quotes since the variable might contain spaces.
But I would suggest using bash's regex match operator for this. For example:
if [[ "$result" =~ "No" ]] ; then
The =~
basically means if what is on the right is contained in $result on the left, or if it has that string as part of it's pattern. Since the word "No" will show up in the result, or not if an EFI password is set, you can just check for that word and not the entire result line. Hope that helps.
Posted on 08-01-2018 12:37 PM
Hi @jhaff
Maybe this can help you out!
#!/bin/sh
# Check if Firmware password is configured and turn it on
/Library/Application Support/JAMF/bin/setregproptool -c
Result="$?"
if [[ "$Result" == "1" ]]; then
/Library/Application Support/JAMF/bin/setregproptool -m 'command' -p 'PUTYOUREFIPASSWORDHERE'
fi
Not sure if this is working on 2018 models, going to find out in 2 weeks. maybe someone else can confirm ?
Posted on 08-01-2018 12:52 PM
Many thanks! I think m.donovan's suggestion worked to get the proper output into the variable. Many thanks! mm2270 going to use the regular expression operator... ;)
I tried all sorts of formats and conditionals: double equal, quotes, no quotes, double brackets vs. single, regular expressions. I was driving myself nuts!
Thanks for the quick help.