-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsignAndPut.sh
More file actions
executable file
·47 lines (37 loc) · 1.31 KB
/
signAndPut.sh
File metadata and controls
executable file
·47 lines (37 loc) · 1.31 KB
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
#!/bin/sh
apkFileName="origin.apk"
configFileName="idFile"
dateWithTime=`date "+%Y%m%d-%H%M%S"`
outputFolderName="output${dateWithTime}"
channelFilePath="assets/res/channel.json"
keystoreFile="fileName.jks"
keystoreFilePassword="password"
tempFilePath="../${outputFolderName}/tmp.apk"
mkdir "${outputFolderName}"
unzip "${apkFileName}" -d "tmp"
cd tmp
rm -rf META-INF
# read idFile line by line, need a empty line at end to read all line.
while IFS= read -r line
do
# split line string to array use splitor ','.
# first is fileName, second is channelID
IFS=',' read -r -a lineToken <<< "$line"
fileName=$(echo "${lineToken[0]}" | tr -d '[:space:][:blank:]')
channelID=$(echo "${lineToken[1]}" | tr -d '[:space:][:blank:]')
echo "fileName = \"${fileName}\", channelID = \"${channelID}\""
# set channel ID and delete redunt file.
sed -i -e -E "s/\"id\":.+/\"id\":${channelID},/g" "${channelFilePath}"
rm -rf "${channelFilePath}-e"
# compress files and align.
zip -qr "$tempFilePath" *
apkFileName="${fileName}.apk"
filePath="../${outputFolderName}/${apkFileName}"
zipalign -f 4 "$tempFilePath" "$filePath"
rm -rf "$tempFilePath"
# resign.
apksigner sign --ks "../${keystoreFile}" --ks-pass "pass:${keystoreFilePassword}" "$filePath"
apksigner verify -v "$filePath"
done < "../${configFileName}"
cd ../
rm -rf tmp