forked from opengapps/opengapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_sources.sh
executable file
·215 lines (196 loc) · 7.7 KB
/
upload_sources.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
#!/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.
#
# set your own OPENGAPPSGIT_EMAIL and/or OPENGAPPSGIT_NAME environment variables if they differ from your regular git credentials
# set your own APKMIRROR_EMAIL and/or APKMIRROR_NAME environment variables if they differ from your git credentials
command -v realpath >/dev/null 2>&1 || { echo "realpath is required but it's not installed, aborting." >&2; exit 1; }
SCRIPT="$(readlink -f "$0")"
TOP="$(dirname "$SCRIPT")"
CACHE="$TOP/cache"
SOURCES="$TOP/sources"
SCRIPTS="$TOP/scripts"
# shellcheck source=scripts/inc.tools.sh
. "$SCRIPTS/inc.tools.sh"
# shellcheck source=scripts/inc.compatibility.sh
. "$SCRIPTS/inc.compatibility.sh"
# shellcheck source=scripts/inc.sourceshelper.sh
. "$SCRIPTS/inc.sourceshelper.sh"
# Check tools
checktools aapt coreutils git lzip
createcommit(){
getapkproperties "$1"
if [ -n "$leanback" ]; then
case "$package" in
*inputmethod*) ;; # if package is an inputmethod, it will have leanback as feature described, but we don't want it recognized as such
*) name="$name ($leanback)" # special leanback versions should be named like that in their commit
esac
fi
if [ -n "$vrmode" ]; then
case "$package" in
com.google.android.apps.photos* |\
com.google.android.videos*)
name="$name ($vrmode)" ;; # if package is whitelisted, we can add vrmode to the commit
*) ;; # Otherwise ignore the vrmode flag
esac
fi
if [ -n "$watch" ]; then
case "$package" in
com.android.vending* |\
com.google.android.apps.enterprise.dmagent* |\
com.google.android.apps.fitness* |\
com.google.android.apps.maps* |\
com.google.android.apps.messaging* |\
com.google.android.apps.walletnfcrel* |\
com.google.android.calculator* |\
com.google.android.deskclock* |\
com.google.android.gms* |\
com.google.android.googlequicksearchbox* |\
com.google.android.inputmethod.latin* |\
com.google.android.keep* |\
com.google.android.marvin.talkback* |\
com.google.android.music* |\
com.google.android.talk*)
name="$name ($watch)" ;; # special watch versions need a different packagename
*) ;; # Otherwise ignore the watch flag
esac
fi
if [ -n "$stub" ]; then
name="$name ($stub)" # stub versions should be named like that in their commit
fi
if [ -n "$beta" ]; then
name="$name ($beta)" # beta versions should be named like that in their commit
fi
git rm -q -r --ignore-unmatch "$(dirname "$1")"
eval "lowestapi=\$LOWESTAPI_$2"
if [ "$sdkversion" -le "$lowestapi" ]; then
for s in $(seq 1 "$lowestapi"); do
paths="$(git ls-tree -r --name-only master "$type/$package/$s")"
if [ -n "$paths" ]; then
for d in $(printf "%s" "$dpis" | sed 's/-/ /g'); do
existing="$(echo "$paths" | grep -o "$type/$package/$s/*$d*/*" | cut -f -4 -d '/')"
if [ -n "$existing" ]; then
git rm -q -r --ignore-unmatch -- "$existing*" # We are already in "$SOURCES/$arch"
fi
done
fi
done
fi
# We don't have to care about empty direcories with git (see http://stackoverflow.com/a/10075480/3315861 for more details.)
git add "$1"
git status -s -uno
echo "Commit changes as '$name $2-$sdkversion $versionname ($dpis)' by $username <$email>? [y/N]"
IFS= read -r REPLY
case "$REPLY" in
y*|Y*) git commit -q -m "$name $2-$sdkversion $versionname ($dpis)" --author="$username <$email>"
echo "Committed $1";;
*) git reset -q HEAD
echo "Did NOT commit $1";;
esac
}
setprecommithook(){
tee "$(git rev-parse --git-dir)/hooks/pre-commit" > /dev/null <<'EOFILE'
#!/bin/sh
#
for f in $(git diff --cached --name-only --diff-filter=ACMR | grep '.apk$'); do
size="$(wc -c "$f" | awk '{print $1}')" # slow, but available with same syntax on both linux and mac
if [ "$size" -gt "95000000" ]; then # Limit set at 95MB
echo "Compressing $f with lzip for GitHub"
lzip -9 -k -f "$f"
echo "$(basename "$f")" >> "$(dirname "$f")/.gitignore"
git rm -q --cached "$f"
git add "$f.lz"
git add "$(dirname "$f")/.gitignore"
fi
done
EOFILE
chmod +x "$(git rev-parse --git-dir)/hooks/pre-commit"
}
newapks=""
modules=""
for arg in "$@"; do
modules="$modules $arg"
done
if [ -z "$modules" ]; then
modules="all arm arm64 x86 x86_64"
fi
for arch in $modules; do
cd "$SOURCES/$arch" || continue
# We set this per architecture repo, because the settings might differ per submodule
if [ -n "$OPENGAPPSGIT_EMAIL" ]; then
email="$OPENGAPPSGIT_EMAIL"
else
email="$(git config user.email)"
fi
if [ -n "$OPENGAPPSGIT_NAME" ]; then
username="$OPENGAPPSGIT_NAME"
else
username="$(git config user.name)"
fi
setprecommithook # Make sure we are using lzip pre-commit hook
echo "Resetting $arch to HEAD before staging new commits..."
git reset -q HEAD #make sure we are not including any other files are already tracked, output is silenced, not to confuse the user with the next output
apks="$(git status -uall --porcelain | grep '.apk$' | grep -e "?? " | cut -c4-)" #get the new apks
for apk in $apks; do
createcommit "$apk" "$arch"
done
changes="$(git shortlog origin/master..HEAD)"
addnewapks="$(git diff --name-only --diff-filter=ACMR origin/master..HEAD | grep '.apk$' | cut -f 2 | sed "s#^#$SOURCES/$arch/#")"
addnewlzapks="$(git diff --name-only --diff-filter=ACMR origin/master..HEAD | grep '.apk.lz$' | cut -f 2 | sed "s#^#$SOURCES/$arch/#" | sed 's#.lz$##')" # cut off the .lz, we want to upload the actual APK to APKMirror
if [ -n "$addnewapks" ]; then
newapks="$newapks
$addnewapks"
fi
if [ -n "$addnewlzapks" ]; then
newapks="$newapks
$addnewlzapks"
fi
if [ -n "$changes" ]; then
echo "$changes"
echo "Push these commits to the '$arch' repository? [y/N]"
IFS= read -r REPLY
case "$REPLY" in
y*|Y*) git push origin HEAD:master;;
*) echo "Did NOT push $arch";;
esac
fi
done
if [ -n "$newapks" ]; then
if [ -n "$APKMIRROR_EMAIL" ]; then
email="$APKMIRROR_EMAIL"
else
email="$(git config user.email)"
fi
if [ -n "$APKMIRROR_NAME" ]; then
name="$APKMIRROR_NAME"
else
name="$(git config user.name)"
fi
echo "$newapks"
echo "Do you want to submit these APKs to APKmirror.com using $name (OpenGApps.org) <$email>? [y/N]"
IFS= read -r REPLY
case "$REPLY" in
y*|Y*)
for apk in $newapks; do
if $(curl -s -S -A "OpenGAppsUploader" "https://www.apkmirror.com/wp-json/apkm/v1/apk_uploadable/$(md5sum "$apk" | cut -f 1 -d ' ')" | grep -q "uploadable"); then
echo "Uploading $apk to APKmirror.com..."
filename="$(basename "$apk")"
curl -s -S -A "OpenGAppsUploader" -X POST -F "fullname=$name (OpenGApps.org)" -F "email=$email" -F "changes=" -F "file=@$apk;filename=$filename" "https://www.apkmirror.com/wp-content/plugins/UploadManager/inc/upload.php" > /dev/null
else
echo "Skipping $apk, already exists on APKmirror.com..."
fi
done
;;
*) echo "Did NOT submit to APKmirror.com";;
esac
fi
cd "$TOP"