/
rakefile
338 lines (271 loc) · 9.76 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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
ROOT_DIR = File.expand_path('.')
TMP_ROOT = File.join(ROOT_DIR, 'tmp')
BIN_DIR = File.join(ROOT_DIR, 'bin')
TMP_DIR = File.join(TMP_ROOT, "asepsis-installer")
RELEASE_DIR = File.join(ROOT_DIR, 'release')
PAYLOADS_DIR = File.join(ROOT_DIR, 'payloads')
INSTALLER_DIR = File.join(ROOT_DIR, 'installer')
BUILD = File.join(BIN_DIR, "Asepsis")
INSTALL_DIR = "/Library/Application Support"
PUBLISH_PREFIX_URL = "http://downloads.binaryage.com"
CHANGELOG_PREFIX_URL = "http://asepsis.binaryage.com"
################################################################################################
# dependencies
require 'rubygems'
begin
require 'colored'
rescue LoadError
raise 'You must "gem install colored" to use terminal colors'
end
def file_color(text); text.yellow; end
def dir_color(text); text.blue; end
def cmd_color(text); text.magenta; end
def red(text); text.red; end
def green(text); text.green; end
def blue(text); text.blue; end
############################################################################################
def die(msg, status=1)
puts "Error[#{status||$?}]: #{msg}".red
exit status||$?
end
def version()
$version = ENV["version"] or die("specify version")
end
def revision()
$revision = `git rev-parse HEAD`.strip
$short_revision = $revision[0...7]
end
def dirty_repo_warning()
is_clean = `git status`.match(/working directory clean/)
puts "Repository is not clean! You should commit all changes before releasing.".red unless is_clean
end
def patch(path, replacers)
puts "#{cmd_color('Patching')} #{file_color(path)}"
lines = []
File.open(path, "r") do |f|
f.each do |line|
replacers.each do |r|
line.gsub!(r[0], r[1])
end
lines << line
end
end
File.open(path, "w") do |f|
f << lines.join
end
end
def announce(cmd)
puts "> " + cmd.yellow
end
def sys(cmd)
announce(cmd)
system(cmd)
end
############################################################################################
def generate_payload_for_pkg(tmp, pkg)
tree = ""
exes = ""
tmp2 = File.join(tmp, File.basename(pkg))
sys("rm -rf \"#{tmp2}\"") if File.exist? tmp2
sys("mkdir -p \"#{tmp2}\"")
sys("cp \"#{pkg}\" \"#{tmp2}\"")
name = File.basename pkg
Dir.chdir(tmp2) do
sys("xar -xf \"#{name}\"")
if (File.exist? "Payload") then
sys("mv Payload Payload.gz")
sys("gunzip Payload.gz")
sys("cpio -id < Payload")
end
`rm \"#{name}\"`
tree = `tree --dirsfirst -apsugif`
exes = ""
Dir.glob("**/MacOS/*") do |exe|
exes += `file "#{exe}"` + "\n"
end
end
res = ""
res << "\n"
res << "#{name}\n"
res << "=======================================================================\n"
res << tree
res << "\n"
res << exes
res
end
def generate_payload(dmg, out)
puts "Generating payload for: ".green + dmg.blue
volume = "/Volumes/Asepsis"
tmp = File.join(TMP_DIR, "payloads", File.basename(dmg, ".dmg"))
sys("rm -rf \"#{tmp}\"") if File.exist? tmp
sys("mkdir -p \"#{tmp}\"")
puts dmg
cmd = "hdiutil attach \"#{dmg}\" | grep Apple_partition_scheme"
announce(cmd)
res = `#{cmd}`
puts res
disk = res.split("\n")[0].split("\t")[0]
die("bad disk") unless disk =~ /\/dev/
sys("cp -r #{volume}/* \"#{tmp}\"")
tree1 = ""
Dir.chdir(tmp) do
tree1 = `tree --dirsfirst -apsugif`
end
pkgs = []
Dir.glob(File.join(tmp, "**/*.pkg")) do |pkg|
pkgs << generate_payload_for_pkg(tmp, pkg)
end
outdir = File.dirname out
`mkdir -p #{outdir}` unless File.exist? outdir
File.open(out, "w") do |f|
f << "BASIC DMG LAYOUT\n"
f << "================\n"
f << tree1
pkgs.each do |pkg|
f << pkg
end
end
puts " -> ".green + out.blue
sys("hdiutil detach #{disk}")
end
def release_version_from_filename(n) # /Users/darwin/code/totalfinder/payloads/TotalFinder-0.7.1.txt
p = File.basename(n, ".txt").split("-")[1]
n = p.split(".")
while n.size < 3 do
n << "0"
end
x = (n[0]||"0").to_i
y = (n[1]||"0").to_i
z = (n[2]||"0").to_i
x*1000000 + y*1000 + z
end
############################################################################################
desc "build"
task :build do
sys('xcodebuild -workspace Asepsis.xcworkspace -scheme "build" -configuration Release')
die("build failed") unless $?==0
end
desc "build debug version (more verbose in Console.app)"
task :build_debug do
sys('xcodebuild -workspace Asepsis.xcworkspace -scheme "build" -configuration Debug')
die("build failed") unless $?==0
end
desc "install"
task :install do
sys("sudo cp -r \"#{BUILD}\" \"#{INSTALL_DIR}\"")
sys("\"#{INSTALL_DIR}/Asepsis/ctl/asepsisctl\" install")
end
desc "clean"
task :clean do
sys('xcodebuild clean -workspace Asepsis.xcworkspace -scheme "build"')
die("clean failed") unless $?==0
end
desc "test asepsis"
task :test do
sys("\"#{INSTALL_DIR}/Asepsis/asepsisTest\"")
end
desc "builds installer+unistaller, point it to products=<path>"
task :release do
puts "#{'Checking environment...'.magenta}"
version()
sys("mkdir -p #{RELEASE_DIR}") unless File.exists? RELEASE_DIR
# work on copy, because we do some dirty patching of sources
sys("rm -rf \"#{TMP_DIR}\"")
sys("mkdir -p \"#{TMP_DIR}\"")
sys("rsync -a --exclude=\"#{TMP_DIR}\" \"#{ROOT_DIR}/\" \"#{TMP_DIR}\"")
Dir.chdir(TMP_DIR) do
# do some patching prior compilation
patch("daemon/main.c", [
["asepsisd v##VERSION##", "asepsisd v#{$version}"]
])
patch("updater/AsepsisUpdater-Info.plist", [
['##VERSION##', $version]
])
sys("rake build")
patch('bin/Asepsis/ctl/asepsisctl', [
['##VERSION##', "#{$version}"],
['##INSTALLER_TITLE##', "Asepsis #{$version}"]
])
installer_profile = File.join("bin", "installer-patched.pkgproj")
sys("cp \"installer/installer.pkgproj\" \"#{installer_profile}\"")
patch(installer_profile, [
['##VERSION##', $version],
['##INSTALLER_TITLE##', "Asepsis #{$version}"],
["/Users/darwin/code/asepsis", "#{TMP_DIR}"],
["#{TMP_DIR}/release", "#{ROOT_DIR}/release"]
])
uninstaller_profile = File.join("bin", "uninstaller-patched.platypus")
sys("cp \"installer/uninstaller.platypus\" \"#{uninstaller_profile}\"")
patch(uninstaller_profile, [
["/Users/darwin/code/asepsis", "#{TMP_DIR}"]
])
uninstaller = File.join("bin", "Asepsis Uninstaller.app")
sys("rm -rf \"#{uninstaller}\"") if File.exist? uninstaller
die("build failed") unless $?==0
sys("platypus -P \"#{uninstaller_profile}\" \"#{uninstaller}\"")
die("build failed") unless $?==0
sys("cp -r \"#{uninstaller}\" \"bin/Asepsis\"")
die("build failed") unless $?==0
release = File.join(RELEASE_DIR, "Asepsis.mpkg") # THIS MUST BE THE SAME NAME AS OF THE APP! REQUIRED BY SPARKLE
sys("rm -rf \"#{release}\"") if File.exist? release
die("build failed") unless $?==0
sys("packagesbuild -v -F \"#{TMP_DIR}\" \"#{installer_profile}\"")
die("build failed") unless $?==0
installer_icon = File.join("installer", "installer.icns")
sys("installer/wincent-icon-util -icon \"#{installer_icon}\" -folder \"#{release}\"")
die("build failed") unless $?==0
releasedmg = File.join(RELEASE_DIR, "Asepsis-#{$version}.dmg")
sys("rm -rf \"#{releasedmg}\"") if File.exist? releasedmg
die("build failed") unless $?==0
readme_source = File.join("installer", "readme.pdf")
readme = File.join("bin", "Readme.pdf")
sys("cp \"#{readme_source}\" \"#{readme}\"")
sys("hdiutil create \"#{releasedmg}\" -volname \"Asepsis\" -format UDBZ -fs HFS+ -srcfolder \"#{release}\" -srcfolder \"#{uninstaller}\" -srcfolder \"#{readme}\"")
die("build failed") unless $?==0
size = File.size(releasedmg)
sig = `ruby "sparkle/sign_update.rb" "#{releasedmg}" keys/dsa_priv.pem`.strip
die("build failed") unless $?==0
snippet = "\
<item>
<title>Version #{$version}</title>
<sparkle:releaseNotesLink>#{CHANGELOG_PREFIX_URL}/changelog.html</sparkle:releaseNotesLink>
<pubDate>#{Time.new}</pubDate>
<enclosure url=\"#{PUBLISH_PREFIX_URL}/Asepsis-#{$version}.dmg\" sparkle:version=\"#{$version}\" length=\"#{size}\" type=\"application/octet-stream\" sparkle:dsaSignature=\"#{sig}\"/>
<sparkle:minimumSystemVersion>10.7.0</sparkle:minimumSystemVersion>
</item>"
puts snippet
puts
puts red("Don't forget: ")+green("git tag -a v#{$version} -m \"Release #{$version}\"")
puts blue("#{PUBLISH_PREFIX_URL}/Asepsis-#{$version}.dmg")
end
end
desc "build missing payloads"
task :payload do
Dir.chdir(RELEASE_DIR) do
Dir.glob("*.dmg").each do |file|
name = File.basename(file, ".dmg")
dest = File.join(PAYLOADS_DIR, name+".txt")
unless File.exist? dest then
generate_payload(file, dest)
end
end
end
end
desc "diff two most recent payloads"
task :paydiff do
res = `ls -1 "#{PAYLOADS_DIR}"/*.txt`
res = res.split("\n")
res = res.sort do |a, b|
va = release_version_from_filename a
vb = release_version_from_filename b
vb<=>va
end
a = res[1]
b = res[0]
`ksdiff "#{a}" "#{b}"`
end
desc "monitor fs usage for DS_Store operations"
task :fs_usage do
sys("sudo fs_usage | grep DS_Store")
end
task :default => :build