-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignApk.sh
executable file
·91 lines (82 loc) · 2.59 KB
/
signApk.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
#!/bin/bash
# Need a meta.txt which including the sha1 of android sign certificate if you want
# to check the apk belong to which Android version(Android 7.0 ro 5.0)。
# It doen't influnce the apk sign funtion
Projects=(ProjectsName1 ProjectsName2 ProjectsName3)
# The Path of Android Source Code at native
Projects_Path=('/home/../../'
'/home/../../'
'/home/../../')
signNow(){
apkName=${2##*/}
dirPath=~/temp_`date +%Y-%m-%d`
if [ -d $dirPath ]; then
echo ""
else
mkdir $dirPath;
fi
# java -jar out/host/linux-x86/framework/signapk.jar -w build/target/product/security/$1.x509.pem build/target/product/security/$1.pk8 $2 $dirPath/$apkName
echo "在下列项目中选择一个进行签名:"
for item in ${Projects[*]}
do
echo " $item"
done
read project_choose
i=0;
for pro in ${Projects[*]}
do
if [ $pro == ${project_choose} ]; then
break
elif [ $pro != ${project_choose} ] && [ "$((++i))" = "${#Projects[@]}" ]; then
echo "请输入正确的项目名称!";
exit 1
fi
done
java -jar $Projects_Path/out/host/linux-x86/framework/signapk.jar -w $Projects_Pathbuild/target/product/security/$1.x509.pem $Projects_Pathbuild/target/product/security/$1.pk8 $2 $dirPath/$apkName
# java -jar `pwd`/keystore/$project_choose/signapk.jar -w `pwd`/keystore/$project_choose/security/$1.x509.pem `pwd`/keystore/$project_choose/security/$1.pk8 $2 $dirPath/$apkName
if [ $? == 0 ]; then
echo "签名成功,新签名的apk生成路径:$dirPath"
else
echo "签名失败"
fi
}
getSignType(){
orignSha=`keytool -printcert -file $1 |grep SHA1:`;
orignShaValue=${orignSha##*SHA1: };
# echo $orignShaValue
# echo `grep -o $orignShaValue ~/meta.txt`
echo "签名类型"
echo `cat ~/meta.txt |grep $orignShaValue`
if [ $? == 0 ]; then
# the key exist in meta.txt
return 0;
fi
}
while getopts :p:t:s: opt;
do
case $opt in
p )
rsaPath=$OPTARG;
getSignType $rsaPath;
# echo "RSAPath $OPTARG"
;;
t )
signType=$OPTARG
# echo "signType $OPTARG ";
;;
s )
apkPath=$OPTARG;
signNow $signType $apkPath
;;
\? )
echo "apk签名改为XX版本,需要到本地相应项目根目录下执行该脚本";
echo "相应项目需要事前成功编译过frameworks";
echo "invalid options :`basename $0` [-p RSA_File_Path] [-t SignType][-s apkPath]"
;;
:)
echo "apk签名改为XX版本,需要到本地相应项目根目录下执行该脚本";
echo "相应项目需要事前成功编译过frameworks";
echo "invalid options :`basename $0` [-p RSA_File_Path] [-t SignType][-s apkPath]"
;;
esac
done