-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsign.py
More file actions
executable file
·51 lines (39 loc) · 1.17 KB
/
sign.py
File metadata and controls
executable file
·51 lines (39 loc) · 1.17 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
48
49
#!/usr/bin/python2
import os
import sys
def show_usage():
print 'usage:\nsign.py [-k] apk\n-k\tkeep origin apk\nexample: sign.py comiz.pk' % ()
if __name__ == '__main__':
#print sys.argv
argc = len(sys.argv)
if argc != 2 and argc != 3:
show_usage()
exit()
keypath = '/mnt/DATA/proj/eclipse/Android/zzlab.keystore'
keyname = 'zzlab.keystore'
zipalign = '/opt/android-sdk/tools/zipalign'
keep = False
if sys.argv[1] == '-k':
keep = True
originapk = sys.argv[argc-1]
pair = os.path.splitext(originapk)
signedapk = pair[0]+'_signed'+pair[1]
if not os.path.exists(originapk):
print 'Error: No such file.'
exit()
if os.path.exists(signedapk):
os.remove(signedapk)
cmd = 'jarsigner -verbose -keystore "%s" -signedjar "%s" "%s" %s' % (keypath, 'tmpapk', originapk, keyname)
print cmd
if os.system(cmd) != 0:
print 'failed'
exit()
cmd = '%s -v 4 "%s" "%s"' % (zipalign, 'tmpapk', signedapk)
print cmd
if os.system(cmd) != 0:
print 'failed'
exit()
os.remove('tmpapk')
if not keep:
os.remove(originapk)
print 'ok'