#!/system/bin/sh

image_location=$1
image_location=${image_location%???}gz

failureFound=0
#BANK A -> 1-uboot / 3-boot / 5-system / 10-vendor / 7-recovery
#BANK B -> 2-uboot / 4-boot / 6-system / 11-vendor / 7-recovery

echo "Flashing recovery image on recovery bank starts:" >> /var/log/upgrade.txt

if [[ ! -f $image_location ]]; then
		echo "...: $image_location not found!" >> /var/log/upgrade.txt
		/system/bin/msg2plalog "recovery image not found! error: $?" platform; failureFound=1;
fi

gunzip -c $image_location | busybox dd  of=/dev/block/mmcblk0p7 bs=2M
if [ $? -ne 0 ]; then
	/system/bin/msg2plalog "dd recovery failed! error: $?" platform
	failureFound=1
	echo "rec image fail in command 1" >> /var/log/upgrade.txt
fi


resize2fs /dev/block/mmcblk0p7
if [ $? -ne 0 ]; then
	/system/bin/msg2plalog "resizefs recovery failed! error: $?" platform
	failureFound=1
	echo "rec image fail in command 2" >> /var/log/upgrade.txt
fi

if [ failureFound -eq 0 ]; then
        echo "Flashing recovery image on recovery bank passed!" >> /var/log/upgrade.txt
				/system/bin/msg2plalog "Flashing recovery image on recovery bank passed!" platform
else
      echo "Flashing recovery image on recovery bank failed!" >> /var/log/upgrade.txt
			/system/bin/msg2plalog "Flashing recovery image on recovery bank failed!" platform
			touch /var/log/upgrade_fail
fi
