blue-merle/files/usr/bin/blue-merle-switch

131 lines
2.4 KiB
Plaintext
Raw Normal View History

2022-10-10 10:30:43 -04:00
#!/bin/sh
. /lib/blue-merle/functions.sh
2023-10-17 03:20:36 -04:00
. /lib/functions/gl_util.sh
2022-10-10 10:30:43 -04:00
if [ ! -f "/tmp/sim_change_start" ]; then
echo 0 > /tmp/sim_change_start
fi
if [ ! -f "/tmp/sim_change_switch" ]; then
sim_switch off
fi
now=$(date +%s)
sim_change_last=`cat /tmp/sim_change_start`
sim_change_diff=$((now-sim_change_last))
if [[ "$sim_change_diff" -lt 60 ]]; then
2023-10-17 03:20:36 -04:00
mcu_send_message "Please wait >1min between two SIM swaps. ($sim_change_diff s)"
2022-10-10 10:30:43 -04:00
exit 1
fi
echo "$now" > /tmp/sim_change_start
2023-10-17 03:20:36 -04:00
mcu_send_message "Starting SIM swap."
2022-10-10 10:30:43 -04:00
sleep 3
i=5
until [[ $i -lt 0 ]]
do
2023-10-17 03:20:36 -04:00
mcu_send_message "Pull switch to abort ($i). "
2022-10-10 10:30:43 -04:00
i=$((i-1))
sleep 1
CHECK_ABORT
done
2023-10-17 03:20:36 -04:00
mcu_send_message "Continuing ..."
2022-10-10 10:30:43 -04:00
sleep 1
2023-10-17 03:20:36 -04:00
mcu_send_message "Disabling the MEfrom transmit- ting and recei- ving RF signals."
2022-10-10 10:30:43 -04:00
sleep 3
old_imei=$(READ_IMEI)
old_imsi=$(READ_IMSI)
CHECK_ABORT
answer=1
while [[ "$answer" -eq 1 ]]; do
gl_modem AT AT+CFUN=4 | grep -q OK
if [[ $? -eq 1 ]]; then
2023-10-17 03:20:36 -04:00
mcu_send_message "Disabling failed. Trying again."
2022-10-10 10:30:43 -04:00
CHECK_ABORT
else
answer=0
2023-10-17 03:20:36 -04:00
mcu_send_message "Disabled."
2022-10-10 10:30:43 -04:00
sleep 2
fi
done
2023-10-17 03:20:36 -04:00
mcu_send_message "Replace the SIM card. Then pull the switch."
2022-10-10 10:30:43 -04:00
while [[ `cat /tmp/sim_change_switch` = "on" ]]; do
2023-10-17 03:20:36 -04:00
mcu_send_message "Replace the SIM card. Then pull the switch."
2022-10-10 10:30:43 -04:00
sleep 3
done
2023-10-17 03:20:36 -04:00
mcu_send_message "Switch pulled. Continuing..."
2022-10-10 10:30:43 -04:00
sleep 1
sim_switch on
leak=0
until gl_modem AT AT+CFUN=0 | grep -q OK
do
2023-10-17 03:20:36 -04:00
mcu_send_message "CFUN=0 failed. Trying again."
2022-10-10 10:30:43 -04:00
sleep 1
done
until gl_modem AT AT+CFUN=4 | grep -q OK
do
leak=1
2023-10-17 03:20:36 -04:00
mcu_send_message "CFUN=4 failed. Trying again."
2022-10-10 10:30:43 -04:00
sleep 1
done
if [[ $leak -eq 1 ]]; then
2023-10-17 03:20:36 -04:00
mcu_send_message "WARNING: Reset took longer than expected."
2022-10-10 10:30:43 -04:00
sleep 3
fi
sleep 1
new_imsi=$(READ_IMSI)
if [[ "$old_imsi" == "$new_imsi" ]]; then
2023-10-17 03:20:36 -04:00
mcu_send_message "WARNING: Old IMSI equals new IMSI."
2022-10-10 10:30:43 -04:00
sleep 3
fi
2023-10-17 03:20:36 -04:00
mcu_send_message "Setting random IMEI"
2022-10-10 10:30:43 -04:00
python3 /lib/blue-merle/imei_generate.py -r
new_imei=$(READ_IMEI)
if [[ "$old_imei" == "$new_imei" ]]; then
2023-10-17 03:20:36 -04:00
mcu_send_message "WARNING: Old IMEI equals new IMEI."
2022-10-10 10:30:43 -04:00
sleep 3
else
mkdir -p /tmp/modem.1-1.2
echo "$new_imei" > /tmp/modem.1-1.2/modem-imei
fi
2023-10-17 03:20:36 -04:00
mcu_send_message "The device will shutdown now."
2022-10-10 10:30:43 -04:00
sleep 3
2023-10-17 03:20:36 -04:00
mcu_send_message "You should change your location before booting again."
2022-10-10 10:30:43 -04:00
sleep 5
i=5
until [[ $i -eq 0 ]]
do
i=$((i-1))
2023-10-17 03:20:36 -04:00
mcu_send_message "Shutting down... ($i)"
2022-10-10 10:30:43 -04:00
sleep 1
done
2023-10-17 03:20:36 -04:00
/sbin/poweroff -d 5