File: install.rb

package info (click to toggle)
libyaml-ruby 0.49.1-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 536 kB
  • ctags: 679
  • sloc: ruby: 7,945; makefile: 38; sh: 1
file content (80 lines) | stat: -rwxr-xr-x 2,138 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /usr/bin/env ruby

require 'getoptlong'
require 'rbconfig'
require 'ftools'
require 'find'

INSTDIR = File.join Config::CONFIG['sitedir'], 
	"#{Config::CONFIG['MAJOR']}.#{Config::CONFIG['MINOR']}"

opts = GetoptLong.new( 
	[ "--uninstall",	"-u",		GetoptLong::NO_ARGUMENT ],
	[ "--i-have-racc",	"-r",		GetoptLong::NO_ARGUMENT ],
    [ "--destdir",      "-d",       GetoptLong::REQUIRED_ARGUMENT ]
)

def install( force = false, dir = INSTDIR )
	begin
		yaml_rb = File.join( "src", "yaml.rb" )
		unless File.exists?( yaml_rb ) and not force
			#
			# Generate the parser
			#
			racc = `which racc`.strip
			if not racc
				puts "RACC not found.  Please install RACC from http://www.ruby-lang.org/en/raa-list.rhtml?name=Racc and run install again."
				exit
			end

			`#{racc} -v -E src/yaml.y.rb -o src/yaml.rb`
		end
				
        unless File.exists?( File.join( dir, "okay" ) )
            Dir.mkdir( File.join( dir, "okay" ) )
        end
		install_files = {
			yaml_rb => File.join( dir, "yaml.rb" ),
			File.join( "src", "okay.rb" ) => File.join( dir, "okay.rb" ),
			File.join( "src", "okay", "news.rb" ) => File.join( dir, "okay", "news.rb" ),
			File.join( "src", "okay", "rpc.rb" ) => File.join( dir, "okay", "rpc.rb" ),
			File.join( "src", "yod.rb" ) => File.join( dir, "yod.rb" )
		}
		install_files.each_pair { |src, dst|
			if File.exists?( dst )
			    File.delete( dst )
			end
			File.install(src, dst, 0644, true)
	  	}
	rescue
		puts $!
	end
end

def uninstall
	begin
		File.delete( File.join( INSTDIR, "yaml.rb" ) )
		File.delete( File.join( INSTDIR, "yod.rb" ) )
		File.delete( File.join( INSTDIR, "okay.rb" ) )
		File.delete( File.join( INSTDIR, "okay", "news.rb" ) )
		File.delete( File.join( INSTDIR, "okay", "rpc.rb" ) )
		puts "Uninstalled YAML.rb."
	rescue
		puts "YAML.rb not found."
	end
end

install_proc = :install
install_force = false
install_dir = INSTDIR
opts.each do |opts, arg|
	case opts
		when "--uninstall"
			install_proc = :uninstall
		when "--i-have-racc"
			install_force = true
        when "--destdir"
            install_dir = arg
	end
end
send( install_proc, install_force, install_dir )