-
Notifications
You must be signed in to change notification settings - Fork 72
/
app2luggage.rb
executable file
·145 lines (125 loc) · 4.73 KB
/
app2luggage.rb
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
#!/usr/bin/ruby
#
# Copyright 2010 Joe Block <jpb@ApesSeekingKnowledge.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# If this breaks your system, you get to keep the parts.
require 'ftools'
require 'rubygems'
require 'trollop'
def generateMakefile()
rawMakefile =<<"END_MAKEFILE"
#
# Package #{$installed_app}
#
# Makefile generated by app2luggage.rb
#
include #{$opts[:luggage_path]}
TITLE=#{$package_id}
REVERSE_DOMAIN=#{$opts[:reverse_domain]}
PAYLOAD=install-app2luggage-#{$app_name}
install-app2luggage-#{$app_name}: l_Applications #{$tarball_name}
@sudo /usr/bin/tar xjf #{$tarball_name} -C ${WORK_D}/Applications
@sudo chown -R root:admin "${WORK_D}/Applications/#{$installed_app}"
END_MAKEFILE
if File.exist?('./Makefile') then
puts "there's already a Makefile here. Bailing out."
exit 3
else
File.open("Makefile", "w") do |content|
content.write(rawMakefile)
end
end
end
def clean_name(name)
# get rid of toxic spaces
cleaned = name.gsub(' ','_')
return cleaned
end
def bundleApplication()
app_dir = File.dirname($opts[:application])
# spaces are toxic.
scratch_tarball = "#{$app_name}.#{$build_date}.tar"
if $opts[:debug] >= 10
puts "app_name: #{$app_name}"
puts "app_dir: #{app_dir}"
puts "tarball_name: #{$tarball_name}"
end
# check for a pre-existing tarball so we don't step on existing files
if File.exist?("#{$app_name}.tar.bz2")
print "#{$app_name}.tar.bz2 already exists. Skipping tarball creation."
return
end
if File.exist?("#{$app_name}.tar")
print "#{$app_name}.tar already exists. Skipping tarball creation."
return
end
# Use Apple's tar so we don't get bitten by resource forks. We only care
# because on 10.6 they started stashing compressed binaries there. Yay.
`/usr/bin/tar cf #{scratch_tarball} -C #{app_dir} "#{File.basename($opts[:application])}"`
`bzip2 -9v #{scratch_tarball}`
end
$opts = Trollop::options do
version "app2luggage 0.1 (c) 2010 Joe Block"
banner <<-EOS
Automagically wrap an Application into a tar.bz2 and spew out a Luggage-compatible Makefile.
Usage:
app2luggage [options] --application=AppName.app
where [options] are:
EOS
opt :application, "Application to package", :type => String
opt :create_tarball, "Create tarball for app", :default => true
opt :debug, "Set debug level", :default => 0
opt :directory_name, "Directory to put Makefile, tarball & dmg into", :type => String
opt :luggage_path, "path to luggage.make", :type => String, :default => "/usr/local/share/luggage/luggage.make"
opt :make_dmg, "Create dmg", :default => true
opt :package_id, "Package id (no spaces!)", :type => String
opt :package_version, "Package version (numeric!)", :type => :int
opt :reverse_domain, "Your domain in reverse format, eg com.example.corp", :type => String
end
# Sanity check args
Trollop::die :application, "#{opts[:application]} must exist" unless File.exist?($opts[:application]) if $opts[:application]
Trollop::die :application, "must specify an application to package" if $opts[:application] == nil
Trollop::die :luggage_path, "#{opts[:luggage_path]} doesn't exist" unless File.exist?($opts[:luggage_path]) if $opts[:luggage_path]
Trollop::die :package_id, "must specify a package id" if $opts[:package_id] == nil
Trollop::die :reverse_domain, "must specify a reversed domain" if $opts[:reverse_domain] == nil
$build_date = `date -u "+%Y-%m-%d"`.chomp
$app_name = clean_name(File.basename($opts[:application]))
$package_id = clean_name($opts[:package_id])
$installed_app = File.basename($opts[:application])
$tarball_name = "#{$app_name}.#{$build_date}.tar.bz2"
# debuggery.
if $opts[:debug] > 0
require 'pp'
puts "$opts: #{pp $opts}"
puts "$package_id: #{$package_id}"
puts "$build_date: #{$build_date}"
puts "$app_name: #{$app_name}"
puts "$installed_app: #{$installed_app}"
puts "$tarball_name: #{$tarball_name}"
end
if $opts[:directory_name] != nil then
target_dir = $opts[:directory_name]
else
target_dir = $package_id
end
if File.directory?(target_dir) then
puts "#{target_dir} already exists. Exiting so we don't step on your data"
exit 5
end
Dir.mkdir(target_dir)
Dir.chdir(target_dir)
bundleApplication() if $opts[:create_tarball]
generateMakefile()
`sudo make dmg` if $opts[:make_dmg]