Skip to main content
Question

firmwarepasswd script not working...


Forum|alt.badge.img+5
  • New Contributor
  • 8 replies

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!

!/bin/bash

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

5 replies

bpavlov
Forum|alt.badge.img+18
  • Esteemed Contributor
  • 1206 replies
  • July 31, 2018

Forum|alt.badge.img+10
  • Valued Contributor
  • 193 replies
  • August 1, 2018

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.


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • August 1, 2018

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.


ThijsX
Forum|alt.badge.img+19
  • Employee
  • 369 replies
  • August 1, 2018

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 ?


Forum|alt.badge.img+5
  • Author
  • New Contributor
  • 8 replies
  • August 1, 2018

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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings