forked from jdleesmiller/gratr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.rb
executable file
·49 lines (41 loc) · 892 Bytes
/
install.rb
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
#! /usr/bin/env ruby
require 'getoptlong'
require 'rbconfig'
require 'ftools'
require 'find'
SRC_BASE = 'lib'
SRC = 'gratr'
INSTDIR = File.join Config::CONFIG['sitedir']
DESTDIR = File.join INSTDIR, SRC
opts = GetoptLong.new( [ "--uninstall", "-u", GetoptLong::NO_ARGUMENT ] )
def install
begin
File.makedirs( DESTDIR )
pwd = Dir.pwd
Dir.chdir(SRC_BASE)
Dir['*.rb'].each do |file|
dst = File.join( INSTDIR, file )
File.install(file, dst, 0644, true)
end
Find.find(SRC) do |file|
dst = File.join( INSTDIR, file )
File.install(file, dst, 0644, true) if file =~ /.rb$/
end
Dir.chdir(pwd)
rescue
puts $!
end
end
def uninstall
begin
puts "Deleting:"
Find.find(DESTDIR) { |file| File.rm_f file,true }
Dir.delete DESTDIR
rescue
end
end
if (opt = opts.get) and opt[0] =~ /^-?-u/
uninstall
else
install
end