#!/usr/bin/env ruby # Install package to site_ruby. # # This script installs Facets to site_ruby location # using Ruby's defualt configuration settings. # If you want to change these, you can supply command # line paramters for '--prefix' and/or '--sitedir'. LIBPATHS = ['lib/core', 'lib/more', 'lib/methods'] require 'rbconfig' require 'fileutils' def start_install # We need to copy them into site_ruby in the opposite order they # would be searched for by require. # (Actually order doesn't matter anymore. I've neutered it.) libpaths = LIBPATHS system_prefix = Config::CONFIG['prefix'] system_libdir = Config::CONFIG['sitelibdir'] prefix = system_prefix if i = ARGV.index('--prefix') prefix = ARGV[i+1] end libdir = nil if i = ARGV.index('--sitedir') libdir = ARGV[i+1] end if ARGV.index('--dryrun') or ARGV.index('--noharm') @noharm = true include FileUtils::DryRun else @noharm = false include FileUtils end unless libdir if (prefix == system_prefix) then libdir = system_libdir else libdir = File.join(prefix, system_libdir[system_prefix.size..-1]) end end # Copy lib files to site_ruby location, in proper order! lib_files = Dir.glob("lib/**/*").select{ |f| File.file?(f) } libpaths.each do |loc| files = lib_files.grep(/^#{loc}/) files.each do |file| dest = File.dirname(file) #dest.sub!('lib/', '') #dest.sub!(loc, '') dest.sub!(loc, '') dest = File.join(libdir, dest) if noharm? puts "mkdir -p #{dest}" unless File.directory?(dest) puts "install -m 0444 #{file} #{dest}" else mkdir_p dest unless File.directory?(dest) install file, dest, :mode => 0444 end end lib_files -= files # speed things up be removing what we've already covered. end # Copy bin files to site_ruby location. bin_files = Dir.glob("bin/*").select{ |f| File.file?(f) } bin_files.each do |file| dest = File.dirname(file) dest = File.join(prefix, dest) if noharm? puts "mkdir -p #{dest}" unless File.directory?(dest) puts "install -m 0555 #{file} #{dest}" else mkdir_p dest unless File.directory?(dest) install file, dest, :mode => 0555 end end end def noharm?; @noharm; end # Start installation. start_install