Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3106d758ec
Fetching contributors…

Cannot retrieve contributors at this time

338 lines (271 sloc) 9.998 kb
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
Jump to Line
Something went wrong with that request. Please try again.