Skip to content

Instantly share code, notes, and snippets.

@retornam
Forked from davehunt/flash.sh
Last active August 29, 2015 14:02
Show Gist options
  • Save retornam/49c85a986185188d0819 to your computer and use it in GitHub Desktop.
Save retornam/49c85a986185188d0819 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
# This script is maintained at:
# https://gist.github.com/davehunt/7646076
# adb root, then remount and stop b2g
function adb_root_remount() {
echo -e "\n\033[1mRoot and remount\033[0m"
adb root
adb wait-for-device
adb remount
adb wait-for-device
adb shell mount -o remount,rw /system
adb wait-for-device
stop_b2g
}
# adb sync then reboot
function adb_reboot() {
echo -e "\n\033[1mRebooting\033[0m"
adb shell sync
adb shell reboot
adb wait-for-device
echo "Done"
}
# stop b2g
function stop_b2g() {
echo "Stopping b2g"
adb shell stop b2g
adb wait-for-device
ATTEMPTS=5
COUNTER=0
RESULT=0
while [ $COUNTER -lt $ATTEMPTS ] && [ $RESULT == 0 ]; do
adb shell lsof | grep b2g > /dev/null && RESULT=0 || RESULT=1
let COUNTER=COUNTER+1
done
if [ $COUNTER == $ATTEMPTS ] && [ $RESULT == 0 ]; then
echo "The b2g process still had files open after $ATTEMPTS attempts"
adb_reboot
adb_root_remount
fi
}
# remove files from the device
function remove() {
echo "Removing $1"
ATTEMPTS=5
COUNTER=0
RESULT=0
while [ $COUNTER -lt $ATTEMPTS ] && [ $RESULT == 0 ]; do
adb shell rm -r $1 | grep "No such file" > /dev/null && RESULT=1 || RESULT=0
let COUNTER=COUNTER+1
done
if [ $COUNTER == $ATTEMPTS ] && [ $RESULT == 0 ]; then
echo "Failed to remove $1 after $ATTEMPTS attempts"
fi
}
# clean cache, gaia (webapps) and profiles
function clean() {
show_free_space
echo -e "\n\033[1mCleaning\033[0m"
remove /cache/*
remove /data/b2g/*
remove /data/local/storage/persistent/*
remove /data/local/svoperapps
remove /data/local/webapps
remove /data/local/user.js
remove /data/local/permissions.sqlite*
remove /data/local/OfflineCache
remove /data/local/indexedDB
remove /data/local/debug_info_trigger
remove /system/b2g/webapps
remove /data/misc/wifi/*
# delete battery charging status
remove /system/bin/battery_charging
show_free_space
}
# push gaia into device
function push_gaia() {
echo -e "\n\033[1mPushing Gaia\033[0m"
GAIA_DIR=shallowflashgaia_temp
rm -rf $GAIA_DIR && mkdir $GAIA_DIR
unzip -q gaia.zip -d $GAIA_DIR
cat $GAIA_DIR/gaia/profile/user.js | sed -e "s/user_pref/pref/" > $GAIA_DIR/user.js
adb shell mkdir -p /system/b2g/defaults/pref
adb push $GAIA_DIR/gaia/profile/webapps /system/b2g/webapps
adb push $GAIA_DIR/user.js /system/b2g/defaults/pref
adb push $GAIA_DIR/gaia/profile/settings.json /system/b2g/defaults
show_free_space
}
# push gecko into device
function push_gecko() {
echo -e "\n\033[1mPushing Gecko\033[0m"
GECKO_DIR=shallowflashgecko_temp
rm -rf $GECKO_DIR && mkdir $GECKO_DIR
tar -xzf b2g.en-US.android-arm.tar.gz -C $GECKO_DIR
adb push $GECKO_DIR/b2g /system/b2g
# uninstall old ril
adb shell rm -r /system/b2g/distribution/bundles/libqc_b2g_location
adb shell rm -r /system/b2g/distribution/bundles/libqc_b2g_ril
# delete incompatible extensions
adb shell rm -r /system/b2g/distribution/bundles/liblge_b2g_extension
show_free_space
}
function show_free_space() {
echo -e "\n\033[1mShowing free space\033[0m"
adb shell df
}
function show_version() {
echo -e "\n\033[1mShowing version details\033[0m"
VIRTUALENV=mozversion_temp
virtualenv -q $VIRTUALENV
source $VIRTUALENV/bin/activate
pip install mozversion -q
set +e
mozversion --sources=sources.xml --device=${ANDROID_SERIAL}
set -e
deactivate
}
adb_reboot
adb_root_remount
clean
push_gaia
push_gecko
adb_reboot
sleep 60
show_version
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment