X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=extras%2Fphysfs_rb%2Finstaller.rb;fp=extras%2Fphysfs_rb%2Finstaller.rb;h=a62bd28800f7b784d83333d61aa5d10213e2531e;hb=1a2e54b98aaab3669eebd38facb83687c4ac7baf;hp=0000000000000000000000000000000000000000;hpb=0b9bdac28929054558b5d7f315403fe3399a1413;p=physicsfs diff --git a/extras/physfs_rb/installer.rb b/extras/physfs_rb/installer.rb new file mode 100644 index 0000000..a62bd28 --- /dev/null +++ b/extras/physfs_rb/installer.rb @@ -0,0 +1,103 @@ +# $Id: installer.rb,v 1.3 2003/07/21 03:46:50 icculus Exp $ + +require 'rbconfig' +require 'find' +require 'ftools' + +include Config + +module Slimb + class Installer + def initialize target_dir = "", &user_skip + @user_skip = user_skip or proc {|f| false} + + @version = CONFIG["MAJOR"] + "." + CONFIG["MINOR"] + @libdir = File.join(CONFIG["libdir"], "ruby", @version) + @sitedir = CONFIG["sitedir"] || File.join(@libdir, "site_ruby") + @dest = File.join @sitedir, target_dir + + File::makedirs @dest + File::chmod 0755, @dest, true + end + + def skip? file + @user_skip[file] or + file[0] == ?. or file[-1] == ?~ or file[-1] == ?# + end + + def install_dir dir + File::makedirs(File.join(@dest, dir)) + File::chmod(0755, File.join(@dest, dir), true) + Dir.foreach(dir) {|file| + next if skip? file + + if File.ftype(File.join(dir, file)) == "directory" + install_dir File.join(dir, file) + else + install_file File.join(dir, file) + end + } + end + + def install_file file + if file =~ /\.so$/ + install_so file + else + File::install file, File.join(@dest, file), 0644, true + end + end + + def install_so file + File::install file, File.join(CONFIG["sitearchdir"], file), 0644, true + end + + def uninstall_so file + file = File.join(CONFIG["sitearchdir"], file) + File::safe_unlink file + end + + def install something + case something + when Array + something.each {|x| + install x if x.is_a? String + } + when String + if File.ftype(something) == "directory" + install_dir something + else + install_file something + end + end + end + + def uninstall what = "*" + case what + when Array + files = what.map {|x| File.join(@dest, x)} + when String + files = Dir[File.join(@dest, what)] + end + + files.each {|x| + # FIXME: recursive uninstall is a must + next if FileTest.directory? x + File::safe_unlink x + } + end + + def run files, argv + if !argv.grep(/--uninstall/).empty? + uninstall files + else + install files + end + end + end +end + +# self-installation +if $0 == __FILE__ + $stderr.puts "Installing slimb installer..." + Slimb::Installer.new("slimb").install File.basename(__FILE__) +end