forked from askeing/B2G-flash-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enable_certified_apps_for_devtools.sh
executable file
·119 lines (99 loc) · 3.59 KB
/
enable_certified_apps_for_devtools.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
#==========================================================================
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#==========================================================================
# Description:
# This script was written for devtools with Certified Apps.
# Please enable "ADB and Devtools" of your device before using App Manager.
#
# Author: Askeing [email protected]
#
# Ref:
# https://developer.mozilla.org/en-US/Firefox_OS/Using_the_App_Manager
# https://developer.mozilla.org/en-US/Firefox_OS/Debugging/Developer_settings#Remote_debugging
#==========================================================================
function helper(){
echo -e "This script was written for devtools with Certified Apps.\nPlease enable \"ADB and Devtools\" of your device before using App Manager.\n"
echo -e "Usage: ./enable_certified_apps_for_devtools.sh [parameters]"
echo -e " -s <serial number>\tdirects command to device with the given serial number."
echo -e " -h|--help\tdisplay help."
exit 0
}
## adb with flags
function run_adb() {
adb $ADB_FLAGS $@
}
## adb root, then remount and stop b2g
function adb_root_remount() {
run_adb root &&
run_adb wait-for-device
run_adb remount &&
run_adb wait-for-device
run_adb shell mount -o remount,rw /system &&
run_adb wait-for-device
run_adb shell stop b2g &&
run_adb wait-for-device
}
#########################
# Processing Parameters #
#########################
## distinguish platform
case `uname` in
"Linux")
## add getopt argument parsing
TEMP=`getopt -o s::h --long help \
-n 'invalid option' -- "$@"`
if [ $? != 0 ]; then echo "Try '--help' for more information." >&2; exit 1; fi
eval set -- "$TEMP";;
"Darwin");;
esac
while true
do
case "$1" in
-s)
case "$2" in
"") shift 2;;
*) ADB_DEVICE=$2; ADB_FLAGS+="-s $2"; shift 2;;
esac ;;
-h|--help) helper; exit 0;;
--) shift;break;;
"") shift;break;;
*) helper; echo error occured; exit 1;;
esac
done
#########
# Start #
#########
set -e
if [[ 'unknown' == $(adb get-state) ]]; then
echo "### Unknown device."
exit -1
fi
adb_root_remount
## Create temp folder
TMP_DIR=$(mktemp -d -t enablecertifiedapps.XXXXXXXXXXXX)
PREFS_FILE="prefs.js"
DEFAULT_PATH=$(adb shell ls /data/b2g/mozilla/ | grep "default" | tr -d '\r\n')
PREFS_PATH="/data/b2g/mozilla/${DEFAULT_PATH}/${PREFS_FILE}"
## Pull prefs.js from the device
echo "### Pull ${PREFS_FILE} from the device..."
adb pull ${PREFS_PATH} ${TMP_DIR}
## Enable Certified Apps
echo "### Enable Devtools and Certified Apps..."
echo "### change ${PREFS_FILE} ..."
echo -e "user_pref(\"devtools.debugger.forbid-certified-apps\", false);" >> ${TMP_DIR}/${PREFS_FILE}
## it doesn't work, seems like will be changed by B2G base on DB of Settings
#echo -e "user_pref(\"devtools.debugger.remote-enabled\", true);" >> ${TMP_DIR}/${PREFS_FILE}
## Push prefs.js into the device
echo "### Push ${PREFS_FILE} into the device..."
adb shell stop b2g
adb push ${TMP_DIR}/${PREFS_FILE} ${PREFS_PATH}
sleep 5
adb shell start b2g
rm -rf ${TMP_DIR}
echo "### Please enable \"ADB and Devtools\" of your device before using App Manager."
echo "### Ref:"
echo "### https://developer.mozilla.org/en-US/Firefox_OS/Using_the_App_Manager"
echo "### https://developer.mozilla.org/en-US/Firefox_OS/Debugging/Developer_settings#Remote_debugging"