Skip to content

Instantly share code, notes, and snippets.

@rpappalax
Created June 19, 2014 17:04
Show Gist options
  • Save rpappalax/88e87a8ed2aaa46cce44 to your computer and use it in GitHub Desktop.
Save rpappalax/88e87a8ed2aaa46cce44 to your computer and use it in GitHub Desktop.
Jenkins managed scripts - Multi-Node B2G
#!/bin/bash -e
DEV_SERIAL="$1"
ADB="adb -s $DEV_SERIAL"
echo "DEV_SERIAL = $DEV_SERIAL"
# 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 -s $DEV_SERIAL 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
}
# push gaia 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
}
function show_free_space() {
echo -e "\n\033[1mShowing free space\033[0m"
$ADB shell df
}
adb_root_remount
clean
push_gaia
push_gecko
adb_reboot
sleep 60
#!/bin/sh -xe
cd $1
DEV_SERIAL=$2
ADB="adb -s $DEV_SERIAL"
echo "DEV_SERIAL = $DEV_SERIAL"
# a few files lack the "adb -s <serial>" option
# so we'll hack them with sed to inject it where needed
sed -i .bak -e "s/adb /$ADB /g" ./build/install-gaia.js
sed -i .bak -e "s/adb /$ADB /g" ./build/test/unit/install-gaia.test.js
sed -i .bak -e "s/\(adb\) /\($ADB \)/g" ./Makefile
sed -i .bak -e "s/adb /$ADB /g" ./test_media/reference-workload/makeReferenceWorkload.sh
sed -i .bak -e "s/adb /$ADB /g" ./test_media/reference-workload/generateImages.sh
sed -i .bak -e "s/adb /$ADB /g" ./test_media/reference-workload/generateMusicFiles.sh
sed -i .bak -e "s/adb /$ADB /g" ./test_media/reference-workload/generateVideos.sh
sed -i .bak -e "s/adb /$ADB /g" ./build/utils-node.js
sed -i .bak -e "s/adb /$ADB /g" ./build/utils-xpc.js
sed -i .bak -e "s/adb /$ADB /g" ./build/test/unit/mock_utils.js
sed -i .bak -e "s/adb shell /$ADB shell /g" ./tests/performance/meminfo.js
GAIA_OPTIMIZE=1 NOFTU=1 make reset-gaia ADB="$ADB"
$ADB wait-for-device
$ADB shell 'i=1;
retries=60
while [ "$(getprop sys.boot_completed)" == "1" ]; do
if (( i++ > ($retries - 1) )); then
exit 1;
fi;
sleep 1;
done'
sleep 30
#!/bin/bash -e
# This script is maintained at:
# https://gist.github.com/davehunt/7646076
DEV_SERIAL="$1"
ADB="adb -s $DEV_SERIAL"
echo "DEV_SERIAL = $DEV_SERIAL"
# 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
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