Class: DanarchyDeploy::System::Gentoo

Inherits:
Object
  • Object
show all
Defined in:
lib/danarchy_deploy/system/gentoo.rb

Class Method Summary collapse

Class Method Details

.check_hostname(hostname) ⇒ Object



61
62
63
# File 'lib/danarchy_deploy/system/gentoo.rb', line 61

def self.check_hostname(hostname)
  `hostname`.chomp == hostname
end

.emerge_sync(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/danarchy_deploy/system/gentoo.rb', line 40

def self.emerge_sync(options)
  File.open('/tmp/datetime', 'a+') do |f|
    last_sync = f.getbyte ? DateTime.parse(f.read) : (DateTime.now - 2)

    if (DateTime.now - last_sync).to_i != 0
      puts "\nUpdating Portage repo..."
      DanarchyDeploy::Helpers.run_command('emerge --sync --quiet 2>/dev/null', options)
      f.truncate(0)
      f.write DateTime.now
    end

    f.close
  end
end

.new(deployment, options) ⇒ Object



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

def self.new(deployment, options)
  puts "\n" + self.name
  puts 'Gentoo detected! Using emerge.'

  hostname = deployment[:hostname]
  if check_hostname(hostname) == false
    puts "Setting hostname to: #{hostname}"
    set_hostname(hostname)
  end

  installer  = 'emerge --usepkg --buildpkg --quiet --noreplace '
  # This needs cpuid2cpuflags to build make.conf; don't --pretend here.
  system("qlist -I cpuid2cpuflags &>/dev/null || #{installer} cpuid2cpuflags &>/dev/null")
  installer += '--pretend ' if options[:pretend]

  updater  = 'emerge --usepkg --buildpkg --update --deep --newuse --quiet --with-bdeps=y @world'
  updater += ' --pretend' if options[:pretend]

  cleaner  = 'emerge --depclean --quiet '
  cleaner += '--pretend ' if options[:pretend]

  if deployment[:portage]
    if deployment[:portage][:templates]
      puts "\nChecking Portage configs."
      DanarchyDeploy::Templater.new(deployment[:portage][:templates], options)
    end

    emerge_sync(options) if deployment[:portage][:sync]
  end

  [installer, updater, cleaner]
end

.set_hostname(hostname) ⇒ Object



55
56
57
58
59
# File 'lib/danarchy_deploy/system/gentoo.rb', line 55

def self.set_hostname(hostname)
  confd_hostname = "hostname=\"#{hostname}\""
  File.write('/etc/conf.d/hostname', confd_hostname)
  `hostname #{hostname}`
end