Module: DanarchyDeploy::System

Defined in:
lib/danarchy_deploy/system.rb,
lib/danarchy_deploy/system/centos.rb,
lib/danarchy_deploy/system/debian.rb,
lib/danarchy_deploy/system/gentoo.rb,
lib/danarchy_deploy/system/opensuse.rb

Defined Under Namespace

Classes: CentOS, Debian, Gentoo, OpenSUSE

Class Method Summary collapse

Class Method Details

.new(deployment, options) ⇒ Object



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
# File 'lib/danarchy_deploy/system.rb', line 8

def self.new(deployment, options)
  abort('Operating System not defined! Exiting!') if !deployment[:os]
  puts "\n" + self.name

  installer, updater, cleaner = prep_operating_system(deployment, options)
  install_result = nil
  if deployment[:packages] && !deployment[:packages].empty?
    packages = deployment[:packages].join(' ')
    puts "\nInstalling packages..."
    install_result = DanarchyDeploy::Helpers.run_command("#{installer} #{packages}", options)
    puts install_result[:stdout] if install_result[:stdout]
  else
    puts "\nNo packages to install."
  end

  if !options[:pretend]
    puts "\nRunning system updates..."
    updater_result = DanarchyDeploy::Helpers.run_command(updater, options)
    puts updater_result[:stdout] if updater_result[:stdout]
    puts "\nCleaning up unused packages..."
    cleanup_result = DanarchyDeploy::Helpers.run_command(cleaner, options)
    puts cleanup_result[:stdout] if cleanup_result[:stdout]
  end

  deployment
end

.prep_operating_system(deployment, options) ⇒ Object



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
# File 'lib/danarchy_deploy/system.rb', line 36

def self.prep_operating_system(deployment, options)
  (installer, updater, cleaner) = nil
  os = deployment[:os]

  if deployment[:system]
    if deployment[:system][:archives]
      puts " > Deploying system archives"
      DanarchyDeploy::Archiver.new(deployment[:system][:archives], options)
    end

    if deployment[:system][:templates]
      puts "\n > Configuring system templates for #{deployment[:os]}"
      DanarchyDeploy::Templater.new(deployment[:system][:templates], options)

      # Add deployment[:system][:dmcrypt], deployment[:system][:lvm], and deployment[:system][:fstab] here
      deployment[:system][:templates].each do |t|
        if t[:target] == '/etc/fstab'
          t[:variables].each do |v|
            if !Dir.exist?(v[:mountpoint])
              puts "Creating mountpoint: #{v[:mountpoint]}"
              FileUtils.mkdir_p(v[:mountpoint]) if !options[:pretend]
            end
          end
        end
      end

    end
  end

  puts "\n > Mounting Filesystems"
  if !options[:pretend]
    mount_result = DanarchyDeploy::Helpers.run_command('mount -a', options)
    abort('   |! Failed to mount filesystems!') if mount_result[:stderr]
  end

  if os.downcase == 'gentoo'
    (installer, updater, cleaner) = DanarchyDeploy::System::Gentoo.new(deployment, options)
  elsif %w[debian ubuntu].include?(os.downcase)
    (installer, updater, cleaner) = DanarchyDeploy::System::Debian.new(deployment, options)
  elsif os.downcase == 'opensuse'
    puts 'OpenSUSE is not fully supported yet!'
    (installer, updater, cleaner) = DanarchyDeploy::System::OpenSUSE.new(deployment, options)
  elsif %w[centos redhat].include?(os.downcase)
    puts 'CentOS/RedHat is not fully supported yet!'
    (installer, updater, cleaner) = DanarchyDeploy::System::CentOS.new(deployment, options)
  end

  [installer, updater, cleaner]
end