extras/physfs_rb/installer.rb
author Ryan C. Gordon <icculus@icculus.org>
Wed, 03 Oct 2018 22:45:05 -0400
branchstable-1.0
changeset 1648 93b4c3bc6b9d
parent 584 c0de7f19aa10
permissions -rw-r--r--
Fixed Win10's GetUserProfileDirectory() bug in stable-1.0 branch.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
584
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
# $Id: installer.rb,v 1.3 2003/07/21 03:46:50 icculus Exp $
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
require 'rbconfig'
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
require 'find'
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
require 'ftools'
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
include Config
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
module Slimb
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
  class Installer
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
    def initialize target_dir = "", &user_skip 
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
      @user_skip = user_skip or proc {|f| false}
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
      
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
      @version = CONFIG["MAJOR"] + "." + CONFIG["MINOR"]
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
      @libdir = File.join(CONFIG["libdir"], "ruby", @version)
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
      @sitedir = CONFIG["sitedir"] || File.join(@libdir, "site_ruby")
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
      @dest = File.join @sitedir, target_dir
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
      File::makedirs @dest
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
      File::chmod 0755, @dest, true
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
    end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
    def skip? file
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
      @user_skip[file] or
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
	file[0] == ?. or file[-1] == ?~ or file[-1] == ?#
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
    end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
    
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
    def install_dir dir 
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
      File::makedirs(File.join(@dest, dir))
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
      File::chmod(0755, File.join(@dest, dir), true)
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
      Dir.foreach(dir) {|file|
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
	next if skip? file
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
	
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
	if File.ftype(File.join(dir, file)) == "directory"
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
	  install_dir File.join(dir, file)
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
	else
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
	  install_file File.join(dir, file)
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
	end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
      }
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    def install_file file
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
      if file =~ /\.so$/
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
	install_so file
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
      else
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
	File::install file, File.join(@dest, file), 0644, true
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
      end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
    end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    def install_so file
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
      File::install file, File.join(CONFIG["sitearchdir"], file), 0644, true
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
    end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
    def uninstall_so file
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
      file = File.join(CONFIG["sitearchdir"], file)
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
      File::safe_unlink file
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    def install something
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
      case something
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
      when Array
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
	something.each {|x|
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
	  install x if x.is_a? String
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
	}
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
      when String
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
	if File.ftype(something) == "directory"
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
	  install_dir something
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
	else
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
	  install_file something
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
	end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
      end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
    end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
    def uninstall what = "*"
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
      case what
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
      when Array
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
	files = what.map {|x| File.join(@dest, x)}
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
      when String
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
	files = Dir[File.join(@dest, what)]
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
      end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
      
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
      files.each {|x|
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
	# FIXME: recursive uninstall is a must
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
	next if FileTest.directory? x
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
	File::safe_unlink x
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
      }
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
    end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
    def run files, argv
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
      if !argv.grep(/--uninstall/).empty?
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
	uninstall files
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
      else
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
	install files
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
      end	
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
    end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
  end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
end
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
# self-installation 
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
if $0 == __FILE__
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
  $stderr.puts "Installing slimb installer..."
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
  Slimb::Installer.new("slimb").install File.basename(__FILE__)
c0de7f19aa10 Readded Ruby bindings, since contributor contacted me with permission to
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
end