Sha256: ff7d9b20265dc45d68b32151c3a2c5e93509d1ca68677f2e9d537a08d6db72d8

Contents?: true

Size: 2 KB

Versions: 7

Compression:

Stored size: 2 KB

Contents

module DanarchyDeploy
  module System
    class Gentoo
      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

      private

      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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
danarchy_deploy-0.2.7 lib/danarchy_deploy/system/gentoo.rb
danarchy_deploy-0.2.6 lib/danarchy_deploy/system/gentoo.rb
danarchy_deploy-0.2.5 lib/danarchy_deploy/system/gentoo.rb
danarchy_deploy-0.2.4 lib/danarchy_deploy/system/gentoo.rb
danarchy_deploy-0.2.3 lib/danarchy_deploy/system/gentoo.rb
danarchy_deploy-0.2.2 lib/danarchy_deploy/system/gentoo.rb
danarchy_deploy-0.2.1 lib/danarchy_deploy/system/gentoo.rb