This repository has been archived by the owner on Nov 22, 2018. It is now read-only.
/
prepare_zip.py
executable file
·189 lines (142 loc) · 5.56 KB
/
prepare_zip.py
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
#!/usr/bin/env python
# This script is to take the signed.zip file from the signing lab and perform
# the necessary steps to prepare the update.rdf and fix the zip file
import os
import sys
import glob
import zipfile
import shutil
import subprocess
import hashlib
import pdb
import MoonlightReleases
import create_update_rdfs
#------------------------------------------------------------------------------
def executeCmd(command, stderr=open(os.devnull)):
ret = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=stderr)
output = ret.communicate()[0]
lines = output.split('\n')
return lines
#------------------------------------------------------------------------------
def clean():
# Delete any old generated files
files = glob.glob("novell*xpi")
#pdb.set_trace()
files.extend(glob.glob("update*rdf"))
files.extend(glob.glob("info*xhtml"))
files.extend(glob.glob("sha1sums-*"))
for f in files:
os.remove(f)
print "cleaned"
#------------------------------------------------------------------------------
def get_sha1sum(filename):
sha = hashlib.sha1()
try:
f = open(filename,'rb')
data = f.read()
sha.update(data)
return sha.hexdigest()
except:
pass
#------------------------------------------------------------------------------
def fail(msg):
print "Failed: %s" % msg
sys.exit(1)
#------------------------------------------------------------------------------
# The purpose of this is the recreate the zip with zigbert.rsa as
# the first file in the zip. Firefox 3 requires this.
# https://developer.mozilla.org/en/Signing_a_XPI#Prepare_XPI_file_for_signing
def callback(filelist,dirname,files):
for f in files:
filelist.append(os.path.join(dirname,f))
def getfiles(dir):
filelist = []
os.path.walk(dir,callback,filelist)
return filelist
# This seems to corrupt the signature somehow, also it's not needed.
def reorder_xpi(xpiname):
shutil.rmtree('tmp',ignore_errors=True)
xpi = zipfile.ZipFile(xpiname,mode='r')
xpi.extractall('tmp')
os.chdir('tmp')
newxpi = zipfile.ZipFile(xpiname,'w',compression=zipfile.ZIP_DEFLATED)
newxpi.write(os.path.join('META-INF','zigbert.rsa'))
newxpi.write(os.path.join('META-INF','zigbert.sf'))
newxpi.write(os.path.join('META-INF','manifest.mf'))
newxpi.write('chrome.manifest')
newxpi.write('install.rdf')
files = getfiles('plugins')
files.extend(getfiles('skin'))
for f in files:
if not os.path.isdir(f):
newxpi.write(f)
#cd ..
os.chdir('..')
#rm $1 # Delete the original xpi
os.remove(xpiname)
#mv tmp/$1 .
os.rename(os.path.join('tmp',xpiname),xpiname)
#rm -rf tmp
shutil.rmtree('tmp',ignore_errors=True)
#------------------------------------------------------------------------------
# Check to make sure there are two xpis in the zip file
def check_zip(z):
xpis_list = z.namelist()
if len(xpis_list) != 2:
fail("There are %d files in the zip file" % len(xpis_list))
#------------------------------------------------------------------------------
# Pass in the rdf file to be signed
def sign_update_rdfs(rdf):
mccoy_exe="/home/ajorg/mccoy/mccoy"
# Passing -xpi just generates and adds the sha1 hash to the file
# The hash is is already generated in create_update_rdfs.py
#cmd = "%s -command update -updateRDF $SCRIPTDIR/$1 -key moonlight" % mccoy_exe
curdir = os.path.dirname(os.path.realpath(__file__))
fullRdfPath = os.path.join(curdir,rdf) # mccoy cli requires full path to rdf file
cmd = "%s -command update -key moonlight -updateRDF %s" % (mccoy_exe,fullRdfPath)
executeCmd(cmd)
#------------------------------------------------------------------------------
# MAIN function
def main():
if len(sys.argv) < 2:
fail("Usage: %s <moonlight_signed.zip" % sys.argv[0])
zipfilename = sys.argv[1]
new_version = MoonlightReleases.new_version
if zipfilename == 'clean':
clean()
return
if not os.path.exists(zipfilename):
fail("Cannot find file %s" % zipfilename)
clean()
z = zipfile.ZipFile(zipfilename,'r')
xpi_list = z.namelist()
# This is not needed anymore and seems to corrupt the signature
for xpi in xpi_list:
# print "Reordering %s" % xpi
z.extract(xpi)
# reorder_xpi(xpi)
#NEW_VERSION=$PREVIEW
#./create_update_rdfs.py -p 2.0 -a i586,x86_64 -n $NEW_VERSION -o $OLD_VERSIONS
create_update_rdfs.create_rdfs(new_version,MoonlightReleases.old_versions,'3.0')
# create_update_rdfs.create_rdfs(new_version,MoonlightReleases.old_1_0_versions,'1.0')
for rdf in glob.glob("update*.rdf"):
print "Signing %s..." % rdf
sign_update_rdfs(rdf)
#mkdir $NEW_VERSION
os.mkdir(new_version)
#mv update*.rdf novell-moonlight*.xpi sha1sums-* info*xhtml $NEW_VERSION
filelist = glob.glob('update*rdf')
filelist.extend(glob.glob('novell-moonlight*xpi'))
filelist.extend(glob.glob('info*.xhtml'))
shafile = open(os.path.join(new_version,'sha1sums-%s' % new_version),'w')
for f in filelist:
if (f[-4:] in ['.xpi','.rdf']): # Only add .xpi and .rdf to the checksum file
shafile.write("%s %s\n" % (get_sha1sum(f),f)) # Two spaces are required between sum and filename
os.rename(f,os.path.join(new_version,f))
shafile.close()
print "Next step:"
print " - Review the contents of the %s directory" % new_version
print " - Run publish_preview.sh"
if __name__ == '__main__':
main()
# vim:ts=4:expandtab: