-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-lin.rb
211 lines (205 loc) · 7.84 KB
/
merge-lin.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
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
module PackShoes
require 'fileutils'
def PackShoes.rewrite a, before, hsh
File.open(before) do |b|
b.each do |line|
a << line.gsub(/\#\{(\w+)\}/) {
if hsh[$1]
hsh[$1]
else
'#{'+$1+'}'
end
}
end
end
end
def PackShoes.merge_linux opts
# setup defaults if not in the opts
opts['publisher'] = 'shoerb' unless opts['publisher']
opts['website'] = 'http://shoesrb.com/' unless opts['website']
#opts['hkey_org'] = 'Hackety.org' unless opts['hkey_org']
opts['linux_where'] = '/usr/local' unless opts['linux_where']
toplevel = []
Dir.chdir(DIR) do
Dir.glob('*') {|f| toplevel << f}
end
exclude = %w(static CHANGELOG.txt cshoes.exe gmon.out README.txt
samples package VERSION.txt)
#exclude = []
#packdir = 'packdir'
packdir = "#{opts['app_name']}-app"
rm_rf packdir
mkdir_p(packdir) # where fpm will find it.
# copy shoes
(toplevel-exclude).each do |p|
cp_r File.join(DIR, p), packdir
end
# do the license stuff
licf = File.open("#{packdir}/COPYING.txt", 'w')
if opts['license'] && File.exist?(opts['license'])
IO.foreach(opts['license']) {|ln| licf.puts ln}
rm_rf "{packdir}/#{File.basename(opts['license'])}"
end
IO.foreach("#{DIR}/COPYING.txt") {|ln| licf.puts ln}
licf.close
# we do need some statics for console to work.
mkdir_p "#{packdir}/static"
Dir.glob("#{DIR}/static/icon*.png") {|p| cp p, "#{packdir}/static" }
if opts['app_png']
cp "#{opts['app_loc']}/#{opts['app_png']}", "#{packdir}/static/app-icon.png"
end
# remove chipmonk and ftsearch unless requested
rbmm = RUBY_VERSION[/\d.\d/].to_str
exts = opts['include_exts'] # returns []
if !exts || ! exts.include?('ftsearch')
puts "removing ftsearchrt.so"
rm "#{packdir}/lib/ruby/#{rbmm}.0/#{RUBY_PLATFORM}/ftsearchrt.so"
rm_rf "#{packdir}/lib/shoes/help.rb"
rm_rf "#{packdir}/lib/shoes/search.rb"
end
if !exts || ! exts.include?('chipmunk')
puts "removing chipmunk"
rm "#{packdir}/lib/ruby/#{rbmm}.0/#{RUBY_PLATFORM}/chipmunk.so"
rm "#{packdir}/lib/shoes/chipmunk.rb"
end
# get rid of some things in lib
rm_rf "#{packdir}/lib/exerb"
rm_rf "#{packdir}/lib/gtk-2.0" if File.exist? "#{packdir}/lib/gtk-2.0"
# remove unreachable code in packdir/lib/shoes/ like help, app-package ...
['cobbler', 'debugger', 'irb', 'pack', 'app_package', 'packshoes',
'remote_debugger', 'winject', 'envgem'].each {|f| rm "#{packdir}/lib/shoes/#{f}.rb" }
# copy app contents (file/dir at a time)
app_contents = Dir.glob("#{opts['app_loc']}/*")
app_contents.each do |p|
cp_r p, packdir
end
#create new lib/shoes.rb with rewrite
newf = File.open("#{packdir}/lib/shoes.rb", 'w')
rewrite newf, 'min-shoes.rb', {'APP_START' => opts['app_start'] }
newf.close
# create a new lib/shoes/log.rb with rewrite
logf = File.open("#{packdir}/lib/shoes/log.rb", 'w')
rewrite logf, 'min-log.rb', {'CONSOLE_HDR' => "#{opts['app_name']} Errors"}
logf.close
# copy/remove gems - tricksy - pay attention
# remove the Shoes built-in gems if not in the list
incl_gems = opts['include_gems']
rm_gems = []
Dir.glob("#{packdir}/lib/ruby/gems/#{rbmm}.0/specifications/*gemspec") do |p|
gem = File.basename(p, '.gemspec')
if incl_gems.include?(gem)
puts "Keeping Shoes gem: #{gem}"
incl_gems.delete(gem)
else
rm_gems << gem
end
end
sgpath = "#{packdir}/lib/ruby/gems/#{rbmm}.0"
# sqlite is a special case so delete it differently - trickery
if !incl_gems.include?('sqlite3')
spec = Dir.glob("#{sgpath}/specifications/default/sqlite3*.gemspec")
rm spec[0]
rm_gems << File.basename(spec[0],'.gemspec')
else
incl_gems.delete("sglite3")
end
rm_gems.each do |g|
puts "Deleting #{g}"
rm_rf "#{sgpath}/specifications/#{g}.gemspec"
rm_rf "#{sgpath}/extensions/#{RUBY_PLATFORM}/#{rbmm}.0/#{g}"
rm_rf "#{sgpath}/gems/#{g}"
end
# copy requested gems from user's Shoes GEMS_DIR
incl_gems.delete('sqlite3') if incl_gems.include?('sqlite3')
incl_gems.each do |name|
puts "Copy #{name}"
cp "#{GEMS_DIR}/specifications/#{name}.gemspec", "#{sgpath}/specifications"
# does the gem have binary?
built = "#{GEMS_DIR}/extensions/#{RUBY_PLATFORM}/#{rbmm}.0/#{name}/gem.build_complete"
if File.exist? built
mkdir_p "#{sgpath}/extensions/#{RUBY_PLATFORM}/#{rbmm}.0/#{name}"
cp "#{GEMS_DIR}/extensions/#{RUBY_PLATFORM}/#{rbmm}.0/#{name}/gem.build_complete",
"#{sgpath}/extensions/#{RUBY_PLATFORM}/#{rbmm}.0/#{name}"
end
cp_r "#{GEMS_DIR}/gems/#{name}", "#{sgpath}/gems"
end
# hide shoes-bin and shoes launch script names
puts "make_installer"
after_install = "#{opts['app_name']}_install.sh"
before_remove = "#{opts['app_name']}_remove.sh"
where = opts['linux_where']
Dir.chdir(packdir) do
mv 'shoes-bin', "#{opts['app_name']}-bin"
File.open("#{opts['app_name']}", 'w') do |f|
f << <<SCR
#!/bin/bash
REALPATH=`readlink -f $0`
APPPATH="${REALPATH%/*}"
if [ "$APPPATH" = "." ]; then
APPPATH=`pwd`
fi
LD_LIBRARY_PATH=$APPPATH $APPPATH/#{opts['app_name']}-bin
SCR
end
chmod 0755, "#{opts['app_name']}"
rm_rf 'shoes'
rm_rf 'debug'
rm_rf 'Shoes.desktop.tmpl'
rm_rf 'Shoes.remove.desktop'
rm_rf 'Shoes.remove.tmpl'
rm_rf 'shoes-install.sh'
rm_rf 'shoes-uninstall.sh'
rm_rf 'Shoes.desktop'
# still inside packdir. Make an fpm after-install script and some
# xdg .desktops
if opts['create_menu'] == true
File.open("#{opts['app_name']}.desktop",'w') do |f|
f << "[Desktop Entry]\n"
f << "Name=#{opts['app_name']}\n"
f << "Exec=#{where}/bin/#{opts['app_name']}\n"
f << "StartupNotify=true\n"
f << "Terminal=false\n"
f << "Type=Application\n"
f << "Comment=#{opts['purpose']}\n"
f << "Icon=#{where}/lib/#{packdir}/#{opts['app_png']}\n"
f << "Categories=#{opts['category']};\n"
end
end
File.open(after_install, 'w') do |f|
f << "#!/bin/bash\n"
f << "cd #{where}/bin\n"
f << "ln -s #{where}/lib/#{packdir}/#{opts['app_name']} .\n"
# do we have a menu?
if opts['create_menu'] == true
f << "cd #{where}/lib/#{packdir}\n"
f << "xdg-desktop-menu install --novendor #{opts['app_name']}.desktop\n"
end
end
chmod 0755, after_install
File.open(before_remove, 'w') do |f|
f << "#!/bin/bash\n"
f << "rm #{where}/bin/#{opts['app_name']}\n"
f << "cd #{where}/lib/#{packdir}\n"
if opts['create_menu'] == true
f << "xdg-desktop-menu uninstall #{opts['app_name']}.desktop\n"
end
end
chmod 0755, before_remove
end
# now we do fpm things - lets build a bash script for debugging
arch = `uname -m`.strip
File.open('fpm.sh','w') do |f|
f << <<SCR
#!/bin/bash
fpm --verbose -t deb -s dir -p #{packdir}.deb -f -n #{opts['app_name']} \\
--prefix '#{opts['linux_where']}/lib' --after-install #{packdir}/#{after_install} \\
-a #{arch} --url "#{opts['website']}" --license '#{opts['license_tag']}' --before-remove #{packdir}/#{before_remove} \\
--vendor '#{opts['publisher']}' --category #{opts['category']} \\
--description "#{opts['purpose']}" -m '#{opts['maintainer']}' #{packdir}
SCR
end
chmod 0755, 'fpm.sh'
#puts "Please examine fpm.sh and then ./ftm.sh to build the deb"
`./fpm.sh`
end
end