mirror of
https://github.com/srlabs/blue-merle.git
synced 2024-10-01 00:55:39 -04:00
131 lines
2.4 KiB
Bash
Executable File
131 lines
2.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
. /lib/blue-merle/functions.sh
|
|
. /lib/functions/gl_util.sh
|
|
|
|
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
|
|
mcu_send_message "Please wait >1min between two SIM swaps. ($sim_change_diff s)"
|
|
exit 1
|
|
fi
|
|
|
|
echo "$now" > /tmp/sim_change_start
|
|
|
|
mcu_send_message "Starting SIM swap."
|
|
sleep 3
|
|
|
|
i=5
|
|
until [[ $i -lt 0 ]]
|
|
do
|
|
mcu_send_message "Pull switch to abort ($i). "
|
|
i=$((i-1))
|
|
sleep 1
|
|
|
|
CHECK_ABORT
|
|
done
|
|
|
|
mcu_send_message "Continuing ..."
|
|
sleep 1
|
|
|
|
mcu_send_message "Disabling the MEfrom transmit- ting and recei- ving RF signals."
|
|
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
|
|
mcu_send_message "Disabling failed. Trying again."
|
|
CHECK_ABORT
|
|
else
|
|
answer=0
|
|
mcu_send_message "Disabled."
|
|
sleep 2
|
|
fi
|
|
done
|
|
|
|
mcu_send_message "Replace the SIM card. Then pull the switch."
|
|
|
|
while [[ `cat /tmp/sim_change_switch` = "on" ]]; do
|
|
mcu_send_message "Replace the SIM card. Then pull the switch."
|
|
sleep 3
|
|
done
|
|
|
|
mcu_send_message "Switch pulled. Continuing..."
|
|
sleep 1
|
|
sim_switch on
|
|
|
|
leak=0
|
|
|
|
until gl_modem AT AT+CFUN=0 | grep -q OK
|
|
do
|
|
mcu_send_message "CFUN=0 failed. Trying again."
|
|
sleep 1
|
|
done
|
|
|
|
until gl_modem AT AT+CFUN=4 | grep -q OK
|
|
do
|
|
leak=1
|
|
mcu_send_message "CFUN=4 failed. Trying again."
|
|
sleep 1
|
|
done
|
|
|
|
if [[ $leak -eq 1 ]]; then
|
|
mcu_send_message "WARNING: Reset took longer than expected."
|
|
sleep 3
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
new_imsi=$(READ_IMSI)
|
|
|
|
if [[ "$old_imsi" == "$new_imsi" ]]; then
|
|
mcu_send_message "WARNING: Old IMSI equals new IMSI."
|
|
sleep 3
|
|
fi
|
|
|
|
mcu_send_message "Setting random IMEI"
|
|
python3 /lib/blue-merle/imei_generate.py -r
|
|
|
|
new_imei=$(READ_IMEI)
|
|
|
|
if [[ "$old_imei" == "$new_imei" ]]; then
|
|
mcu_send_message "WARNING: Old IMEI equals new IMEI."
|
|
sleep 3
|
|
else
|
|
mkdir -p /tmp/modem.1-1.2
|
|
echo "$new_imei" > /tmp/modem.1-1.2/modem-imei
|
|
fi
|
|
|
|
|
|
mcu_send_message "The device will shutdown now."
|
|
sleep 3
|
|
mcu_send_message "You should change your location before booting again."
|
|
sleep 5
|
|
|
|
|
|
i=5
|
|
until [[ $i -eq 0 ]]
|
|
do
|
|
i=$((i-1))
|
|
mcu_send_message "Shutting down... ($i)"
|
|
sleep 1
|
|
done
|
|
|
|
/sbin/poweroff -d 5
|