Class: Construqt::Flavour::Ubuntu::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb

Defined Under Namespace

Classes: ArrayWithRight

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Result

Returns a new instance of Result.



459
460
461
462
463
464
465
466
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 459

def initialize(host)
  @host = host
  @etc_network_interfaces = EtcNetworkInterfaces.new(self)
  @etc_network_iptables = EtcNetworkIptables.new
  @etc_conntrackd_conntrackd = EtcConntrackdConntrackd.new(self)
  @etc_network_vrrp = EtcNetworkVrrp.new
  @result = {}
end

Instance Attribute Details

#etc_conntrackd_conntrackdObject (readonly)

Returns the value of attribute etc_conntrackd_conntrackd.



458
459
460
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 458

def etc_conntrackd_conntrackd
  @etc_conntrackd_conntrackd
end

#etc_network_interfacesObject (readonly)

Returns the value of attribute etc_network_interfaces.



458
459
460
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 458

def etc_network_interfaces
  @etc_network_interfaces
end

#etc_network_iptablesObject (readonly)

Returns the value of attribute etc_network_iptables.



458
459
460
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 458

def etc_network_iptables
  @etc_network_iptables
end

Instance Method Details

#add(clazz, block, right, *path) ⇒ Object



487
488
489
490
491
492
493
494
495
496
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 487

def add(clazz, block, right, *path)
  path = File.join(*path)
  throw "not a right #{path}" unless right.respond_to?('right') && right.respond_to?('owner')
  unless @result[path]
    @result[path] = ArrayWithRight.new(right)
    #binding.pry
    #@result[path] << [clazz.xprefix(@host)].compact
  end
  @result[path] << block+"\n"
end

#commitObject



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 518

def commit
  add(EtcNetworkIptables, etc_network_iptables.commitv4, Construqt::Resources::Rights::ROOT_0644, "etc", "network", "iptables.cfg")
  add(EtcNetworkIptables, etc_network_iptables.commitv6, Construqt::Resources::Rights::ROOT_0644, "etc", "network", "ip6tables.cfg")
  add(EtcNetworkInterfaces, etc_network_interfaces.commit, Construqt::Resources::Rights::ROOT_0644, "etc", "network", "interfaces")
  add(EtcConntrackdConntrackd, etc_conntrackd_conntrackd.commit, Construqt::Resources::Rights::ROOT_0644, "etc", "conntrack", "conntrackd.conf")
  @etc_network_vrrp.commit(self)
  out = [<<BASH]
#!/bin/bash
hostname=`hostname`
if [ $hostname != "" ]
then
  hostname=`grep '^\s*[^#]' /etc/hostname`
fi
if [ $hostname != #{@host.name} ]
then
 echo 'You try to run a deploy script on a host which has not the right name $hostname != #{@host.name}'
 exit 47
else
 echo Configure Host #{@host.name}
fi
updates=''
for i in language-pack-en language-pack-de git aptitude traceroute vlan bridge-utils tcpdump mtr-tiny \\
bird keepalived strace iptables conntrack openssl racoon ulogd2 ifenslave conntrackd conntrack bind9
do
 dpkg -l $i > /dev/null 2> /dev/null
 if [ $? != 0 ]
 then
    updates="$updates $i"
 fi
done
apt-get -qq -y install $updates
if [ ! -d /root/construqt.git ]
then
 echo generate history in /root/construqt.git
 git init --bare /root/construqt.git
fi
BASH
  out += @result.map do |fname, block|
    text = block.flatten.select{|i| !(i.nil? || i.strip.empty?) }.join("\n")
    next if text.strip.empty?
    Util.write_str(text, @host.name, fname)
    #          binding.pry
    #
    [
      File.dirname("/#{fname}").split('/')[1..-1].inject(['']) do |res, part|
        res << File.join(res.last, part); res
      end.select{|i| !i.empty? }.map do |i|
        "[ ! -d #{i} ] && mkdir #{i} && chown #{block.right.owner} #{i} && chmod #{directory_mode(block.right.right)} #{i}"
      end,
      "openssl enc -base64 -d > #{import_fname(fname)} <<BASE64", Base64.encode64(text), "BASE64",
      <<BASH]
chown #{block.right.owner} #{import_fname(fname)}
chmod #{block.right.right} #{import_fname(fname)}
if [ ! -f /#{fname} ]
then
    mv #{import_fname(fname)} /#{fname}
    echo created /#{fname} to #{block.right.owner}:#{block.right.right}
else
  diff -rq #{import_fname(fname)} /#{fname}
  if [ $? != 0 ]
  then
    mv #{import_fname(fname)} /#{fname}
    echo updated /#{fname} to #{block.right.owner}:#{block.right.right}
  else
    rm #{import_fname(fname)}
  fi
  git --git-dir /root/construqt.git --work-tree=/ add /#{fname}
fi
BASH
  end.flatten
  out += [<<BASH]
git --git-dir /root/construqt.git config user.name #{ENV['USER']}
git --git-dir /root/construqt.git config user.email #{ENV['USER']}@construqt.net
git --git-dir /root/construqt.git --work-tree=/ commit -q -m '#{ENV['USER']} #{`hostname`.strip} "#{`git log --pretty=format:"%h - %an, %ar : %s" -1`.strip.inspect}"' > /dev/null && echo COMMITED
BASH
  Util.write_str(out.join("\n"), @host.name, "deployer.sh")
end

#directory_mode(mode) ⇒ Object



506
507
508
509
510
511
512
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 506

def directory_mode(mode)
  mode = mode.to_i(8)
  0!=(mode & 06) && (mode = (mode | 01))
  0!=(mode & 060) && (mode = (mode | 010))
  0!=(mode & 0600) && (mode = (mode | 0100))
  "0#{mode.to_s(8)}"
end

#empty?(name) ⇒ Boolean

Returns:

  • (Boolean)


476
477
478
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 476

def empty?(name)
  not @result[name]
end

#etc_network_vrrp(ifname) ⇒ Object



468
469
470
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 468

def etc_network_vrrp(ifname)
  @etc_network_vrrp.get(ifname)
end

#hostObject



472
473
474
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 472

def host
  @host
end

#import_fname(fname) ⇒ Object



514
515
516
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 514

def import_fname(fname)
  '/'+File.dirname(fname)+"/.#{File.basename(fname)}.import"
end

#replace(clazz, block, right, *path) ⇒ Object



498
499
500
501
502
503
504
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 498

def replace(clazz, block, right, *path)
  path = File.join(*path)
  replaced = !!@result[path]
  @result.delete(path) if @result[path]
  add(clazz, block, right, *path)
  replaced
end