mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-04 17:47:00 +03:00
Merge branch 'master' of git.opennebula.org:one
This commit is contained in:
commit
9823b23cd9
@ -2,9 +2,6 @@
|
||||
|
||||
require 'pp'
|
||||
|
||||
PACKAGES=%w{optional sunstone quota cloud ozones_client ozones_server
|
||||
ozones_server_mysql ozones_server_sqlite}
|
||||
|
||||
DEFAULT=%w{optional sunstone quota cloud ozones_server acct}
|
||||
|
||||
if defined?(RUBY_VERSION) && RUBY_VERSION>="1.8.7"
|
||||
@ -12,6 +9,10 @@ if defined?(RUBY_VERSION) && RUBY_VERSION>="1.8.7"
|
||||
|
||||
# xmlparser gem is not compatible with ruby 1.9
|
||||
OPTIONAL=%w{nokogiri}
|
||||
|
||||
if RUBY_VERSION=='1.8.7'
|
||||
OPTIONAL << 'xmlparser'
|
||||
end
|
||||
else
|
||||
SQLITE='sqlite3-ruby --version 1.2.0'
|
||||
OPTIONAL=%w{nokogiri xmlparser}
|
||||
@ -33,6 +34,8 @@ GROUPS={
|
||||
:acct_mysql => ['sequel', 'mysql']
|
||||
}
|
||||
|
||||
PACKAGES=GROUPS.keys
|
||||
|
||||
DISTRIBUTIONS={
|
||||
:debian => {
|
||||
:id => ['Ubuntu', 'Debian'],
|
||||
@ -82,6 +85,15 @@ class String
|
||||
end
|
||||
end
|
||||
|
||||
def installed_gems
|
||||
text=`gem list --no-versions --no-details`
|
||||
if $?.exitstatus!=0
|
||||
nil
|
||||
else
|
||||
text.split(/\s+/)
|
||||
end
|
||||
end
|
||||
|
||||
def try_library(name, error_message)
|
||||
begin
|
||||
require name.to_s
|
||||
@ -107,12 +119,14 @@ def help
|
||||
puts
|
||||
puts "If no parameters are specified then this list will be used:"
|
||||
puts DEFAULT.join(' ')
|
||||
puts
|
||||
puts "Use --check parameter to search for non installed libraries."
|
||||
end
|
||||
|
||||
def get_gems(packages)
|
||||
packages.map do |package|
|
||||
GROUPS[package.to_sym]
|
||||
end.flatten.uniq
|
||||
end.flatten.uniq-installed_gems
|
||||
end
|
||||
|
||||
def detect_distro
|
||||
@ -191,6 +205,88 @@ def install_dependencies(gems, distro)
|
||||
end
|
||||
end
|
||||
|
||||
def run_command(cmd)
|
||||
puts cmd
|
||||
system cmd
|
||||
#system "true"
|
||||
|
||||
if $?!=0
|
||||
puts "Error executing #{cmd}"
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
def install_gems(packages)
|
||||
gems_list=get_gems(packages)
|
||||
|
||||
if gems_list.empty?
|
||||
puts "Gems already installed"
|
||||
exit(0)
|
||||
end
|
||||
|
||||
dist=detect_distro
|
||||
|
||||
install_dependencies(gems_list, dist)
|
||||
|
||||
packages_string=gems_list.join(' ')
|
||||
|
||||
prefix=""
|
||||
|
||||
if dist && dist.last[:gem_env]
|
||||
prefix=dist.last[:gem_env].collect do |name, value|
|
||||
"#{name}=\"#{value}\""
|
||||
end.join(' ')+' '
|
||||
end
|
||||
|
||||
command_string = "#{prefix}gem install --no-ri --no-rdoc"
|
||||
|
||||
install_warning(packages)
|
||||
|
||||
simple_gems=gems_list.select {|g| !(g.match(/\s/)) }
|
||||
if simple_gems and !simple_gems.empty?
|
||||
cmd=command_string+" " << simple_gems.join(' ')
|
||||
run_command(cmd)
|
||||
end
|
||||
|
||||
special_gems=gems_list.select {|g| g.match(/\s/) }
|
||||
special_gems.each do |gem|
|
||||
cmd=command_string+" "<<gem
|
||||
run_command(cmd)
|
||||
end
|
||||
end
|
||||
|
||||
def check_lib(lib)
|
||||
begin
|
||||
require lib
|
||||
true
|
||||
rescue LoadError, Exception
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def check_gems(packages)
|
||||
list=get_gems(packages).compact
|
||||
gems=list.map {|g| g.strip.split(/\s+/).first }
|
||||
|
||||
not_installed=Array.new
|
||||
|
||||
gems.each do |lib_name|
|
||||
if !check_lib(lib_name)
|
||||
not_installed << lib_name
|
||||
end
|
||||
end
|
||||
|
||||
if not_installed.empty?
|
||||
puts "All ruby libraries installed"
|
||||
exit(0)
|
||||
else
|
||||
puts "These ruby libraries are not installed:"
|
||||
puts ""
|
||||
puts "* "+not_installed.join("\n* ")
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
try_library :rubygems, <<-EOT.unindent
|
||||
rubygems required to use this tool
|
||||
|
||||
@ -224,45 +320,37 @@ try_library :mkmf, <<-EOT.unindent
|
||||
* Install the ruby development package for your distro
|
||||
EOT
|
||||
|
||||
if ARGV.include?('-h')
|
||||
help
|
||||
exit(0)
|
||||
|
||||
command=''
|
||||
params=ARGV
|
||||
|
||||
if params.include?('-h')
|
||||
params-=['-h']
|
||||
command='help'
|
||||
elsif params.include?('--check')
|
||||
params-=['--check']
|
||||
command='check'
|
||||
else
|
||||
command='install'
|
||||
end
|
||||
|
||||
if ARGV.length>0
|
||||
packages=ARGV
|
||||
if params.length>0
|
||||
packages=params
|
||||
else
|
||||
packages=DEFAULT
|
||||
end
|
||||
|
||||
gems_list=get_gems(packages)
|
||||
|
||||
dist=detect_distro
|
||||
|
||||
install_dependencies(gems_list, dist)
|
||||
|
||||
packages_string=gems_list.join(' ')
|
||||
|
||||
prefix=""
|
||||
|
||||
if dist && dist.last[:gem_env]
|
||||
prefix=dist.last[:gem_env].collect do |name, value|
|
||||
"#{name}=\"#{value}\""
|
||||
end.join(' ')+' '
|
||||
case command
|
||||
when 'help'
|
||||
help
|
||||
exit(0)
|
||||
when 'check'
|
||||
check_gems(packages)
|
||||
when 'install'
|
||||
install_gems(packages)
|
||||
end
|
||||
|
||||
command_string = "#{prefix}gem install --no-ri --no-rdoc"
|
||||
|
||||
install_warning(packages)
|
||||
|
||||
gems_list.each do |gem|
|
||||
cmd=command_string+" "<<gem
|
||||
puts cmd
|
||||
system cmd
|
||||
|
||||
if $?!=0
|
||||
puts "Error installing #{gem}"
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user