fix tidycache command
[opengapps/opengapps.git] / upload_sources.sh
blobb3a813e7189be1bb6023f17af68946f85f451ad8
1 #!/bin/sh
2 #This file is part of The Open GApps script of @mfonville.
4 # The Open GApps scripts are free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # These scripts are distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
15 # set your own OPENGAPPSGIT_EMAIL and/or OPENGAPPSGIT_NAME environment variables if they differ from your regular git credentials
16 # set your own APKMIRROR_EMAIL and/or APKMIRROR_NAME environment variables if they differ from your git credentials
18 command -v realpath >/dev/null 2>&1 || { echo "realpath is required but it's not installed, aborting." >&2; exit 1; }
19 SCRIPT="$(readlink -f "$0")"
20 TOP="$(dirname "$SCRIPT")"
21 SOURCES="$TOP/sources"
22 SCRIPTS="$TOP/scripts"
23 # shellcheck source=scripts/inc.tools.sh
24 . "$SCRIPTS/inc.tools.sh"
25 # shellcheck source=scripts/inc.compatibility.sh
26 . "$SCRIPTS/inc.compatibility.sh"
27 # shellcheck source=scripts/inc.sourceshelper.sh
28 . "$SCRIPTS/inc.sourceshelper.sh"
30 # Check tools
31 checktools aapt coreutils git lzip
33 createcommit(){
34 getapkproperties "$1"
36 if [ -n "$leanback" ]; then
37 case "$package" in
38 *inputmethod*) ;; # if package is an inputmethod, it will have leanback as feature described, but we don't want it recognized as such
39 *) name="$name ($leanback)" # special leanback versions should be named like that in their commit
40 esac
43 if [ -n "$vrmode" ]; then
44 case "$package" in
45 com.google.android.apps.photos* |\
46 com.google.android.videos*)
47 name="$name ($vrmode)" ;; # if package is whitelisted, we can add vrmode to the commit
48 *) ;; # Otherwise ignore the vrmode flag
49 esac
52 if [ -n "$watch" ]; then
53 case "$package" in
54 com.android.vending* |\
55 com.google.android.apps.fitness* |\
56 com.google.android.apps.maps* |\
57 com.google.android.apps.messaging* |\
58 com.google.android.calculator* |\
59 com.google.android.deskclock* |\
60 com.google.android.gms* |\
61 com.google.android.googlequicksearchbox* |\
62 com.google.android.inputmethod.latin* |\
63 com.google.android.marvin.talkback* |\
64 com.google.android.music* |\
65 com.google.android.talk*)
66 name="$name ($watch)" ;; # special watch versions need a different packagename
67 *) ;; # Otherwise ignore the watch flag
68 esac
71 if [ -n "$stub" ]; then
72 name="$name ($stub)" # stub versions should be named like that in their commit
75 if [ -n "$beta" ]; then
76 name="$name ($beta)" # beta versions should be named like that in their commit
79 git rm -q -r --ignore-unmatch "$(dirname "$1")"
80 eval "lowestapi=\$LOWESTAPI_$2"
81 if [ "$sdkversion" -le "$lowestapi" ]; then
82 for s in $(seq 1 "$lowestapi"); do
83 paths="$(git ls-tree -r --name-only master "$type/$package/$s")"
84 if [ -n "$paths" ]; then
85 for d in $(printf "%s" "$dpis" | sed 's/-/ /g'); do
86 existing="$(echo "$paths" | grep -o "$type/$package/$s/*$d*/*" | cut -f -4 -d '/')"
87 if [ -n "$existing" ]; then
88 git rm -q -r --ignore-unmatch -- "$existing*" # We are already in "$SOURCES/$arch"
90 done
92 done
94 # We don't have to care about empty direcories with git (see http://stackoverflow.com/a/10075480/3315861 for more details.)
95 git add "$1"
96 git status -s -uno
97 echo "Commit changes as '$name $2-$sdkversion $versionname ($dpis)' by $username <$email>? [y/N]"
98 IFS= read -r REPLY
99 case "$REPLY" in
100 y*|Y*) git commit -q -m "$name $2-$sdkversion $versionname ($dpis)" --author="$username <$email>"
101 echo "Committed $1";;
102 *) git reset -q HEAD
103 echo "Did NOT commit $1";;
104 esac
107 setprecommithook(){
108 tee "$(git rev-parse --git-dir)/hooks/pre-commit" > /dev/null <<'EOFILE'
109 #!/bin/sh
111 for f in $(git diff --cached --name-only --diff-filter=ACMR | grep '.apk$'); do
112 size="$(wc -c "$f" | awk '{print $1}')" # slow, but available with same syntax on both linux and mac
113 if [ "$size" -gt "95000000" ]; then # Limit set at 95MB
114 echo "Compressing $f with lzip for GitHub"
115 lzip -9 -k -f "$f"
116 echo "$(basename "$f")" >> "$(dirname "$f")/.gitignore"
117 git rm -q --cached "$f"
118 git add "$f.lz"
119 git add "$(dirname "$f")/.gitignore"
121 done
122 EOFILE
123 chmod +x "$(git rev-parse --git-dir)/hooks/pre-commit"
126 newapks=""
127 modules=""
129 for arg in "$@"; do
130 modules="$modules $arg"
131 done
133 if [ -z "$modules" ]; then
134 modules="all arm arm64 x86 x86_64"
137 for arch in $modules; do
138 cd "$SOURCES/$arch" || continue
140 # We set this per architecture repo, because the settings might differ per submodule
141 if [ -n "$OPENGAPPSGIT_EMAIL" ]; then
142 email="$OPENGAPPSGIT_EMAIL"
143 else
144 email="$(git config user.email)"
146 if [ -n "$OPENGAPPSGIT_NAME" ]; then
147 username="$OPENGAPPSGIT_NAME"
148 else
149 username="$(git config user.name)"
152 setprecommithook # Make sure we are using lzip pre-commit hook
154 echo "Resetting $arch to HEAD before staging new commits..."
155 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
156 apks="$(git status -uall --porcelain | grep '.apk$' | grep -e "?? " | cut -c4-)" #get the new apks
157 for apk in $apks; do
158 createcommit "$apk" "$arch"
159 done
160 changes="$(git shortlog origin/master..HEAD)"
161 addnewapks="$(git diff --name-only --diff-filter=ACMR origin/master..HEAD | grep '.apk$' | cut -f 2 | sed "s#^#$SOURCES/$arch/#")"
162 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
163 if [ -n "$addnewapks" ]; then
164 newapks="$newapks
165 $addnewapks"
167 if [ -n "$addnewlzapks" ]; then
168 newapks="$newapks
169 $addnewlzapks"
172 if [ -n "$changes" ]; then
173 echo "$changes"
174 echo "Push these commits to the '$arch' repository? [y/N]"
175 IFS= read -r REPLY
176 case "$REPLY" in
177 y*|Y*) git push origin HEAD:master;;
178 *) echo "Did NOT push $arch";;
179 esac
181 done
182 if [ -n "$newapks" ]; then
183 if [ -n "$APKMIRROR_EMAIL" ]; then
184 email="$APKMIRROR_EMAIL"
185 else
186 email="$(git config user.email)"
188 if [ -n "$APKMIRROR_NAME" ]; then
189 name="$APKMIRROR_NAME"
190 else
191 name="$(git config user.name)"
193 echo "$newapks"
194 echo "Do you want to submit these APKs to APKmirror.com using $name (OpenGApps.org) <$email>? [y/N]"
195 IFS= read -r REPLY
196 case "$REPLY" in
197 y*|Y*)
198 for apk in $newapks; do
199 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
200 echo "Uploading $apk to APKmirror.com..."
201 filename="$(basename "$apk")"
202 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
203 else
204 echo "Skipping $apk, already exists on APKmirror.com..."
206 done
208 *) echo "Did NOT submit to APKmirror.com";;
209 esac
211 cd "$TOP"