-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
executable file
·195 lines (179 loc) · 7.51 KB
/
script.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
#!/bin/bash
set -e
shopt -s extglob
APPS="com.valvesoftware.android.steam.community com.valvesoftware.android.steam.friendsui com.valvesoftware.steamlink"
Commit_message="Daily update"
VerifyRequirements()
{
echo "Verifying requirements"
command -v identify >/dev/null 2>&1 || { echo >&2 "identify missing. Aborting."; exit 1; }
command -v apkeep >/dev/null 2>&1 || { echo >&2 "apkeep missing. Aborting."; exit 1; }
command -v unzip >/dev/null 2>&1 || { echo >&2 "unzip missing. Aborting."; exit 1; }
command -v jadx >/dev/null 2>&1 || { echo >&2 "jadx missing. Aborting."; exit 1; }
command -v xpath >/dev/null 2>&1 || { echo >&2 "xpath missing. Aborting."; exit 1; }
command -v hbc-decompiler >/dev/null 2>&1 || { echo >&2 "hbc-decompiler missing. Aborting."; exit 1; }
command -v hbc-file-parser >/dev/null 2>&1 || { echo >&2 "hbc-file-parser missing. Aborting."; exit 1; }
command -v git >/dev/null 2>&1 || { echo >&2 "git missing. Aborting."; exit 1; }
}
MergeDPIPNG()
{
echo "Merging DPI PNG"
while IFS= read -r FILE
do
echo "Checking $FILE"
if [[ ! $(dirname "$FILE") == *-@(ldpi|mdpi|hdpi|xhdpi|xxhdpi|xxxhdpi) ]]; then
continue
fi
if [[ -f "$FILE" ]]; then
echo "Merging $FILE"
filename=$(basename "$FILE")
folder=$(basename $(dirname "$FILE"))
# test if folder exists in the parent folder if not create it
foldernodpi=$(dirname $(dirname "$FILE"))/${folder%-*}
[ -d $foldernodpi ] || ( mkdir -p "$foldernodpi" && touch "$foldernodpi/.folderisnotreal" )
# if the file already exists in that folder compare pixel count and keep the bigger one
if [[ -f "$foldernodpi/$filename" ]]; then
new=($(identify -format "%w %h" "$FILE"))
old=($(identify -format "%w %h" "$foldernodpi/$filename"))
if [[ $(expr ${new[0]} \* ${new[1]}) -gt $(expr ${old[0]} \* ${old[1]}) ]]; then
mv -f "$FILE" "$foldernodpi/$filename"
else
rm -f "$FILE"
fi
else
mv -f "$FILE" "$foldernodpi/$filename"
fi
fi
done < <(find $1 -type f -name "*.png")
}
DownloadAPK()
{
if [[ "$SOURCE" == "google" ]]; then
apkeep -a $1 -d google-play -e $GOOGLE_MAIL -t $AAS_TOKEN $1
elif [[ "$SOURCE" == "apk-pure" || "$SOURCE" == "" ]]; then
if [[ -n "$2" ]]; then
apkeep -a $1@$2 -d apk-pure $1
for FILE in $1/*@*apk
do
echo "Renaming $FILE"
extension="${FILE##*.}"
filename="${FILE%@*}"
mv $FILE $filename.$extension
done
Commit_message="$1 Version $2"
else
apkeep -a $1 -d apk-pure $1
fi
if [[ -f $1/$1.xapk ]]; then
unzip -o $1/$1.xapk -d $1
fi
elif [[ "$SOURCE" == "manual" ]]; then
cp $2 $1/$1.apk
else
echo "Unknown source"
exit 1
fi
}
ProcessApp()
{
echo "Processing $1"
prev_version_code=''
if [[ -f $1/resources/AndroidManifest.xml ]]; then
prev_version_code=$(xpath -q -e "string(/manifest/@android:versionCode)" $1/resources/AndroidManifest.xml)
prev_version_name=$(xpath -q -e "string(/manifest/@android:versionName)" $1/resources/AndroidManifest.xml)
fi
echo "Previous version: $prev_version_name - $prev_version_code"
rm -rf $1
mkdir -p $1
DownloadAPK $1 $2
set +e
jadx --deobf --show-bad-code -d $1 $1/$1.apk
set -e
find $1 -type f -exec md5sum {} >> $1/$1.apk.jadx.txt \;
sort -k 2 -o "$1/$1.apk.jadx.txt"{,}
for FILE in $1/*.apk
do
rm -f "/tmp/apkunzip.txt"
unzip -lv "$FILE" | head -n -2 | tail -n+4 | awk '{print $1,$(NF-1),$NF}' >> "/tmp/apkunzip.txt"
sort -k 3 -o "/tmp/apkunzip.txt"{,}
column -t "/tmp/apkunzip.txt" > "$FILE.txt"
done
# decompile bundle
if [[ -f $1/resources/assets/index.android.bundle ]]; then
echo "Decompiling $1/resources/assets/index.android.bundle"
hbc-decompiler $1/resources/assets/index.android.bundle $1/resources/assets/index.android.bundle.decompiled.js
hbc-file-parser $1/resources/assets/index.android.bundle > /tmp/index.android.bundle.header.txt
while read -r line; do
# each case to handle:
# => 1: '(keep what's inside here)'
# => 0: '(keep what's inside here)'
# => [Function #12891 (keep what's here if there's something) of
case $line in
"=> 0:"*)
string=${line#"=> 0: "}
echo ${string:1:-1} >> $1/resources/assets/index.android.bundle.0.txt
;;
"=> 1:"*)
string=${line#"=> 1: "}
echo ${string:1:-1} >> $1/resources/assets/index.android.bundle.1.txt
;;
"=> [Function"*)
echo ${line% of *} | sed -r 's/^=> \[Function #[0-9]+ ?//' >> $1/resources/assets/index.android.bundle.function.txt
;;
esac
done < /tmp/index.android.bundle.header.txt
sort -uo $1/resources/assets/index.android.bundle.0.txt $1/resources/assets/index.android.bundle.0.txt
sort -uo $1/resources/assets/index.android.bundle.1.txt $1/resources/assets/index.android.bundle.1.txt
sort -uo $1/resources/assets/index.android.bundle.function.txt $1/resources/assets/index.android.bundle.function.txt
fi
MergeDPIPNG $1
cur_version_code=''
cur_version_name=''
if [[ -f $1/resources/AndroidManifest.xml ]]; then
cur_version_code=$(xpath -q -e "string(/manifest/@android:versionCode)" $1/resources/AndroidManifest.xml)
cur_version_name=$(xpath -q -e "string(/manifest/@android:versionName)" $1/resources/AndroidManifest.xml)
fi
echo "Current version: $cur_version_name - $cur_version_code"
if [ -n "$APP_TO_PROCESS" ] || [[ -z "$prev_version_code" ]] || [ "$cur_version_code" -gt "$prev_version_code" ] || [ -n "$FORCE" -a "$FORCE" = "true" ]; then
git add $1
if [[ -n "$prev_version_code" ]]; then
Commit_message="$1 Version $cur_version_name - $prev_version_code -> $cur_version_code"
else
Commit_message="$1 Initial Version $cur_version_name - $cur_version_code"
fi
if ! git diff-index --cached --quiet HEAD; then
git commit -m "$Commit_message | $(git status --porcelain | wc -l) files | $(git status --porcelain|awk '{print "basename " $2}'| sh | sed '{:q;N;s/\n/, /g;t q}')"
fi
else
echo "Skipping staging changes: apk version didn't change"
fi
}
VerifyRequirements
if [[ "$SOURCE" == "manual" ]]; then
for APP in "./.storage/*";
do
# untested, future-proofing
if [[ -n "$APP_TO_PROCESS" && "$APP" != *"$APP_TO_PROCESS"* ]]; then
echo "Skipping $APP"
continue
fi
declare -a APKS=($(find $APP -name "*.apk" | sort -V))
for APK in ${APKS[@]};
do
if [[ -n "$APK_VERSION_TO_PROCESS" && "$APK" != *"$APK_VERSION_TO_PROCESS"* ]]; then
echo "Skipping $APK"
continue
fi
echo "Processing $APK"
ProcessApp $(basename $APP) $APK
done
done
elif [[ -n "$APP_TO_PROCESS" ]]; then
ProcessApp $APP_TO_PROCESS $APP_VERSION
else
for APP in $APPS;
do
ProcessApp $APP
done
fi
git push