-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
99 lines (83 loc) · 2.67 KB
/
Rakefile
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
require 'rexml/document'
require 'digest/sha1'
require 'rake/clean'
include REXML
include FileUtils::Verbose
CLEAN.include ['*.xpi']
EXTENSION_NAME = 'tabundle'
XPI_URL = 'http://www.relucks.org/tabundle/tabundle.xpi'
PROFILE_DIR = '/Users/youhei/Library/Application Support/Firefox/Profiles/e2gtwgy4.development'
MCCOY_DIR = '/Users/youhei/Library/Application\ Support/McCoy/Profiles/977xwbo1.default'
NSS_SIGN_DATA = '/Applications/Firefox3.app/Contents/MacOS/nss_sign_data'
desc "create the xpi file and use the version number in the file name"
task :xpi do
FileUtils.rm_rf Dir.glob('*.xpi')
file = xpi_filename
# sh "zip -qr -9 #{file} *"
# chrome chrome.manifest install.rdf modules update.rdf
sh "zip -qr -9 #{file} chrome chrome.manifest install.rdf modules update.rdf"
puts "create #{file}"
end
desc "install to local profile directory"
task :install => [:clean] do
install_path = "#{PROFILE_DIR}/extensions/#{extension_id}"
FileUtils.cp_r Dir.glob('*'), install_path
puts "copy #{install_path}"
end
desc "uninstall from local profile directory"
task :uninstall do
install_path = "#{PROFILE_DIR}/extensions/#{extension_id}"
FileUtils.rm_rf install_path
puts "remove #{install_path}"
end
desc "update update.rdf"
task :update_rdf => :xpi do
update_update_rdf
puts 'update update.rdf'
# sign_update_rdf
# puts 'sign update.rdf'
end
desc "deploy xpi and update.rdf"
task :deploy do
system "scp update.rdf tabundle.xpi relucks.org:www/default/tabundle/"
end
task :default => :xpi
def extension_id
open('install.rdf','r') do |file|
install_rdf_xmldoc = Document.new(file)
install_rdf_xmldoc.elements.each('RDF/Description/em:id') do |element|
return element.text
end
end
end
def version_number
open('install.rdf') do |f|
install_rdf_xmldoc = Document.new(f.read)
install_rdf_xmldoc.elements.each('RDF/Description/em:version') do |element|
return element.text
end
end
end
def xpi_filename
"#{EXTENSION_NAME}.xpi"
end
def update_update_rdf
source = IO.read 'update.rdf'
source.sub!(/(em:version)="[^"]+"/, %(\\1="#{version_number}"))
source.sub!(/(em:updateHash)="[^"]+"/, %(\\1="#{xpi_hash}"))
source.sub!(/(em:updateLink)="[^"]+"/, %(\\1="#{XPI_URL}"))
open('update.rdf', 'w') { |f| f.puts source }
end
def xpi_hash
'sha1:' + Digest::SHA1.hexdigest(open(xpi_filename).read)
end
def sign_update_rdf
source = IO.read 'update.rdf'
source.sub!(/(em:signature)="[^"]+"/, %(\\1="#{sign}"))
open('update.rdf', 'w') { |f| f.puts source }
end
# not working
def sign
# http://ido.nu/kuma/2008/02/22/signing-firefox3-extension-updaterdf-with-spock/
`cat update.rdf | #{NSS_SIGN_DATA} #{MCCOY_DIR}`.strip
end