make .sh for flashing FirefoxOS images (based on work of final boss Pancake (https://github.com/trufae)) [added recovery & optional userdata]
#!/bin/sh
D=peak
N=`date +%Y%m%d`
R="gp-$D-b2g-$N"
rm -rf "$R"
mkdir -p "$R/images"
cp -f out/target/product/$D/*.img "$R/images"
cat <<EOF > $R/README
This firmware has been compiled from b2g-git on $N for GeeksPhone Peak.
Contact: leandro <leandro@leandro.org>
EOF
cat <<EOF > $R/flash.sh
#!/bin/sh
[ -z "\${ADB}" ] && ADB=adb
[ -z "\${FASTBOOT}" ] && FASTBOOT=fastboot
adb get-state || {
echo adb tool not found, can\'t flash
exit -1
}
fastboot help || {
echo fastboot tool not found, can\'t flash
exit -1
}
run_adb() {
\$ADB \$ADB_FLAGS \$@
}
run_fastboot() {
if [ "\$1" = "devices" ]; then
\$FASTBOOT \$@
else
\$FASTBOOT \$FASTBOOT_FLAGS \$@
fi
return \$?
}
update_time() {
if [ \`uname\` = Darwin ]; then
OFFSET=\`date +%z\`
OFFSET=\${OFFSET:0:3}
TIMEZONE=\`date +%Z$OFFSET|tr +- -+\`
else
TIMEZONE=\`date +%Z%:::z|tr +- -+\`
fi
echo Attempting to set the time on the device
run_adb wait-for-device || exit 1
run_adb shell toolbox date \`date +%s\` &&
run_adb shell setprop persist.sys.timezone \$TIMEZONE
}
fastboot_flash_image() {
imgpath="./images/\$1.img"
out="\$(run_fastboot flash "\$1" "\$imgpath" 2>&1)"
rv="\$?"
echo "\$out"
if [[ "\$rv" != "0" ]]; then
# Print a nice error message if we understand what went wrong.
echo \$out | grep -q "too large" && {
echo ""
echo "Flashing $imgpath failed because the image was too large."
echo "Try re-flashing after running"
echo " \\\$ rm -rf \$(dirname "\$imgpath")/data && ./build.sh"
}
return \$rv
fi
}
flash_fastboot() {
run_adb reboot bootloader
run_fastboot devices >/dev/null 2>&1 &&
( [ "\$1" = "nounlock" ] || \
run_fastboot oem unlock > /dev/null 2>&1 || true )
if [ \$? -ne 0 ]; then
echo Couldn\'t setup fastboot
return -1
fi
case \$2 in
"system" | "boot" | "userdata")
fastboot_flash_image \$2 &&
run_fastboot reboot
;;
*)
run_fastboot erase cache &&
if [ -f images/boot.img ]; then
fastboot_flash_image boot
fi
if [ -f images/recovery.img ]; then
fastboot_flash_image recovery
fi
echo "Do you want to keep your user data ?"
select yn in "Yes" "No"; do
case \$yn in
Yes ) break;;
No ) run_fastboot erase userdata; fastboot_flash_image userdata; break;;
esac
done &&
fastboot_flash_image system &&
run_fastboot reboot &&
update_time
;;
esac
echo -ne \\a
}
flash_fastboot nounlock
EOF
tar cJvf ${R}.tar.xz $R
rm -rf $R
echo $R.tar.xz
exit 0