forked from binaryage/totalfinder-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrakefile
More file actions
148 lines (117 loc) · 5.17 KB
/
Copy pathrakefile
File metadata and controls
148 lines (117 loc) · 5.17 KB
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
require 'rake'
ROOT_DIR = File.expand_path('.')
TMP_DIR = File.join(ROOT_DIR, 'tmp')
TMP_DIR_BUILD = File.join(TMP_DIR, 'build')
PARENT_DIR = File.expand_path('..')
RELEASE_DIR = File.join(PARENT_DIR, 'release')
BIN_DIR = File.join(PARENT_DIR, 'bin') #
OSAX_DIR = File.join(PARENT_DIR, 'totalfinder-osax')
KEXT_DIR = File.join(PARENT_DIR, 'totalfinder-kext')
BREAKPAD_DIR = File.join(PARENT_DIR, 'totalfinder-breakpad')
I18N_DIR = File.join(PARENT_DIR, 'totalfinder-i18n')
I18N_DIR_INSTALLER = File.join(I18N_DIR, 'installer')
################################################################################################
# dependencies
begin
require 'colored'
rescue LoadError
raise 'You must "gem install colored" to use terminal colors'
end
################################################################################################
# helpers
def die(msg, status=1)
puts "Error[#{status||$?}]: #{msg}".red
exit status||$?
end
def sys(cmd)
puts "> #{cmd}".yellow
system(cmd)
end
################################################################################################
# routines
def version()
$version = ENV["version"] or die("specify version")
end
def patch(path, replacers)
puts "#{'Patching'.red} #{path.blue}"
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
end
end
################################################################################################
# tasks
desc "builds installer+unistaller, point it to products=<path>"
task :build do
puts "#{'Checking environment ...'.magenta}"
version()
sys("rm -rf \"#{TMP_DIR}\"")
sys("mkdir -p #{TMP_DIR}") unless File.exists? TMP_DIR
sys("mkdir -p #{TMP_DIR_BUILD}") unless File.exists? TMP_DIR_BUILD
sys("mkdir -p #{RELEASE_DIR}") unless File.exists? RELEASE_DIR
$products = ENV["products"]
unless $products then
puts "no products path specified, using dummy products".red
sys("mkdir -p \"#{BIN_DIR}\"")
Dir.chdir BIN_DIR do
sys("mkdir -p TotalFinder.app/Contents/Resources")
end
$products = BIN_DIR
end
$products = File.expand_path($products)
$release = File.expand_path(ENV["release"] || RELEASE_DIR)
sys("cp \"#{ROOT_DIR}/installer.pkgproj\" \"#{ROOT_DIR}/installer-patched.pkgproj\"")
patch("#{ROOT_DIR}/installer-patched.pkgproj", [
['##VERSION##', $version],
['##INSTALLER_TITLE##', "TotalFinder #{$version}"],
['/Users/darwin/code/totalfinder/release', $release]
])
sys("cp \"#{ROOT_DIR}/TotalFinder Uninstaller.platypus\" \"#{ROOT_DIR}/uninstaller-patched.platypus\"")
patch("#{ROOT_DIR}/uninstaller-patched.platypus", [
["/Users/darwin/code/totalfinder/totalfinder-installer", ROOT_DIR]
])
uninstaller = File.join(ROOT_DIR, "TotalFinder Uninstaller.app")
uninstaller_profile = File.join(ROOT_DIR, "uninstaller-patched.platypus")
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_DIR}/TotalFinder.app/Contents/Resources\"")
die("build failed") unless $?==0
sys("lipo \"#{BIN_DIR}/TotalFinder.app/Contents/MacOS/applet\" -remove ppc7400 -output \"#{BIN_DIR}/TotalFinder.app/Contents/MacOS/applet\"")
release = File.join($release, "TotalFinder.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 \"#{ROOT_DIR}\" \"#{ROOT_DIR}/installer-patched.pkgproj\"")
die("build failed") unless $?==0
installer_icon = File.join(I18N_DIR_INSTALLER, "totalfinder.icns")
sys("./wincent-icon-util -icon \"#{installer_icon}\" -folder \"#{release}\"")
die("build failed") unless $?==0
releasedmg = File.join($release, "TotalFinder-#{$version}.dmg")
sys("rm -rf \"#{releasedmg}\"") if File.exist? releasedmg
die("build failed") unless $?==0
sys("wkpdf --source \"#{I18N_DIR_INSTALLER}/readme.html\" --output \"#{TMP_DIR}/Readme.pdf\"")
readme = File.join(TMP_DIR, "Readme.pdf")
sys("hdiutil create \"#{releasedmg}\" -volname \"TotalFinder\" -fs HFS+ -srcfolder \"#{release}\" -srcfolder \"#{uninstaller}\" -srcfolder \"#{readme}\"")
die("build failed") unless $?==0
Rake::Task["clean"].execute
end
desc "removes intermediate build files"
task :clean do
puts "Cleaning intermediate build files...".magenta
sys("rm -rf \"#{TMP_DIR}\"")
sys("rm -rf \"#{BIN_DIR}\"")
sys("rm \"#{ROOT_DIR}/uninstaller-patched.platypus\"") if File.exists?("#{ROOT_DIR}/uninstaller-patched.platypus")
sys("rm \"#{ROOT_DIR}/installer-patched.pkgproj\"") if File.exists?("#{ROOT_DIR}/installer-patched.pkgproj")
sys("rm -rf \"#{ROOT_DIR}/TotalFinder Uninstaller.app\"")
sys("rm -rf \"#{File.expand_path(ENV["release"] || RELEASE_DIR)}/TotalFinder.mpkg\"")
end
task :default => :build