-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenv
More file actions
executable file
·64 lines (53 loc) · 1.49 KB
/
env
File metadata and controls
executable file
·64 lines (53 loc) · 1.49 KB
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
#!/usr/bin/env ruby
require 'optparse'
options = {}
opts = OptionParser.new
opts.banner = "Usage: env [options] command"
opts.on("-e", "--environment ENVIRONMENT", "chimera environment to run in") do |env|
options[:env] = env
end
opts.on("-h", "--help", "display this help") do
puts opts
exit
end
opts.on("-r", "--chroot", "use chroot jail to launch scripts") do |chroot|
options[:chroot] = true
end
opts.parse!
cwd = Dir.pwd
if (options[:env])
environment = options[:env]
elsif (not options[:env] and cwd =~ /chimera\/_env?\/([^\/]+)\//)
environment = $1
else
puts "UNKNOWN ENVIRONMENT"
end
cmd = ARGV[0]
if not cmd
puts opts
puts "NO COMMAND GIVEN TO RUN"
exit
end
pass_on = []
ENV["ENV_NAME"] = environment
ENV["ENV_ROOT"] = "/chimera/env/#{environment}"
index = 1
while index < ARGV.length do
pass_on.push(ARGV[index])
index = index + 1
end
c_pre = "/chimera/env/#{environment}"
chroot = options[:chroot]
if not chroot
ENV["PATH"] = "#{c_pre}/usr/local/sbin:#{c_pre}/usr/local/bin:#{c_pre}/usr/sbin:#{c_pre}/usr/bin:#{c_pre}/sbin:#{c_pre}/bin:" + ENV["PATH"]
ENV["LD_LIBRARY_PATH"] = "#{c_pre}/usr/lib:#{c_pre}/lib"
# ENV["LD_PRELOAD"] = "#{c_pre}/usr/lib:#{c_pre}/lib"
Kernel.exec("#{cmd}", *pass_on)
else
ENV["PATH"] = "#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:" + ENV["PATH"]
ENV["LD_LIBRARY_PATH"] = "/usr/lib:/lib"
Dir.chroot("#{c_pre}")
#Dir.chdir("/usr/sbin")
#puts Dir.entries(".").join("\n")
Kernel.system("#{cmd}", *pass_on)
end