#! /usr/bin/env ruby
#
# Copyright (c) 2001 by Sean Chittenden <sean@chittenden.org>
# Adapted from an install script originally by Jim Menard <jimm@io.com>
#

=begin

= Introduction

This script uninstalls ruby-tmpl from the Ruby site-local library directory.

= Usage

    uninstall.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()
Find.find(SRCDIR) { |f|
    File.delete(f, File.join(INSTALL_DIR, f).gsub(/#{SRCDIR}/, '')) if f =~ /.rb$/
}
