rrba 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,5 @@
1
+ === 1.0.0 / 21.2.2011
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
data/LICENSE ADDED
@@ -0,0 +1,339 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
@@ -0,0 +1,15 @@
1
+ History.txt
2
+ LICENSE
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ install.rb
7
+ lib/rrba.rb
8
+ lib/rrba/error.rb
9
+ lib/rrba/server.rb
10
+ lib/rrba/user.rb
11
+ test/mock.rb
12
+ test/stub/odba.rb
13
+ test/suite.rb
14
+ test/test_server.rb
15
+ test/test_user.rb
@@ -0,0 +1,28 @@
1
+ = rrba
2
+
3
+ * http://scm.ywesee.com/?p=rrba/.git;a=summary
4
+ * http://rrba.rubforge.org
5
+
6
+ == DESCRIPTION:
7
+
8
+ Ruby Role-Based Authentication
9
+
10
+ == INSTALL:
11
+
12
+ * sudo gem install rrba
13
+
14
+ or
15
+
16
+ * ruby install.rb config
17
+ * ruby install.rb setup
18
+ * sudo ruby install.rb install
19
+
20
+ == DEVELOPERS:
21
+
22
+ * Zeno R.R. Davatz
23
+ * Masaomi Hatakeyama
24
+ * Hannes Wyss (upto Version 1.0)
25
+
26
+ == LICENSE:
27
+
28
+ * GPLv2.0
@@ -0,0 +1,37 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :git
7
+
8
+ # Hoe.plugin :compiler
9
+ # Hoe.plugin :compiler
10
+ # Hoe.plugin :cucumberfeatures
11
+ # Hoe.plugin :gem_prelude_sucks
12
+ # Hoe.plugin :gem_prelude_sucks
13
+ # Hoe.plugin :git
14
+ # Hoe.plugin :inline
15
+ # Hoe.plugin :inline
16
+ # Hoe.plugin :inline
17
+ # Hoe.plugin :manifest
18
+ # Hoe.plugin :newgem
19
+ # Hoe.plugin :racc
20
+ # Hoe.plugin :racc
21
+ # Hoe.plugin :rubyforge
22
+ # Hoe.plugin :rubyforge
23
+ # Hoe.plugin :rubyforge
24
+ # Hoe.plugin :website
25
+ # Hoe.plugin :yard
26
+
27
+ Hoe.spec 'rrba' do
28
+ # HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
29
+ # you'll never have to touch them again!
30
+ # (delete this comment too, of course)
31
+
32
+ developer('Masaomi Hatakeyama, Zeno R.R. Davatz', 'mhatakeyama@ywesee.com, zdavatz@ywesee.com')
33
+
34
+ # self.rubyforge_name = 'rrbax' # if different than 'rrba'
35
+ end
36
+
37
+ # vim: syntax=ruby
@@ -0,0 +1,1098 @@
1
+ #
2
+ # This file is automatically generated. DO NOT MODIFY!
3
+ #
4
+ # install.rb
5
+ #
6
+ # Copyright (c) 2000-2003 Minero Aoki <aamine@loveruby.net>
7
+ #
8
+ # This program is free software.
9
+ # You can distribute/modify this program under the terms of
10
+ # the GNU Lesser General Public License version 2.
11
+ #
12
+
13
+ ### begin compat.rb
14
+
15
+ module Enumerable
16
+ methods = instance_methods()
17
+
18
+ unless methods.include?('map')
19
+ alias map collect
20
+ end
21
+
22
+ unless methods.include?('select')
23
+ alias select find_all
24
+ end
25
+
26
+ unless methods.include?('reject')
27
+ def reject
28
+ result = []
29
+ each do |i|
30
+ result.push i unless yield(i)
31
+ end
32
+ result
33
+ end
34
+ end
35
+
36
+ unless methods.include?('inject')
37
+ def inject( result )
38
+ each do |i|
39
+ result = yield(result, i)
40
+ end
41
+ result
42
+ end
43
+ end
44
+
45
+ unless methods.include?('any?')
46
+ def any?
47
+ each do |i|
48
+ return true if yield(i)
49
+ end
50
+ false
51
+ end
52
+ end
53
+ end
54
+
55
+ def File.read_all( fname )
56
+ File.open(fname, 'rb') {|f| return f.read }
57
+ end
58
+
59
+ def File.write( fname, str )
60
+ File.open(fname, 'wb') {|f| f.write str }
61
+ end
62
+
63
+ ### end compat.rb
64
+ ### begin config.rb
65
+
66
+ if i = ARGV.index(/\A--rbconfig=/)
67
+ file = $'
68
+ ARGV.delete_at(i)
69
+ require file
70
+ else
71
+ require 'rbconfig'
72
+ end
73
+
74
+
75
+ class ConfigTable
76
+
77
+ c = ::Config::CONFIG
78
+
79
+ rubypath = c['bindir'] + '/' + c['ruby_install_name']
80
+
81
+ major = c['MAJOR'].to_i
82
+ minor = c['MINOR'].to_i
83
+ teeny = c['TEENY'].to_i
84
+ version = "#{major}.#{minor}"
85
+
86
+ # ruby ver. >= 1.4.4?
87
+ newpath_p = ((major >= 2) or
88
+ ((major == 1) and
89
+ ((minor >= 5) or
90
+ ((minor == 4) and (teeny >= 4)))))
91
+
92
+ re = Regexp.new('\A' + Regexp.quote(c['prefix']))
93
+ subprefix = lambda {|path|
94
+ re === path and path.sub(re, '$prefix')
95
+ }
96
+
97
+ if c['rubylibdir']
98
+ # V < 1.6.3
99
+ stdruby = subprefix.call(c['rubylibdir'])
100
+ siteruby = subprefix.call(c['sitedir'])
101
+ versite = subprefix.call(c['sitelibdir'])
102
+ sodir = subprefix.call(c['sitearchdir'])
103
+ elsif newpath_p
104
+ # 1.4.4 <= V <= 1.6.3
105
+ stdruby = "$prefix/lib/ruby/#{version}"
106
+ siteruby = subprefix.call(c['sitedir'])
107
+ versite = siteruby + '/' + version
108
+ sodir = "$site-ruby/#{c['arch']}"
109
+ else
110
+ # V < 1.4.4
111
+ stdruby = "$prefix/lib/ruby/#{version}"
112
+ siteruby = "$prefix/lib/ruby/#{version}/site_ruby"
113
+ versite = siteruby
114
+ sodir = "$site-ruby/#{c['arch']}"
115
+ end
116
+
117
+ DESCRIPTER = [
118
+ [ 'prefix', [ c['prefix'],
119
+ 'path',
120
+ 'path prefix of target environment' ] ],
121
+ [ 'std-ruby', [ stdruby,
122
+ 'path',
123
+ 'the directory for standard ruby libraries' ] ],
124
+ [ 'site-ruby-common', [ siteruby,
125
+ 'path',
126
+ 'the directory for version-independent non-standard ruby libraries' ] ],
127
+ [ 'site-ruby', [ versite,
128
+ 'path',
129
+ 'the directory for non-standard ruby libraries' ] ],
130
+ [ 'bin-dir', [ '$prefix/bin',
131
+ 'path',
132
+ 'the directory for commands' ] ],
133
+ [ 'rb-dir', [ '$site-ruby',
134
+ 'path',
135
+ 'the directory for ruby scripts' ] ],
136
+ [ 'so-dir', [ sodir,
137
+ 'path',
138
+ 'the directory for ruby extentions' ] ],
139
+ [ 'data-dir', [ '$prefix/share',
140
+ 'path',
141
+ 'the directory for shared data' ] ],
142
+ [ 'ruby-path', [ rubypath,
143
+ 'path',
144
+ 'path to set to #! line' ] ],
145
+ [ 'ruby-prog', [ rubypath,
146
+ 'name',
147
+ 'the ruby program using for installation' ] ],
148
+ [ 'make-prog', [ 'make',
149
+ 'name',
150
+ 'the make program to compile ruby extentions' ] ],
151
+ [ 'without-ext', [ 'no',
152
+ 'yes/no',
153
+ 'does not compile/install ruby extentions' ] ]
154
+ ]
155
+
156
+ SAVE_FILE = 'config.save'
157
+
158
+ def ConfigTable.each_name( &block )
159
+ keys().each(&block)
160
+ end
161
+
162
+ def ConfigTable.keys
163
+ DESCRIPTER.map {|k,*dummy| k }
164
+ end
165
+
166
+ def ConfigTable.each_definition( &block )
167
+ DESCRIPTER.each(&block)
168
+ end
169
+
170
+ def ConfigTable.get_entry( name )
171
+ name, ent = DESCRIPTER.assoc(name)
172
+ ent
173
+ end
174
+
175
+ def ConfigTable.get_entry!( name )
176
+ get_entry(name) or raise ArgumentError, "no such config: #{name}"
177
+ end
178
+
179
+ def ConfigTable.add_entry( name, vals )
180
+ ConfigTable::DESCRIPTER.push [name,vals]
181
+ end
182
+
183
+ def ConfigTable.remove_entry( name )
184
+ get_entry name or raise ArgumentError, "no such config: #{name}"
185
+ DESCRIPTER.delete_if {|n,arr| n == name }
186
+ end
187
+
188
+ def ConfigTable.config_key?( name )
189
+ get_entry(name) ? true : false
190
+ end
191
+
192
+ def ConfigTable.bool_config?( name )
193
+ ent = get_entry(name) or return false
194
+ ent[1] == 'yes/no'
195
+ end
196
+
197
+ def ConfigTable.value_config?( name )
198
+ ent = get_entry(name) or return false
199
+ ent[1] != 'yes/no'
200
+ end
201
+
202
+ def ConfigTable.path_config?( name )
203
+ ent = get_entry(name) or return false
204
+ ent[1] == 'path'
205
+ end
206
+
207
+
208
+ class << self
209
+ alias newobj new
210
+
211
+ def new
212
+ c = newobj()
213
+ c.__send__ :init
214
+ c
215
+ end
216
+
217
+ def load
218
+ c = newobj()
219
+ raise InstallError, "#{File.basename $0} config first"\
220
+ unless FileTest.file?(SAVE_FILE)
221
+ File.foreach(SAVE_FILE) do |line|
222
+ k, v = line.split(/=/, 2)
223
+ c.instance_eval {
224
+ @table[k] = v.strip
225
+ }
226
+ end
227
+ c
228
+ end
229
+ end
230
+
231
+ def initialize
232
+ @table = {}
233
+ end
234
+
235
+ def init
236
+ DESCRIPTER.each do |k, (default, vname, desc, default2)|
237
+ @table[k] = default
238
+ end
239
+ end
240
+ private :init
241
+
242
+ def save
243
+ File.open(SAVE_FILE, 'w') {|f|
244
+ @table.each do |k, v|
245
+ f.printf "%s=%s\n", k, v if v
246
+ end
247
+ }
248
+ end
249
+
250
+ def []=( k, v )
251
+ ConfigTable.config_key? k or raise InstallError, "unknown config option #{k}"
252
+ if ConfigTable.path_config? k
253
+ @table[k] = (v[0,1] != '$') ? File.expand_path(v) : v
254
+ else
255
+ @table[k] = v
256
+ end
257
+ end
258
+
259
+ def []( key )
260
+ @table[key] or return nil
261
+ @table[key].gsub(%r<\$([^/]+)>) { self[$1] }
262
+ end
263
+
264
+ def set_raw( key, val )
265
+ @table[key] = val
266
+ end
267
+
268
+ def get_raw( key )
269
+ @table[key]
270
+ end
271
+
272
+ end
273
+
274
+
275
+ module MetaConfigAPI
276
+
277
+ def eval_file_ifexist( fname )
278
+ instance_eval File.read_all(fname), fname, 1 if FileTest.file?(fname)
279
+ end
280
+
281
+ def config_names
282
+ ConfigTable.keys
283
+ end
284
+
285
+ def config?( name )
286
+ ConfigTable.config_key? name
287
+ end
288
+
289
+ def bool_config?( name )
290
+ ConfigTable.bool_config? name
291
+ end
292
+
293
+ def value_config?( name )
294
+ ConfigTable.value_config? name
295
+ end
296
+
297
+ def path_config?( name )
298
+ ConfigTable.path_config? name
299
+ end
300
+
301
+ def add_config( name, argname, default, desc )
302
+ ConfigTable.add_entry name,[default,argname,desc]
303
+ end
304
+
305
+ def add_path_config( name, default, desc )
306
+ add_config name, 'path', default, desc
307
+ end
308
+
309
+ def add_bool_config( name, default, desc )
310
+ add_config name, 'yes/no', default ? 'yes' : 'no', desc
311
+ end
312
+
313
+ def set_config_default( name, default )
314
+ if bool_config? name
315
+ ConfigTable.get_entry!(name)[0] = default ? 'yes' : 'no'
316
+ else
317
+ ConfigTable.get_entry!(name)[0] = default
318
+ end
319
+ end
320
+
321
+ def remove_config( name )
322
+ ent = ConfigTable.get_entry(name)
323
+ ConfigTable.remove_entry name
324
+ ent
325
+ end
326
+
327
+ end
328
+
329
+ ### end config.rb
330
+ ### begin fileop.rb
331
+
332
+ module FileOperations
333
+
334
+ def mkdir_p( dname, prefix = nil )
335
+ dname = prefix + dname if prefix
336
+ $stderr.puts "mkdir -p #{dname}" if verbose?
337
+ return if no_harm?
338
+
339
+ # does not check '/'... it's too abnormal case
340
+ dirs = dname.split(%r<(?=/)>)
341
+ if /\A[a-z]:\z/i === dirs[0]
342
+ disk = dirs.shift
343
+ dirs[0] = disk + dirs[0]
344
+ end
345
+ dirs.each_index do |idx|
346
+ path = dirs[0..idx].join('')
347
+ Dir.mkdir path unless dir? path
348
+ end
349
+ end
350
+
351
+ def rm_f( fname )
352
+ $stderr.puts "rm -f #{fname}" if verbose?
353
+ return if no_harm?
354
+
355
+ if File.exist? fname or File.symlink? fname
356
+ File.chmod 0777, fname
357
+ File.unlink fname
358
+ end
359
+ end
360
+
361
+ def rm_rf( dn )
362
+ $stderr.puts "rm -rf #{dn}" if verbose?
363
+ return if no_harm?
364
+
365
+ Dir.chdir dn
366
+ Dir.foreach('.') do |fn|
367
+ next if fn == '.'
368
+ next if fn == '..'
369
+ if dir? fn
370
+ verbose_off {
371
+ rm_rf fn
372
+ }
373
+ else
374
+ verbose_off {
375
+ rm_f fn
376
+ }
377
+ end
378
+ end
379
+ Dir.chdir '..'
380
+ Dir.rmdir dn
381
+ end
382
+
383
+ def mv( src, dest )
384
+ rm_f dest
385
+ begin
386
+ File.link src, dest
387
+ rescue
388
+ File.write dest, File.read_all(src)
389
+ File.chmod File.stat(src).mode, dest
390
+ end
391
+ rm_f src
392
+ end
393
+
394
+ def install( from, dest, mode, prefix = nil )
395
+ $stderr.puts "install #{from} #{dest}" if verbose?
396
+ return if no_harm?
397
+
398
+ realdest = prefix + dest if prefix
399
+ if dir? realdest
400
+ realdest += '/' + File.basename(from)
401
+ end
402
+ str = File.read_all(from)
403
+ if diff? str, realdest
404
+ verbose_off {
405
+ rm_f realdest if File.exist? realdest
406
+ }
407
+ File.write realdest, str
408
+ File.chmod mode, realdest
409
+
410
+ File.open(objdir + '/InstalledFiles', 'a') {|f| f.puts realdest }
411
+ end
412
+ end
413
+
414
+ def diff?( orig, targ )
415
+ return true unless File.exist? targ
416
+ orig != File.read_all(targ)
417
+ end
418
+
419
+ def command( str )
420
+ $stderr.puts str if verbose?
421
+ system str or raise RuntimeError, "'system #{str}' failed"
422
+ end
423
+
424
+ def ruby( str )
425
+ command config('ruby-prog') + ' ' + str
426
+ end
427
+
428
+ def dir?( dname )
429
+ # for corrupted windows stat()
430
+ File.directory?((dname[-1,1] == '/') ? dname : dname + '/')
431
+ end
432
+
433
+ def all_files_in( dname )
434
+ Dir.open(dname) {|d|
435
+ return d.select {|n| FileTest.file? "#{dname}/#{n}" }
436
+ }
437
+ end
438
+
439
+ REJECT_DIRS = %w(
440
+ CVS SCCS RCS CVS.adm
441
+ )
442
+
443
+ def all_dirs_in( dname )
444
+ Dir.open(dname) {|d|
445
+ return d.select {|n| dir? "#{dname}/#{n}" } - %w(. ..) - REJECT_DIRS
446
+ }
447
+ end
448
+
449
+ end
450
+
451
+ ### end fileop.rb
452
+ ### begin base.rb
453
+
454
+ class InstallError < StandardError; end
455
+
456
+
457
+ class Installer
458
+
459
+ Version = '3.1.4'
460
+ Copyright = 'Copyright (c) 2000-2003 Minero Aoki'
461
+
462
+
463
+ @toplevel = nil
464
+
465
+ def self.declare_toplevel_installer( inst )
466
+ raise ArgumentError, 'two toplevel installers declared' if @toplevel
467
+ @toplevel = inst
468
+ end
469
+
470
+ def self.toplevel_installer
471
+ @toplevel
472
+ end
473
+
474
+
475
+ FILETYPES = %w( bin lib ext data )
476
+
477
+ include FileOperations
478
+
479
+ def initialize( config, opt, srcroot, objroot )
480
+ @config = config
481
+ @options = opt
482
+ @srcdir = File.expand_path(srcroot)
483
+ @objdir = File.expand_path(objroot)
484
+ @currdir = '.'
485
+ end
486
+
487
+ def inspect
488
+ "#<#{self.class} #{__id__}>"
489
+ end
490
+
491
+ #
492
+ # configs/options
493
+ #
494
+
495
+ def get_config( key )
496
+ @config[key]
497
+ end
498
+
499
+ alias config get_config
500
+
501
+ def set_config( key, val )
502
+ @config[key] = val
503
+ end
504
+
505
+ def no_harm?
506
+ @options['no-harm']
507
+ end
508
+
509
+ def verbose?
510
+ @options['verbose']
511
+ end
512
+
513
+ def verbose_off
514
+ save, @options['verbose'] = @options['verbose'], false
515
+ yield
516
+ @options['verbose'] = save
517
+ end
518
+
519
+ #
520
+ # srcdir/objdir
521
+ #
522
+
523
+ attr_reader :srcdir
524
+ alias srcdir_root srcdir
525
+ alias package_root srcdir
526
+
527
+ def curr_srcdir
528
+ "#{@srcdir}/#{@currdir}"
529
+ end
530
+
531
+ attr_reader :objdir
532
+ alias objdir_root objdir
533
+
534
+ def curr_objdir
535
+ "#{@objdir}/#{@currdir}"
536
+ end
537
+
538
+ def srcfile( path )
539
+ curr_srcdir + '/' + path
540
+ end
541
+
542
+ def srcexist?( path )
543
+ File.exist? srcfile(path)
544
+ end
545
+
546
+ def srcdirectory?( path )
547
+ dir? srcfile(path)
548
+ end
549
+
550
+ def srcfile?( path )
551
+ FileTest.file? srcfile(path)
552
+ end
553
+
554
+ def srcentries( path = '.' )
555
+ Dir.open(curr_srcdir + '/' + path) {|d|
556
+ return d.to_a - %w(. ..) - hookfilenames
557
+ }
558
+ end
559
+
560
+ def srcfiles( path = '.' )
561
+ srcentries(path).select {|fname|
562
+ FileTest.file? File.join(curr_srcdir, path, fname)
563
+ }
564
+ end
565
+
566
+ def srcdirectories( path = '.' )
567
+ srcentries(path).select {|fname|
568
+ dir? File.join(curr_srcdir, path, fname)
569
+ }
570
+ end
571
+
572
+ def dive_into( rel )
573
+ return unless dir?("#{@srcdir}/#{rel}")
574
+
575
+ dir = File.basename(rel)
576
+ Dir.mkdir dir unless dir?(dir)
577
+ prevdir = Dir.pwd
578
+ Dir.chdir dir
579
+ $stderr.puts '---> ' + rel if verbose?
580
+ @currdir = rel
581
+ yield
582
+ Dir.chdir prevdir
583
+ $stderr.puts '<--- ' + rel if verbose?
584
+ @currdir = File.dirname(rel)
585
+ end
586
+
587
+ #
588
+ # TASK config
589
+ #
590
+
591
+ def exec_config
592
+ exec_task_traverse 'config'
593
+ end
594
+
595
+ def config_dir_bin( rel )
596
+ end
597
+
598
+ def config_dir_lib( rel )
599
+ end
600
+
601
+ def config_dir_ext( rel )
602
+ extconf if extdir? curr_srcdir
603
+ end
604
+
605
+ def extconf
606
+ opt = @options['config-opt'].join(' ')
607
+ command "#{config('ruby-prog')} #{curr_srcdir}/extconf.rb #{opt}"
608
+ end
609
+
610
+ def config_dir_data( rel )
611
+ end
612
+
613
+ #
614
+ # TASK setup
615
+ #
616
+
617
+ def exec_setup
618
+ exec_task_traverse 'setup'
619
+ end
620
+
621
+ def setup_dir_bin( relpath )
622
+ all_files_in(curr_srcdir()).each do |fname|
623
+ add_rubypath "#{curr_srcdir}/#{fname}"
624
+ end
625
+ end
626
+
627
+ SHEBANG_RE = /\A\#!\s*\S*ruby\S*/
628
+
629
+ def add_rubypath( path )
630
+ $stderr.puts %Q<set #! line to "\#!#{config('ruby-path')}" for #{path} ...> if verbose?
631
+ return if no_harm?
632
+
633
+ tmpfile = File.basename(path) + '.tmp'
634
+ begin
635
+ File.open(path) {|r|
636
+ File.open(tmpfile, 'w') {|w|
637
+ first = r.gets
638
+ return unless SHEBANG_RE === first # reject '/usr/bin/env ruby'
639
+
640
+ w.print first.sub(SHEBANG_RE, '#!' + config('ruby-path'))
641
+ w.write r.read
642
+ } }
643
+ mv tmpfile, File.basename(path)
644
+ ensure
645
+ rm_f tmpfile if File.exist? tmpfile
646
+ end
647
+ end
648
+
649
+ def setup_dir_lib( relpath )
650
+ end
651
+
652
+ def setup_dir_ext( relpath )
653
+ make if extdir?(curr_srcdir)
654
+ end
655
+
656
+ def setup_dir_data( relpath )
657
+ end
658
+
659
+ #
660
+ # TASK install
661
+ #
662
+
663
+ def exec_install
664
+ exec_task_traverse 'install'
665
+ end
666
+
667
+ def install_dir_bin( rel )
668
+ install_files target_filenames(), config('bin-dir') + '/' + rel, 0755
669
+ end
670
+
671
+ def install_dir_lib( rel )
672
+ install_files target_filenames(), config('rb-dir') + '/' + rel, 0644
673
+ end
674
+
675
+ def install_dir_ext( rel )
676
+ install_dir_ext_main File.dirname(rel) if extdir?(curr_srcdir)
677
+ end
678
+
679
+ def install_dir_ext_main( rel )
680
+ install_files allext('.'), config('so-dir') + '/' + rel, 0555
681
+ end
682
+
683
+ def install_dir_data( rel )
684
+ install_files target_filenames(), config('data-dir') + '/' + rel, 0644
685
+ end
686
+
687
+ def install_files( list, dest, mode )
688
+ mkdir_p dest, @options['install-prefix']
689
+ list.each do |fname|
690
+ install fname, dest, mode, @options['install-prefix']
691
+ end
692
+ end
693
+
694
+ def target_filenames
695
+ if FileTest.file? "#{curr_srcdir()}/MANIFEST"
696
+ mapdir(target_filenames_MANIFEST())
697
+ else
698
+ mapdir(target_filenames_AUTO())
699
+ end
700
+ end
701
+
702
+ def mapdir( filelist )
703
+ filelist.map {|fname|
704
+ if File.exist? fname # current objdir == '.'
705
+ fname
706
+ else
707
+ File.join(curr_srcdir(), fname)
708
+ end
709
+ }
710
+ end
711
+
712
+ def target_filenames_MANIFEST
713
+ File.read_all("#{curr_srcdir()}/MANIFEST").split
714
+ end
715
+
716
+ # picked up many entries from cvs-1.11.1/src/ignore.c
717
+ REJECT_PATTERNS = %w(
718
+ core RCSLOG tags TAGS .make.state
719
+ .nse_depinfo #* .#* cvslog.* ,* .del-* *.a *.olb *.o *.obj
720
+ *.so *.Z *~ *.old *.elc *.ln *.bak *.BAK *.orig *.rej *.exe _$* *$
721
+
722
+ *.org *.in .*
723
+ ).map {|pattern|
724
+ Regexp.compile('\A' + pattern.gsub(/[\.\$]/) {|s| '\\' + s }.gsub(/\*/, '.*') + '\z')
725
+ }
726
+
727
+ def target_filenames_AUTO
728
+ (existfiles() - hookfiles()).reject {|fname|
729
+ REJECT_PATTERNS.any? {|re| re === fname }
730
+ }
731
+ end
732
+
733
+ def existfiles
734
+ all_files_in(curr_srcdir()) | all_files_in(curr_objdir())
735
+ end
736
+
737
+ def hookfiles
738
+ %w( pre-%s post-%s pre-%s.rb post-%s.rb ).map {|fmt|
739
+ %w( config setup install clean ).map {|t| sprintf(fmt, t) }
740
+ }.flatten
741
+ end
742
+
743
+ def allext( dir )
744
+ _allext(dir) or raise InstallError,
745
+ "no extention exists: Have you done 'ruby #{$0} setup' ?"
746
+ end
747
+
748
+ DLEXT = /\.#{ ::Config::CONFIG['DLEXT'] }\z/
749
+
750
+ def _allext( dir )
751
+ Dir.open(dir) {|d|
752
+ return d.select {|fname| DLEXT === fname }
753
+ }
754
+ end
755
+
756
+ #
757
+ # TASK clean
758
+ #
759
+
760
+ def exec_clean
761
+ exec_task_traverse 'clean'
762
+ rm_f 'config.save'
763
+ rm_f 'InstalledFiles'
764
+ end
765
+
766
+ def clean_dir_bin( rel )
767
+ end
768
+
769
+ def clean_dir_lib( rel )
770
+ end
771
+
772
+ def clean_dir_ext( rel )
773
+ make 'clean' if FileTest.file?('Makefile')
774
+ end
775
+
776
+ def clean_dir_data( rel )
777
+ end
778
+
779
+ #
780
+ # TASK distclean
781
+ #
782
+
783
+ def exec_distclean
784
+ exec_task_traverse 'distclean'
785
+ rm_f 'config.save'
786
+ rm_f 'InstalledFiles'
787
+ end
788
+
789
+ def distclean_dir_bin( rel )
790
+ end
791
+
792
+ def distclean_dir_lib( rel )
793
+ end
794
+
795
+ def distclean_dir_ext( rel )
796
+ make 'distclean' if FileTest.file?('Makefile')
797
+ end
798
+
799
+ #
800
+ # lib
801
+ #
802
+
803
+ def make( task = '' )
804
+ command config('make-prog') + ' ' + task
805
+ end
806
+
807
+ def exec_task_traverse( task )
808
+ run_hook 'pre-' + task
809
+ FILETYPES.each do |type|
810
+ if config('without-ext') == 'yes' and type == 'ext'
811
+ $stderr.puts 'skipping ext/* by user option' if verbose?
812
+ next
813
+ end
814
+ traverse task, type, task + '_dir_' + type
815
+ end
816
+ run_hook 'post-' + task
817
+ end
818
+
819
+ def traverse( task, rel, mid )
820
+ dive_into(rel) {
821
+ run_hook 'pre-' + task
822
+ __send__ mid, rel.sub(%r[\A.*?(?:/|\z)], '')
823
+ all_dirs_in(curr_srcdir()).each do |d|
824
+ traverse task, rel + '/' + d, mid
825
+ end
826
+ run_hook 'post-' + task
827
+ }
828
+ end
829
+
830
+ def run_hook( name )
831
+ try_run_hook curr_srcdir + '/' + name or
832
+ try_run_hook curr_srcdir + '/' + name + '.rb'
833
+ end
834
+
835
+ def try_run_hook( fname )
836
+ return false unless FileTest.file?(fname)
837
+
838
+ env = self.dup
839
+ begin
840
+ env.instance_eval File.read_all(fname), fname, 1
841
+ rescue
842
+ raise InstallError, "hook #{fname} failed:\n" + $!.message
843
+ end
844
+ true
845
+ end
846
+
847
+ def extdir?( dir )
848
+ File.exist? dir + '/MANIFEST'
849
+ end
850
+
851
+ end
852
+
853
+ ### end base.rb
854
+ ### begin toplevel.rb
855
+
856
+ class ToplevelInstaller < Installer
857
+
858
+ def self.invoke
859
+ new(File.dirname($0)).invoke
860
+ end
861
+
862
+
863
+ TASKS = [
864
+ [ 'config', 'saves your configurations' ],
865
+ [ 'show', 'shows current configuration' ],
866
+ [ 'setup', 'compiles extention or else' ],
867
+ [ 'install', 'installs files' ],
868
+ [ 'clean', "does `make clean' for each extention" ],
869
+ [ 'distclean',"does `make distclean' for each extention" ]
870
+ ]
871
+
872
+
873
+ def initialize( root )
874
+ super nil, {'verbose' => true}, root, '.'
875
+ Installer.declare_toplevel_installer self
876
+ end
877
+
878
+
879
+ def invoke
880
+ run_metaconfigs
881
+
882
+ case task = parsearg_global()
883
+ when 'config'
884
+ @config = ConfigTable.new
885
+ else
886
+ @config = ConfigTable.load
887
+ end
888
+ parsearg_TASK task
889
+
890
+ exectask task
891
+ end
892
+
893
+ include MetaConfigAPI
894
+
895
+ def run_metaconfigs
896
+ eval_file_ifexist "#{srcdir_root()}/metaconfig"
897
+ end
898
+
899
+
900
+ def exectask( task )
901
+ if task == 'show'
902
+ exec_show
903
+ else
904
+ try task
905
+ end
906
+ end
907
+
908
+ def try( task )
909
+ $stderr.printf "#{File.basename $0}: entering %s phase...\n", task if verbose?
910
+ begin
911
+ __send__ 'exec_' + task
912
+ rescue
913
+ $stderr.printf "%s failed\n", task
914
+ raise
915
+ end
916
+ $stderr.printf "#{File.basename $0}: %s done.\n", task if verbose?
917
+ end
918
+
919
+ #
920
+ # processing arguments
921
+ #
922
+
923
+ def parsearg_global
924
+ task_re = /\A(?:#{TASKS.map {|i| i[0] }.join '|'})\z/
925
+
926
+ while arg = ARGV.shift
927
+ case arg
928
+ when /\A\w+\z/
929
+ task_re === arg or raise InstallError, "wrong task: #{arg}"
930
+ return arg
931
+
932
+ when '-q', '--quiet'
933
+ @options['verbose'] = false
934
+
935
+ when '--verbose'
936
+ @options['verbose'] = true
937
+
938
+ when '-h', '--help'
939
+ print_usage $stdout
940
+ exit 0
941
+
942
+ when '-v', '--version'
943
+ puts "#{File.basename $0} version #{Version}"
944
+ exit 0
945
+
946
+ when '--copyright'
947
+ puts Copyright
948
+ exit 0
949
+
950
+ else
951
+ raise InstallError, "unknown global option '#{arg}'"
952
+ end
953
+ end
954
+
955
+ raise InstallError, "No task or global option given.
956
+ Typical installation procedure is:
957
+ $ ruby #{File.basename $0} config
958
+ $ ruby #{File.basename $0} setup
959
+ # ruby #{File.basename $0} install (may require root privilege)
960
+ "
961
+ end
962
+
963
+
964
+ def parsearg_TASK( task )
965
+ mid = "parsearg_#{task}"
966
+ if respond_to? mid, true
967
+ __send__ mid
968
+ else
969
+ ARGV.empty? or
970
+ raise InstallError, "#{task}: unknown options: #{ARGV.join ' '}"
971
+ end
972
+ end
973
+
974
+ def parsearg_config
975
+ re = /\A--(#{ConfigTable.keys.join '|'})(?:=(.*))?\z/
976
+ @options['config-opt'] = []
977
+
978
+ while i = ARGV.shift
979
+ if /\A--?\z/ === i
980
+ @options['config-opt'] = ARGV.dup
981
+ break
982
+ end
983
+ m = re.match(i) or raise InstallError, "config: unknown option #{i}"
984
+ name, value = m.to_a[1,2]
985
+ if value
986
+ if ConfigTable.bool_config?(name)
987
+ /\A(y(es)?|n(o)?|t(rue)?|f(alse))\z/i === value or raise InstallError, "config: --#{name} allows only yes/no for argument"
988
+ value = (/\Ay(es)?|\At(rue)/i === value) ? 'yes' : 'no'
989
+ end
990
+ else
991
+ ConfigTable.bool_config?(name) or raise InstallError, "config: --#{name} requires argument"
992
+ value = 'yes'
993
+ end
994
+ @config[name] = value
995
+ end
996
+ end
997
+
998
+ def parsearg_install
999
+ @options['no-harm'] = false
1000
+ @options['install-prefix'] = ''
1001
+ while a = ARGV.shift
1002
+ case a
1003
+ when /\A--no-harm\z/
1004
+ @options['no-harm'] = true
1005
+ when /\A--prefix=(.*)\z/
1006
+ path = $1
1007
+ path = File.expand_path(path) unless path[0,1] == '/'
1008
+ @options['install-prefix'] = path
1009
+ else
1010
+ raise InstallError, "install: unknown option #{a}"
1011
+ end
1012
+ end
1013
+ end
1014
+
1015
+
1016
+ def print_usage( out )
1017
+ out.puts 'Typical Installation Procedure:'
1018
+ out.puts " $ ruby #{File.basename $0} config"
1019
+ out.puts " $ ruby #{File.basename $0} setup"
1020
+ out.puts " # ruby #{File.basename $0} install (may require root privilege)"
1021
+ out.puts
1022
+ out.puts 'Detailed Usage:'
1023
+ out.puts " ruby #{File.basename $0} <global option>"
1024
+ out.puts " ruby #{File.basename $0} [<global options>] <task> [<task options>]"
1025
+
1026
+ fmt = " %-20s %s\n"
1027
+ out.puts
1028
+ out.puts 'Global options:'
1029
+ out.printf fmt, '-q,--quiet', 'suppress message outputs'
1030
+ out.printf fmt, ' --verbose', 'output messages verbosely'
1031
+ out.printf fmt, '-h,--help', 'print this message'
1032
+ out.printf fmt, '-v,--version', 'print version and quit'
1033
+ out.printf fmt, ' --copyright', 'print copyright and quit'
1034
+
1035
+ out.puts
1036
+ out.puts 'Tasks:'
1037
+ TASKS.each do |name, desc|
1038
+ out.printf " %-10s %s\n", name, desc
1039
+ end
1040
+
1041
+ out.puts
1042
+ out.puts 'Options for config:'
1043
+ ConfigTable.each_definition do |name, (default, arg, desc, default2)|
1044
+ out.printf " %-20s %s [%s]\n",
1045
+ '--'+ name + (ConfigTable.bool_config?(name) ? '' : '='+arg),
1046
+ desc,
1047
+ default2 || default
1048
+ end
1049
+ out.printf " %-20s %s [%s]\n",
1050
+ '--rbconfig=path', 'your rbconfig.rb to load', "running ruby's"
1051
+
1052
+ out.puts
1053
+ out.puts 'Options for install:'
1054
+ out.printf " %-20s %s [%s]\n",
1055
+ '--no-harm', 'only display what to do if given', 'off'
1056
+ out.printf " %-20s %s [%s]\n",
1057
+ '--prefix', 'install path prefix', '$prefix'
1058
+
1059
+ out.puts
1060
+ end
1061
+
1062
+ #
1063
+ # config
1064
+ #
1065
+
1066
+ def exec_config
1067
+ super
1068
+ @config.save
1069
+ end
1070
+
1071
+ #
1072
+ # show
1073
+ #
1074
+
1075
+ def exec_show
1076
+ ConfigTable.each_name do |k|
1077
+ v = @config.get_raw(k)
1078
+ if not v or v.empty?
1079
+ v = '(not specified)'
1080
+ end
1081
+ printf "%-10s %s\n", k, v
1082
+ end
1083
+ end
1084
+
1085
+ end
1086
+
1087
+ ### end toplevel.rb
1088
+
1089
+ if $0 == __FILE__
1090
+ begin
1091
+ ToplevelInstaller.invoke
1092
+ rescue
1093
+ raise if $DEBUG
1094
+ $stderr.puts $!.message
1095
+ $stderr.puts "Try 'ruby #{$0} --help' for detailed usage."
1096
+ exit 1
1097
+ end
1098
+ end