#! /usr/bin/env ruby # # Copyright (c) 2001 by Sean Chittenden # Adapted from an install script originally by Jim Menard # =begin = Introduction This script installs ruby-tmpl into the Ruby site-local library directory. = Usage install.rb =end require 'getoptlong' require 'ftools' require 'find' SRCDIR = 'src' def instdir g = GetoptLong.new(['--install-dir', '-i', GetoptLong::REQUIRED_ARGUMENT]) g.each { | name, arg | if name == '--install-dir' return arg else $stderr.puts "usage: $0 [--install-dir dir]" end } begin require 'rbconfig' libdir = Config::CONFIG['sitedir'] + "/" + Config::CONFIG['MAJOR'] + "." + Config::CONFIG['MINOR'] rescue ScriptError $LOAD_PATH.each do |l| if l =~ /site_ruby/ && l =~ /\d$/ && l !~ /#{PLATFORM}/ libdir = l break end end STDERR.puts "Can't find required file `rbconfig.rb'." STDERR.puts "The `ruby-tmpl' files need to be installed manually in" + " #{libdir}" end return libdir end INSTALL_DIR = instdir() File.makedirs(File.join(INSTALL_DIR)) Find.find(SRCDIR) { |f| File.install(f, File.join(INSTALL_DIR, f).gsub(/#{SRCDIR}/, ''), 0644, true) if f =~ /.rb$/ }