class Construqt::Flavour::Ubuntu::Result
Attributes
etc_conntrackd_conntrackd[R]
etc_network_interfaces[R]
etc_network_iptables[R]
Public Class Methods
new(host)
click to toggle source
# 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
Public Instance Methods
add(clazz, block, right, *path)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb, line 497 def empty?(name) not @result[name] end
etc_network_vrrp(ifname)
click to toggle source
# File lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb, line 485 def etc_network_vrrp(ifname) @etc_network_vrrp.get(ifname) end
host()
click to toggle source
# File lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb, line 489 def host @host end
import_fname(fname)
click to toggle source
# 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)
click to toggle source
# 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