diff options
| author | Einar Egilsson <einar@einaregilsson.com> | 2015-10-05 10:58:39 +0000 | 
|---|---|---|
| committer | Einar Egilsson <einar@einaregilsson.com> | 2015-10-05 10:58:39 +0000 | 
| commit | 60341ef37cf9046d0f99b5d3eb4dc1a2ad90acf9 (patch) | |
| tree | 8c887593b655549ba353ebf6b6aad7d0f5b29c1d | |
| parent | 36d4fe49ee7ff432fd0c270ddec5800d26c1ee5a (diff) | |
Build that works for Opera
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | .jpmignore | 1 | ||||
| -rwxr-xr-x | build.py | 40 | ||||
| -rw-r--r-- | manifest.json | 2 | ||||
| -rwxr-xr-x | nex-build.sh | 33 | ||||
| -rw-r--r-- | package.json | 2 | 
6 files changed, 59 insertions, 21 deletions
| @@ -5,4 +5,4 @@ build/*  ffox.sh  devprofile/*  debug.sh - +*.pem @@ -3,6 +3,7 @@  *.xpi  manifest.json  .git/* +*.pem  .gitignore  .jpmignore  *.py @@ -5,21 +5,15 @@ import os, os.path, re, zipfile, json  def get_files_to_zip():  	#Exclude git stuff, build scripts etc.  	exclude = [ -		r'(\\|/)\.git(\\|/)',  -		r'\.(py|sh)$',  -		r'\.DS_Store$',  -		r'\.gitignore$', -		r'\.jpmignore$', -		r'package\.json$', -		r'icon\.html', -		r'.*unittest.*', -		r'(\\|/)promo(\\|/)', -		r'(\\|/)build(\\|/)',  -		r'debug\.sh' +		r'\.(py|sh|pem)$', #file endings +		r'(\\|/)\.', #hidden files +		r'package\.json|icon\.html', #file names +		r'(\\|/)(promo|unittest|build)(\\|/)' #folders  	]  	zippable_files = []  	for root, folders, files in os.walk('.'): +		print root  		for f in files:  			file = os.path.join(root,f)  			if not any(re.search(p, file) for p in exclude): @@ -27,6 +21,8 @@ def get_files_to_zip():  	return zippable_files  def create_firefox_addon(): +	print '' +	print '**** Creating addon for Firefox ****'  	os.system('jpm xpi')  	import glob, shutil  	name = glob.glob('*.xpi')[0] @@ -38,15 +34,17 @@ def create_addon(files, browser):  	if not os.path.isdir(output_folder):  		os.mkdir(output_folder) -	extension = 'zip' -	if browser == 'firefox': -		extension = 'xpi' - -	output_file = os.path.join(output_folder, 'redirector-%s.%s' % (browser, extension)) +	output_file = os.path.join(output_folder, 'redirector-%s.zip' % browser)  	zf = zipfile.ZipFile(output_file, 'w', zipfile.ZIP_STORED) -	 +	cert = 'extension-certificate.pem' +  	print ''  	print '**** Creating addon for %s ****' % browser +	 +	if browser == 'opera' and not os.path.exists(cert): +		print 'Extension certificate does not exist, cannot create .nex file for Opera' +		return +  	for f in files:  		print 'Adding', f  		if f.endswith('manifest.json'): @@ -55,7 +53,7 @@ def create_addon(files, browser):  				del manifest['applications'] #Firefox specific, and causes warnings in other browsers...  			if browser == 'opera': -				manifest['options_ui']['page'] = 'data/redirector.html' #Opera opens options in new tab, where the popup would look really ugly +				manifest['options_ui']['page'] = 'redirector.html' #Opera opens options in new tab, where the popup would look really ugly  				manifest['options_ui']['chrome_style'] = False  			zf.writestr(f[2:], json.dumps(manifest, indent=2))  @@ -64,6 +62,12 @@ def create_addon(files, browser):  	zf.close() +	if browser == 'opera': +		#Create .nex +		os.system('./nex-build.sh %s %s %s' % (output_file, output_file.replace('.zip', '.nex'), cert)) + + +  if __name__ == '__main__':  	#Make sure we can run this from anywhere  	folder = os.path.dirname(os.path.realpath(__file__)) diff --git a/manifest.json b/manifest.json index fe2a049..d6f277f 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@    "manifest_version": 2,    "name": "Redirector",    "description": "Automatically redirect pages based on user-defined rules. E.g. always redirect an article url to its printer-friendly version.", -  "version": "3.0.4", +  "version": "3.0.5",    "icons": {   "16": "images/icon-active-16.png",                 "32": "images/icon-active-32.png", diff --git a/nex-build.sh b/nex-build.sh new file mode 100755 index 0000000..ade44cc --- /dev/null +++ b/nex-build.sh @@ -0,0 +1,33 @@ +#!/bin/bash -e +# +# Purpose: Convert a .zip file into a .nex file for Opera +# Adapted from  + +dir=$PWD +zip="$PWD/$1" +nex="$PWD/$2" +key=$3 +pub="tmp.pub" +sig="tmp.sig" +trap 'rm -f "$pub" "$sig" "$zip"' EXIT + +# signature +openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig" + +# public key +openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null + +byte_swap () { +  # Take "abcdefgh" and return it as "ghefcdab" +  echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}" +} + +crmagic_hex="4372 3234" # Cr24 +version_hex="0200 0000" # 2 +pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}'))) +sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}'))) +( +  echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p +  cat "$pub" "$sig" "$zip" +) > "$nex" +echo "Wrote $nex"
\ No newline at end of file diff --git a/package.json b/package.json index d54264b..669fa28 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@    "title": "Redirector",    "name": "redirector",    "id" : "redirector@einaregilsson.com", -  "version": "3.0.4", +  "version": "3.0.5",    "homepage" : "http://einaregilsson.com/redirector",    "icon" : "resource://redirector-at-einaregilsson-dot-com/images/icon-active-48.png",    "icon64" : "resource://redirector-at-einaregilsson-dot-com/images/icon-active-64.png", | 
