/
gapps.sh
executable file
·286 lines (239 loc) · 6.61 KB
/
gapps.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/bash
#
# Copyright (C) 2017 RTAndroid Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# OpenGApps installation script
# Author: Igor Kalkov
# https://github.com/RTAndroid/android_vendor_brcm_rpi3_scripts/blob/aosp-7.1/scripts/gapps.sh
#
TIMESTAMP="20170207"
VERSION="7.1"
VARIANT="pico"
SHOW_HELP=false
ADB_ADDRESS=""
ARCHITECTURE=""
PACKAGE_NAME=""
INIT_FILE="/etc/init.d/gapps"
# ------------------------------------------------
# Helping functions
# ------------------------------------------------
show_help()
{
cat << EOF
USAGE:
$0 [-h] -a ARCH -i IP
OPTIONS:
-a Device architecture: x86, x86_64, arm, arm64
-h Show help
-i IP address for ADB
EOF
}
check_agreement()
{
echo "AGREEMENT NOTE:"
echo "This script is supplied 'as is', please use it at your own risk."
echo "We take no responsibility for any hardware damage or data loss"
echo "caused by the installation of third-party applications. As these"
echo "applications are not part of the official RTAndroid distribution,"
echo "we provide no support for GApps-related issues."
echo ""
read -p "Please indicate your agreement by typing 'Y': " -n 1 -r response
echo ""
echo ""
if [[ ! $response =~ ^[yY]$ ]]; then
exit 1
fi
}
check_dependency()
{
which $1 > /dev/null
if (($? != 0)); then
echo "ERR: $1 not found. Please install: \"$2\""
exit 1
fi
}
reboot_device()
{
adb reboot bootloader > /dev/null &
sleep 10
}
is_booted()
{
[[ "$(adb shell getprop sys.boot_completed | tr -d '\r')" == 1 ]]
}
wait_for_adb()
{
while true; do
sleep 1
adb kill-server > /dev/null
sleep 1
adb connect $ADB_ADDRESS > /dev/null
sleep 1
if is_booted; then
break
fi
done
}
prepare_device()
{
echo " * Checking available devices..."
ping -c 1 $ADB_ADDRESS > /dev/null 2>&1
reachable="$?"
if [ "$reachable" -ne "0" ]; then
echo "ERR: no device with address $ADB_ADDRESS found"
echo ""
show_help
exit 1
fi
echo " * Enabling root access..."
wait_for_adb
adb root
echo " * Remounting system partition..."
wait_for_adb
adb remount
}
prepare_gapps()
{
mkdir -p gapps
if [ ! -d "gapps/pkg" ]; then
echo " * Downloading OpenGApps package..."
echo ""
wget https://github.com/opengapps/$ARCHITECTURE/releases/download/$TIMESTAMP/$PACKAGE_NAME -O gapps/$PACKAGE_NAME
fi
if [ ! -f "gapps/$PACKAGE_NAME" ]; then
echo "ERR: package download failed!"
fi
if [ ! -d "gapps/pkg" ]; then
echo " * Unzipping package..."
echo ""
unzip "gapps/$PACKAGE_NAME" -d "gapps/pkg"
echo ""
fi
if [ ! -d "gapps/pkg" ]; then
echo "ERR: unzipping the package failed!"
exit 1
fi
}
create_partition()
{
echo " * Extracting supplied packages..."
rm -rf gapps/tmp > /dev/null 2>&1
mkdir -p gapps/tmp
find . -name "*.tar.[g|l|x]z" -exec tar -xf {} -C gapps/tmp/ \;
echo " * Creating local system partition..."
rm -rf gapps/sys > /dev/null 2>&1
mkdir -p gapps/sys
for dir in gapps/tmp/*/
do
pkg=${dir%*/}
dpi=$(ls -1 $pkg | head -1)
echo " - including $pkg/$dpi"
rsync -aq $pkg/$dpi/ gapps/sys/
done
# no leftovers
rm -rf gapps/tmp
}
install_package()
{
echo " * Waiting for ADB..."
wait_for_adb
echo " * Pushing system files..."
adb push gapps/sys/. /system/.
echo " * Setting up the package installer..."
count=$(adb shell ls -al /system/priv-app/ | grep -o Installer | wc -l)
if [ "$count" == 1 ]; then
echo " - only one package installer found, leaving it as it is..."
elif [ "$count" == 2 ]; then
echo " - two package installers found, removing the stock one..."
adb shell "rm -rf /system/priv-app/PackageInstaller"
else
echo " - $count package installers found, something is very wrong!"
fi
}
write_script()
{
adb shell "echo '$1' >> $INIT_FILE"
}
create_script()
{
echo " * Waiting for ADB..."
wait_for_adb
echo " * Creating initialization script..."
echo " - creating a new init file"
adb shell rm -rf $INIT_FILE
adb shell touch $INIT_FILE
adb shell chmod 755 $INIT_FILE
echo " - adding required permissions"
write_script "#!/system/bin/sh"
write_script ""
write_script "### BEGIN INIT INFO"
write_script "# Exec: ready"
write_script "# Type: onetime"
write_script "### END INIT INFO"
write_script ""
write_script "pm grant com.google.android.gms android.permission.ACCESS_COARSE_LOCATION"
write_script "pm grant com.google.android.gms android.permission.ACCESS_FINE_LOCATION"
}
# ------------------------------------------------
# Script entry point
# ------------------------------------------------
# save the passed options
while getopts ":i:a:h" flag; do
case $flag in
"i") ADB_ADDRESS="$OPTARG" ;;
"a") ARCHITECTURE="$OPTARG" ;;
"h") SHOW_HELP=true ;;
*)
echo ""
echo "ERR: invalid option (-$flag $OPTARG)"
echo ""
show_help
exit 1
esac
done
if [[ "$ARCHITECTURE" != "x86" && "$ARCHITECTURE" != "x86_64" && "$ARCHITECTURE" != "arm" && "$ARCHITECTURE" != "arm64" ]]; then
echo "ERR: $ARCHITECTURE is not a valid architecture!";
show_help
exit 1
fi
if [[ "$SHOW_HELP" = true ]]; then
show_help
exit 1
fi
# create the full package name
PACKAGE_NAME="open_gapps-$ARCHITECTURE-$VERSION-$VARIANT-$TIMESTAMP.zip"
echo "GApps installation script"
echo "Used package: $PACKAGE_NAME"
echo "ADB version: $(adb version)"
echo "ADB IP address: $ADB_ADDRESS"
echo ""
check_dependency adb phablet-tools
check_dependency lzip lzip
check_agreement
prepare_device
prepare_gapps
create_partition
install_package
create_script
echo " * Waiting for ADB..."
wait_for_adb
echo ""
echo "All done. The device will be rebooted."
echo ""
echo "NOTE: Please be patient and give it time to initialize the installed packages."
echo "It can take up to 10 minutes for the system to get responsive after boot."
reboot_device
adb kill-server