#!/bin/bash
#
soft="删除固件锁密码"
rand_num=$(echo $(($RANDOM % 10000 +1 )))
soft_file="/tmp/self_install_soft_${rand_num}.txt"
echo $soft > $soft_file
sudo -E jamf policy -id 607 # 607 是通用的 被包含文件的 策略的 id # -E 表示能把环境变量 soft 传过去
passwords=("11111111" "22222222" "33333333" "44444444" "55555555" "66666666") # 替换为您想要尝试的密码列表
status=1 #初始值
for p in "${passwords[@]}"
do
output=`/usr/bin/expect <<EOF
spawn sudo firmwarepasswd -delete
expect "password:"
send "$p\r"
expect eof
EOF
`
echo $output | grep -i "remove"
#结果中有 remove ,就是正确的固件锁密码
if [ $? = 0 ];then
status=0
(/usr/bin/osascript -e 'display dialog "固件锁密码已删除,重启后生效!" buttons {"OK"} default button "OK"')
break;
fi
done
if [ $status -ne 0 ];then
(/usr/bin/osascript -e 'display dialog "固件锁密码全不对,无法重置密码,也有可能没有固件锁!" buttons {"OK"} default button "OK"')
fi
#我们在策略范围内移除它吧
computer_id=$(sudo jamf recon -showComputerID | grep -oE "<computer_id>[0-9]+</computer_id>" | awk -F'[><]' '{print $3}')
serial=$(system_profiler SPHardwareDataType | grep "Serial Number" | awk '{print $4}')
policy_id="$4"
#qy 是 启用的意思,,,qy=0就是禁用
curl -X POST \
-d "qy=0" \
-d "policy_id=${policy_id}" \
-d "computer_id=${computer_id}" \
-d "serial=${serial}" # > /tmp/aa.txt
sudo jamf policy #从mac终端同步到 jamf