-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.rb
executable file
·180 lines (138 loc) · 3.83 KB
/
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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'fileutils'
require 'pathname'
require 'erb'
require 'ostruct'
require 'yaml'
def env
e = ENV['WEBMO_ENVIRONMENT']
raise StandardError, "No environment variable 'WEBMO_ENVIRONMENT'. Don't know where to install." if e.nil?
unless ['dev', 'test', 'production'].include?(e)
raise StandardError, "WEBMO_ENVIRONMENT must be set to 'dev', 'test' or 'production'. '#{e}' is invalid."
end
e
end
def template(name)
fname = "#{name}.int.erb"
File.read("#{templates_dir}/#{fname}")
end
def deployment_base_dir
"#{__dir__}/deployments/#{env}"
end
def user_base
"#{deployment_base_dir}/user_data"
end
def install_base_dir
"#{deployment_base_dir}/install"
end
def cgi_base
"#{install_base_dir}/cgi-bin"
end
def templates_dir
"#{__dir__}/templates"
end
def globals_result_location
"#{interfaces_dir}/globals.int"
end
def interfaces_dir
"#{cgi_base}/interfaces"
end
def pbs_conf_src
"#{__dir__}/pbs.conf"
end
def pbs_conf_dest
"#{interfaces_dir}/pbs.conf"
end
def enabled_libraries
[ 'gamess', 'gaussian', 'mopac', 'qchem', 'tinker' ]
end
def license
lic = ENV['WEBMO_LICENSE']
raise StandardError, "No environment variable 'WEBMO_LICENSE'. Did you source .webmo.info?" if lic.nil?
lic
end
def version
webmo_tar.to_s.match(/WebMO\.(?<version>.+)\.tar\.gz/)[:version]
end
def template_context(name)
data = {
'globals' => {
'cgi_base' => cgi_base,
'html_base' => "#{install_base_dir}/source",
'license' => license,
'user_base' => user_base,
'version' => version
}
}.merge(YAML.load_file("#{__dir__}/lib_config.yml", aliases: true))
OpenStruct.new(data[name.to_s])
end
def prep_and_untar
FileUtils.mkdir_p(user_base)
FileUtils.mkdir_p(install_base_dir)
Dir.chdir(install_base_dir) do
system("tar -xzf #{webmo_tar} --strip-components=1")
end
add_shebangs
end
def add_shebangs
Dir.glob("#{cgi_base}/**/*.{pm,cgi}") do |file|
original_content = File.read(file)
new_content = <<HEREDOC
#!/usr/bin/perl
# This script is copyright (c) 2019 by WebMO, LLC, all rights reserved
# Its use is subject to the license agreement that can be found at the following
# URL: http://www.webmo.net/license
#{original_content}
HEREDOC
File.open(file, 'w') { |f| f.write(new_content) }
end
end
def configure_queues
int_files = Dir.glob("#{interfaces_dir}/*.int.disabled")
# cleanup the old directories if they exist
if Dir.exist?("#{cgi_base}/queues")
old_dirs = Dir.children("#{cgi_base}/queues").reject { |d| d == 'cpu' }
old_dirs.each do |dir|
FileUtils.rm_rf("#{cgi_base}/queues/#{dir}")
end
end
['cpu'].each do |queue|
dir = "#{cgi_base}/queues/#{queue}"
FileUtils.mkdir_p(dir)
FileUtils.cp_r(int_files, dir)
enabled_libraries.each do |lib|
dest_file = "#{dir}/#{lib}.int"
FileUtils.mv("#{dir}/#{lib}.int.disabled", dest_file)
context = template_context(lib)
context = fix_parallel_context(context) if queue == 'parallel'
content = ERB.new(template(lib)).result(context.instance_eval { binding })
File.open(dest_file, 'w') { |f| f.write(content) }
end
end
end
def fix_parallel_context(context)
context.nodes_min = 2
context.nodes_max = 10
context
end
def add_webmo_profile
FileUtils.copy("#{__dir__}/webmo_profile", "#{user_base}/.webmo_profile")
end
def configure
content = ERB.new(template('globals')).result(template_context('globals').instance_eval { binding })
File.open(globals_result_location, 'w') { |f| f.write(content) }
FileUtils.copy(pbs_conf_src, pbs_conf_dest)
configure_queues
add_webmo_profile
end
def install
prep_and_untar
configure
end
def webmo_tar
tar = Pathname.glob("#{__dir__}/WebMO.*.tar.gz").max
raise StandardError, "Cannot find any WebMo.*.tar.gz in #{__dir__}" if tar.nil?
tar
end
install