Skip to content

Instantly share code, notes, and snippets.

@lmandel
Created December 15, 2012 05:21
Show Gist options
  • Save lmandel/4291503 to your computer and use it in GitHub Desktop.
Save lmandel/4291503 to your computer and use it in GitHub Desktop.
Script to add/remove an UA override to B2G.
#!/bin/sh
# Script to add a UA override to B2G
# Based on Dave Hyland's script https://gist.github.com/2656232
# Options:
# remove - removes the override
# Usage:
# ./uaOverride.sh add example.com
# ./uaOverride.sh remove example.com
LOCAL_USER_JS=/tmp/user.js
PROFILE_DIR=/system/b2g/defaults/pref
REMOTE_USER_JS=${PROFILE_DIR}/user.js
rm -f ${LOCAL_USER_JS}
adb pull ${REMOTE_USER_JS} ${LOCAL_USER_JS}
if [ "${1}" == "remove" ]
then
echo "Removing UA override for ${2}"
ua=
else
echo "Adding fennec UA override for ${2}"
ua=fennec
fi
grep -v ${2} ${LOCAL_USER_JS} > ${LOCAL_USER_JS}.tmp
if [ "${ua}" != "" ]
then
echo 'pref("general.useragent.override.'${2}'", "\Mobile#(Android; Mobile");' >> ${LOCAL_USER_JS}.tmp
fi
set -x
adb shell mount -o rw,remount /system
adb push ${LOCAL_USER_JS}.tmp ${REMOTE_USER_JS}
adb shell mount -o ro,remount /system
#adb shell stop b2g && adb shell start b2g
adb reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment