Skip to content

Instantly share code, notes, and snippets.

@lithid
Created March 24, 2012 01:07
Show Gist options
  • Save lithid/2176948 to your computer and use it in GitHub Desktop.
Save lithid/2176948 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Installing Boot 2 Gecko Nexus S 4g
# Lithid
ROOTDIR=$(pwd)
ADB="sudo ${ROOTDIR}/tools/Linux/adb"
FASTBOOT="sudo ${ROOTDIR}/tools/Linux/fastboot"
SADB="sudo ${ADB} start-server"
KADB="sudo ${ADB} kill-server"
CLR="\e[0;91m"
OFF="\e[0m"
if [ `id -u` -ne 0 ]; then
echo -e "${CLR}Error${OFF}: Need to be root to install B2G, use sudo!"
exit 0
fi
function adb_reset () {
echo "Restarting adb services"
${KADB} &>> /dev/null
sleep 1
${SADB} &>> /dev/null
}
function waiting_4_device () {
echo -n "Waiting for device to attach to ${1} devices..."
PROCEED=0
COUNT=0
while [ ${PROCEED} -eq 0 ]; do
sleep 1
CHK=$(${2} devices |grep "${3}$" |wc -w)
if [ ${CHK} -eq 2 ]; then
PROCEED=1
fi
let COUNT=COUNT+1
if [ ${COUNT} -eq 300 ]; then
echo "No device in 5 mins, kill script, please restart..."
exit 1
fi
done
}
PROCEED=0
echo "Got root!"
echo -e "Press any key to continue, press ${CLR}x${OFF} to quit and not install B2G!"
echo -n "> "
read response
case ${response} in
X|x)
echo "Leaving... Nothing happened here...";;
*)
PROCEED=1;;
esac
if [ ${PROCEED} -eq 0 ]; then
exit 0
fi
adb_reset
waiting_4_device "adb" "${ADB}" "device" ; echo
${ADB} reboot bootloader
waiting_4_device "fastboot" "${FASTBOOT}" "fastboot" ; echo
read -sn 1 -p "Watch your screen, we are now flashing the Boot2Geck ROM.
If this fails it will be due to your bootloader/baseband version.
Press any key to continue..."
${FASTBOOT} flash boot boot.img
${FASTBOOT} flash system system.img
${FASTBOOT} flash userdata userdata.img
${FASTBOOT} reboot
waiting_4_device "adb" "${ADB}" "device" ; echo
CHK_DATA=$(${ADB} shell ls /data |wc -l)
echo "Waiting for /data to be mounted...."
while [ ${CHK_DATA} -eq 0 ]; do
CHK_DATA=$(${ADB} shell ls /data |wc -l)
sleep 1
done
${ADB} push data/ /data/
${ADB} reboot
echo "Yay, it installed!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment