#!/bin/sh
#
# Id:      com.zjlotto.iLiberty.FlashBBTo040405
# Name:    Reflash baseband to version 04.04.05_G (BL3.9 only)
# Author:  George Zhu
# Version: 1.1
# Script:  http://iLiberty.zjlotto.com/Payloads2/01BL39BasebandTo040405.sh
# Pack:    http://iLiberty.zjlotto.com/Payloads2/BL39BasebandTo040405.zip
# URL:     http://george.zjlotto.com/
# Desc:    This payload reflashes baseband (from up to 04.04.05_G) to
#          version 04.04.05_G. This payload requires bootloader 3.9.
#

. $FUNCTIONS

echo "Reflash baseband to 04.04.05_G"
echo "------------------------------"

PACK=BL39BasebandTo040405

echo "Checking baseband versoin..."
GetBootloaderVersion bl_ver
if [ ${bl_ver} != "3.9_M3S2" ]; then
	echo "Wrong bootloader version: ${bl_ver}"
	echo "Abort in 10 seconds"
	sleep 10
	exit 1
else
	echo "Bootloader version: ${bl_ver}"
fi

echo "Extracting package..."
run unzip -o ${PL_DIR}/${PACK}.zip -d ${PL_DIR}
if [ $? -ne 0 ]; then
	echo "Failed, abort in 10 seconds"
	sleep 10
	exit 1
else
	echo "Completed"
fi
rm -f ${PL_DIR}/${PACK}.zip

echo "Erasing baseband (approx 40\")..."
cd ${PL_DIR}/${PACK}
chmod a+x *
run ./ieraser
if [ $? -ne 0 ]; then
	echo "Failed, abort in 10 seconds"
	sleep 10
	exit 1
else
	echo "Completed"
fi

echo "Flashing baseband (approx 2'00\")..."
run ./bbupdater -f ICE04.04.05_G.fls -e ICE04.04.05_G.eep
if [ $? -ne 0 ]; then
	echo "Failed, abort in 10 seconds"
	sleep 10
	exit 1
else
	echo "Completed"
fi
cd ${PL_DIR} && rm -rf ${PL_DIR}/${PACK}

echo "Done"

