forked from askeing/B2G-flash-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_comril.sh
executable file
·188 lines (161 loc) · 5.82 KB
/
install_comril.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/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/.
#==========================================================================
#
# IMPORTANT: internal tool
#
# Description:
# This script was written for uninstall/install com-ril.
#
# Author: Askeing [email protected]
# History:
# 2013/10/31 Askeing: v1.0 First release.
# 2014/02/05 Askeing: Added support of install com-ril.
#
#==========================================================================
####################
# Parameter Flags #
####################
VERY_SURE=false
RIL_CLEAN=false
RIL_INSTALL=false
RIL_DEBUG=false
####################
# Functions #
####################
## Show usage
function helper(){
echo -e "This script was written for uninstall/install com-ril."
echo -e "Usage: ./install_comril.sh [parameters]"
echo -e " -u|--uninstall\tuninstall the com-ril."
echo -e " -r|--ril\tinstall the com-ril from the file."
echo -e " -d|--ril-debug\tturn on ril debugging."
echo -e " -s <serial number>\tdirects command to device with the given serial number."
echo -e " -y\t\tAssume \"yes\" to all questions"
echo -e " -h|--help\tdisplay help."
exit 0
}
## adb with flags
function run_adb(){
# TODO: Bug 875534 - Unable to direct ADB forward command to inari devices due to colon (:) in serial ID
# If there is colon in serial number, this script will have some warning message.
adb $ADB_FLAGS $@
}
function check_ril_file(){
RIL_FILE=$1
if [ -f ${RIL_FILE} ]; then
if ! which mktemp > /dev/null; then
echo "Package \"mktemp\" not found!"
rm -rf ./ril_temp
mkdir ril_temp
cd ril_temp
RIL_DIR=`pwd`
cd ..
else
RIL_DIR=`mktemp -d -t ril_temp.XXXXXXXXXXXX`
fi
# Extract RIL file to temp folder
tar -C ${RIL_DIR} -xf ${RIL_FILE}
if [ $? != 0 ]; then echo "Extract com-ril file ${RIL_FILE} error." >&2; rm -rf ${RIL_DIR}; exit -1; fi
else
echo "The com-ril file ${RIL_FILE} do not exist." && exit -1
fi
}
function remount_system(){
echo "gaining root access"
run_adb root
run_adb wait-for-device
echo "remounting the system partition"
run_adb remount
run_adb shell mount -o remount,rw /system
echo "Waiting for adb to come back up"
run_adb wait-for-device
echo "Stopping b2g"
run_adb shell stop b2g
}
function reboot_system(){
echo "Rebooting"
run_adb shell sync
run_adb reboot
}
#########################
# Processing Parameters #
#########################
## distinguish platform
case `uname` in
"Linux")
## add getopt argument parsing
TEMP=`getopt -o ur::ds::yh --long uninstall,ril::,ril-debug,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
-u|--uninstall) RIL_CLEAN=true; shift;;
-r|--ril)
case "$2" in
"") helper; exit 0; shift 2;;
*) RIL_INSTALL=true; check_ril_file $2; shift 2;;
esac ;;
-d|--ril-debug) RIL_DEBUG=true; shift;;
-s)
case "$2" in
"") shift 2;;
*) ADB_FLAGS+="-s $2"; shift 2;;
esac ;;
-y) VERY_SURE=true; shift;;
-h|--help) helper; exit 0;;
--) shift;break;;
"") shift;break;;
*) helper; echo error occured; exit 1;;
esac
done
remount_system
if [ ${RIL_CLEAN} == true ]; then
if [ ${VERY_SURE} == false ]; then
read -p "Are you sure you want to UN-INSTALL com-ril? [y/N]" isClean
test "$isClean" != "y" && test "$isClean" != "Y" && reboot_system && echo "byebye." && exit 0
fi
echo "Uninstalling old RIL..."
run_adb shell rm -r /system/b2g/distribution/bundles/libqc_b2g_location
run_adb shell rm -r /system/b2g/distribution/bundles/libqc_b2g_ril
echo "Removing incompatible extensions"
run_adb shell rm -r /system/b2g/distribution/bundles/liblge_b2g_extension > /dev/null
echo "Done uninstalling RIL!"
fi
if [ ${RIL_INSTALL} == true ]; then
if [ ${VERY_SURE} == false ]; then
read -p "Are you sure you want to INSTALL com-ril? [y/N]" isInstall
test "$isInstall" != "y" && test "$isInstall" != "Y" && echo "byebye." && rm -rf ${RIL_DIR} && reboot_system && exit 0
fi
RIL_BUNDLES=${RIL_DIR}/vendor/*/proprietary/*/target/product/*/system/b2g/distribution/bundles/
if [ -d ${RIL_BUNDLES} ]; then
echo "Installing new RIL..."
run_adb push ${RIL_BUNDLES} /system/b2g/distribution/bundles/
echo "Removing incompatible extensions"
run_adb shell rm -r /system/b2g/distribution/bundles/liblge_b2g_extension > /dev/null
echo "Done installing RIL!"
rm -rf ${RIL_DIR}
else
echo "Can NOT found the Com RIL from ${RIL_DIR}." && rm -rf ${RIL_DIR} && reboot_system && exit -1
fi
fi
if [ ${RIL_DEBUG} == true ]; then
if [ ${VERY_SURE} == false ]; then
read -p "Are you sure you want to enable ril debugging? [y/N]" isDebug
test "$isDebug" != "y" && test "$isDebug" != "Y" && echo "byebye." && exit 0
fi
rm -f user.js user.js.org
run_adb pull /system/b2g/defaults/pref/user.js user.js.org
cat user.js.org | sed -e "s/ril.debugging.enabled\", false/ril.debugging.enabled\", true/" | sed -e "s/ril.debugging.enabled', false/ril.debugging.enabled', true/" > user.js
run_adb push user.js /system/b2g/defaults/pref
rm -f user.js user.js.org
fi
reboot_system
echo "Done!"