Class: PKGWizard::InitEnv

Inherits:
Command
  • Object
show all
Defined in:
lib/pkg-wizard/commands/init_env.rb

Class Method Summary collapse

Methods inherited from Command

registry, #run

Class Method Details

.abort_if_err(cmd, msg = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/pkg-wizard/commands/init_env.rb', line 67

def self.abort_if_err(cmd, msg = nil)
  msg = "Failed running command: #{cmd}" if msg.nil?
  output = `#{cmd} 2>&1`
  if $? != 0
    $stderr.puts msg
    $stderr.puts output
    exit 1
  end
end

.performObject



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
# File 'lib/pkg-wizard/commands/init_env.rb', line 22

def self.perform
  $stdout.sync = true
  cmd = InitEnv.new
  cmd.banner = "\nUsage: pkgwiz init-env\n\n"
  cmd.parse_options
  if `whoami`.strip.chomp != 'root'
    $stderr.puts 'Run this command as root.'
    exit 1
  end
  if File.exist?('/etc/redhat-release')
    puts '* Installing RHEL/Fedora requirements... '
    rhel_ver = File.readlines('/etc/redhat-release').first.match(/release\s+(\d+)/)[1] rescue nil
    if not rhel_ver
      $stderr.puts "Unsupported RHEL/Fedora distribution"
      exit 1
    end
    if rhel_ver == "6"
      puts "* Installing EPEL 6 repo.."
      abort_if_err "rpm -Uvh #{File.dirname(__FILE__)}/../../../packages/epel-release-6-5.noarch.rpm --force"
      puts "* Installing RBEL 6 repo.." 
      abort_if_err "rpm -Uvh #{File.dirname(__FILE__)}/../../../packages/rbel6-release-1.0-1.el6.noarch.rpm --force"
    elsif rhel_ver == "5"
      puts "* Installing EPEL 5 repo.."
      abort_if_err "rpm -Uvh #{File.dirname(__FILE__)}/../../../packages/epel-release-5-4.noarch.rpm --force"
      puts "* Installing RBEL 5 repo.." 
      abort_if_err "rpm -Uvh #{File.dirname(__FILE__)}/../../../packages/rbel5-release-1.0-1.el5.noarch.rpm --force"
    else
    end
    
    puts "* Installing init script..."
    FileUtils.cp File.dirname(__FILE__) + '/../../../resources/init-scripts/pkgwiz-buildbot', '/etc/init.d/'
    abort_if_err "chkconfig --add pkgwiz-buildbot"

    puts "* Installing dependencies..."
    abort_if_err "yum clean metadata"
    abort_if_err "yum install -y nodejs git rpm-build rpmdevtools mock createrepo yum-utils screen"
  elsif File.exist?('/etc/lsb-release') and \
    File.read('/etc/lsb-release') =~ /DISTRIB_ID=Ubuntu/
      puts '* Installing Ubuntu requirements... '
      abort_if_err "apt-get install -y nodejs git-core mock createrepo rpm yum screen"
  else
    $stderr.puts 'ERROR: Unsupported distribuition'
  end
  puts "* Done"
end