install.rb (modified for bin programs)

A

Ara.T.Howard

i am sorry i do not know the orginal author to credit - but this is a modified
install.rb that installs anything found in ./bin into the same bin dir as ruby
(or that passed as '--bindir=' from the command line). simple, but it works.


file: install.rb
========
require 'rbconfig'
require 'find'
require 'ftools'
include Config

LIBDIR = "lib"
LIBDIR_MODE = 0644

BINDIR = "bin"
BINDIR_MODE = 0755


$srcdir = CONFIG["srcdir"]
$version = CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
$libdir = File.join(CONFIG["libdir"], "ruby", $version)
$archdir = File.join($libdir, CONFIG["arch"])
$site_libdir = $:.find {|x| x =~ /site_ruby$/}
$bindir = CONFIG["bindir"]

if !$site_libdir
$site_libdir = File.join($libdir, "site_ruby")
elsif $site_libdir !~ %r/#{Regexp.quote($version)}/
$site_libdir = File.join($site_libdir, $version)
end

def install_rb(srcdir=nil, destdir=nil, mode=nil)
path = []
dir = []
Find.find(srcdir) do |f|
next unless FileTest.file?(f)
next if (f = f[srcdir.length+1..-1]) == nil
next if (/CVS$/ =~ File.dirname(f))
path.push f
dir |= [File.dirname(f)]
end
for f in dir
next if f == "."
next if f == "CVS"
File::makedirs(File.join(destdir, f))
end
for f in path
next if (/\~$/ =~ f)
next if (/^\./ =~ File.basename(f))
File::install(File.join(srcdir, f), File.join(destdir, f), mode, true)
end
end

def ARGV.switch
return nil if self.empty?
arg = self.shift
return nil if arg == '--'
if arg =~ /^-(.)(.*)/
return arg if $1 == '-'
raise 'unknown switch "-"' if $2.index('-')
self.unshift "-#{$2}" if $2.size > 0
"-#{$1}"
else
self.unshift arg
nil
end
end

def ARGV.req_arg
self.shift || raise('missing argument')
end


# main program
libdir = $site_libdir
bindir = $bindir

begin
while switch = ARGV.switch
case switch
when '-d', '--destdir'
libdir = ARGV.req_arg
when '-l', '--libdir'
libdir = ARGV.req_arg
when '-b', '--bindir'
bindir = ARGV.req_arg
else
raise "unknown switch #{switch.dump}"
end
end
rescue
STDERR.puts $!.to_s
STDERR.puts File.basename($0) +
" -d <destdir>" +
" -l <libdir>" +
" -b <bindir>"
exit 1
end

install_rb(LIBDIR, libdir, LIBDIR_MODE)
install_rb(BINDIR, bindir, BINDIR_MODE)
========


-a
--

ATTN: please update your address books with address below!

===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top