forked from opengapps/opengapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_sourceapp.sh
executable file
·185 lines (170 loc) · 6.03 KB
/
add_sourceapp.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
#!/bin/sh
#This file is part of The Open GApps script of @mfonville.
#
# The Open GApps scripts are free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# These scripts are distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
command -v realpath >/dev/null 2>&1 || { echo "realpath is required but it's not installed, aborting." >&2; exit 1; }
TOP="$(realpath .)"
SOURCES="$TOP/sources"
SCRIPTS="$TOP/scripts"
CERTIFICATES="$SCRIPTS/certificates"
. "$SCRIPTS/inc.compatibility.sh"
. "$SCRIPTS/inc.sourceshelper.sh"
. "$SCRIPTS/inc.tools.sh"
BETA=""
# Check tools
checktools aapt file coreutils jarsigner keytool openssl unzip
installapk() {
architecture="$1"
eval "lowestapi=\$LOWESTAPI_$architecture"
if [ "$sdkversion" -lt "$lowestapi" ]; then
for i in $(seq "$(($sdkversion + 1))" "$lowestapi")
do
existing="$SOURCES/$architecture/$type/$package/$i/$dpis"
if [ -e "$existing" ];then
echo "ERROR: API level is lower than minimum level $lowestapi and lower than existing level $i of the same package"
return 1;
fi
done
fi
#targetlocation: sources/platform/type/package/sdkversion/dpi1-dpi2-dpi3/versioncode.apk
target="$SOURCES/$1/$type/$package/$sdkversion/$dpis"
install -d "$target"
if stat --printf='' "$target/"* 2>/dev/null; then
existing=$(find "$target/" -name "*.apk" | sort -r | cut -c1-) #we only look for lowercase .apk, since basename later assumes the same
echo "Existing version $existing"
existingversion=$(basename -s.apk "$existing")
if [ "$versioncode" -gt "$existingversion" ]; then
echo "Replaced with $target/$versioncode.apk"
rm "$existing"
install -D "$apk" "$target/$versioncode.apk"
else
echo "ERROR: APK is not newer than existing"
fi
else
install -D "$apk" "$target/$versioncode.apk"
echo "SUCCESS: Added $target/$versioncode.apk"
fi
if [ "$sdkversion" -le "$lowestapi" ]; then
for i in $(seq 1 "$((sdkversion - 1))")
do
remove="$SOURCES/$architecture/$type/$package/$i/$dpis"
if [ -e "$remove" ];then
rm -rf "$remove"
rmdir --ignore-fail-on-non-empty "$(dirname "$remove")"
echo "Cleaned up old API: $remove"
fi
done
fi
}
addapk() {
apk="$1"
getapkproperties "$apk"
echo "Importing $name"
echo "Package $package | VersionName $versionname | VersionCode $versioncode | API level $sdkversion"
if [ "$dpis" = "nodpi" ]; then
echo "Universal DPI package"
else
echo "Package supports DPIs: $(echo "$dpis" | tr '-' ' ')"
fi
getarchitectures "$apk"
echo "Native code for architecture(s): $architectures"
if ! verifyapk "$apk"; then
if [ -n "$notinzip" ]; then
echo "ERROR: The following files were mentioned in the signed manifest of $1 but are not present in the APK:
$notinzip"
else
echo "ERROR: $1 contains files or a certificate not signed by Google. APK not imported";
fi
echo "ERROR: Unsigned or incomplete APKs are not allowed. APK is not imported."
return 1
fi
echo "APK is complete, certificate is valid and signed by Google"
#We manually check for each of our set of supported architectures
#We assume NO universal packages for 32vs64 bit, so start with the 'highest' architectures first, if it matches one of those, we will NOT add it to a lower architecture
if echo "$architectures" | grep -q "arm64"; then #no space, all arm64 types are valid
installapk "arm64"
else
if echo "$architectures" | grep -q "armeabi"; then #no space, all armearbi types are valid
installapk "arm"
fi
fi
if echo "$architectures" | grep -q "x86_64 "; then
installapk "x86_64"
else
if echo "$architectures" | grep -q "x86 "; then
installapk "x86"
fi
fi
if echo "$architectures" | grep -q "all"; then #no space (single entry)
installapk "all"
fi
}
addlib() {
lib="$1"
libname="$(basename "$lib")"
architecture="$2"
case "$libname" in
libfrsdk.so) prefix="vendor/";;
*) prefix="";;
esac
case $architecture in
arm64|x86_64) libfolder="lib64";;
*) libfolder="lib";;
esac
path="$SOURCES/$architecture/$prefix$libfolder/API/$libname"
echo "For which API level should $path be installed? [#]"
IFS= read -r REPLY
case "$REPLY" in
(*[!0-9]*|'') echo "ERROR: $REPLY is not a valid API level";;
(*) install -D "$lib" "$SOURCES/$architecture/$prefix$libfolder/$REPLY/$libname"
echo "SUCCESS: Added $libname to $architecture/$prefix$libfolder/$REPLY/";;
esac
}
for argument in "$@"; do
if [ "$argument" = "beta" ]; then
BETA="beta"
continue
fi
file="$(readlink -f "$argument")"
if [ -f "$file" ]; then
filetype="$(file -b -0 "$file" | tr '[:upper:]' '[:lower:]')"
case "$filetype" in
*jar*|*zip*)
if aapt dump configurations "$file" >/dev/null; then
addapk "$file"
else
echo "ERROR: File $file not a valid APK!"
fi;;
*x86-64*) addlib "$file" "x86_64";;
*aarch64*) addlib "$file" "arm64";;
*32-bit*intel*) addlib "$file" "x86";;
*32-bit*arm*) addlib "$file" "arm";;
*) echo "ERROR: File $f has an unrecognized filetype!";;
esac
else
echo "ERROR: File $file does not exist!"
fi
done
#Full list of 'our' architecture classification compared to the Android NDK architectures:
#arm:
# armeabi - ARMv5TE based CPU with software floating point operations;
# armeabi-v7a - ARMv7 based devices with hardware FPU instructions
#arm64:
# arm64-v8a - ARMv8 AArch64 instruction set
#x86:
# x86 - IA-32 instruction set
#x86_64:
# x86_64 - Intel64 instruction set
#
#unsupported at the moment:
#mips - MIPS32 instruction set
#mips64 - MIPS64 instruction set