Skip to content

Commit 60341ef

Browse files
author
Einar Egilsson
committed
Build that works for Opera
1 parent 36d4fe4 commit 60341ef

6 files changed

+59
-21
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ build/*
55
ffox.sh
66
devprofile/*
77
debug.sh
8-
8+
*.pem

.jpmignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.xpi
44
manifest.json
55
.git/*
6+
*.pem
67
.gitignore
78
.jpmignore
89
*.py

build.py

+22-18
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,24 @@
55
def get_files_to_zip():
66
#Exclude git stuff, build scripts etc.
77
exclude = [
8-
r'(\\|/)\.git(\\|/)',
9-
r'\.(py|sh)$',
10-
r'\.DS_Store$',
11-
r'\.gitignore$',
12-
r'\.jpmignore$',
13-
r'package\.json$',
14-
r'icon\.html',
15-
r'.*unittest.*',
16-
r'(\\|/)promo(\\|/)',
17-
r'(\\|/)build(\\|/)',
18-
r'debug\.sh'
8+
r'\.(py|sh|pem)$', #file endings
9+
r'(\\|/)\.', #hidden files
10+
r'package\.json|icon\.html', #file names
11+
r'(\\|/)(promo|unittest|build)(\\|/)' #folders
1912
]
2013

2114
zippable_files = []
2215
for root, folders, files in os.walk('.'):
16+
print root
2317
for f in files:
2418
file = os.path.join(root,f)
2519
if not any(re.search(p, file) for p in exclude):
2620
zippable_files.append(file)
2721
return zippable_files
2822

2923
def create_firefox_addon():
24+
print ''
25+
print '**** Creating addon for Firefox ****'
3026
os.system('jpm xpi')
3127
import glob, shutil
3228
name = glob.glob('*.xpi')[0]
@@ -38,15 +34,17 @@ def create_addon(files, browser):
3834
if not os.path.isdir(output_folder):
3935
os.mkdir(output_folder)
4036

41-
extension = 'zip'
42-
if browser == 'firefox':
43-
extension = 'xpi'
44-
45-
output_file = os.path.join(output_folder, 'redirector-%s.%s' % (browser, extension))
37+
output_file = os.path.join(output_folder, 'redirector-%s.zip' % browser)
4638
zf = zipfile.ZipFile(output_file, 'w', zipfile.ZIP_STORED)
47-
39+
cert = 'extension-certificate.pem'
40+
4841
print ''
4942
print '**** Creating addon for %s ****' % browser
43+
44+
if browser == 'opera' and not os.path.exists(cert):
45+
print 'Extension certificate does not exist, cannot create .nex file for Opera'
46+
return
47+
5048
for f in files:
5149
print 'Adding', f
5250
if f.endswith('manifest.json'):
@@ -55,7 +53,7 @@ def create_addon(files, browser):
5553
del manifest['applications'] #Firefox specific, and causes warnings in other browsers...
5654

5755
if browser == 'opera':
58-
manifest['options_ui']['page'] = 'data/redirector.html' #Opera opens options in new tab, where the popup would look really ugly
56+
manifest['options_ui']['page'] = 'redirector.html' #Opera opens options in new tab, where the popup would look really ugly
5957
manifest['options_ui']['chrome_style'] = False
6058

6159
zf.writestr(f[2:], json.dumps(manifest, indent=2))
@@ -64,6 +62,12 @@ def create_addon(files, browser):
6462

6563
zf.close()
6664

65+
if browser == 'opera':
66+
#Create .nex
67+
os.system('./nex-build.sh %s %s %s' % (output_file, output_file.replace('.zip', '.nex'), cert))
68+
69+
70+
6771
if __name__ == '__main__':
6872
#Make sure we can run this from anywhere
6973
folder = os.path.dirname(os.path.realpath(__file__))

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"manifest_version": 2,
44
"name": "Redirector",
55
"description": "Automatically redirect pages based on user-defined rules. E.g. always redirect an article url to its printer-friendly version.",
6-
"version": "3.0.4",
6+
"version": "3.0.5",
77

88
"icons": { "16": "images/icon-active-16.png",
99
"32": "images/icon-active-32.png",

nex-build.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash -e
2+
#
3+
# Purpose: Convert a .zip file into a .nex file for Opera
4+
# Adapted from
5+
6+
dir=$PWD
7+
zip="$PWD/$1"
8+
nex="$PWD/$2"
9+
key=$3
10+
pub="tmp.pub"
11+
sig="tmp.sig"
12+
trap 'rm -f "$pub" "$sig" "$zip"' EXIT
13+
14+
# signature
15+
openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig"
16+
17+
# public key
18+
openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null
19+
20+
byte_swap () {
21+
# Take "abcdefgh" and return it as "ghefcdab"
22+
echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}"
23+
}
24+
25+
crmagic_hex="4372 3234" # Cr24
26+
version_hex="0200 0000" # 2
27+
pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}')))
28+
sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}')))
29+
(
30+
echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p
31+
cat "$pub" "$sig" "$zip"
32+
) > "$nex"
33+
echo "Wrote $nex"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"title": "Redirector",
33
"name": "redirector",
44
5-
"version": "3.0.4",
5+
"version": "3.0.5",
66
"homepage" : "http://einaregilsson.com/redirector",
77
"icon" : "resource://redirector-at-einaregilsson-dot-com/images/icon-active-48.png",
88
"icon64" : "resource://redirector-at-einaregilsson-dot-com/images/icon-active-64.png",

0 commit comments

Comments
 (0)