Class: Construqt::Flavour::Ubuntu::Result
- Inherits:
-
Object
- Object
- Construqt::Flavour::Ubuntu::Result
- Defined in:
- lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb
Defined Under Namespace
Classes: ArrayWithRight
Instance Attribute Summary collapse
-
#etc_conntrackd_conntrackd ⇒ Object
readonly
Returns the value of attribute etc_conntrackd_conntrackd.
-
#etc_network_interfaces ⇒ Object
readonly
Returns the value of attribute etc_network_interfaces.
-
#etc_network_iptables ⇒ Object
readonly
Returns the value of attribute etc_network_iptables.
Instance Method Summary collapse
- #add(clazz, block, right, *path) ⇒ Object
- #add_component(component) ⇒ Object
- #commit ⇒ Object
- #component_to_packages(component) ⇒ Object
- #directory_mode(mode) ⇒ Object
- #empty?(name) ⇒ Boolean
- #etc_network_vrrp(ifname) ⇒ Object
- #host ⇒ Object
- #import_fname(fname) ⇒ Object
-
#initialize(host) ⇒ Result
constructor
A new instance of Result.
- #replace(clazz, block, right, *path) ⇒ Object
Constructor Details
#initialize(host) ⇒ Result
Returns a new instance of Result.
476 477 478 479 480 481 482 483 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 476 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_conntrackd ⇒ Object (readonly)
Returns the value of attribute etc_conntrackd_conntrackd.
475 476 477 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 475 def etc_conntrackd_conntrackd @etc_conntrackd_conntrackd end |
#etc_network_interfaces ⇒ Object (readonly)
Returns the value of attribute etc_network_interfaces.
475 476 477 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 475 def etc_network_interfaces @etc_network_interfaces end |
#etc_network_iptables ⇒ Object (readonly)
Returns the value of attribute etc_network_iptables.
475 476 477 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 475 def etc_network_iptables @etc_network_iptables end |
Instance Method Details
#add(clazz, block, right, *path) ⇒ Object
508 509 510 511 512 513 514 515 516 517 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 508 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 |
#add_component(component) ⇒ Object
493 494 495 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 493 def add_component(component) @result[component] ||= ArrayWithRight.new(Construqt::Resources::Rights.root_0644(component)) end |
#commit ⇒ Object
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 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 566 def commit add(EtcNetworkIptables, etc_network_iptables.commitv4, Construqt::Resources::Rights.root_0644(Construqt::Resources::Component::FW4), "etc", "network", "iptables.cfg") add(EtcNetworkIptables, etc_network_iptables.commitv6, Construqt::Resources::Rights.root_0644(Construqt::Resources::Component::FW6), "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(Construqt::Resources::Component::CONNTRACKD), "etc", "conntrack", "conntrackd.conf") @etc_network_vrrp.commit(self) components = @result.values.inject({ "language-pack-en" => true, "language-pack-de" => true, "git" => true, "aptitude" => true, "traceroute" => true, "tcpdump" => true, "strace" => true, "lsof" => true, "ifstat" => true, "mtr-tiny" => true, "openssl" => true, }) do |r, block| r.merge(component_to_packages(block.right.component)) end.keys 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 #{components.join(" ")} 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| if host.files next [] if host.files.find{|file| file.path == fname && file.kind_of?(Construqt::Resources::SkipFile) } end 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 |
#component_to_packages(component) ⇒ Object
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 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 539 def component_to_packages(component) cp = Construqt::Resources::Component ret = { cp::UNREF => {}, "Construqt::Flavour::DeviceDelegate" => {}, "Construqt::Flavour::Ubuntu::Bond" => { "ifenslave" => true }, "Construqt::Flavour::VlanDelegate" => { "vlan" => true }, "Construqt::Flavour::Ubuntu::Gre" => { }, "Construqt::Flavour::BridgeDelegate" => { "bridge-utils" => true }, cp::NTP => { "ntpd" => true}, cp::USB_MODESWITCH => { "usb-modeswitch" => true, "usb-modeswitch-data" => true }, cp::VRRP => { "keepalived" => true }, cp::FW4 => { "iptables" => true, "ulogd2" => true }, cp::FW6 => { "iptables" => true, "ulogd2" => true }, cp::IPSEC => { "racoon" => true }, cp::SSH => { "openssh-server" => true }, cp::BGP => { "bird" => true }, cp::OPENVPN => { "openvpn" => true }, cp::DNS => { "bind9" => true }, cp::RADVD => { "radvd" => true }, cp::CONNTRACKD => { "conntrackd" => true, "conntrack" => true }, cp::DHCPRELAY => { "wide-dhcpv6-relay" => true, "dhcp-helper" => true } }[component] throw "Component with name not found #{component}" unless ret ret end |
#directory_mode(mode) ⇒ Object
527 528 529 530 531 532 533 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 527 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
497 498 499 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 497 def empty?(name) not @result[name] end |
#etc_network_vrrp(ifname) ⇒ Object
485 486 487 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 485 def etc_network_vrrp(ifname) @etc_network_vrrp.get(ifname) end |
#host ⇒ Object
489 490 491 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 489 def host @host end |
#import_fname(fname) ⇒ Object
535 536 537 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 535 def import_fname(fname) '/'+File.dirname(fname)+"/.#{File.basename(fname)}.import" end |
#replace(clazz, block, right, *path) ⇒ Object
519 520 521 522 523 524 525 |
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 519 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 |