#!/bin/bash
#
#管理员密码
Passwd=$(/usr/bin/osascript -e 'display dialog "请输入管理员密码" with hidden answer default answer "" with icon note buttons {"Continue"} default button "Continue"
set result1 to result
set the text_data to text returned of the result
set the button_data to button returned of the result1
if button_data = "Cancel" then
return ""
end if
return text_data')
if [ -z "$Passwd" ];then
exit 0;
fi
if [ $Passwd != 'aaaaaaa' ]; then
$(/usr/bin/osascript -e 'display dialog "管理员密码不对!" buttons {"OK"} default button "OK"')
exit 0;
fi
passwords=("password1" "password2" "password3") # 替换为您想要尝试的密码列表
status=1 #初始值
for p in "${passwords[@]}"
do
output=`/usr/bin/expect <<EOF
spawn sudo firmwarepasswd -delete
expect "password:"
send "$p\r"
expect eof
EOF
`
#上面的EOF后面不能有空格
echo $output | grep -i "remove"
#结果中有 remove ,就是正确的固件锁密码
if [ $? = 0 ];then
status=0
break
fi
done
if [ $status = 0 ];then
(/usr/bin/osascript -e 'display dialog "已删除已知密码的固件锁,重启后生效!" buttons {"OK"} default button "OK"')
else
(/usr/bin/osascript -e 'display dialog "固件锁密码全不对,无法删除密码,也有可能没有固件锁!" buttons {"OK"} default button "OK"')
fi