specinfra-2.89.0/0000755000004100000410000000000014575463425013633 5ustar www-datawww-dataspecinfra-2.89.0/lib/0000755000004100000410000000000014575463425014401 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra.rb0000644000004100000410000000257714575463425016713 0ustar www-datawww-datarequire 'specinfra/core' include Specinfra include Specinfra::Helper::Os include Specinfra::Helper::Properties include Specinfra::Helper::HostInventory module Specinfra class << self def command Specinfra::CommandFactory.instance end def backend type = Specinfra.configuration.backend if type.nil? if Specinfra.configuration.error_on_missing_backend_type raise "No backend type is specified." end warn "No backend type is specified. Fall back to :exec type." type = :exec end eval "Specinfra::Backend::#{type.to_s.to_camel_case}.instance" end end end if defined?(RSpec) RSpec.configure do |c| c.include(Specinfra::Helper::Configuration) c.add_setting :os, :default => nil c.add_setting :host, :default => nil c.add_setting :ssh, :default => nil c.add_setting :scp, :default => nil c.add_setting :sudo_password, :default => nil c.add_setting :winrm, :default => nil c.add_setting :docker_container, :default => nil c.add_setting :architecture, :default => :x86_64 Specinfra.configuration.defaults.each { |k, v| c.add_setting k, :default => v } c.before :each do example = RSpec.respond_to?(:current_example) ? RSpec.current_example : self.example Specinfra.backend.set_example(example) end end end specinfra-2.89.0/lib/specinfra/0000755000004100000410000000000014575463425016353 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/ec2_metadata.rb0000644000004100000410000000353414575463425021216 0ustar www-datawww-data# -*- coding: utf-8 -*- module Specinfra class Ec2Metadata def initialize(host_inventory) @host_inventory = host_inventory @base_uri = 'http://169.254.169.254/latest/meta-data/' @metadata = {} end def get @metadata = get_metadata self end def [](key) if key.is_a?(Symbol) key = key.to_s end if @metadata[key].nil? begin require "specinfra/ec2_metadata/#{key}" inventory_class = Specinfra::Ec2Metadata.const_get(key.to_s.to_camel_case) @metadata[key] = inventory_class.new(@host_inventory).get rescue LoadError @metadata[key] = nil end end @metadata[key] end def empty? @metadata.empty? end def each keys.each do |k| yield k, @metadata[k] end end def each_key keys.each do |k| yield k end end def each_value keys.each do |k| yield @metadata[k] end end def keys @metadata.keys end def inspect @metadata end private def get_metadata(path='') metadata = {} keys = @host_inventory.backend.run_command("curl -s #{@base_uri}#{path}").stdout.split("\n") keys.each do |key| if key =~ %r{/$} metadata[key[0..-2]] = get_metadata(path + key) else if key =~ %r{=} key = key.split('=')[0] + '/' metadata[key[0..-2]] = get_metadata(path + key) else ret = get_endpoint(path) metadata[key] = get_endpoint(path + key) if ret end end end metadata end def get_endpoint(path) ret = @host_inventory.backend.run_command("curl -s #{@base_uri}#{path}") if ret.success? ret.stdout else nil end end end end specinfra-2.89.0/lib/specinfra/runner.rb0000644000004100000410000000145614575463425020217 0ustar www-datawww-datamodule Specinfra class Runner def self.method_missing(meth, *args) backend = Specinfra.backend processor = Specinfra::Processor if ! os.include?(:family) || os[:family] != 'windows' if processor.respond_to?(meth) processor.send(meth, *args) elsif backend.respond_to?(meth) backend.send(meth, *args) else run(meth, *args) end else if backend.respond_to?(meth) backend.send(meth, *args) else run(meth, *args) end end end private def self.run(meth, *args) cmd = Specinfra.command.get(meth, *args) ret = Specinfra.backend.run_command(cmd) if meth.to_s =~ /^check/ ret.success? else ret end end end end specinfra-2.89.0/lib/specinfra/configuration.rb0000644000004100000410000000332114575463425021546 0ustar www-datawww-datamodule Specinfra module Configuration class << self VALID_OPTIONS_KEYS = [ :backend, :env, :path, :shell, :interactive_shell, :login_shell, :pre_command, :stdout, :stderr, :exit_status, :sudo_path, :disable_sudo, :sudo_options, :docker_container_create_options, :docker_container_exec_options, :docker_image, :docker_url, :lxc, :lxd_remote, :lxd_instance, :request_pty, :ssh_options, :ssh_without_env, :dockerfile_finalizer, :telnet_options, :jail_name, ].freeze def defaults VALID_OPTIONS_KEYS.inject({}) { |o, k| o.merge!(k => send(k)) } end # Define os method explicitly to avoid stack level # too deep caused by Helper::DetectOS#os def os(value=nil) @os = value if value if @os.nil? && defined?(RSpec) && RSpec.configuration.respond_to?(:os) @os = RSpec.configuration.os end @os end def method_missing(meth, val=nil) key = meth.to_s.gsub(/=$/, '') ret = nil begin if ! val.nil? instance_variable_set("@#{key}", val) RSpec.configuration.send(:"#{key}=", val) if defined?(RSpec) end if instance_variable_defined?("@#{key}") ret = instance_variable_get("@#{key}") end rescue NameError ret = nil ensure if ret.nil? && defined?(RSpec) && RSpec.configuration.respond_to?(key) ret = RSpec.configuration.send(key) end end ret end end end end specinfra-2.89.0/lib/specinfra/command_factory.rb0000644000004100000410000000467414575463425022060 0ustar www-datawww-dataclass Specinfra::CommandFactory @@types = nil def self.instance self.new(os) end def initialize(os_info) @os_info = os_info end def get(meth, *args) action, resource_type, subaction = breakdown(meth) method = action method += "_#{subaction}" if subaction command_class = create_command_class(resource_type) if command_class.respond_to?(method) command_class.send(method, *args) else raise NotImplementedError.new("#{method} is not implemented in #{command_class}") end end private def create_command_class(resource_type) family = @os_info[:family] version = @os_info[:release] ? "V#{@os_info[:release].to_i}" : nil common_class = Specinfra::Command base_class = common_class.const_get('Base') os_class = family.nil? ? base_class : common_class.const_get(family.capitalize) if family && version begin version_class = os_class.const_get(version) rescue version_class = os_class.const_get('Base') end elsif family.nil? version_class = os_class elsif family != 'base' && version.nil? version_class = os_class.const_get('Base') end begin command_class = version_class.const_get(resource_type.to_camel_case) rescue end if command_class.nil? ||( (command_class < Specinfra::Command::Base).nil? && (command_class < Specinfra::Command::Windows::Base).nil? ) command_class = base_class.const_get(resource_type.to_camel_case) end begin command_class.create(@os_info) rescue ArgumentError command_class.create end end def breakdown(meth) # Sometimes `selinux_module' type matches `selinux' and error occurs. # Reverse sorting is needed to avoid this problem. types = resource_types.map {|t| t.to_snake_case }.sort.reverse.join('|') md = meth.to_s.match(/^([^_]+)_(#{types})_?(.+)?$/) if md.nil? message = "Could not break down `#{meth}' to appropriate type and method.\n" message += "The method name shoud be in the form of `action_type_subaction'." raise message end return md[1], md[2], md[3] end def resource_types if @@types.nil? @@types = [] Specinfra::Command::Base.subclasses.each do |s| @@types << s.to_s.split(':')[-1] end Specinfra::Command::Windows::Base.subclasses.each do |s| @@types << s.to_s.split(':')[-1] end @@types.uniq! end @@types end end specinfra-2.89.0/lib/specinfra/helper.rb0000644000004100000410000000033014575463425020153 0ustar www-datawww-datarequire 'specinfra/helper/os' require 'specinfra/helper/docker' require 'specinfra/helper/lxc' require 'specinfra/helper/configuration' require 'specinfra/helper/properties' require 'specinfra/helper/host_inventory' specinfra-2.89.0/lib/specinfra/backend.rb0000644000004100000410000000104614575463425020270 0ustar www-datawww-datarequire 'specinfra/backend/base' require 'specinfra/backend/exec' require 'specinfra/backend/ssh' require 'specinfra/backend/powershell/script_helper' require 'specinfra/backend/powershell/command' require 'specinfra/backend/cmd' require 'specinfra/backend/docker' require 'specinfra/backend/dockercli' require 'specinfra/backend/lxc' require 'specinfra/backend/lxd' require 'specinfra/backend/winrm' require 'specinfra/backend/shell_script' require 'specinfra/backend/dockerfile' require 'specinfra/backend/telnet' require 'specinfra/backend/jexec' specinfra-2.89.0/lib/specinfra/host_inventory.rb0000644000004100000410000000247114575463425021776 0ustar www-datawww-datamodule Specinfra class HostInventory KEYS = %w{ memory ec2 hostname domain fqdn platform platform_version filesystem cpu virtualization kernel block_device user group facter ohai mount } include Enumerable attr_reader :backend def self.instance property[:host_inventory] ||= {} self.new(Specinfra.backend, property[:host_inventory]) end def initialize(backend, inventory = {}) @backend = backend @inventory = inventory end def [](key) @inventory[key.to_sym] ||= {} if @inventory[key.to_sym].empty? begin inventory_class = Specinfra::HostInventory.const_get(key.to_s.to_camel_case) @inventory[key.to_sym] = inventory_class.new(self).get rescue @inventory[key.to_sym] = nil end end @inventory[key.to_sym] end def each KEYS.each do |k| yield k, self[k] end end def each_key KEYS.each do |k| yield k end end def each_value KEYS.each do |k| yield self[k] end end end end require "specinfra/host_inventory/base" Specinfra::HostInventory::KEYS.each do |k| require "specinfra/host_inventory/#{k}" end specinfra-2.89.0/lib/specinfra/helper/0000755000004100000410000000000014575463425017632 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/helper/lxc.rb0000644000004100000410000000041714575463425020747 0ustar www-datawww-datamodule Specinfra module Helper module Lxc def self.included(klass) require 'lxc/extra' unless defined?(::LXC::Extra) rescue LoadError fail "LXC client library is not available. Try installing `ruby-lxc' gem." end end end end specinfra-2.89.0/lib/specinfra/helper/configuration.rb0000644000004100000410000000254114575463425023030 0ustar www-datawww-datamodule Specinfra module Helper module Configuration def subject example = RSpec.respond_to?(:current_example) ? RSpec.current_example : self.example example.metadata[:subject] = described_class build_configurations super end # You can create a set of configurations provided to all specs in your spec_helper: # # RSpec.configure { |c| c.pre_command = "source ~/.zshrc" } # # Any configurations you provide with `let(:option_name)` in a spec will # automatically be merged on top of the configurations. # # @example # # describe 'Gem' do # let(:pre_command) { "source ~/.zshrc" } # # %w(pry awesome_print bundler).each do |p| # describe package(p) do # it { should be_installed.by('gem') } # end # end # end def build_configurations Specinfra::Configuration.defaults.keys.each do |c| if self.respond_to?(c.to_sym) value = self.send(c) else value = RSpec.configuration.send(c) if defined?(RSpec) end next if c == :lxc && defined?(Serverspec::Type::Lxc) && value.is_a?(Serverspec::Type::Lxc) Specinfra::Configuration.instance_variable_set("@#{c}", value) end end end end end specinfra-2.89.0/lib/specinfra/helper/set.rb0000644000004100000410000000023614575463425020753 0ustar www-datawww-datamodule Specinfra module Helper module Set def set(param, *value) Specinfra.configuration.send(param, *value) end end end end specinfra-2.89.0/lib/specinfra/helper/docker.rb0000644000004100000410000000042014575463425021422 0ustar www-datawww-datamodule Specinfra module Helper module Docker def self.included(klass) require 'docker' unless defined?(::Docker) rescue LoadError fail "Docker client library is not available. Try installing `docker-api' gem." end end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/0000755000004100000410000000000014575463425021603 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/helper/detect_os/clearlinux.rb0000644000004100000410000000061214575463425024275 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Clearlinux < Specinfra::Helper::DetectOs def detect swupd_info = run_command('swupd info') if swupd_info.success? release = nil swupd_info.stdout.each_line do |line| release = line.gsub(/\s+/, '').split(':').last if line =~ /^Installed version:/ end { :family => 'clearlinux', :release => release } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/gentoo.rb0000644000004100000410000000031414575463425023421 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Gentoo < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/gentoo-release').success? { :family => 'gentoo', :release => nil } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/freebsd.rb0000644000004100000410000000050614575463425023543 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Freebsd < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -sr').stdout ) && uname =~ /FreeBSD/i if uname =~ /(\d+)\./ { :family => 'freebsd', :release => $1 } else { :family => 'freebsd', :release => nil } end end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/redhat.rb0000644000004100000410000000172414575463425023403 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Redhat < Specinfra::Helper::DetectOs def detect # Fedora also has an /etc/redhat-release so the Fedora check must # come before the RedHat check if run_command('ls /etc/fedora-release').success? line = run_command('cat /etc/redhat-release').stdout if line =~ /release (\d[\d]*)/ release = $1 end { :family => 'fedora', :release => release } elsif run_command('ls /etc/redhat-release').success? line = run_command('cat /etc/redhat-release').stdout if line =~ /release (\d[\d.]*)/ release = $1 end { :family => 'redhat', :release => release } elsif run_command('ls /etc/system-release').success? line = run_command('cat /etc/system-release').stdout if line =~ /release (\d[\d.]*)/ release = $1 elsif line =~ /Amazon Linux (\d+)/ release = $1 end { :family => 'amazon', :release => release } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/guix.rb0000644000004100000410000000044214575463425023104 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Guix < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/os-release').success? line = run_command('cat /etc/os-release').stdout if line =~ /ID=guix/ { :family => 'guix', :release => nil } end end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/devuan.rb0000644000004100000410000000144614575463425023417 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Devuan < Specinfra::Helper::DetectOs def detect if (devuan_version = run_command('cat /etc/devuan_version')) && devuan_version.success? distro = nil release = nil if (lsb_release = run_command("lsb_release -ir")) && lsb_release.success? lsb_release.stdout.each_line do |line| distro = line.split(':').last.strip if line =~ /^Distributor ID:/ release = line.split(':').last.strip if line =~ /^Release:/ end else if devuan_version.stdout.chomp =~ /^[[:digit:]]+\.[[:digit:]]+$/ release = devuan_version.stdout.chomp end end distro ||= 'devuan' release ||= nil { :family => distro.gsub(/[^[:alnum:]]/, '').downcase, :release => release } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/coreos.rb0000644000004100000410000000115414575463425023423 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Coreos < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/coreos/update.conf').success? distro = nil release = nil lsb_release = run_command("cat /etc/lsb-release") if lsb_release.success? lsb_release.stdout.each_line do |line| distro = 'coreos' if line.include? "CoreOS" release = line.split('=').last.strip if line =~ /^DISTRIB_RELEASE=/ end end distro ||= 'coreos' release ||= nil { :family => distro.gsub(/[^[:alnum:]]/, '').downcase, :release => release } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/arch.rb0000644000004100000410000000030614575463425023044 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Arch < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/arch-release').success? { :family => 'arch', :release => nil } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/solaris.rb0000644000004100000410000000125114575463425023603 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Solaris < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -sr').stdout) && uname =~ /SunOS/i if uname =~ /5.10/ { :family => 'solaris', :release => 10 } elsif run_command('grep -q "Oracle Solaris 11" /etc/release').success? { :family => 'solaris', :release => 11 } elsif run_command('grep -q "OpenIndiana" /etc/release').success? { :family => 'solaris', :release => 11 } elsif run_command('grep -q SmartOS /etc/release').success? { :family => 'smartos', :release => nil } else { :family => 'solaris', :release => nil } end end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/eos.rb0000644000004100000410000000054014575463425022715 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Eos < Specinfra::Helper::DetectOs def detect # Arista Networks EOS if run_command('ls /etc/Eos-release').success? line = run_command('cat /etc/Eos-release').stdout if line =~ /EOS (\d[\d.]*[A-Z]*)/ release = $1 end { :family => 'eos', :release => release } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/alpine.rb0000644000004100000410000000041614575463425023401 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Alpine < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/alpine-release').success? release = run_command('cat /etc/alpine-release').stdout { :family => 'alpine', :release => release } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/aix.rb0000644000004100000410000000060514575463425022712 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Aix < Specinfra::Helper::DetectOs def detect if run_command('uname -s').stdout =~ /AIX/i line = run_command('uname -rvp').stdout if line =~ /(\d+)\s+(\d+)\s+(.*)/ then { :family => 'aix', :release => "#{$2}.#{$1}", :arch => $3 } else { :family => 'aix', :release => nil, :arch => nil } end end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/plamo.rb0000644000004100000410000000031514575463425023237 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Plamo < Specinfra::Helper::DetectOs def detect if run_command('ls /usr/lib/setup/Plamo-*').success? { :family => 'plamo', :release => nil } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/nixos.rb0000644000004100000410000000032114575463425023264 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Nixos < Specinfra::Helper::DetectOs def detect if run_command('ls /var/run/current-system/sw').success? { :family => 'nixos', :release => nil } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/suse.rb0000644000004100000410000000170314575463425023110 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Suse < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/os-release').success? and run_command('zypper -V').success? line = run_command('cat /etc/os-release').stdout if line =~ /ID="?opensuse/ family = 'opensuse' elsif line =~ /ID="sles"/ family = 'sles' elsif line =~ /ID="sles_sap"/ family = 'sles' end if line =~ /VERSION_ID=\"(\d+\.\d+|\d+)\"/ release = $1 end { :family => family, :release => release } elsif run_command('ls /etc/SuSE-release').success? and run_command('zypper -V').success? line = run_command('cat /etc/SuSE-release').stdout if line =~ /SUSE Linux Enterprise Server (\d+)/ release = $1 family = 'suse' elsif line =~ /openSUSE (\d+\.\d+|\d+)/ release = $1 family = 'opensuse' end { :family => family, :release => release } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/debian.rb0000644000004100000410000000212014575463425023345 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Debian < Specinfra::Helper::DetectOs def detect if (debian_version = run_command('cat /etc/debian_version')) && debian_version.success? distro = nil release = nil if (lsb_release = run_command("lsb_release -ir")) && lsb_release.success? lsb_release.stdout.each_line do |line| distro = line.split(':').last.strip if line =~ /^Distributor ID:/ release = line.split(':').last.strip if line =~ /^Release:/ end elsif (lsb_release = run_command("cat /etc/lsb-release")) && lsb_release.success? lsb_release.stdout.each_line do |line| distro = line.split('=').last.strip if line =~ /^DISTRIB_ID=/ release = line.split('=').last.strip if line =~ /^DISTRIB_RELEASE=/ end else if debian_version.stdout.chomp =~ /^[[:digit:]]+\.[[:digit:]]+$/ release = debian_version.stdout.chomp end end distro ||= 'debian' release ||= nil { :family => distro.gsub(/[^[:alnum:]]/, '').downcase, :release => release } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/openbsd.rb0000644000004100000410000000051114575463425023557 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Openbsd < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -sr').stdout ) && uname =~ /OpenBSD/i if uname =~ /(\d+\.\d+)/ { :family => 'openbsd', :release => $1 } else { :family => 'openbsd', :release => nil } end end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/photon.rb0000644000004100000410000000062614575463425023443 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Photon < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/os-release').success? line = run_command('cat /etc/os-release').stdout if line =~ /ID=photon/ family = 'photon' if line =~ /VERSION_ID=(\d+\.\d+|\d+)/ release = $1 end { :family => family, :release => release } end end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/poky.rb0000644000004100000410000000037314575463425023115 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Poky < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -r').stdout ) && uname =~ /poky/i { :family => 'poky', :release => run_command('cat /etc/version').stdout } end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/esxi.rb0000644000004100000410000000042714575463425023103 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Esxi < Specinfra::Helper::DetectOs def detect if run_command('vmware -v').success? line = run_command('vmware -v').stdout if line =~ /VMware ESXi (.*)/ { :family => 'esxi', :release => $1 } end end end end specinfra-2.89.0/lib/specinfra/helper/detect_os/darwin.rb0000644000004100000410000000050714575463425023416 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Darwin < Specinfra::Helper::DetectOs def detect if ( uname = run_command('uname -sr').stdout ) && uname =~ /Darwin/i if uname =~ /([\d.]+)$/ { :family => 'darwin', :release => $1 } else { :family => 'darwin', :release => nil } end end end end specinfra-2.89.0/lib/specinfra/helper/host_inventory.rb0000644000004100000410000000027614575463425023256 0ustar www-datawww-datarequire 'specinfra/host_inventory' module Specinfra module Helper module HostInventory def host_inventory Specinfra::HostInventory.instance end end end end specinfra-2.89.0/lib/specinfra/helper/os.rb0000644000004100000410000000037614575463425020606 0ustar www-datawww-datarequire 'specinfra/helper/detect_os' module Specinfra module Helper module Os def os property[:os] = Specinfra.configuration.os ? Specinfra.configuration.os : Specinfra.backend.os_info end end end end specinfra-2.89.0/lib/specinfra/helper/detect_os.rb0000644000004100000410000000230114575463425022124 0ustar www-datawww-datamodule Specinfra module Helper class DetectOs def self.detect self.new(Specinfra.backend).detect end def initialize(backend) @backend = backend end def run_command(cmd) @backend.run_command(cmd) end def detect raise NotImplementedError end end end end require 'specinfra/helper/detect_os/aix' require 'specinfra/helper/detect_os/alpine' require 'specinfra/helper/detect_os/arch' require 'specinfra/helper/detect_os/clearlinux' require 'specinfra/helper/detect_os/coreos' require 'specinfra/helper/detect_os/darwin' require 'specinfra/helper/detect_os/debian' require 'specinfra/helper/detect_os/esxi' require 'specinfra/helper/detect_os/eos' require 'specinfra/helper/detect_os/freebsd' require 'specinfra/helper/detect_os/gentoo' require 'specinfra/helper/detect_os/guix' require 'specinfra/helper/detect_os/nixos' require 'specinfra/helper/detect_os/openbsd' require 'specinfra/helper/detect_os/photon' require 'specinfra/helper/detect_os/plamo' require 'specinfra/helper/detect_os/poky' require 'specinfra/helper/detect_os/redhat' require 'specinfra/helper/detect_os/solaris' require 'specinfra/helper/detect_os/suse' specinfra-2.89.0/lib/specinfra/helper/properties.rb0000644000004100000410000000042714575463425022356 0ustar www-datawww-datarequire 'specinfra/properties' module Specinfra module Helper module Properties def property Specinfra::Properties.instance.properties end def set_property(prop) Specinfra::Properties.instance.properties(prop) end end end end specinfra-2.89.0/lib/specinfra/command_result.rb0000644000004100000410000000114314575463425021713 0ustar www-datawww-datamodule Specinfra class CommandResult attr_reader :stdout, :stderr, :exit_status, :exit_signal def initialize(args = {}) @stdout = args[:stdout] || '' @stderr = args[:stderr] || '' @exit_status = args[:exit_status] || 0 @exit_signal = args[:exit_signal] end def success? @exit_status == 0 end def failure? @exit_status != 0 end def [](x) warn "CommandResult#[] is obsolete. Use accessors instead. in #{caller[0]}" case x when :stdout, :stderr, :exit_status, :exit_signal self.send(x) end end end end specinfra-2.89.0/lib/specinfra/command.rb0000644000004100000410000003454414575463425020330 0ustar www-datawww-datamodule Specinfra module Command end end # Module require 'specinfra/command/module' require 'specinfra/command/module/service/init' require 'specinfra/command/module/service/systemd' require 'specinfra/command/module/service/daemontools' require 'specinfra/command/module/service/supervisor' require 'specinfra/command/module/service/upstart' require 'specinfra/command/module/service/runit' require 'specinfra/command/module/service/monit' require 'specinfra/command/module/service/god' require 'specinfra/command/module/service/delegator' require 'specinfra/command/module/service/openrc' require 'specinfra/command/module/systemd' require 'specinfra/command/module/zfs' require 'specinfra/command/module/ss' require 'specinfra/command/module/openrc' # Base require 'specinfra/command/base' require 'specinfra/command/base/bridge' require 'specinfra/command/base/bond' require 'specinfra/command/base/cron' require 'specinfra/command/base/file' require 'specinfra/command/base/fstab' require 'specinfra/command/base/group' require 'specinfra/command/base/host' require 'specinfra/command/base/interface' require 'specinfra/command/base/inventory' require 'specinfra/command/base/ipfilter' require 'specinfra/command/base/ipnat' require 'specinfra/command/base/iptables' require 'specinfra/command/base/ip6tables' require 'specinfra/command/base/kernel_module' require 'specinfra/command/base/lxc_container' require 'specinfra/command/base/kvm_guest' require 'specinfra/command/base/localhost' require 'specinfra/command/base/mail_alias' require 'specinfra/command/base/package' require 'specinfra/command/base/port' require 'specinfra/command/base/ppa' require 'specinfra/command/base/process' require 'specinfra/command/base/routing_table' require 'specinfra/command/base/selinux' require 'specinfra/command/base/selinux_module' require 'specinfra/command/base/service' require 'specinfra/command/base/user' require 'specinfra/command/base/yumrepo' require 'specinfra/command/base/zfs' # Linux (inherit Base) require 'specinfra/command/linux' require 'specinfra/command/linux/base' require 'specinfra/command/linux/base/bridge' require 'specinfra/command/linux/base/bond' require 'specinfra/command/linux/base/file' require 'specinfra/command/linux/base/fstab' require 'specinfra/command/linux/base/interface' require 'specinfra/command/linux/base/inventory' require 'specinfra/command/linux/base/iptables' require 'specinfra/command/linux/base/ip6tables' require 'specinfra/command/linux/base/kernel_module' require 'specinfra/command/linux/base/lxc_container' require 'specinfra/command/linux/base/kvm_guest' require 'specinfra/command/linux/base/package' require 'specinfra/command/linux/base/ppa' require 'specinfra/command/linux/base/selinux' require 'specinfra/command/linux/base/selinux_module' require 'specinfra/command/linux/base/service' require 'specinfra/command/linux/base/yumrepo' require 'specinfra/command/linux/base/zfs' # ESXi (inherit Linux) require 'specinfra/command/esxi' require 'specinfra/command/esxi/base' require 'specinfra/command/esxi/base/package' # RedHat (inherit Linux) require 'specinfra/command/redhat' require 'specinfra/command/redhat/base' require 'specinfra/command/redhat/base/host' require 'specinfra/command/redhat/base/iptables' require 'specinfra/command/redhat/base/package' require 'specinfra/command/redhat/base/port' require 'specinfra/command/redhat/base/selinux_module' require 'specinfra/command/redhat/base/service' require 'specinfra/command/redhat/base/yumrepo' # RedHat V5 (inherit RedHat) require 'specinfra/command/redhat/v5' require 'specinfra/command/redhat/v5/iptables' # RedHat V7 (inherit RedHat) require 'specinfra/command/redhat/v7' require 'specinfra/command/redhat/v7/host' require 'specinfra/command/redhat/v7/service' require 'specinfra/command/redhat/v7/port' # RedHat V8 (inherit RedHat) require 'specinfra/command/redhat/v8' require 'specinfra/command/redhat/v8/yumrepo' require 'specinfra/command/redhat/v8/selinux_module' # Fedora (inherit RedhHat) require 'specinfra/command/fedora' require 'specinfra/command/fedora/base' require 'specinfra/command/fedora/base/service' # Fedora >= V15 (inherit Fedora) require 'specinfra/command/fedora/v15' require 'specinfra/command/fedora/v15/service' # Arista EOS (inherit Fedora) require 'specinfra/command/eos' require 'specinfra/command/eos/base' # Amazon Linux (inherit RedHat) require 'specinfra/command/amazon' require 'specinfra/command/amazon/base' # Amazon Linux V2 (inherit RedHat) require 'specinfra/command/amazon/v2' require 'specinfra/command/amazon/v2/service' require 'specinfra/command/amazon/v2/port' # Amazon Linux V2022 (inherit RedHat) require 'specinfra/command/amazon/v2022' require 'specinfra/command/amazon/v2022/package' require 'specinfra/command/amazon/v2022/port' require 'specinfra/command/amazon/v2022/service' require 'specinfra/command/amazon/v2022/yumrepo' # Amazon Linux V2023 (inherit Amazon Linux V2022) require 'specinfra/command/amazon/v2023' # AIX (inherit Base) require 'specinfra/command/aix' require 'specinfra/command/aix/base' require 'specinfra/command/aix/base/file' require 'specinfra/command/aix/base/group' require 'specinfra/command/aix/base/host' require 'specinfra/command/aix/base/inventory' require 'specinfra/command/aix/base/package' require 'specinfra/command/aix/base/port' require 'specinfra/command/aix/base/service' require 'specinfra/command/aix/base/user' # Alpine (inherit Linux) require 'specinfra/command/alpine' require 'specinfra/command/alpine/base' require 'specinfra/command/alpine/base/host' require 'specinfra/command/alpine/base/package' require 'specinfra/command/alpine/base/process' require 'specinfra/command/alpine/base/service' # Arch (inherit Linux) require 'specinfra/command/arch' require 'specinfra/command/arch/base' require 'specinfra/command/arch/base/service' require 'specinfra/command/arch/base/package' # Clear Linux (inherit Linux) require 'specinfra/command/clearlinux' require 'specinfra/command/clearlinux/base' require 'specinfra/command/clearlinux/base/package' require 'specinfra/command/clearlinux/base/service' # CoreOS (inherit Linux) require 'specinfra/command/coreos' require 'specinfra/command/coreos/base' require 'specinfra/command/coreos/base/service' # Darwin (inherit Base) require 'specinfra/command/darwin' require 'specinfra/command/darwin/base' require 'specinfra/command/darwin/base/file' require 'specinfra/command/darwin/base/host' require 'specinfra/command/darwin/base/interface' require 'specinfra/command/darwin/base/inventory' require 'specinfra/command/darwin/base/service' require 'specinfra/command/darwin/base/package' require 'specinfra/command/darwin/base/port' require 'specinfra/command/darwin/base/process' require 'specinfra/command/darwin/base/user' require 'specinfra/command/darwin/base/group' # Debian (inherit Linux) require 'specinfra/command/debian' require 'specinfra/command/debian/base' require 'specinfra/command/debian/base/package' require 'specinfra/command/debian/base/ppa' require 'specinfra/command/debian/base/port' require 'specinfra/command/debian/base/service' # Debian V8 (inherit Debian) require 'specinfra/command/debian/v8' require 'specinfra/command/debian/v8/service' require 'specinfra/command/debian/v8/port' # Devuan (inherit Debian) require 'specinfra/command/devuan' require 'specinfra/command/devuan/base' # Raspbian (inherit Debian) require 'specinfra/command/raspbian' # Ubuntu (inherit Debian) require 'specinfra/command/ubuntu' require 'specinfra/command/ubuntu/base' require 'specinfra/command/ubuntu/base/ppa' require 'specinfra/command/ubuntu/base/service' # Ubuntu v15.xx (inherit Ubuntu) require 'specinfra/command/ubuntu/v15' require 'specinfra/command/ubuntu/v15/service' # Linux Mint (inherit Ubuntu) require 'specinfra/command/linuxmint' require 'specinfra/command/linuxmint/base' # elementary OS (inherit Ubuntu) require 'specinfra/command/elementary' require 'specinfra/command/elementary/base' # Neon (inherit Ubuntu) require 'specinfra/command/neon' require 'specinfra/command/neon/base' # Cumulus Networks (inherit Debian) require 'specinfra/command/cumulus' require 'specinfra/command/cumulus/base' require 'specinfra/command/cumulus/base/ppa' require 'specinfra/command/cumulus/base/service' # VyOS (inherit Debian) require 'specinfra/command/vyos' require 'specinfra/command/vyos/base' # Gentoo (inherit Linux) require 'specinfra/command/gentoo' require 'specinfra/command/gentoo/base' require 'specinfra/command/gentoo/base/package' require 'specinfra/command/gentoo/base/service' # Guix (inherit Linux) require 'specinfra/command/guix' require 'specinfra/command/guix/base' require 'specinfra/command/guix/base/service' # Plamo (inherit Linux) require 'specinfra/command/plamo' require 'specinfra/command/plamo/base' require 'specinfra/command/plamo/base/package' require 'specinfra/command/plamo/base/service' # NixOS (inherit Linux) require 'specinfra/command/nixos' require 'specinfra/command/nixos/base' require 'specinfra/command/nixos/base/package' require 'specinfra/command/nixos/base/service' # SuSE (inherit Linux) require 'specinfra/command/suse' require 'specinfra/command/suse/base' require 'specinfra/command/suse/base/package' require 'specinfra/command/suse/base/service' # OpenSuSE (inherit SuSE) require 'specinfra/command/opensuse' require 'specinfra/command/opensuse/base' require 'specinfra/command/opensuse/base/service' # SLES (inherit SuSE) require 'specinfra/command/sles' require 'specinfra/command/sles/base' require 'specinfra/command/sles/base/service' require 'specinfra/command/sles/v11' require 'specinfra/command/sles/v11/user' require 'specinfra/command/sles/v12' require 'specinfra/command/sles/v12/service' # FreeBSD (inherit Base) require 'specinfra/command/freebsd' require 'specinfra/command/freebsd/base' require 'specinfra/command/freebsd/base/file' require 'specinfra/command/freebsd/base/group' require 'specinfra/command/freebsd/base/host' require 'specinfra/command/freebsd/base/interface' require 'specinfra/command/freebsd/base/inventory' require 'specinfra/command/freebsd/base/kernel_module' require 'specinfra/command/freebsd/base/package' require 'specinfra/command/freebsd/base/port' require 'specinfra/command/freebsd/base/process' require 'specinfra/command/freebsd/base/service' require 'specinfra/command/freebsd/base/routing_table' require 'specinfra/command/freebsd/base/user' require 'specinfra/command/freebsd/base/zfs' # FreeBSD V6 (inherit FreeBSD) require 'specinfra/command/freebsd/v6' require 'specinfra/command/freebsd/v6/user' require 'specinfra/command/freebsd/v6/package' require 'specinfra/command/freebsd/v6/service' # FreeBSD V7 (inherit FreeBSD) require 'specinfra/command/freebsd/v7' require 'specinfra/command/freebsd/v7/package' require 'specinfra/command/freebsd/v7/service' # FreeBSD V8 (inherit FreeBSD) require 'specinfra/command/freebsd/v8' require 'specinfra/command/freebsd/v8/package' require 'specinfra/command/freebsd/v8/service' # FreeBSD V9 (inherit FreeBSD) require 'specinfra/command/freebsd/v9' require 'specinfra/command/freebsd/v9/package' require 'specinfra/command/freebsd/v9/service' # FreeBSD V11 (inherit FreeBSD) require 'specinfra/command/freebsd/v11' require 'specinfra/command/freebsd/v11/interface' # OpenBSD (inherit Base) require 'specinfra/command/openbsd' require 'specinfra/command/openbsd/base' require 'specinfra/command/openbsd/base/bond' require 'specinfra/command/openbsd/base/bridge' require 'specinfra/command/openbsd/base/file' require 'specinfra/command/openbsd/base/fstab' require 'specinfra/command/openbsd/base/host' require 'specinfra/command/openbsd/base/interface' require 'specinfra/command/openbsd/base/inventory' require 'specinfra/command/openbsd/base/mail_alias' require 'specinfra/command/openbsd/base/package' require 'specinfra/command/openbsd/base/port' require 'specinfra/command/openbsd/base/routing_table' require 'specinfra/command/openbsd/base/service' require 'specinfra/command/openbsd/base/user' # OpenBSD >= V5.7 (inherit OpenBSD) require 'specinfra/command/openbsd/v57' require 'specinfra/command/openbsd/v57/service' # Solaris (inherit Base) require 'specinfra/command/solaris' require 'specinfra/command/solaris/base' require 'specinfra/command/solaris/base/cron' require 'specinfra/command/solaris/base/file' require 'specinfra/command/solaris/base/group' require 'specinfra/command/solaris/base/host' require 'specinfra/command/solaris/base/inventory' require 'specinfra/command/solaris/base/ipfilter' require 'specinfra/command/solaris/base/ipnat' require 'specinfra/command/solaris/base/kernel_module' require 'specinfra/command/solaris/base/package' require 'specinfra/command/solaris/base/port' require 'specinfra/command/solaris/base/service' require 'specinfra/command/solaris/base/user' require 'specinfra/command/solaris/base/zfs' # Solaris 10 (inherit Solaris) require 'specinfra/command/solaris/v10' require 'specinfra/command/solaris/v10/file' require 'specinfra/command/solaris/v10/group' require 'specinfra/command/solaris/v10/host' require 'specinfra/command/solaris/v10/package' require 'specinfra/command/solaris/v10/user' # Solaris 11 (inherit Solaris) require 'specinfra/command/solaris/v11' require 'specinfra/command/solaris/v11/user' # SmartOS (inherit Solaris) require 'specinfra/command/smartos' require 'specinfra/command/smartos/base' require 'specinfra/command/smartos/base/file' require 'specinfra/command/smartos/base/package' require 'specinfra/command/smartos/base/service' # Windows (inherit nothing) require 'specinfra/command/windows' require 'specinfra/command/windows/base' require 'specinfra/command/windows/base/feature' require 'specinfra/command/windows/base/file' require 'specinfra/command/windows/base/group' require 'specinfra/command/windows/base/host' require 'specinfra/command/windows/base/hot_fix' require 'specinfra/command/windows/base/iis_app_pool' require 'specinfra/command/windows/base/iis_website' require 'specinfra/command/windows/base/package' require 'specinfra/command/windows/base/port' require 'specinfra/command/windows/base/process' require 'specinfra/command/windows/base/service' require 'specinfra/command/windows/base/user' require 'specinfra/command/windows/base/registry_key' require 'specinfra/command/windows/base/scheduled_task' # Poky (inherit Linux) require 'specinfra/command/poky' require 'specinfra/command/poky/base' require 'specinfra/command/poky/base/interface' require 'specinfra/command/poky/base/inventory' require 'specinfra/command/poky/base/package' require 'specinfra/command/poky/base/service' specinfra-2.89.0/lib/specinfra/host_inventory/0000755000004100000410000000000014575463425021445 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/host_inventory/group.rb0000644000004100000410000000137714575463425023136 0ustar www-datawww-datamodule Specinfra class HostInventory class Group < Base def get cmd = backend.command.get(:get_inventory_group) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(cmd_ret) groups = {} lines = cmd_ret.split(/\n/) lines.each do |line| group = line.split(':') members = if group[3] group[3].split(',') else [] end groups[group[0]] = { 'name' => group[0], 'gid' => group[2], 'members' => members } end groups end end end end specinfra-2.89.0/lib/specinfra/host_inventory/platform.rb0000644000004100000410000000021414575463425023613 0ustar www-datawww-datamodule Specinfra class HostInventory class Platform < Base def get backend.os_info[:family] end end end end specinfra-2.89.0/lib/specinfra/host_inventory/kernel.rb0000644000004100000410000000126414575463425023255 0ustar www-datawww-datamodule Specinfra class HostInventory class Kernel < Base def get kernel = {} kernel['machine'] = backend.os_info[:arch] cmd = backend.command.get(:get_inventory_kernel) ret = backend.run_command(cmd) if ret.exit_status == 0 kernel = kernel.merge(parse_uname(ret.stdout)) end kernel end def parse_uname(ret) match = ret.match(/^(\w+) (((\d+\.\d+)\.\d+).*)$/) if match name, release, version, major = match.captures Hash['name', name, "release", release, "version", version, "version_major", major] else nil end end end end end specinfra-2.89.0/lib/specinfra/host_inventory/mount.rb0000644000004100000410000000134314575463425023135 0ustar www-datawww-datamodule Specinfra class HostInventory class Mount < Base def get cmd = backend.command.get(:get_inventory_mount) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(ret) mounts = [] ret.each_line do |line| mount = {} if line =~ /^(.+)\s+(.+)\s+(.+)\s+(.+)\s+(\d+)\s+(\d+)$/ mount['device'] = $1 mount['point'] = $2 mount['type'] = $3 mount['options'] = $4.split(',') mount['dump'] = $5 mount['pass'] = $6 end mounts << mount end mounts end end end end specinfra-2.89.0/lib/specinfra/host_inventory/user.rb0000644000004100000410000000130214575463425022744 0ustar www-datawww-datamodule Specinfra class HostInventory class User < Base def get cmd = backend.command.get(:get_inventory_user) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(cmd_ret) users = {} lines = cmd_ret.split(/\n/) lines.each do |line| user = line.split(':') users[user[0]] = { 'name' => user[0], 'uid' => user[2], 'gid' => user[3], 'gecos' => user[4], 'directory' => user[5], 'shell' => user[6] } end users end end end end specinfra-2.89.0/lib/specinfra/host_inventory/base.rb0000644000004100000410000000033614575463425022706 0ustar www-datawww-datamodule Specinfra class HostInventory class Base def initialize(host_inventory) @host_inventory = host_inventory end def backend @host_inventory.backend end end end end specinfra-2.89.0/lib/specinfra/host_inventory/hostname.rb0000644000004100000410000000047114575463425023612 0ustar www-datawww-datamodule Specinfra class HostInventory class Hostname < Base def get cmd = backend.command.get(:get_inventory_hostname) result = backend.run_command(cmd) if result.exit_status == 0 result.stdout.strip else nil end end end end end specinfra-2.89.0/lib/specinfra/host_inventory/filesystem.rb0000644000004100000410000000153214575463425024157 0ustar www-datawww-datamodule Specinfra class HostInventory class Filesystem < Base def get cmd = backend.command.get(:get_inventory_filesystem) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(ret) filesystem = {} ret.each_line do |line| next if line =~ /^Filesystem\s+/ if line =~ /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ device = $1 filesystem[device] = {} filesystem[device]['kb_size'] = $2 filesystem[device]['kb_used'] = $3 filesystem[device]['kb_available'] = $4 filesystem[device]['percent_used'] = $5 filesystem[device]['mount'] = $6 end end filesystem end end end end specinfra-2.89.0/lib/specinfra/host_inventory/memory.rb0000644000004100000410000000616714575463425023314 0ustar www-datawww-datamodule Specinfra class HostInventory class Memory < Base def get cmd = backend.command.get(:get_inventory_memory) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(ret) memory = { 'swap' => {} } ret.each_line do |line| case line when /^SwapCached:\s+(\d+) (.+)$/ memory['swap']['cached'] = "#{$1}#{$2}" when /^SwapTotal:\s+(\d+) (.+)$/ memory['swap']['total'] = "#{$1}#{$2}" when /^SwapFree:\s+(\d+) (.+)$/ memory['swap']['free'] = "#{$1}#{$2}" when /^MemTotal:\s+(\d+) (.+)$/ memory['total'] = "#{$1}#{$2}" when /^MemFree:\s+(\d+) (.+)$/ memory['free'] = "#{$1}#{$2}" when /^Buffers:\s+(\d+) (.+)$/ memory['buffers'] = "#{$1}#{$2}" when /^Cached:\s+(\d+) (.+)$/ memory['cached'] = "#{$1}#{$2}" when /^Active:\s+(\d+) (.+)$/ memory['active'] = "#{$1}#{$2}" when /^Inactive:\s+(\d+) (.+)$/ memory['inactive'] = "#{$1}#{$2}" when /^Dirty:\s+(\d+) (.+)$/ memory['dirty'] = "#{$1}#{$2}" when /^Writeback:\s+(\d+) (.+)$/ memory['writeback'] = "#{$1}#{$2}" when /^AnonPages:\s+(\d+) (.+)$/ memory['anon_pages'] = "#{$1}#{$2}" when /^Mapped:\s+(\d+) (.+)$/ memory['mapped'] = "#{$1}#{$2}" when /^Slab:\s+(\d+) (.+)$/ memory['slab'] = "#{$1}#{$2}" when /^SReclaimable:\s+(\d+) (.+)$/ memory['slab_reclaimable'] = "#{$1}#{$2}" when /^SUnreclaim:\s+(\d+) (.+)$/ memory['slab_unreclaim'] = "#{$1}#{$2}" when /^PageTables:\s+(\d+) (.+)$/ memory['page_tables'] = "#{$1}#{$2}" when /^NFS_Unstable:\s+(\d+) (.+)$/ memory['nfs_unstable'] = "#{$1}#{$2}" when /^Bounce:\s+(\d+) (.+)$/ memory['bounce'] = "#{$1}#{$2}" when /^CommitLimit:\s+(\d+) (.+)$/ memory['commit_limit'] = "#{$1}#{$2}" when /^Committed_AS:\s+(\d+) (.+)$/ memory['committed_as'] = "#{$1}#{$2}" when /^VmallocTotal:\s+(\d+) (.+)$/ memory['vmalloc_total'] = "#{$1}#{$2}" when /^VmallocUsed:\s+(\d+) (.+)$/ memory['vmalloc_used'] = "#{$1}#{$2}" when /^VmallocChunk:\s+(\d+) (.+)$/ memory['vmalloc_chunk'] = "#{$1}#{$2}" when /^AnonHugePages:\s+(\d+) (.+)$/ memory['annon_huge_pages'] = "#{$1}#{$2}" when /^HugePages_Total:\s+(\d+)$/ memory['huge_pages_total'] = "#{$1}" when /^HugePages_Free:\s+(\d+)$/ memory['huge_pages_free'] = "#{$1}" when /^HugePages_Rsvd:\s+(\d+)$/ memory['huge_pages_rsvd'] = "#{$1}" when /^HugePages_Surp:\s+(\d+)$/ memory['huge_pages_surp'] = "#{$1}" when /^Hugepagesize:\s+(\d+) (.+)$/ memory['huge_page_size'] = "#{$1}#{$2}" end end memory end end end end specinfra-2.89.0/lib/specinfra/host_inventory/ohai.rb0000644000004100000410000000061214575463425022711 0ustar www-datawww-datamodule Specinfra class HostInventory class Ohai < Base def get begin require 'json' rescue LoadError return nil end begin ret = backend.run_command('ohai --log_level error') rescue StandardError nil end ret.exit_status.zero? ? JSON.parse(ret.stdout) : nil end end end end specinfra-2.89.0/lib/specinfra/host_inventory/cpu.rb0000644000004100000410000000534714575463425022572 0ustar www-datawww-datamodule Specinfra class HostInventory class Cpu < Base def get cmd = backend.command.get(:get_inventory_cpu) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(cmd_ret) cpuinfo = {} cpus = cmd_ret.split(/[^^]processor/) cpuinfo['total'] = cpus.length.to_s cpus.each_with_index do |cpu, idx| idx = idx.to_s cpuinfo[idx] = {} cpu.each_line do |line| case line when /^vendor_id\s*:\s+(.+)$/ cpuinfo[idx]['vendor_id'] = $1 when /^cpu family\s*:\s+(\d+)$/ cpuinfo[idx]['cpu_family'] = $1 when /^model\s*:\s+(\d+)$/ cpuinfo[idx]['model'] = $1 when /^model\sname\s*:\s+(.+)$/ cpuinfo[idx]['model_name'] = $1 when /^stepping\s*:\s+(\d+)$/ cpuinfo[idx]['stepping'] = $1 when /^microcode\s*:\s+(.+)$/ cpuinfo[idx]['microcode'] = $1 when /^cpu MHz\s*:\s+(.+)$/ cpuinfo[idx]['cpu_mhz'] = $1 when /^cache size\s*:\s+(\d+) (.+)$/ cpuinfo[idx]['cache_size'] = "#{$1}#{$2}" when /^physical id\s*:\s+(\d+)$/ cpuinfo[idx]['physical_id'] = $1 when /^siblings\s*:\s+(\d+)$/ cpuinfo[idx]['siblings'] = $1 when /^core id\s*:\s+(\d+)$/ cpuinfo[idx]['core_id'] = $1 when /^cpu cores\s*:\s+(\d+)$/ cpuinfo[idx]['cpu_cores'] = $1 when /^apicid\s*:\s+(\d+)$/ cpuinfo[idx]['apicid'] = $1 when /^initial apicid\s*:\s+(\d+)$/ cpuinfo[idx]['initial_apicid'] = $1 when /^fpu\s*:\s+(.+)$/ cpuinfo[idx]['fpu'] = $1 when /^fpu_exception\s*:\s+(.+)$/ cpuinfo[idx]['fpu_exception'] = $1 when /^cpuid level\s*:\s+(\d+)$/ cpuinfo[idx]['cpuid_level'] = $1 when /^wp\s*:\s+(.+)$/ cpuinfo[idx]['wp'] = $1 when /^flags\s*:\s+(.+)$/ cpuinfo[idx]['flags'] = $1.split(/\s/) when /^bogomips\s*:\s+(.+)$/ cpuinfo[idx]['bogomips'] = $1 when /^clflush size\s*:\s+(\d+)$/ cpuinfo[idx]['clflush_size'] = $1 when /^cache_alignment\s*:\s+(\d+)$/ cpuinfo[idx]['cache_alignment'] = $1 when /^address sizes\s*:\s+(.+)$/ cpuinfo[idx]['address_sizes'] = $1 when /^power management\s*:\s+(.*)$/ cpuinfo[idx]['power_management'] = $1 end end end cpuinfo end end end end specinfra-2.89.0/lib/specinfra/host_inventory/block_device.rb0000644000004100000410000000163314575463425024406 0ustar www-datawww-datamodule Specinfra class HostInventory class BlockDevice < Base # examples: # /sys/block/sda/size 10000 # /sys/block/sr0/device/model CD-ROM BLOCK_DEVICE_REGEX = %r|\A/sys/block/(\w+)/(\w+)(?:/(\w+))?\t(.+)\z| def get cmd = backend.command.get(:get_inventory_block_device) ret = backend.run_command(cmd) if ret.exit_status == 0 parse(ret.stdout) else nil end end def parse(ret) block_device = {} ret.each_line do |line| line.strip! if m = line.match(BLOCK_DEVICE_REGEX) device = m[1].to_s check = m[3].nil? ? m[2].to_s : m[3].to_s value = m[4].to_s block_device[device] = {} if block_device[device].nil? block_device[device][check] = value end end block_device end end end end specinfra-2.89.0/lib/specinfra/host_inventory/facter.rb0000644000004100000410000000047614575463425023245 0ustar www-datawww-datamodule Specinfra class HostInventory class Facter < Base require 'yaml' def get begin ret = backend.run_command('facter --puppet --yaml') rescue StandardError nil end ret.exit_status == 0 ? YAML.load(ret.stdout) : nil end end end end specinfra-2.89.0/lib/specinfra/host_inventory/platform_version.rb0000644000004100000410000000023214575463425025360 0ustar www-datawww-datamodule Specinfra class HostInventory class PlatformVersion < Base def get backend.os_info[:release] end end end end specinfra-2.89.0/lib/specinfra/host_inventory/virtualization.rb0000644000004100000410000000275714575463425025071 0ustar www-datawww-datamodule Specinfra class HostInventory class Virtualization < Base def get res = {} ## docker if backend.run_command('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit').success? res[:system] = 'docker' return res end ## OpenVZ on Linux if backend.run_command('test -d /proc/vz -a ! -d /proc/bc').success? res[:system] = 'openvz' return res end cmd = backend.command.get(:get_inventory_system_product_name) ret = backend.run_command(cmd) if ret.success? and (parsed = parse_system_product_name(ret.stdout)) res[:system] = parsed return res end ret = backend.run_command('systemd-detect-virt') if ret.success? res[:system] = parse_systemd_detect_virt_output(ret.stdout) end res end def parse_system_product_name(ret) product_name = case ret when /.*(VMware Virtual Platform|VMware7,1)/ 'vmware' when /.*VirtualBox/ 'vbox' when /.*KVM/ 'kvm' when /.*OpenStack/ 'openstack' else nil end product_name end def parse_systemd_detect_virt_output(ret) detected = ret.strip case detected when 'vmware', 'kvm', 'qemu' detected when 'oracle' 'vbox' end end end end end specinfra-2.89.0/lib/specinfra/host_inventory/domain.rb0000644000004100000410000000046514575463425023246 0ustar www-datawww-datamodule Specinfra class HostInventory class Domain < Base def get cmd = backend.command.get(:get_inventory_domain) result = backend.run_command(cmd) if result.exit_status == 0 result.stdout.strip else nil end end end end end specinfra-2.89.0/lib/specinfra/host_inventory/ec2.rb0000644000004100000410000000030014575463425022434 0ustar www-datawww-datarequire 'specinfra/ec2_metadata' module Specinfra class HostInventory class Ec2 < Base def get Specinfra::Ec2Metadata.new(@host_inventory).get end end end end specinfra-2.89.0/lib/specinfra/host_inventory/fqdn.rb0000644000004100000410000000046114575463425022723 0ustar www-datawww-datamodule Specinfra class HostInventory class Fqdn < Base def get cmd = backend.command.get(:get_inventory_fqdn) result = backend.run_command(cmd) if result.exit_status == 0 result.stdout.strip else nil end end end end end specinfra-2.89.0/lib/specinfra/ext.rb0000644000004100000410000000007514575463425017502 0ustar www-datawww-datarequire 'specinfra/ext/class' require 'specinfra/ext/string' specinfra-2.89.0/lib/specinfra/core.rb0000644000004100000410000000062214575463425017630 0ustar www-datawww-datarequire 'specinfra/version' require 'specinfra/ext' require 'specinfra/helper' require 'specinfra/command' require 'specinfra/command_factory' require 'specinfra/command_result' require 'specinfra/backend' require 'specinfra/configuration' require 'specinfra/runner' require 'specinfra/processor' module Specinfra class << self def configuration Specinfra::Configuration end end end specinfra-2.89.0/lib/specinfra/ext/0000755000004100000410000000000014575463425017153 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/ext/string.rb0000644000004100000410000000045614575463425021013 0ustar www-datawww-dataclass String def to_snake_case self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end def to_camel_case return self if self !~ /_/ && self =~ /[A-Z]+.*/ split('_').map{|e| e.capitalize}.join end end specinfra-2.89.0/lib/specinfra/ext/class.rb0000644000004100000410000000034614575463425020610 0ustar www-datawww-dataclass Class def subclasses result = [] ObjectSpace.each_object(Class) do |k| next unless k < self next if k.respond_to?(:singleton_class?) && k.singleton_class? result << k end result end end specinfra-2.89.0/lib/specinfra/version.rb0000644000004100000410000000022414575463425020363 0ustar www-datawww-datamodule Specinfra VERSION = "2.89.0" def self.ruby_is_older_than?(*version) (RUBY_VERSION.split('.').map(&:to_i) <=> version) < 0 end end specinfra-2.89.0/lib/specinfra/command/0000755000004100000410000000000014575463425017771 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/clearlinux/0000755000004100000410000000000014575463425022137 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/clearlinux/base/0000755000004100000410000000000014575463425023051 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/clearlinux/base/service.rb0000644000004100000410000000025014575463425025033 0ustar www-datawww-dataclass Specinfra::Command::Clearlinux::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::Systemd end endspecinfra-2.89.0/lib/specinfra/command/clearlinux/base/package.rb0000644000004100000410000000106514575463425024773 0ustar www-datawww-dataclass Specinfra::Command::Clearlinux::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) "swupd bundle-list --quiet | grep -w #{escape(package)}" end alias :check_is_installed_by_swupd :check_is_installed def get_version(package, opts=nil) "true" end def install(package, version=nil, option='') "swupd bundle-add --quiet #{package}" end def remove(package, option='') "swupd bundle-remove --quiet #{option} #{package}" end end end specinfra-2.89.0/lib/specinfra/command/clearlinux/base.rb0000644000004100000410000000012014575463425023367 0ustar www-datawww-dataclass Specinfra::Command::Clearlinux::Base < Specinfra::Command::Linux::Base endspecinfra-2.89.0/lib/specinfra/command/windows/0000755000004100000410000000000014575463425021463 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/windows/base/0000755000004100000410000000000014575463425022375 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/windows/base/group.rb0000644000004100000410000000057514575463425024065 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Group < Specinfra::Command::Windows::Base class << self def check_exists(group) group_id, domain = windows_account group Backend::PowerShell::Command.new do using 'find_group.ps1' exec "(FindGroup -groupName '#{group_id}'#{domain.nil? ? "" : " -domain '#{domain}'"}) -ne $null" end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/iis_app_pool.rb0000644000004100000410000000420014575463425025373 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::IisAppPool < Specinfra::Command::Windows::Base class << self def check_exists(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "@(FindIISAppPool -name '#{name}').count -gt 0" end end def check_has_dotnet_version(name, dotnet) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').managedRuntimeVersion -match 'v#{dotnet}'" end end def check_has_32bit_enabled(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').enable32BitAppOnWin64 -eq $true" end end def check_has_idle_timeout(name, minutes) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').processModel.idleTimeout.Minutes -eq #{minutes}" end end def check_has_identity_type(name, type) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').processModel.identityType -eq '#{type}'" end end def check_has_user_profile(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').processModel.loadUserProfile -eq $true" end end def check_has_username(name, username) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').processModel.username -eq '#{username}'" end end def check_has_periodic_restart(name, minutes) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').recycling.periodicRestart.time.TotalMinutes -eq #{minutes}" end end def check_has_managed_pipeline_mode(name, mode) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISAppPool -name '#{name}').managedPipelineMode -eq '#{mode}'" end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/process.rb0000644000004100000410000000174114575463425024403 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Process < Specinfra::Command::Windows::Base class << self def check_process(process) Backend::PowerShell::Command.new do exec "(Get-Process '#{process}') -ne $null" end end def get(process, opts) column = opts[:format].chomp '=' case column when 'pid' # map 'pid' to its windows equivalent get_process_property(process, 'processid') when 'user' %Q!gwmi win32_process -filter "name = '#{process}'" | select -first 1 | %{$_.getowner().user}! when 'group' # no concept of process group on Windows raise NotImplementedError.new('Unable to get process group on Windows') else get_process_property(process, column) end end private def get_process_property(process, property) %Q!Get-WmiObject Win32_Process -Filter "name = '#{process}'" | select -First 1 #{property} -ExpandProperty #{property}! end end end specinfra-2.89.0/lib/specinfra/command/windows/base/service.rb0000644000004100000410000000303114575463425024357 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Service < Specinfra::Command::Windows::Base class << self def check_is_installed(service) Backend::PowerShell::Command.new do using 'find_service.ps1' exec "@(FindService -name '#{service}').count -gt 0" end end def check_has_start_mode(service, mode) Backend::PowerShell::Command.new do using 'find_service.ps1' exec "'#{mode}' -match (FindService -name '#{service}').StartMode -and (FindService -name '#{service}') -ne $null" end end def check_is_enabled(service, level=nil) Backend::PowerShell::Command.new do using 'find_service.ps1' exec "(FindService -name '#{service}').StartMode -eq 'Auto'" end end def check_is_running(service) Backend::PowerShell::Command.new do using 'find_service.ps1' exec "(FindService -name '#{service}').State -eq 'Running'" end end def check_has_property(service, property) command = [] property.keys.each do |key| value= property[key] command << "(FindService -name '#{service}').#{key} -eq '#{value}'" end executable = command.join(' -and ') Backend::PowerShell::Command.new do using 'find_service.ps1' exec executable end end def get_property(service) Backend::PowerShell::Command.new do using 'find_service.ps1' exec "(FindService -name '#{service}') | Select-Object *" end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/feature.rb0000644000004100000410000000074214575463425024360 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Feature < Specinfra::Command::Windows::Base class << self def check_is_enabled(name, provider) if provider.nil? cmd = "@(ListWindowsFeatures -feature #{name}).count -gt 0" else cmd = "@(ListWindowsFeatures -feature #{name} -provider #{provider.to_s}).count -gt 0" end Backend::PowerShell::Command.new do using 'list_windows_features.ps1' exec cmd end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/user.rb0000644000004100000410000000156514575463425023707 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::User < Specinfra::Command::Windows::Base class << self def check_exists(user) user_id, domain = windows_account user Backend::PowerShell::Command.new do using 'find_user.ps1' exec "(FindUser -userName '#{user_id}'#{domain.nil? ? "" : " -domain '#{domain}'"}) -ne $null" end end def check_belongs_to_group(user, group) user_id, user_domain = windows_account user group_id, group_domain = windows_account group Backend::PowerShell::Command.new do using 'find_user.ps1' using 'find_group.ps1' using 'find_usergroup.ps1' exec "(FindUserGroup -userName '#{user_id}'#{user_domain.nil? ? "" : " -userDomain '#{user_domain}'"} -groupName '#{group_id}'#{group_domain.nil? ? "" : " -groupDomain '#{group_domain}'"}) -ne $null" end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/registry_key.rb0000644000004100000410000000337614575463425025453 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::RegistryKey < Specinfra::Command::Windows::Base class << self REGISTRY_KEY_TYPES = { :type_string => 'String', :type_binary => 'Binary', :type_dword => 'DWord', :type_qword => 'QWord', :type_multistring => 'MultiString', :type_expandstring => 'ExpandString' } def check_exists(key_name) cmd = "(Get-Item 'Registry::#{key_name}') -ne $null" create_command cmd end def check_has_property(key_name, key_property) cmd = "(Get-Item 'Registry::#{key_name}').GetValueKind('#{key_property[:name]}') -eq '#{get_key_type(key_property[:type])}'" create_command cmd end def check_has_value(key_name, key_property) value = convert_key_property_value key_property cmd = "(Compare-Object (Get-Item 'Registry::#{key_name}').GetValue('#{key_property[:name]}') #{value}) -eq $null" create_command cmd end private def do_not_convert?(key_type) key_type.to_s =~ /_converted/i end def get_key_type(key_type) REGISTRY_KEY_TYPES[key_type.to_s.gsub("_converted",'').to_sym] end def convert_key_property_value property return property[:value] if do_not_convert? property[:type] case property[:type] when :type_binary byte_array = [property[:value]].pack('H*').bytes.to_a "([byte[]] #{byte_array.join(',')})" when :type_dword [property[:value].rjust(8, '0').scan(/[0-9a-f]{2}/i).reverse.join].pack("H*").unpack("l").first when :type_qword property[:value].hex else string_array = property[:value].split("\n").map {|s| "'#{s}'"}.reduce {|acc, s| "#{acc},#{s}"} "@(#{string_array})" end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/package.rb0000644000004100000410000000137314575463425024321 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Package < Specinfra::Command::Windows::Base class << self def check_is_installed(package, version=nil) version_selection = version.nil? ? "" : "-appVersion '#{version}'" Backend::PowerShell::Command.new do using 'find_installed_application.ps1' exec "(FindInstalledApplication -appName '#{package}' #{version_selection}) -eq $true" end end def check_is_installed_by_gem(name, version=nil, gem_binary="gem") version_selection = version.nil? ? "" : "-gemVersion '#{version}'" Backend::PowerShell::Command.new do using 'find_installed_gem.ps1' exec "(FindInstalledGem -gemName '#{name}' #{version_selection}) -eq $true" end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/host.rb0000644000004100000410000000170014575463425023675 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Host < Specinfra::Command::Windows::Base class << self def check_is_resolvable(name, type) if type == "hosts" cmd = "@(Select-String -path (Join-Path -Path $($env:windir) -ChildPath 'system32/drivers/etc/hosts') -pattern '#{name}\\b').count -gt 0" else cmd = "@([System.Net.Dns]::GetHostAddresses('#{name}')).count -gt 0" end Backend::PowerShell::Command.new { exec cmd } end def check_is_reachable(host, port, proto, timeout) if port.nil? Backend::PowerShell::Command.new do exec "(New-Object System.Net.NetworkInformation.Ping).send('#{host}').Status -eq 'Success'" end else Backend::PowerShell::Command.new do using 'is_remote_port_listening.ps1' exec"(IsRemotePortListening -hostname #{host} -port #{port} -timeout #{timeout} -proto #{proto}) -eq $true" end end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/iis_website.rb0000644000004100000410000000413014575463425025226 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::IisWebsite < Specinfra::Command::Windows::Base class << self def check_is_enabled(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISWebsite -name '#{name}').serverAutoStart -eq $true" end end def check_is_installed(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "@(FindIISWebsite -name '#{name}').count -gt 0" end end def check_is_running(name) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISWebsite -name '#{name}').state -eq 'Started'" end end def check_is_in_app_pool(name, app_pool) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindIISWebsite -name '#{name}').applicationPool -match '#{app_pool}'" end end def check_has_physical_path(name, path) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "[System.Environment]::ExpandEnvironmentVariables( ( FindIISWebsite -name '#{name}' ).physicalPath ).replace('\\', '/' ) -eq ('#{path}'.trimEnd('/').replace('\\', '/'))" end end def check_has_site_bindings(name, port, protocol, ipaddress, host_header) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindSiteBindings -name '#{name}' -protocol '#{protocol}' -hostHeader '#{host_header}' -port #{port} -ipAddress '#{ipaddress}').count -gt 0" end end def check_has_virtual_dir(name, vdir, path) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindSiteVirtualDir -name '#{name}' -vdir '#{vdir}' -path '#{path}') -eq $true" end end def check_has_site_application(name, app, pool, physical_path) Backend::PowerShell::Command.new do using 'find_iis_component.ps1' exec "(FindSiteApplication -name '#{name}' -app '#{app}' -pool '#{pool}' -physicalPath '#{physical_path}') -eq $true" end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/file.rb0000644000004100000410000000735614575463425023654 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::File < Specinfra::Command::Windows::Base class << self def check_exists(file) cmd = %Q!Test-Path -Path "#{file}"! Backend::PowerShell::Command.new do exec cmd end end def check_is_file(file) cmd = item_has_attribute file, 'Archive' Backend::PowerShell::Command.new do exec cmd end end def check_is_directory(dir) cmd = item_has_attribute dir, 'Directory' Backend::PowerShell::Command.new do exec cmd end end def check_is_hidden(file) cmd = item_has_attribute file, 'Hidden' Backend::PowerShell::Command.new do exec cmd end end def check_is_readonly(file) cmd = item_has_attribute file, 'ReadOnly' Backend::PowerShell::Command.new do exec cmd end end def check_is_system(file) cmd = item_has_attribute file, 'System' Backend::PowerShell::Command.new do exec cmd end end def get_content(file) %Q!Get-Content("#{file}") | Write-Host! end def get_md5sum(file) <<-EOT $md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider $sum = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes("#{file}"))) echo $sum.ToLower().Replace("-","") EOT end def check_is_accessible_by_user(file, user, access) case access when 'r' check_is_readable(file, user) when 'w' check_is_writable(file, user) when 'x' check_is_executable(file, user) end end def check_is_readable(file, by_whom) Backend::PowerShell::Command.new do using 'check_file_access_rules.ps1' exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'Read', 'ListDirectory')" end end def check_is_writable(file, by_whom) Backend::PowerShell::Command.new do using 'check_file_access_rules.ps1' exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'Write')" end end def check_is_executable(file, by_whom) Backend::PowerShell::Command.new do using 'check_file_access_rules.ps1' exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'ExecuteFile')" end end def check_contains(file, pattern) Backend::PowerShell::Command.new do exec %Q!(Get-Content("#{file}") | Out-String) -match '#{convert_regexp(pattern)}'! end end def check_contains_within file, pattern, from=nil, to=nil from ||= '^' to ||= '$' Backend::PowerShell::Command.new do using 'crop_text.ps1' exec %Q!(CropText -text (Get-Content("#{file}") | Out-String) -fromPattern '#{convert_regexp(from)}' -toPattern '#{convert_regexp(to)}') -match '#{pattern}'! end end def check_has_version(name,version) cmd = "((Get-Command '#{name}').FileVersionInfo.ProductVersion -eq '#{version}') -or ((Get-Command '#{name}').FileVersionInfo.FileVersion -eq '#{version}')" Backend::PowerShell::Command.new { exec cmd } end def check_is_owned_by(file, owner) Backend::PowerShell::Command.new do exec "$(if((Get-Item '#{file}').GetAccessControl().Owner -match '#{owner}' -or ((Get-Item '#{file}').GetAccessControl().Owner -match '#{owner}').Length -gt 0){ $TRUE } else { $FALSE })" end end private def item_has_attribute item, attribute %Q!((Get-Item -Path "#{item}" -Force).attributes.ToString() -Split ', ') -contains '#{attribute}'! end end end specinfra-2.89.0/lib/specinfra/command/windows/base/port.rb0000644000004100000410000000102614575463425023705 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Port < Specinfra::Command::Windows::Base class << self def check_is_listening(port, options=nil) Backend::PowerShell::Command.new do using 'is_port_listening.ps1' exec "IsPortListening -portNumber #{port}" end end def check_is_listening_with_protocol(port, protocol) Backend::PowerShell::Command.new do using 'is_port_listening.ps1' exec "IsPortListening -portNumber #{port} -protocol '#{protocol}'" end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/hot_fix.rb0000644000004100000410000000114414575463425024362 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::HotFix < Specinfra::Command::Windows::Base class << self def check_is_installed(description, hot_fix_id=nil) hot_fix_id_match = /(KB\d+)/i.match(description) hot_fix_id = hot_fix_id_match ? hot_fix_id_match[1] : description if hot_fix_id.nil? args = [ '-description', "'#{description}'", '-hotFixId', "'#{hot_fix_id}'" ] cmd = "(FindInstalledHotFix #{args.join(' ')})" Backend::PowerShell::Command.new do using 'find_installed_hot_fix.ps1' exec "#{cmd} -eq $true" end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/scheduled_task.rb0000644000004100000410000000050014575463425025677 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::ScheduledTask < Specinfra::Command::Windows::Base class << self def check_exists(name) Backend::PowerShell::Command.new do using 'find_scheduled_task.ps1' exec "(FindScheduledTask -name '#{name}').TaskName -eq '\\#{name}'" end end end end specinfra-2.89.0/lib/specinfra/command/windows/base/firewall.rb0000644000004100000410000000242514575463425024532 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::Firewall < Specinfra::Command::Windows::Base class << self def check_exists(displayName) cmd = "(Get-NetFirewallRule -DisplayName '#{displayName}') -ne $null" create_command cmd end def check_is_enabled(displayName) cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | where {$_.Enabled -eq 'True'}) -ne $null" create_command cmd end def check_has_action(displayName, action) cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | where {$_.Action -eq '#{action}'}) -ne $null" create_command cmd end def check_has_protocol(displayName, protocol) cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | Get-NetFirewallPortFilter | where {$_.Protocol -eq '#{protocol}'}) -ne $null" create_command cmd end def check_has_localport(displayName, localport) cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | Get-NetFirewallPortFilter | where {$_.LocalPort -eq '#{localport}'}) -ne $null" create_command cmd end def check_has_direction(displayName, direction) cmd = "((Get-NetFirewallRule -DisplayName '#{displayName}') | where {$_.Direction -eq '#{direction}'}) -ne $null" create_command cmd end end end specinfra-2.89.0/lib/specinfra/command/windows/base.rb0000644000004100000410000000066014575463425022724 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base class << self def create self end private def create_command(command, using_ps1 = nil) Backend::PowerShell::Command.new do using using_ps1 if using_ps1 exec command end end def windows_account account match = /((.+)\\)?(.+)/.match account domain = match[2] name = match[3] [name, domain] end end end specinfra-2.89.0/lib/specinfra/command/cumulus.rb0000644000004100000410000000014514575463425022013 0ustar www-datawww-dataclass Specinfra::Command::Cumuluslinux; end class Specinfra::Command::Cumulusnetworks; end specinfra-2.89.0/lib/specinfra/command/sles/0000755000004100000410000000000014575463425020737 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/sles/base/0000755000004100000410000000000014575463425021651 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/sles/base/service.rb0000644000004100000410000000042414575463425023636 0ustar www-datawww-dataclass Specinfra::Command::Sles::Base::Service < Specinfra::Command::Suse::Base::Service class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 12 self else Specinfra::Command::Sles::V12::Service end end end end specinfra-2.89.0/lib/specinfra/command/sles/v11/0000755000004100000410000000000014575463425021346 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/sles/v11/user.rb0000644000004100000410000000062514575463425022654 0ustar www-datawww-dataclass Specinfra::Command::Sles::V11::User < Specinfra::Command::Sles::Base::User class << self def get_minimum_days_between_password_change(user) "chage -l #{escape(user)} | sed -n 's/^Minimum://p' | sed 's|^[[:blank:]]*||g'" end def get_maximum_days_between_password_change(user) "chage -l #{escape(user)} | sed -n 's/^Maximum://p' | sed 's|^[[:blank:]]*||g'" end end endspecinfra-2.89.0/lib/specinfra/command/sles/base.rb0000644000004100000410000000011214575463425022170 0ustar www-datawww-dataclass Specinfra::Command::Sles::Base < Specinfra::Command::Suse::Base end specinfra-2.89.0/lib/specinfra/command/sles/v12.rb0000644000004100000410000000011214575463425021666 0ustar www-datawww-dataclass Specinfra::Command::Sles::V12 < Specinfra::Command::Sles::Base end specinfra-2.89.0/lib/specinfra/command/sles/v12/0000755000004100000410000000000014575463425021347 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/sles/v12/service.rb0000644000004100000410000000024114575463425023331 0ustar www-datawww-dataclass Specinfra::Command::Sles::V12::Service < Specinfra::Command::Sles::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.89.0/lib/specinfra/command/sles/v11.rb0000644000004100000410000000011114575463425021664 0ustar www-datawww-dataclass Specinfra::Command::Sles::V11 < Specinfra::Command::Sles::Base end specinfra-2.89.0/lib/specinfra/command/clearlinux.rb0000644000004100000410000000005114575463425022460 0ustar www-datawww-dataclass Specinfra::Command::Clearlinux; endspecinfra-2.89.0/lib/specinfra/command/linuxmint.rb0000644000004100000410000000005114575463425022341 0ustar www-datawww-dataclass Specinfra::Command::Linuxmint; end specinfra-2.89.0/lib/specinfra/command/gentoo.rb0000644000004100000410000000004614575463425021611 0ustar www-datawww-dataclass Specinfra::Command::Gentoo; end specinfra-2.89.0/lib/specinfra/command/solaris/0000755000004100000410000000000014575463425021445 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/solaris/v10.rb0000644000004100000410000000011714575463425022377 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10 < Specinfra::Command::Solaris::Base end specinfra-2.89.0/lib/specinfra/command/solaris/base/0000755000004100000410000000000014575463425022357 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/solaris/base/ipfilter.rb0000644000004100000410000000032114575463425024516 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Ipfilter < Specinfra::Command::Base::Ipfilter class << self def check_has_rule(rule) "ipfstat -io 2> /dev/null | grep -- #{escape(rule)}" end end end specinfra-2.89.0/lib/specinfra/command/solaris/base/group.rb0000644000004100000410000000042014575463425024034 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Group < Specinfra::Command::Base::Group class << self def check_has_gid(group, gid) regexp = "^#{group}:" "getent group | grep -- #{escape(regexp)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}" end end end specinfra-2.89.0/lib/specinfra/command/solaris/base/zfs.rb0000644000004100000410000000023314575463425023504 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Zfs < Specinfra::Command::Base::Zfs class << self include Specinfra::Command::Module::Zfs end end specinfra-2.89.0/lib/specinfra/command/solaris/base/service.rb0000644000004100000410000000130114575463425024337 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Service < Specinfra::Command::Base::Service class << self def check_is_enabled(service, level=nil) "svcs -l #{escape(service)} 2> /dev/null | egrep '^enabled *true$'" end def check_is_running(service) "svcs -H -o state #{escape(service)} 2> /dev/null | egrep '^online$'" end def check_has_property(svc, property) commands = [] property.sort.each do |key, value| regexp = "^#{value}$" commands << "svcprop -p #{escape(key)} #{escape(svc)} | grep -- #{escape(regexp)}" end commands.join(' && ') end def get_property(service) "svcprop -a #{escape(service)}" end end end specinfra-2.89.0/lib/specinfra/command/solaris/base/ipnat.rb0000644000004100000410000000035314575463425024020 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Ipnat < Specinfra::Command::Base::Ipnat class << self def check_has_rule(rule) regexp = "^#{rule}$" "ipnat -l 2> /dev/null | grep -- #{escape(regexp)}" end end end specinfra-2.89.0/lib/specinfra/command/solaris/base/user.rb0000644000004100000410000000101414575463425023656 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::User < Specinfra::Command::Base::User class << self def check_belongs_to_group(user, group) "id -Gn #{escape(user)} | grep -- #{escape(group)}" end def check_has_home_directory(user, path_to_home) "getent passwd #{escape(user)} | cut -f 6 -d ':' | grep -w -- #{escape(path_to_home)}" end def check_has_login_shell(user, path_to_shell) "getent passwd #{escape(user)} | cut -f 7 -d ':' | grep -w -- #{escape(path_to_shell)}" end end end specinfra-2.89.0/lib/specinfra/command/solaris/base/package.rb0000644000004100000410000000050214575463425024274 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) cmd = "pkg list -H #{escape(package)} 2> /dev/null" if version cmd = "#{cmd} | grep -qw -- #{escape(version)}" end cmd end end end specinfra-2.89.0/lib/specinfra/command/solaris/base/host.rb0000644000004100000410000000055114575463425023662 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Host < Specinfra::Command::Base::Host class << self def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -n #{escape(host)} #{escape(timeout)}" else "nc -vvvvz#{escape(proto[0].chr)} -w #{escape(timeout)} #{escape(host)} #{escape(port)}" end end end end specinfra-2.89.0/lib/specinfra/command/solaris/base/file.rb0000644000004100000410000000166614575463425023634 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::File < Specinfra::Command::Base::File class << self def check_contains_within(file, expected_pattern, from=nil, to=nil) from ||= '1' to ||= '$' sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}" sed_end = "sed -n 1,#{escape(to)}p" checker_with_regexp = check_contains_with_regexp("/dev/stdin", expected_pattern) checker_with_fixed = check_contains_with_fixed_strings("/dev/stdin", expected_pattern) "#{sed} | #{sed_end} | #{checker_with_regexp}|| #{sed} | #{sed_end} | #{checker_with_fixed}" end def check_is_accessible_by_user(file, user, access) # http://docs.oracle.com/cd/E23823_01/html/816-5166/su-1m.html ## No need for login shell as it seems that behavior as superuser is favorable for us, but needs ## to be better tested under real solaris env "su #{user} -c \"test -#{access} #{file}\"" end end end specinfra-2.89.0/lib/specinfra/command/solaris/base/port.rb0000644000004100000410000000071514575463425023673 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, opts=nil) regexp = "\\.#{port} " "netstat -an 2> /dev/null | grep -- LISTEN | grep -- #{escape(regexp)}" end def check_is_listening_with_protocol(port, protocol) regexp = ".*\\.#{port} " "netstat -an -P #{escape(protocol)} 2> /dev/null | grep -- LISTEN | grep -- #{escape(regexp)}" end end end specinfra-2.89.0/lib/specinfra/command/solaris/base/kernel_module.rb0000644000004100000410000000036014575463425025530 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::KernelModule < Specinfra::Command::Base::KernelModule class << self def check_is_loaded(name) "modinfo -c | awk '$3 == \"#{escape(name)}\" { print $4 }' | grep ^LOADED" end end end specinfra-2.89.0/lib/specinfra/command/solaris/base/cron.rb0000644000004100000410000000064214575463425023647 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Cron < Specinfra::Command::Base::Cron class << self def check_has_entry(user, entry) entry_escaped = entry.gsub(/\*/, '\\*').gsub(/\[/, '\\[').gsub(/\]/, '\\]').gsub(/\%/, '\\%') if user.nil? "crontab -l | grep -- #{escape(entry_escaped)}" else "crontab -l #{escape(user)} | grep -- #{escape(entry_escaped)}" end end end end specinfra-2.89.0/lib/specinfra/command/solaris/base/inventory.rb0000644000004100000410000000240614575463425024743 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'false' end def get_cpu 'false' end def get_hostname 'uname -n' end def get_domain # There is no sure way to get the hostname like on linux # This code is somewhat resembiling the functionality # of the dnsdomainname command. # Assumes either /etc/hosts or DNS is properly configured. %Q{getent hosts `uname -n` | } + %Q{nawk -v h=`uname -n` '{sub(h".", "", $2); if ($2 != h){ print $2 } else { exit 1 } }'} end def get_fqdn # Same as with get_domain assumes that either # /etc/hosts or DNS are configured correctly. %Q{getent hosts `uname -n` | } + %Q{nawk -v h=`unme -n` '{ if ($2 ~ h".") { print $2 } else { exit 1 } }'} end def get_filesystem # emulates df -kP on Linux # Also offers a creative solution for the # multiple swap entries by adding a number suffix. # e.g. swap0, swap1 and so on. %Q{df -k | nawk -v i=0 '$1 == "swap" { $1=$1i; i++ }; NF == 1 { printf($1); next }; { print }'} end def get_system_product_name "prtdiag | grep 'System Configuration'" end end end specinfra-2.89.0/lib/specinfra/command/solaris/v11/0000755000004100000410000000000014575463425022054 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/solaris/v11/user.rb0000644000004100000410000000063214575463425023360 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V11::User < Specinfra::Command::Solaris::Base::User class << self def get_minimum_days_between_password_change(user) "passwd -s #{escape(user)} | sed 's/ \\{1,\\}/%/g' | tr '%' '\n' | sed '4q;d'" end def get_maximum_days_between_password_change(user) "passwd -s #{escape(user)} | sed 's/ \\{1,\\}/%/g' | tr '%' '\n' | sed '5q;d'" end end end specinfra-2.89.0/lib/specinfra/command/solaris/base.rb0000644000004100000410000000010714575463425022702 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/solaris/v10/0000755000004100000410000000000014575463425022053 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/solaris/v10/group.rb0000644000004100000410000000031214575463425023530 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10::Group < Specinfra::Command::Solaris::Base::Group class << self def check_exists(group) "getent group | grep -w -- #{escape(group)}" end end end specinfra-2.89.0/lib/specinfra/command/solaris/v10/user.rb0000644000004100000410000000063714575463425023364 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10::User < Specinfra::Command::Solaris::Base::User class << self def check_belongs_to_group(user, group) "id -ap #{escape(user)} | grep -- #{escape(group)}" end def check_has_authorized_key(user, key) key.sub!(/\s+\S*$/, '') if key.match(/^\S+\s+\S+\s+\S*$/) "grep -- #{escape(key)} ~#{escape(user)}/.ssh/authorized_keys" end end end specinfra-2.89.0/lib/specinfra/command/solaris/v10/package.rb0000644000004100000410000000046614575463425024001 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10::Package < Specinfra::Command::Solaris::Base::Package class << self def check_is_installed(package, version=nil) cmd = "pkginfo -q #{escape(package)}" if version cmd = "#{cmd} | grep -- #{escape(version)}" end cmd end end end specinfra-2.89.0/lib/specinfra/command/solaris/v10/host.rb0000644000004100000410000000064314575463425023360 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10::Host < Specinfra::Command::Solaris::Base::Host class << self def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -n #{escape(host)} #{escape(timeout)}" elsif proto == 'tcp' "echo 'quit' | mconnect -p #{escape(port)} #{escape(host)} > /dev/null 2>&1" else raise NotImplementedError.new end end end end specinfra-2.89.0/lib/specinfra/command/solaris/v10/file.rb0000644000004100000410000000306314575463425023321 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10::File < Specinfra::Command::Solaris::Base::File class << self # reference: http://perldoc.perl.org/functions/stat.html def check_has_mode(file, mode) regexp = "^#{mode}$" "perl -e 'printf \"%o\", (stat shift)[2]&07777' #{escape(file)} | grep -- #{escape(regexp)}" end # reference: http://perldoc.perl.org/functions/stat.html # http://www.tutorialspoint.com/perl/perl_getpwuid.htm def check_is_owned_by(file, owner) regexp = "^#{owner}$" "perl -e 'printf \"%s\", getpwuid((stat(\"#{escape(file)}\"))[4])' | grep -- #{escape(regexp)}" end # reference: http://perldoc.perl.org/functions/stat.html # http://www.tutorialspoint.com/perl/perl_getgrgid.htm def check_is_grouped(file, group) regexp = "^#{group}$" "perl -e 'printf \"%s\", getgrgid((stat(\"#{escape(file)}\"))[5])' | grep -- #{escape(regexp)}" end # reference: http://www.tutorialspoint.com/perl/perl_readlink.htm def check_is_linked_to(link, target) regexp = "^#{target}$" "perl -e 'printf \"%s\", readlink(\"#{escape(link)}\")' | grep -- #{escape(regexp)}" end def check_contain(file, expected_pattern) "grep -- #{escape(expected_pattern)} #{escape(file)}" end def get_md5sum(file) "digest -a md5 -v #{escape(file)} | cut -d '=' -f 2 | cut -c 2-" end # reference: http://perldoc.perl.org/functions/stat.html def get_mode(file) "perl -e 'printf \"%o\", (stat shift)[2]&07777' #{escape(file)}" end end end specinfra-2.89.0/lib/specinfra/command/solaris/v11.rb0000644000004100000410000000011714575463425022400 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V11 < Specinfra::Command::Solaris::Base end specinfra-2.89.0/lib/specinfra/command/freebsd.rb0000644000004100000410000000004714575463425021731 0ustar www-datawww-dataclass Specinfra::Command::Freebsd; end specinfra-2.89.0/lib/specinfra/command/debian/0000755000004100000410000000000014575463425021213 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/debian/v8.rb0000644000004100000410000000011414575463425022071 0ustar www-datawww-dataclass Specinfra::Command::Debian::V8 < Specinfra::Command::Debian::Base end specinfra-2.89.0/lib/specinfra/command/debian/base/0000755000004100000410000000000014575463425022125 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/debian/base/service.rb0000644000004100000410000000202114575463425024105 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base::Service < Specinfra::Command::Linux::Base::Service class << self def create(os_info=nil) release = (os_info || os)[:release] if ["testing", "unstable"].include?(release) || release.to_i >= 8 Specinfra::Command::Debian::V8::Service else self end end def check_is_enabled(service, level=3) # Until everything uses Upstart, this needs an OR. "ls /etc/rc#{level}.d/ | grep -- '^S..#{escape(service)}$' || grep '^\s*start on' /etc/init/#{escape(service)}.conf" end def enable(service) "update-rc.d #{escape(service)} defaults" end def disable(service) "update-rc.d -f #{escape(service)} remove" end def start(service) "service #{escape(service)} start" end def stop(service) "service #{escape(service)} stop" end def restart(service) "service #{escape(service)} restart" end def reload(service) "service #{escape(service)} reload" end end end specinfra-2.89.0/lib/specinfra/command/debian/base/package.rb0000644000004100000410000000223514575463425024047 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) escaped_package = escape(package) if version cmd = "dpkg-query -f '${Status} ${Version}' -W #{escaped_package} | grep -E '^(install|hold) ok installed #{Regexp.escape(version)}$'" else cmd = "dpkg-query -f '${Status}' -W #{escaped_package} | grep -E '^(install|hold) ok installed$'" end cmd end alias :check_is_installed_by_apt :check_is_installed def install(package, version=nil, option='') if version full_package = "#{package}=#{version}" else full_package = package end "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' #{option} install #{escape(full_package)}" end def get_version(package, opts=nil) "dpkg-query -f '${Status} ${Version}' -W #{package} | sed -n 's/^install ok installed //p'" end def remove(package, option='') "DEBIAN_FRONTEND='noninteractive' apt-get -y #{option} remove #{package}" end end end specinfra-2.89.0/lib/specinfra/command/debian/base/port.rb0000644000004100000410000000052414575463425023437 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base::Port < Specinfra::Command::Linux::Base::Port class << self def create(os_info=nil) release = (os_info || os)[:release] if ["testing", "unstable"].include?(release) || release.to_i >= 8 Specinfra::Command::Debian::V8::Port else self end end end end specinfra-2.89.0/lib/specinfra/command/debian/base/ppa.rb0000644000004100000410000000012714575463425023232 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base::Ppa < Specinfra::Command::Linux::Base::Ppa end specinfra-2.89.0/lib/specinfra/command/debian/base.rb0000644000004100000410000000012614575463425022451 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/command/debian/v8/0000755000004100000410000000000014575463425021550 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/debian/v8/service.rb0000644000004100000410000000065014575463425023536 0ustar www-datawww-dataclass Specinfra::Command::Debian::V8::Service < Specinfra::Command::Debian::Base::Service class << self include Specinfra::Command::Module::Systemd def check_is_enabled_under_systemd(service, level=nil) [ super(service), "ls /etc/rc[S5].d/S??#{escape(service)} >/dev/null 2>/dev/null" ].join('||') end alias_method :check_is_enabled, :check_is_enabled_under_systemd end end specinfra-2.89.0/lib/specinfra/command/debian/v8/port.rb0000644000004100000410000000023114575463425023055 0ustar www-datawww-dataclass Specinfra::Command::Debian::V8::Port < Specinfra::Command::Debian::Base::Port class << self include Specinfra::Command::Module::Ss end end specinfra-2.89.0/lib/specinfra/command/base/0000755000004100000410000000000014575463425020703 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/base/ipfilter.rb0000644000004100000410000000011014575463425023036 0ustar www-datawww-dataclass Specinfra::Command::Base::Ipfilter < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/group.rb0000644000004100000410000000245714575463425022374 0ustar www-datawww-dataclass Specinfra::Command::Base::Group < Specinfra::Command::Base class << self def check_exists(group) "getent group #{escape(group)}" end def check_has_gid(group, gid) "getent group #{escape(group)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}" end def check_is_system_group(group) exists = "getent group #{escape(group)} > /dev/null 2>&1" gid = "getent group #{escape(group)} | cut -f 3 -d ':'" sys_gid_min = "awk 'BEGIN{sys_gid_min=101} {if($1~/^SYS_GID_MIN/){sys_gid_min=$2}} END{print sys_gid_min}' /etc/login.defs" sys_gid_max = "awk 'BEGIN{sys_gid_max=0;gid_min=1000} {if($1~/^SYS_GID_MAX/){sys_gid_max=$2}if($1~/^GID_MIN/){gid_min=$2}} END{if(sys_gid_max!=0){print sys_gid_max}else{print gid_min-1}}' /etc/login.defs" %Q|#{exists} && test "$(#{gid})" -ge "$(#{sys_gid_min})" && test "$(#{gid})" -le "$(#{sys_gid_max})"| end def get_gid(group) "getent group #{escape(group)} | cut -f 3 -d ':'" end def update_gid(group, gid) "groupmod -g #{escape(gid)} #{escape(group)}" end def add(group, options) command = ['groupadd'] command << '-g' << escape(options[:gid]) if options[:gid] command << '-r' if options[:system_group] command << escape(group) command.join(' ') end end end specinfra-2.89.0/lib/specinfra/command/base/ip6tables.rb0000644000004100000410000000011114575463425023112 0ustar www-datawww-dataclass Specinfra::Command::Base::Ip6tables < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/bond.rb0000644000004100000410000000010414575463425022145 0ustar www-datawww-dataclass Specinfra::Command::Base::Bond < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/selinux_module.rb0000644000004100000410000000011514575463425024261 0ustar www-datawww-dataclass Specinfra::Command::Base::SelinuxModule < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/zfs.rb0000644000004100000410000000010414575463425022025 0ustar www-datawww-dataclass Specinfra::Command::Base::Zfs < Specinfra::Command::Base; end specinfra-2.89.0/lib/specinfra/command/base/process.rb0000644000004100000410000000103614575463425022706 0ustar www-datawww-dataclass Specinfra::Command::Base::Process < Specinfra::Command::Base class << self def get(process, opts) "ps -C #{escape(process)} -o #{opts[:format]} | head -1" end def count(process) "ps aux | grep -w -- #{escape(process)} | grep -v grep | wc -l" end def check_is_running(process) "ps aux | grep -w -- #{escape(process)} | grep -qv grep" end def check_count(process,count) "test $(ps aux | grep -w -- #{escape(process)} | grep -v grep | wc -l) -eq #{escape(count)}" end end end specinfra-2.89.0/lib/specinfra/command/base/service.rb0000644000004100000410000000120314575463425022664 0ustar www-datawww-dataclass Specinfra::Command::Base::Service < Specinfra::Command::Base class << self include Specinfra::Command::Module::Service::Init include Specinfra::Command::Module::Service::Systemd include Specinfra::Command::Module::Service::Daemontools include Specinfra::Command::Module::Service::Supervisor include Specinfra::Command::Module::Service::Upstart include Specinfra::Command::Module::Service::Runit include Specinfra::Command::Module::Service::Monit include Specinfra::Command::Module::Service::God extend Specinfra::Command::Module::Service::Delegator def_delegator_service_under :init end end specinfra-2.89.0/lib/specinfra/command/base/interface.rb0000644000004100000410000000011114575463425023161 0ustar www-datawww-dataclass Specinfra::Command::Base::Interface < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/mail_alias.rb0000644000004100000410000000102714575463425023323 0ustar www-datawww-dataclass Specinfra::Command::Base::MailAlias < Specinfra::Command::Base class << self def check_is_aliased_to(mail_alias, recipient) ## if the recipient contains pipes escape them ## or egrep will interpret it as an OR recipient = recipient.gsub(/\|/, '\|') recipient = "[[:space:]]([\"']?)#{recipient}\\1(,|$)" "getent aliases #{escape(mail_alias)} | egrep -- #{escape(recipient)}" end def add(mail_alias, recipient) "echo #{mail_alias}: #{recipient} >> /etc/aliases" end end end specinfra-2.89.0/lib/specinfra/command/base/ipnat.rb0000644000004100000410000000010514575463425022337 0ustar www-datawww-dataclass Specinfra::Command::Base::Ipnat < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/user.rb0000644000004100000410000000661514575463425022216 0ustar www-datawww-dataclass Specinfra::Command::Base::User < Specinfra::Command::Base class << self def check_exists(user) "id #{escape(user)}" end def check_belongs_to_group(user, group) "id #{escape(user)} | sed 's/ context=.*//g' | cut -f 4 -d '=' | grep -- #{escape(group)}" end def check_belongs_to_primary_group(user, group) "id -gn #{escape(user)}| grep ^#{escape(group)}$" end def check_is_system_user(user) exists = "getent passwd #{escape(user)} > /dev/null 2>&1" uid = "getent passwd #{escape(user)} | cut -f 3 -d ':'" sys_uid_min = "awk 'BEGIN{sys_uid_min=101} {if($1~/^SYS_UID_MIN/){sys_uid_min=$2}} END{print sys_uid_min}' /etc/login.defs" sys_uid_max = "awk 'BEGIN{sys_uid_max=0;uid_min=1000} {if($1~/^SYS_UID_MAX/){sys_uid_max=$2}if($1~/^UID_MIN/){uid_min=$2}} END{if(sys_uid_max!=0){print sys_uid_max}else{print uid_min-1}}' /etc/login.defs" %Q|#{exists} && test "$(#{uid})" -ge "$(#{sys_uid_min})" && test "$(#{uid})" -le "$(#{sys_uid_max})"| end def check_has_uid(user, uid) regexp = "^uid=#{uid}(" "id #{escape(user)} | grep -- #{escape(regexp)}" end def check_has_home_directory(user, path_to_home) "getent passwd #{escape(user)} | cut -f 6 -d ':' | grep -w -- #{escape(path_to_home)}" end def check_has_login_shell(user, path_to_shell) "getent passwd #{escape(user)} | cut -f 7 -d ':' | grep -w -- #{escape(path_to_shell)}" end def check_has_authorized_key(user, key) key.sub!(/\s+\S*$/, '') if key.match(/^\S+\s+\S+\s+\S*$/) "grep -w -- #{escape(key)} ~#{escape(user)}/.ssh/authorized_keys" end def get_minimum_days_between_password_change(user) "chage -l #{escape(user)} | sed -n 's/^Minimum.*: //p'" end def get_maximum_days_between_password_change(user) "chage -l #{escape(user)} | sed -n 's/^Maximum.*: //p'" end def get_uid(user) "id -u #{escape(user)}" end def get_gid(user) "id -g #{escape(user)}" end def get_home_directory(user) "getent passwd #{escape(user)} | cut -f 6 -d ':'" end def get_login_shell(user) "getent passwd #{escape(user)} | cut -f 7 -d ':'" end def update_home_directory(user, directory) "usermod -d #{escape(directory)} #{escape(user)}" end def update_login_shell(user, shell) "usermod -s #{escape(shell)} #{escape(user)}" end def update_uid(user, uid) "usermod -u #{escape(uid)} #{escape(user)}" end def update_gid(user, gid) "usermod -g #{escape(gid)} #{escape(user)}" end def add(user, options) command = ['useradd'] command << '-g' << escape(options[:gid]) if options[:gid] command << '-d' << escape(options[:home_directory]) if options[:home_directory] command << '-p' << escape(options[:password]) if options[:password] command << '-s' << escape(options[:shell]) if options[:shell] command << '-m' if options[:create_home] command << '-r' if options[:system_user] command << '-u' << escape(options[:uid]) if options[:uid] command << escape(user) command.join(' ') end def update_encrypted_password(user, encrypted_password) %Q!echo #{escape("#{user}:#{encrypted_password}")} | chpasswd -e! end def get_encrypted_password(user) "getent shadow #{escape(user)} | cut -f 2 -d ':'" end end end specinfra-2.89.0/lib/specinfra/command/base/package.rb0000644000004100000410000000446314575463425022632 0ustar www-datawww-dataclass Specinfra::Command::Base::Package < Specinfra::Command::Base class << self def check_is_installed_by_gem(name, version=nil, gem_binary="gem") gem_installed_command(gem_binary, name, version) end def check_is_installed_by_td_agent_gem(name, version=nil) gem_installed_command("/usr/sbin/td-agent-gem", name, version) end def check_is_installed_by_rvm(name, version=nil) regexp = "^#{name}" cmd = "rvm list strings | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_npm(name, version=nil) cmd = "npm ls #{escape(name)} -g" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_pecl(name, version=nil) regexp = "^#{name}" cmd = "pecl list | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_pear(name, version=nil) regexp = "^#{name}" cmd = "pear list -a | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_pip(name, version=nil) regexp = "^#{name}" cmd = "pip list | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_pip2(name, version=nil) regexp = "^#{name}" cmd = "pip2 list | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_pip3(name, version=nil) regexp = "^#{name} " cmd = "pip3 list | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end def check_is_installed_by_cpan(name, version=nil) regexp = "^#{name}" cmd = "cpan -l | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end private def gem_installed_command(gem_binary, name, version=nil) regexp = "^#{name} " cmd = "#{gem_binary} list --local | grep -iw -- #{escape(regexp)}" cmd = %Q!#{cmd} | grep -w -- "[( ]#{escape(version)}[,)]"! if version cmd end end end specinfra-2.89.0/lib/specinfra/command/base/host.rb0000644000004100000410000000251514575463425022210 0ustar www-datawww-dataclass Specinfra::Command::Base::Host < Specinfra::Command::Base class << self def check_is_resolvable(name, type) if type == "dns" %Q[lookup=$(nslookup -timeout=1 #{escape(name)} | grep -A1 'Name:' | grep Address | awk -F': ' '{print $2}'); if [ "$lookup" ]; then $(exit 0); else $(exit 1); fi] elsif type == "hosts" "sed 's/#.*$//' /etc/hosts | grep -w -- #{escape(name)} /etc/hosts" else "getent hosts #{escape(name)}" end end def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -w #{escape(timeout)} -c 2 -n #{escape(host)}" else "nc -w #{escape(timeout)} -vvvvz#{escape(proto[0].chr)} #{escape(host)} #{escape(port)}" end end # getent hosts on a dualstack machine will most likely # return the ipv6 address to ensure one can more cleary # define the outcome the ipv{4,6}_address are used. def get_ipaddress(name) "getent hosts #{escape(name)} | awk '{print $1}'" end def get_ipv4_address(name) # Will return multiple values pick the first and exit "getent ahostsv4 #{escape(name)} | awk '{print $1; exit}'" end def get_ipv6_address(name) # Will return multiple values pick the first and exit "getent ahostsv6 #{escape(name)} | awk '{print $1; exit}'" end end end specinfra-2.89.0/lib/specinfra/command/base/fstab.rb0000644000004100000410000000010514575463425022323 0ustar www-datawww-dataclass Specinfra::Command::Base::Fstab < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/bridge.rb0000644000004100000410000000010614575463425022461 0ustar www-datawww-dataclass Specinfra::Command::Base::Bridge < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/iptables.rb0000644000004100000410000000011014575463425023023 0ustar www-datawww-dataclass Specinfra::Command::Base::Iptables < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/yumrepo.rb0000644000004100000410000000011014575463425022720 0ustar www-datawww-dataclass Specinfra::Command::Base::Yumrepo < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/file.rb0000644000004100000410000001222414575463425022150 0ustar www-datawww-dataclass Specinfra::Command::Base::File < Specinfra::Command::Base class << self def check_is_file(file) "test -f #{escape(file)}" end def check_is_directory(directory) "test -d #{escape(directory)}" end def check_is_pipe(file) "test -p #{escape(file)}" end def check_is_socket(file) "test -S #{escape(file)}" end def check_is_block_device(file) "test -b #{escape(file)}" end def check_is_character_device(file) "test -c #{escape(file)}" end def check_is_symlink(file) "test -L #{escape(file)}" end def check_contains(file, expected_pattern) "#{check_contains_with_regexp(file, expected_pattern)} || #{check_contains_with_fixed_strings(file, expected_pattern)}" end def check_is_grouped(file, group) regexp = "^#{group}$" if group.is_a?(Numeric) || (group =~ /\A\d+\z/ ? true : false) "stat -c %g #{escape(file)} | grep -- #{escape(regexp)}" else "stat -c %G #{escape(file)} | grep -- #{escape(regexp)}" end end def check_is_owned_by(file, owner) regexp = "^#{owner}$" if owner.is_a?(Numeric) || (owner =~ /\A\d+\z/ ? true : false) "stat -c %u #{escape(file)} | grep -- #{escape(regexp)}" else "stat -c %U #{escape(file)} | grep -- #{escape(regexp)}" end end def check_has_mode(file, mode) regexp = "^#{mode}$" "stat -c %a #{escape(file)} | grep -- #{escape(regexp)}" end def check_contains_within(file, expected_pattern, from=nil, to=nil) from ||= '1' to ||= '$' sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}" sed += " | sed -n 1,#{escape(to)}p" if from != '1' and to != '$' checker_with_regexp = check_contains_with_regexp("-", expected_pattern) checker_with_fixed = check_contains_with_fixed_strings("-", expected_pattern) "#{sed} | #{checker_with_regexp} || #{sed} | #{checker_with_fixed}" end def check_contains_lines(file, expected_lines, from=nil, to=nil) require 'digest/md5' from ||= '1' to ||= '$' sed = "sed -n #{escape(from)},#{escape(to)}p #{escape(file)}" head_line = expected_lines.first.chomp lines_checksum = Digest::MD5.hexdigest(expected_lines.map(&:chomp).join("\n") + "\n") afterwards_length = expected_lines.length - 1 "#{sed} | grep -A #{escape(afterwards_length)} -F -- #{escape(head_line)} | md5sum | grep -qiw -- #{escape(lines_checksum)}" end def check_contains_with_regexp(file, expected_pattern) "grep -qs -- #{escape(expected_pattern)} #{escape(file)}" end def check_contains_with_fixed_strings(file, expected_pattern) "grep -qFs -- #{escape(expected_pattern)} #{escape(file)}" end def check_exists(file) "test -e #{escape(file)}" end def get_md5sum(file) "md5sum #{escape(file)} | cut -d ' ' -f 1" end def get_sha256sum(file) "sha256sum #{escape(file)} | cut -d ' ' -f 1" end def get_content(file) "cat #{escape(file)} 2> /dev/null || echo -n" end def check_is_mounted(path) regexp = "on #{path} " "mount | grep -- '#{escape(regexp)}'" end def get_mode(file) "stat -c %a #{escape(file)}" end def get_owner_user(file) "stat -c %U #{escape(file)}" end def get_owner_group(file) "stat -c %G #{escape(file)}" end def check_is_linked_to(link, target) %Q|test x"$(readlink #{escape(link)})" = x"#{escape(target)}"| end def check_is_link(link) "test -L #{escape(link)}" end def get_link_target(link) "readlink #{escape(link)}" end def get_link_realpath(link) "readlink -e #{escape(link)}" end def check_is_dereferenceable(link) %Q|test -n "$(readlink -e #{escape(link)})"| end def get_mtime(file) "stat -c %Y #{escape(file)}" end def get_size(file) "stat -c %s #{escape(file)}" end def change_mode(file, mode, options = {}) option = '-R' if options[:recursive] "chmod #{option} #{mode} #{escape(file)}".squeeze(' ') end def change_owner(file, owner, group=nil, options = {}) option = '-R' if options[:recursive] owner = "#{owner}:#{group}" if group "chown #{option} #{escape(owner)} #{escape(file)}".squeeze(' ') end def change_group(file, group, options = {}) option = '-R' if options[:recursive] "chgrp #{option} #{escape(group)} #{escape(file)}".squeeze(' ') end def create_as_directory(file) "mkdir -p #{escape(file)}" end def copy(src, dest, options = {}) option = '-p' option << 'R' if options[:recursive] "cp #{option} #{escape(src)} #{escape(dest)}" end def move(src, dest) "mv #{escape(src)} #{escape(dest)}" end def link_to(link, target, options = {}) option = '-s' option << 'f' if options[:force] option << 'n' if options[:no_dereference] "ln #{option} #{escape(target)} #{escape(link)}" end def remove(file) "rm -rf #{escape(file)}" end def download(src, dest) "curl -sSL #{escape(src)} -o #{escape(dest)}" end end end specinfra-2.89.0/lib/specinfra/command/base/selinux.rb0000644000004100000410000000010714575463425022715 0ustar www-datawww-dataclass Specinfra::Command::Base::Selinux < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/port.rb0000644000004100000410000000057514575463425022223 0ustar www-datawww-dataclass Specinfra::Command::Base::Port < Specinfra::Command::Base class << self def check_is_listening(port, options={}) pattern = ":#{port} " pattern = " #{options[:local_address]}#{pattern}" if options[:local_address] pattern = "^#{options[:protocol]} .*#{pattern}" if options[:protocol] "netstat -tunl | grep -- #{escape(pattern)}" end end end specinfra-2.89.0/lib/specinfra/command/base/lxc_container.rb0000644000004100000410000000011414575463425024054 0ustar www-datawww-dataclass Specinfra::Command::Base::LxcContainer < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/ppa.rb0000644000004100000410000000010314575463425022002 0ustar www-datawww-dataclass Specinfra::Command::Base::Ppa < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/kernel_module.rb0000644000004100000410000000011414575463425024051 0ustar www-datawww-dataclass Specinfra::Command::Base::KernelModule < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/kvm_guest.rb0000644000004100000410000000011014575463425023224 0ustar www-datawww-dataclass Specinfra::Command::Base::KvmGuest < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/base/cron.rb0000644000004100000410000000111014575463425022162 0ustar www-datawww-dataclass Specinfra::Command::Base::Cron < Specinfra::Command::Base class << self def check_has_entry(user, entry) entry_escaped = entry.gsub(/\\/, '\\\\\\').gsub(/\*/, '\\*').gsub(/\[/, '\\[').gsub(/\]/, '\\]') grep_command = "grep -v '^[[:space:]]*#' | grep -- ^#{escape(entry_escaped)}$" if user.nil? "crontab -l | #{grep_command}" else "crontab -u #{escape(user)} -l | #{grep_command}" end end def get_table 'cat /etc/cron.d/* /etc/crontab /var/spool/cron/* /var/spool/cron/crontabs/* 2> /dev/null' end end end specinfra-2.89.0/lib/specinfra/command/base/inventory.rb0000644000004100000410000000027614575463425023272 0ustar www-datawww-dataclass Specinfra::Command::Base::Inventory < Specinfra::Command::Base class << self def get_user 'getent passwd' end def get_group 'getent group' end end end specinfra-2.89.0/lib/specinfra/command/base/routing_table.rb0000644000004100000410000000045114575463425024066 0ustar www-datawww-dataclass Specinfra::Command::Base::RoutingTable < Specinfra::Command::Base class << self def check_has_entry(destination) if destination == "default" destination = "0.0.0.0/0" end "ip route show #{destination}" end alias :get_entry :check_has_entry end end specinfra-2.89.0/lib/specinfra/command/base/localhost.rb0000644000004100000410000000030114575463425023212 0ustar www-datawww-dataclass Specinfra::Command::Base::Localhost < Specinfra::Command::Base class << self def check_is_ec2_instance 'curl --connect-timeout=1 http://169.254.169.254:80/' end end end specinfra-2.89.0/lib/specinfra/command/aix/0000755000004100000410000000000014575463425020552 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/aix/base/0000755000004100000410000000000014575463425021464 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/aix/base/group.rb0000644000004100000410000000045614575463425023152 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Group < Specinfra::Command::Base::Group class << self def check_exists(group) "lsgroup #{escape(group)}" end def check_has_gid(group, gid) "lsgroup -a id #{escape(group)} | cut -f 2 -d '=' | grep -w -- #{escape(gid)}" end end end specinfra-2.89.0/lib/specinfra/command/aix/base/service.rb0000644000004100000410000000046414575463425023455 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Service < Specinfra::Command::Base::Service class << self def check_is_enabled(service,level=nil) "lssrc -s #{escape(service)} | grep active" end def check_is_running(service) "ps -ef | grep -v grep | grep #{escape(service)}" end end end specinfra-2.89.0/lib/specinfra/command/aix/base/user.rb0000644000004100000410000000112014575463425022761 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::User < Specinfra::Command::Base::User class << self def check_belongs_to_group(user, group) "lsuser -a groups #{escape(user)} | awk -F'=' '{print $2}'| sed -e 's/,/ /g' |grep -w -- #{escape(group)}" end def check_has_login_shell(user, path_to_shell) "lsuser -a shell #{escape(user)} |awk -F'=' '{print $2}' | grep -w -- #{escape(path_to_shell)}" end def check_has_home_directory(user, path_to_home) "lsuser -a home #{escape(user)} | awk -F'=' '{print $2}' | grep -w -- #{escape(path_to_home)}" end end end specinfra-2.89.0/lib/specinfra/command/aix/base/package.rb0000644000004100000410000000050214575463425023401 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) if version "lslpp -L #{escape(package)} | awk '{print $2}' | grep -w -- #{version}" else "lslpp -L #{escape(package)}" end end end end specinfra-2.89.0/lib/specinfra/command/aix/base/host.rb0000644000004100000410000000105514575463425022767 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Host < Specinfra::Command::Base::Host class << self def check_is_resolvable(name, type) if type == "dns" %Q[lookup=$(nslookup -timeout=1 #{escape(name)} | grep -A1 'Name:' | grep Address | awk -F': ' '{print $2}'); if [ "$lookup" ]; then $(exit 0); else $(exit 1); fi] elsif type == "hosts" "grep -w -- #{escape(name)} /etc/hosts" else "host #{escape(name)}" end end def get_ipaddress(name) "host #{escape(name)} | awk '{print $3}'" end end end specinfra-2.89.0/lib/specinfra/command/aix/base/file.rb0000644000004100000410000000116714575463425022735 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::File < Specinfra::Command::Base::File class << self def check_is_accessible_by_user(file, user, access) "su -s sh -c \"test -#{access} #{file}\" #{user}" end def check_has_mode(file, mode) "find #{file} -prune -perm #{mode} | grep ^#{file}$" end def check_is_owned_by(file, owner) regexp = "^#{owner}$" "ls -al #{escape(file)} | awk '{print $3}' | grep -- #{escape(regexp)}" end def check_is_grouped(file, group) regexp = "^#{group}$" "ls -al #{escape(file)} | awk '{print $4}' | grep -- #{escape(regexp)}" end end end specinfra-2.89.0/lib/specinfra/command/aix/base/port.rb0000644000004100000410000000037214575463425022777 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, options={}) regexp = "*.#{port} " "netstat -an -f inet | awk '{print $4}' | grep -- #{regexp}" end end end specinfra-2.89.0/lib/specinfra/command/aix/base/inventory.rb0000644000004100000410000000202214575463425024042 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'false' end def get_cpu 'false' end def get_hostname 'uname -n' end def get_domain # This is emulating the dnsdomainname command in Linux # Requires proper configuration of /etc/resolv.conf # and DNS. # The exit at the end is to only return one entry if # the host is running in dualstack mode (IPv4 and IPv6) 'host -n `uname -n` | ' + 'awk -v h=`uname -n` \'$1 ~ h { sub(h".", "", $1); print $1; exit }\'' end def get_fqdn # This is emulating the hostname -f command in Linux # Requires proper configuration of /etc/resolv.conf # and DNS. # The exit at the end is to only return one entry if # the host is running in dualstack mode (IPv4 and IPv6) 'host -n `uname -n` | awk -v h=`uname -n` \'$1 ~ h"." { print $1; exit }\'' end def get_filesystem 'df -kP' end end end specinfra-2.89.0/lib/specinfra/command/aix/base.rb0000644000004100000410000000010314575463425022003 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/linux/0000755000004100000410000000000014575463425021130 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/linux/base/0000755000004100000410000000000014575463425022042 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/linux/base/ip6tables.rb0000644000004100000410000000073314575463425024263 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Ip6tables < Specinfra::Command::Base::Ip6tables class << self def check_has_rule(rule, table=nil, chain=nil) cmd = "ip6tables" cmd += " -t #{escape(table)}" if table cmd += " -S" cmd += " #{escape(chain)}" if chain cmd += " | grep -- #{escape(rule)}" cmd += " || ip6tables-save" cmd += " -t #{escape(table)}" if table cmd += " | grep -- #{escape(rule)}" cmd end end end specinfra-2.89.0/lib/specinfra/command/linux/base/bond.rb0000644000004100000410000000044714575463425023316 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Bond < Specinfra::Command::Base::Bond class << self def check_exists(name) "ip link show #{name}" end def check_has_interface(name, interface) "grep -o 'Slave Interface: #{interface}' /proc/net/bonding/#{name}" end end end specinfra-2.89.0/lib/specinfra/command/linux/base/selinux_module.rb0000644000004100000410000000074514575463425025431 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::SelinuxModule < Specinfra::Command::Base::SelinuxModule class << self def check_is_installed(name, version=nil) cmd = "semodule -l | grep $'^#{escape(name)}\\t" cmd += "#{escape(version)}\\t" unless version.nil? cmd += "'" cmd end def check_is_enabled(name) cmd = "semodule -l | grep $'^#{escape(name)}\\t'" cmd += " | grep -v $'^#{escape(name)}\\t.*\\tDisabled$'" cmd end end end specinfra-2.89.0/lib/specinfra/command/linux/base/zfs.rb0000644000004100000410000000022114575463425023164 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Zfs < Specinfra::Command::Base::Zfs class << self include Specinfra::Command::Module::Zfs end end specinfra-2.89.0/lib/specinfra/command/linux/base/service.rb0000644000004100000410000000012714575463425024027 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Service < Specinfra::Command::Base::Service end specinfra-2.89.0/lib/specinfra/command/linux/base/interface.rb0000644000004100000410000000233314575463425024330 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Interface < Specinfra::Command::Base::Interface class << self def check_exists(name) "ip link show #{name}" end def get_speed_of(name) "cat /sys/class/net/#{name}/speed" end def get_mtu_of(name) "cat /sys/class/net/#{name}/mtu" end def check_has_ipv4_address(interface, ip_address) ip_address = ip_address.dup if ip_address =~ /\/\d+$/ ip_address << " " else ip_address << "/" end ip_address.gsub!(".", "\\.") "ip -4 addr show #{interface} | grep 'inet #{ip_address}'" end def check_has_ipv6_address(interface, ip_address) ip_address = ip_address.dup if ip_address =~ /\/\d+$/ ip_address << " " else ip_address << "/" end ip_address.downcase! "ip -6 addr show #{interface} | grep 'inet6 #{ip_address}'" end def get_ipv4_address(interface) "ip -4 addr show #{interface} | grep #{interface}$ | awk '{print $2}'" end def get_ipv6_address(interface) "ip -6 addr show #{interface} | grep inet6 | awk '{print $2}'" end def get_link_state(name) "cat /sys/class/net/#{name}/operstate" end end end specinfra-2.89.0/lib/specinfra/command/linux/base/package.rb0000644000004100000410000000012714575463425023762 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Package < Specinfra::Command::Base::Package end specinfra-2.89.0/lib/specinfra/command/linux/base/fstab.rb0000644000004100000410000000043314575463425023466 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Fstab < Specinfra::Command::Base::Fstab class << self def check_has_entry(mount_point) %Q(awk '{if($2=="#{escape(mount_point)}")print}' /etc/fstab | grep -v '^[[:space:]]*#') end alias :get_entry :check_has_entry end end specinfra-2.89.0/lib/specinfra/command/linux/base/bridge.rb0000644000004100000410000000042314575463425023622 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Bridge < Specinfra::Command::Base::Bridge class << self def check_exists(name) "ip link show #{name}" end def check_has_interface(name, interface) "brctl show #{name} | grep -o #{interface}" end end end specinfra-2.89.0/lib/specinfra/command/linux/base/iptables.rb0000644000004100000410000000053714575463425024177 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Iptables < Specinfra::Command::Base::Iptables class << self def check_has_rule(rule, table=nil, chain=nil) cmd = "iptables" cmd += " -t #{escape(table)}" if table cmd += " -S" cmd += " #{escape(chain)}" if chain cmd += " | grep -- #{escape(rule)}" cmd end end end specinfra-2.89.0/lib/specinfra/command/linux/base/yumrepo.rb0000644000004100000410000000012714575463425024067 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Yumrepo < Specinfra::Command::Base::Yumrepo end specinfra-2.89.0/lib/specinfra/command/linux/base/file.rb0000644000004100000410000000103314575463425023303 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::File < Specinfra::Command::Base::File class << self def check_is_accessible_by_user(file, user, access) "sudo -u #{user} test -#{access} #{file}" end def check_is_immutable(file) check_attribute(file, 'i') end def check_attribute(file, attribute) "lsattr -d #{escape(file)} 2>&1 | " + "awk '$1~/^[A-Za-z-]+$/ && $1~/#{escape(attribute)}/ {exit 0} {exit 1}'" end def get_selinuxlabel(file) "stat -c %C #{escape(file)}" end end end specinfra-2.89.0/lib/specinfra/command/linux/base/selinux.rb0000644000004100000410000000233414575463425024060 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Selinux < Specinfra::Command::Base::Selinux class << self def check_has_mode(mode, policy = nil) cmd = "" # If disabled, then the absence of /etc/selinux/config is sufficient cmd += "test ! -f /etc/selinux/config || " if mode == "disabled" # If disabled, wrap the rest of the test in parentheses # i.e. only test this stuff if /etc/selinux/config exists cmd += "( ( " if mode == "disabled" # Does getenforce return the same value as we are checking for? cmd += "(getenforce | grep -i -- #{escape(mode)})" # If disabled, then permissive is considered a pass cmd += " || (getenforce | grep -i -- #{escape('permissive')}) )" if mode == "disabled" # Ensure that /etc/selinux/config contains the mode we specify cmd += %Q{ && grep -iE -- '^\\s*SELINUX=#{escape(mode)}\\>' /etc/selinux/config} # If we have specified a policy, ensure that is included in /etc/selinux/config cmd += %Q{ && grep -iE -- '^\\s*SELINUXTYPE=#{escape(policy)}\\>' /etc/selinux/config} if policy != nil # End parenthesis for tests when /etc/selinux/config exists cmd += ")" if mode == "disabled" cmd end end end specinfra-2.89.0/lib/specinfra/command/linux/base/lxc_container.rb0000644000004100000410000000104714575463425025221 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::LxcContainer < Specinfra::Command::Base::LxcContainer class << self def check_exists(container) [ "lxc-ls -1 | grep -w #{escape(container)}", "virsh -c lxc:/// list --all --name | grep -w '^#{escape(container)}$'" ].join(' || ') end def check_is_running(container) [ "lxc-info -n #{escape(container)} -s | grep -w RUNNING", "virsh -c lxc:/// list --all --name --state-running | grep -w '^#{escape(container)}$'" ].join(' || ') end end end specinfra-2.89.0/lib/specinfra/command/linux/base/ppa.rb0000644000004100000410000000011714575463425023146 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Ppa < Specinfra::Command::Base::Ppa end specinfra-2.89.0/lib/specinfra/command/linux/base/kernel_module.rb0000644000004100000410000000027314575463425025216 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::KernelModule < Specinfra::Command::Base::KernelModule class << self def check_is_loaded(name) "lsmod | grep ^#{name}" end end end specinfra-2.89.0/lib/specinfra/command/linux/base/kvm_guest.rb0000644000004100000410000000073414575463425024377 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::KvmGuest < Specinfra::Command::Base::KvmGuest class << self def check_exists(guest) "virsh -c qemu:///system list --all --name | grep -w '^#{escape(guest)}$'" end def check_is_running(guest) "virsh -c qemu:///system list --name | grep -w '^#{escape(guest)}$'" end def check_is_enabled(guest) "virsh -c qemu:///system dominfo #{escape(guest)} | grep -E '^Autostart:\s+enable$'" end end end specinfra-2.89.0/lib/specinfra/command/linux/base/inventory.rb0000644000004100000410000000150314575463425024423 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'cat /proc/meminfo' end def get_cpu 'cat /proc/cpuinfo' end def get_hostname 'hostname -s' end def get_domain 'dnsdomainname' end def get_fqdn 'hostname -f' end def get_filesystem 'df -P' end def get_kernel 'uname -s -r' end def get_block_device block_device_dirs = '/sys/block/*/{size,removable,device/{model,rev,state,timeout,vendor},queue/rotational}' %Q[bash -c 'for f in $(ls #{block_device_dirs}); do echo -e "${f}\t$(cat ${f})"; done'] end def get_system_product_name "dmidecode -s system-product-name" end def get_mount 'cat /proc/mounts' end end end specinfra-2.89.0/lib/specinfra/command/linux/base.rb0000644000004100000410000000010514575463425022363 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/devuan/0000755000004100000410000000000014575463425021253 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/devuan/base/0000755000004100000410000000000014575463425022165 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/devuan/base/package.rb0000644000004100000410000000014014575463425024100 0ustar www-datawww-dataclass Specinfra::Command::Devuan::Base::Package < Specinfra::Command::Debian::Base::Package end specinfra-2.89.0/lib/specinfra/command/devuan/base.rb0000644000004100000410000000011614575463425022510 0ustar www-datawww-dataclass Specinfra::Command::Devuan::Base < Specinfra::Command::Debian::Base end specinfra-2.89.0/lib/specinfra/command/coreos/0000755000004100000410000000000014575463425021263 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/coreos/base/0000755000004100000410000000000014575463425022175 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/coreos/base/service.rb0000644000004100000410000000024514575463425024163 0ustar www-datawww-dataclass Specinfra::Command::Coreos::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.89.0/lib/specinfra/command/coreos/base.rb0000644000004100000410000000011514575463425022517 0ustar www-datawww-dataclass Specinfra::Command::Coreos::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/command/amazon/0000755000004100000410000000000014575463425021256 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/amazon/v2/0000755000004100000410000000000014575463425021605 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/amazon/v2/service.rb0000644000004100000410000000024414575463425023572 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2::Service < Specinfra::Command::Amazon::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.89.0/lib/specinfra/command/amazon/v2/port.rb0000644000004100000410000000023114575463425023112 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2::Port < Specinfra::Command::Amazon::Base::Port class << self include Specinfra::Command::Module::Ss end end specinfra-2.89.0/lib/specinfra/command/amazon/base.rb0000644000004100000410000000011614575463425022513 0ustar www-datawww-dataclass Specinfra::Command::Amazon::Base < Specinfra::Command::Redhat::Base end specinfra-2.89.0/lib/specinfra/command/amazon/v2.rb0000644000004100000410000000011414575463425022126 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2 < Specinfra::Command::Redhat::Base end specinfra-2.89.0/lib/specinfra/command/amazon/v2023.rb0000644000004100000410000000012014575463425022350 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2023 < Specinfra::Command::Amazon::V2022 end specinfra-2.89.0/lib/specinfra/command/amazon/v2022/0000755000004100000410000000000014575463425022031 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/amazon/v2022/service.rb0000644000004100000410000000024714575463425024021 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2022::Service < Specinfra::Command::Amazon::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.89.0/lib/specinfra/command/amazon/v2022/package.rb0000644000004100000410000000152314575463425023752 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2022::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) cmd = "rpm -q #{escape(package)}" if version full_package = "#{package}-#{version}" cmd = "#{cmd} | grep -w -- #{Regexp.escape(full_package)}" end cmd end alias :check_is_installed_by_rpm :check_is_installed def get_version(package, opts=nil) "rpm -q --qf '%{VERSION}-%{RELEASE}' #{package}" end def install(package, version=nil, option='') if version full_package = "#{package}-#{version}" else full_package = package end cmd = "dnf -y #{option} install #{escape(full_package)}" end def remove(package, option='') "dnf -y #{option} remove #{package}" end end end specinfra-2.89.0/lib/specinfra/command/amazon/v2022/yumrepo.rb0000644000004100000410000000056314575463425024062 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2022::Yumrepo < Specinfra::Command::Redhat::Base::Yumrepo class << self def check_exists(repository) "dnf repolist all | grep -qsE \"^[\\!\\*]?#{escape(repository)}\(\\s\|$\|\\/)\"" end def check_is_enabled(repository) "dnf repolist enabled | grep -qs \"^[\\!\\*]\\?#{escape(repository)}\"" end end end specinfra-2.89.0/lib/specinfra/command/amazon/v2022/port.rb0000644000004100000410000000023414575463425023341 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2022::Port < Specinfra::Command::Amazon::Base::Port class << self include Specinfra::Command::Module::Ss end end specinfra-2.89.0/lib/specinfra/command/amazon/v2022.rb0000644000004100000410000000011714575463425022355 0ustar www-datawww-dataclass Specinfra::Command::Amazon::V2022 < Specinfra::Command::Redhat::Base end specinfra-2.89.0/lib/specinfra/command/suse/0000755000004100000410000000000014575463425020750 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/suse/base/0000755000004100000410000000000014575463425021662 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/suse/base/service.rb0000644000004100000410000000035414575463425023651 0ustar www-datawww-dataclass Specinfra::Command::Suse::Base::Service < Specinfra::Command::Linux::Base::Service class << self def check_is_enabled(service, level=3) "chkconfig --list #{escape(service)} | grep #{level}:on" end end end specinfra-2.89.0/lib/specinfra/command/suse/base/package.rb0000644000004100000410000000110514575463425023577 0ustar www-datawww-dataclass Specinfra::Command::Suse::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package,version=nil) cmd = "rpm -q #{escape(package)}" if version cmd = "#{cmd} | grep -w -- #{escape(version)}" end cmd end alias :check_is_installed_by_rpm :check_is_installed def install(package, version=nil, option='') cmd = "zypper -n #{option} install #{package}" end def get_version(package, opts=nil) "rpm -qi #{package} | grep Version | awk '{print $3}'" end end end specinfra-2.89.0/lib/specinfra/command/suse/base.rb0000644000004100000410000000011314575463425022202 0ustar www-datawww-dataclass Specinfra::Command::Suse::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/command/esxi/0000755000004100000410000000000014575463425020741 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/esxi/base/0000755000004100000410000000000014575463425021653 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/esxi/base/package.rb0000644000004100000410000000051714575463425023576 0ustar www-datawww-dataclass Specinfra::Command::Esxi::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) cmd = "esxcli software vib list | grep -w -- #{escape(package)}" if version cmd = "#{cmd} | grep -w -- #{escape(version)}" end cmd end end end specinfra-2.89.0/lib/specinfra/command/esxi/base.rb0000644000004100000410000000011314575463425022173 0ustar www-datawww-dataclass Specinfra::Command::Esxi::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/command/neon/0000755000004100000410000000000014575463425020730 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/neon/base.rb0000644000004100000410000000011414575463425022163 0ustar www-datawww-dataclass Specinfra::Command::Neon::Base < Specinfra::Command::Ubuntu::Base end specinfra-2.89.0/lib/specinfra/command/redhat.rb0000644000004100000410000000004514575463425021564 0ustar www-datawww-dataclass Specinfra::Command::Redhat;end specinfra-2.89.0/lib/specinfra/command/elementary.rb0000644000004100000410000000005214575463425022460 0ustar www-datawww-dataclass Specinfra::Command::Elementary; end specinfra-2.89.0/lib/specinfra/command/smartos/0000755000004100000410000000000014575463425021461 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/smartos/base/0000755000004100000410000000000014575463425022373 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/smartos/base/service.rb0000644000004100000410000000057614575463425024370 0ustar www-datawww-dataclass Specinfra::Command::Smartos::Base::Service < Specinfra::Command::Solaris::Base::Service class << self def check_is_enabled(service, level=nil) "svcs -l #{escape(service)} 2>/dev/null | grep '^enabled *true$' >/dev/null" end def check_is_running(service) "svcs -Ho state #{escape(service)} 2>/dev/null |grep '^online$' >/dev/null" end end end specinfra-2.89.0/lib/specinfra/command/smartos/base/package.rb0000644000004100000410000000064014575463425024313 0ustar www-datawww-dataclass Specinfra::Command::Smartos::Base::Package < Specinfra::Command::Solaris::Base::Package class << self def check_is_installed(package, version=nil) cmd = "pkg_info -qE #{escape(package)}" if version cmd = "#{cmd}-#{escape(version)}" end cmd end def get_version(package, opts=nil) "pkg_info -E #{escape(package)} | awk -F '-' '{print $NF}'" end end end specinfra-2.89.0/lib/specinfra/command/smartos/base/file.rb0000644000004100000410000000054114575463425023637 0ustar www-datawww-dataclass Specinfra::Command::Smartos::Base::File < Specinfra::Command::Solaris::Base::File class << self def get_md5sum(file) "/usr/bin/digest -a md5 -v #{escape(file)} | cut -d '=' -f 2 | cut -c 2-" end def get_sha256sum(file) "/usr/bin/digest -a sha256 -v #{escape(file)} | cut -d '=' -f 2 | cut -c 2-" end end end specinfra-2.89.0/lib/specinfra/command/smartos/base.rb0000644000004100000410000000012114575463425022712 0ustar www-datawww-dataclass Specinfra::Command::Smartos::Base < Specinfra::Command::Solaris::Base end specinfra-2.89.0/lib/specinfra/command/smartos.rb0000644000004100000410000000004714575463425022007 0ustar www-datawww-dataclass Specinfra::Command::Smartos; end specinfra-2.89.0/lib/specinfra/command/guix.rb0000644000004100000410000000004414575463425021270 0ustar www-datawww-dataclass Specinfra::Command::Guix; end specinfra-2.89.0/lib/specinfra/command/sles.rb0000644000004100000410000000004414575463425021262 0ustar www-datawww-dataclass Specinfra::Command::Sles; end specinfra-2.89.0/lib/specinfra/command/cumulus/0000755000004100000410000000000014575463425021466 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/cumulus/base/0000755000004100000410000000000014575463425022400 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/cumulus/base/service.rb0000644000004100000410000000056614575463425024374 0ustar www-datawww-dataclass Specinfra::Command::Cumuluslinux::Base::Service < Specinfra::Command::Debian::Base::Service class << self def check_is_running(service) "service #{escape(service)} status && service #{escape(service)} status | grep 'running'" end end end class Specinfra::Command::Cumulusnetworks::Base::Service < Specinfra::Command::Cumuluslinux::Base::Service end specinfra-2.89.0/lib/specinfra/command/cumulus/base/ppa.rb0000644000004100000410000000117214575463425023506 0ustar www-datawww-dataclass Specinfra::Command::Cumuluslinux::Base::Ppa < Specinfra::Command::Debian::Base::Ppa class << self def check_exists(package) %Q{find /etc/apt/ -name \*.list | xargs grep -o "deb +http://repo.cumulusnetworks.com/#{to_apt_line_uri(package)}"} end def check_is_enabled(package) %Q{find /etc/apt/ -name \*.list | xargs grep -o "^deb +http://repo.cumulusnetworks.com/#{to_apt_line_uri(package)}"} end private def to_apt_line_uri(repo) escape(repo.gsub(/^ppa:/,'')) end end end class Specinfra::Command::Cumulusnetworks::Base::Ppa < Specinfra::Command::Cumuluslinux::Base::Ppa end specinfra-2.89.0/lib/specinfra/command/cumulus/base.rb0000644000004100000410000000026314575463425022726 0ustar www-datawww-dataclass Specinfra::Command::Cumuluslinux::Base < Specinfra::Command::Debian::Base end class Specinfra::Command::Cumulusnetworks::Base < Specinfra::Command::Cumuluslinux::Base end specinfra-2.89.0/lib/specinfra/command/base.rb0000644000004100000410000000055214575463425021232 0ustar www-datawww-datarequire 'shellwords' class Specinfra::Command::Base class << self class NotImplementedError < Exception; end def create self end def escape(target) str = case target when Regexp target.source else target.to_s end Shellwords.shellescape(str) end end end specinfra-2.89.0/lib/specinfra/command/devuan.rb0000644000004100000410000000004614575463425021600 0ustar www-datawww-dataclass Specinfra::Command::Devuan; end specinfra-2.89.0/lib/specinfra/command/elementary/0000755000004100000410000000000014575463425022136 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/elementary/base.rb0000644000004100000410000000012214575463425023370 0ustar www-datawww-dataclass Specinfra::Command::Elementary::Base < Specinfra::Command::Ubuntu::Base end specinfra-2.89.0/lib/specinfra/command/windows.rb0000644000004100000410000000004714575463425022011 0ustar www-datawww-dataclass Specinfra::Command::Windows; end specinfra-2.89.0/lib/specinfra/command/linuxmint/0000755000004100000410000000000014575463425022020 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/linuxmint/base.rb0000644000004100000410000000012114575463425023251 0ustar www-datawww-dataclass Specinfra::Command::Linuxmint::Base < Specinfra::Command::Ubuntu::Base end specinfra-2.89.0/lib/specinfra/command/coreos.rb0000644000004100000410000000004614575463425021610 0ustar www-datawww-dataclass Specinfra::Command::Coreos; end specinfra-2.89.0/lib/specinfra/command/arch/0000755000004100000410000000000014575463425020706 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/arch/base/0000755000004100000410000000000014575463425021620 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/arch/base/service.rb0000644000004100000410000000024314575463425023604 0ustar www-datawww-dataclass Specinfra::Command::Arch::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.89.0/lib/specinfra/command/arch/base/package.rb0000644000004100000410000000161514575463425023543 0ustar www-datawww-dataclass Specinfra::Command::Arch::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package,version=nil) if version grep = version.include?('-') ? "^#{escape(version)}$" : "^#{escape(version)}-" "pacman -Q #{escape(package)} | awk '{print $2}' | grep '#{grep}'" else "pacman -Q #{escape(package)} || pacman -Qg #{escape(package)}" end end def get_version(package, opts=nil) "pacman -Qi #{package} | grep Version | awk '{print $3}'" end def install(package, version=nil, option='') # Pacman doesn't support to install specific version. "pacman -S --noconfirm #{option} #{package}" end # Should this method be here or not ? def sync_repos "pacman -Syy" end def remove(package, option='') "pacman -R --noconfirm #{option} #{package}" end end end specinfra-2.89.0/lib/specinfra/command/arch/base.rb0000644000004100000410000000012414575463425022142 0ustar www-datawww-dataclass Specinfra::Command::Arch::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/command/openbsd/0000755000004100000410000000000014575463425021423 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/openbsd/base/0000755000004100000410000000000014575463425022335 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/openbsd/base/bond.rb0000644000004100000410000000041314575463425023602 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Bond < Specinfra::Command::Base::Bond class << self def check_exists(name) "ifconfig #{name}" end def check_has_interface(name, interface) "ifconfig #{name} | grep -o #{interface}" end end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/service.rb0000644000004100000410000000071514575463425024325 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Service < Specinfra::Command::Base::Service class << self def create(os_info=nil) if (os_info || os)[:release].to_f < 5.7 self else Specinfra::Command::Openbsd::V57::Service end end def check_is_enabled(service, level=nil) "/etc/rc.d/#{escape(service)} status" end def check_is_running(service) "/etc/rc.d/#{escape(service)} check" end end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/interface.rb0000644000004100000410000000375214575463425024631 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Interface < Specinfra::Command::Base::Interface class << self def check_exists(name) "ifconfig #{name}" end def get_speed_of(name) "ifconfig #{name} | grep 'media\:' | perl -pe 's|.*media\:.*\\((.*?)\\)|\\1|'" end def check_has_ipv4_address(interface, ip_address) ip_address = ip_address.dup if ip_address =~ /\/\d+$/ # remove the prefix - better would be to calculate the netmask ip_address.gsub!(/\/\d+$/, "") end ip_address << " " ip_address.gsub!(".", "\\.") "ifconfig #{interface} inet | grep 'inet #{ip_address}'" end def check_has_ipv6_address(interface, ip_address) ip_address = ip_address.dup (ip_address, prefixlen) = ip_address.split(/\//) ip_address.downcase! if ip_address =~ /^fe80::/i # link local needs the scope (interface) appended ip_address << "%#{interface}" end unless prefixlen.to_s.empty? # append prefixlen ip_address << " prefixlen #{prefixlen}" else ip_address << " " end "ifconfig #{interface} inet6 | grep 'inet6 #{ip_address}'" end def get_ipv4_address(interface) "ifconfig #{interface} inet | grep inet | awk '{print $2}'" end def get_ipv6_address(interface) # Awk refuses to print '/' even with using escapes or hex so workaround with sed employed here. "ifconfig #{interface} inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" end def get_link_state(interface) # Checks if interfaces is administratively up by parsing the options. # L1 check via status. Virtual interfaces like tapX missing the status will report up. # Emulates operstate in linux with exception of the unknown status. %Q{ifconfig #{interface} 2>&1 | awk -v s=down -F '[:<>,]' } + %Q{'NR == 1 && $3 == "UP" { s="up" }; /status:/ && $2 != " active" { s="down" }; END{ print s }'} end end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/mail_alias.rb0000644000004100000410000000046714575463425024764 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::MailAlias < Specinfra::Command::Base::MailAlias class << self def check_is_aliased_to(recipient, target) target = %Q{([[:space:]]|,)["']?#{escape(target)}["']?(,|$)} "egrep ^#{escape(recipient)}:.*#{escape(target)} /etc/mail/aliases" end end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/user.rb0000644000004100000410000000062114575463425023637 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::User < Specinfra::Command::Base::User class << self def check_has_login_shell(user, path_to_shell) "getent passwd #{escape(user)} | cut -f 7 -d ':' | grep #{escape(path_to_shell)}" end def check_has_home_directory(user, path_to_home) "getent passwd #{escape(user)} | cut -f 6 -d ':' | grep #{escape(path_to_home)}" end end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/package.rb0000644000004100000410000000110114575463425024246 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) if version "pkg_info -a | cut -d ' ' -f 1 | grep #{escape(package)}-#{escape(version)}" else "pkg_info -a | cut -d ' ' -f 1 | grep #{escape(package)}" end end def install(package, version=nil, option='') "pkg_add #{option} #{package}" end def get_version(package, _opts=nil) "pkg_info -I #{package} | sed -e 's/#{package}-//' | cut -d' ' -f1" end end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/host.rb0000644000004100000410000000125714575463425023644 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Host < Specinfra::Command::Base::Host class << self def get_ipaddress(name) # getent hosts will return both the ipv6 and ipv4 record. # this will only pick the first one. (Linux behavior) "getent hosts #{escape(name)} | awk '{print $1; exit}'" end def get_ipv4_address(name) # May return multiple values pick the one matching ipv4 "getent hosts #{escape(name)} | awk '$1 ~ /^[0-9.]+$/ {print $1}'" end def get_ipv6_address(name) # May return multiple values pick the one matching ipv6 "getent hosts #{escape(name)} | awk 'tolower($1) ~ /^[0-9a-f:]+$/ {print $1}'" end end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/fstab.rb0000644000004100000410000000043514575463425023763 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Fstab < Specinfra::Command::Base::Fstab class << self def check_has_entry(mount_point) %Q(awk '{if($2=="#{escape(mount_point)}")print}' /etc/fstab | grep -v '^[[:space:]]*#') end alias :get_entry :check_has_entry end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/bridge.rb0000644000004100000410000000041714575463425024120 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Bridge < Specinfra::Command::Base::Bridge class << self def check_exists(name) "ifconfig #{name}" end def check_has_interface(name, interface) "ifconfig #{name} | grep -o #{interface}" end end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/file.rb0000644000004100000410000000214314575463425023601 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::File < Specinfra::Command::Base::File class << self def get_md5sum(file) "cksum -qa md5 #{escape(file)} | cut -d ' ' -f 1" end def get_sha256sum(file) "cksum -qa sha256 #{escape(file)} | cut -d ' ' -f 1" end def check_is_linked_to(link, target) "stat -f %Y #{escape(link)} | grep -- #{escape(target)}" end def check_has_mode(file, mode) regexp = "^#{mode}$" "stat -f%Lp #{escape(file)} | grep #{escape(regexp)}" end def check_is_owned_by(file, owner) regexp = "^#{owner}$" "stat -f %Su #{escape(file)} | grep -- #{escape(regexp)}" end def check_is_grouped(file, group) regexp = "^#{group}$" "stat -f %Sg #{escape(file)} | grep -- #{escape(regexp)}" end def check_is_mounted(path) regexp = "on #{path} " "mount | grep #{escape(regexp)}" end def get_mode(file) "stat -f%Lp #{escape(file)}" end def get_mtime(file) "stat -f %m #{escape(file)}" end def get_size(file) "stat -f %z #{escape(file)}" end end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/port.rb0000644000004100000410000000071714575463425023653 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, opts={}) protocol = opts[:protocol] case protocol when 'tcp' return "netstat -nat -f inet | egrep '(tcp.*.#{port}.*LISTEN$)'" when 'udp' return "netstat -nat -f inet | egrep '(udp.*.#{port}.*$)'" end "netstat -nat -f inet | egrep '((tcp|udp).*\.#{port}.*LISTEN$)'" end end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/inventory.rb0000644000004100000410000000102514575463425024715 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'false' end def get_cpu 'false' end def get_hostname 'hostname -s' end def get_domain 'hostname | ' + 'awk -v h=`hostname -s` \'$1 ~ h { sub(h".", "", $1); print $1 }\'' end def get_fqdn 'hostname' end def get_filesystem 'df -kP' end def get_system_product_name 'sysctl -n hw.product' end end end specinfra-2.89.0/lib/specinfra/command/openbsd/base/routing_table.rb0000644000004100000410000000042014575463425025514 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::RoutingTable < Specinfra::Command::Base::RoutingTable class << self def check_has_entry(destination) "route -n show -gateway | egrep '^#{destination}' | head -1" end alias :get_entry :check_has_entry end end specinfra-2.89.0/lib/specinfra/command/openbsd/base.rb0000644000004100000410000000011114575463425022653 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/openbsd/v57.rb0000644000004100000410000000011714575463425022370 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::V57 < Specinfra::Command::Openbsd::Base end specinfra-2.89.0/lib/specinfra/command/openbsd/v57/0000755000004100000410000000000014575463425022044 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/openbsd/v57/service.rb0000644000004100000410000000135414575463425024034 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::V57::Service < Specinfra::Command::Openbsd::Base::Service class << self def check_is_enabled(service, level=nil) "rcctl get #{escape(service)} status" end def check_is_running(service) "rcctl check #{escape(service)}" end def enable(service) "rcctl set #{escape(service)} status on" end def disable(service) "rcctl set #{escape(service)} status off" end def start(service) "rcctl start #{escape(service)}" end def stop(service) "rcctl stop #{escape(service)}" end def restart(service) "rcctl restart #{escape(service)}" end def reload(service) "rcctl reload #{escape(service)}" end end end specinfra-2.89.0/lib/specinfra/command/arch.rb0000644000004100000410000000004414575463425021231 0ustar www-datawww-dataclass Specinfra::Command::Arch; end specinfra-2.89.0/lib/specinfra/command/module.rb0000644000004100000410000000010714575463425021601 0ustar www-datawww-datamodule Specinfra module Command module Module end end end specinfra-2.89.0/lib/specinfra/command/poky/0000755000004100000410000000000014575463425020753 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/poky/base/0000755000004100000410000000000014575463425021665 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/poky/base/service.rb0000644000004100000410000000024314575463425023651 0ustar www-datawww-dataclass Specinfra::Command::Poky::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.89.0/lib/specinfra/command/poky/base/interface.rb0000644000004100000410000000014114575463425024146 0ustar www-datawww-dataclass Specinfra::Command::Poky::Base::Interface < Specinfra::Command::Linux::Base::Interface end specinfra-2.89.0/lib/specinfra/command/poky/base/package.rb0000644000004100000410000000141214575463425023603 0ustar www-datawww-dataclass Specinfra::Command::Poky::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) package_escaped = escape(package) cmd = "opkg status #{package_escaped} | grep -E '^Version|(user|ok) installed$'" cmd = "#{cmd} | grep -E #{escape(version)}" if version cmd end alias :check_is_installed_by_opkg :check_is_installed def install(package, version=nil, option='') # opkg doesn't support to install specific version. "opkg install #{option} #{package}" end def get_version(package, opts=nil) "opkg list-installed #{package} | cut -d ' ' -f 3" end def remove(package, option='') "opkg remove #{option} #{package}" end end end specinfra-2.89.0/lib/specinfra/command/poky/base/inventory.rb0000644000004100000410000000014114575463425024243 0ustar www-datawww-dataclass Specinfra::Command::Poky::Base::Inventory < Specinfra::Command::Linux::Base::Inventory end specinfra-2.89.0/lib/specinfra/command/poky/base.rb0000644000004100000410000000011314575463425022205 0ustar www-datawww-dataclass Specinfra::Command::Poky::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/command/linux.rb0000644000004100000410000000004514575463425021454 0ustar www-datawww-dataclass Specinfra::Command::Linux; end specinfra-2.89.0/lib/specinfra/command/ubuntu/0000755000004100000410000000000014575463425021313 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/ubuntu/v15/0000755000004100000410000000000014575463425021726 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/ubuntu/v15/service.rb0000644000004100000410000000024514575463425023714 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::V15::Service < Specinfra::Command::Ubuntu::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.89.0/lib/specinfra/command/ubuntu/v18.rb0000644000004100000410000000011614575463425022254 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::V18 < Specinfra::Command::Ubuntu::Base; end specinfra-2.89.0/lib/specinfra/command/ubuntu/base/0000755000004100000410000000000014575463425022225 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/ubuntu/base/service.rb0000644000004100000410000000065514575463425024220 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::Base::Service < Specinfra::Command::Debian::Base::Service class << self def check_is_running(service) "service #{escape(service)} status && service #{escape(service)} status | egrep 'running|online'" end def create(os_info=nil) if (os_info || os)[:release].to_i < 15 self else Specinfra::Command::Ubuntu::V15::Service end end end end specinfra-2.89.0/lib/specinfra/command/ubuntu/base/port.rb0000644000004100000410000000042014575463425023532 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::Base::Port < Specinfra::Command::Linux::Base::Port class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 18 self else Specinfra::Command::Ubuntu::V18::Port end end end end specinfra-2.89.0/lib/specinfra/command/ubuntu/base/ppa.rb0000644000004100000410000000102214575463425023325 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::Base::Ppa < Specinfra::Command::Debian::Base::Ppa class << self def check_exists(package) %Q{find /etc/apt/ -name \*.list | xargs grep -o -E "deb +[\\"']?http://ppa.launchpad.net/#{to_apt_line_uri(package)}"} end def check_is_enabled(package) %Q{find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/#{to_apt_line_uri(package)}"} end private def to_apt_line_uri(repo) escape(repo.gsub(/^ppa:/,'')) end end end specinfra-2.89.0/lib/specinfra/command/ubuntu/base.rb0000644000004100000410000000011614575463425022550 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::Base < Specinfra::Command::Debian::Base end specinfra-2.89.0/lib/specinfra/command/ubuntu/v18/0000755000004100000410000000000014575463425021731 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/ubuntu/v18/port.rb0000644000004100000410000000023214575463425023237 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::V18::Port < Specinfra::Command::Ubuntu::Base::Port class << self include Specinfra::Command::Module::Ss end end specinfra-2.89.0/lib/specinfra/command/ubuntu/v15.rb0000644000004100000410000000011614575463425022251 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::V15 < Specinfra::Command::Ubuntu::Base; end specinfra-2.89.0/lib/specinfra/command/redhat/0000755000004100000410000000000014575463425021240 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/redhat/v7.rb0000644000004100000410000000011514575463425022116 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V7 < Specinfra::Command::Redhat::Base end specinfra-2.89.0/lib/specinfra/command/redhat/v8.rb0000644000004100000410000000011414575463425022116 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V8 < Specinfra::Command::Redhat::Base end specinfra-2.89.0/lib/specinfra/command/redhat/base/0000755000004100000410000000000014575463425022152 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/redhat/base/selinux_module.rb0000644000004100000410000000045114575463425025533 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::SelinuxModule < Specinfra::Command::Linux::Base::SelinuxModule class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 8 self else Specinfra::Command::Redhat::V8::SelinuxModule end end end end specinfra-2.89.0/lib/specinfra/command/redhat/base/service.rb0000644000004100000410000000054514575463425024143 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Service < Specinfra::Command::Linux::Base::Service class << self def create(os_info=nil) release = (os_info || os)[:release].to_i # Dirty hack for Amazon Linux if release < 7 || release > 2000 self else Specinfra::Command::Redhat::V7::Service end end end end specinfra-2.89.0/lib/specinfra/command/redhat/base/package.rb0000644000004100000410000000152214575463425024072 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) cmd = "rpm -q #{escape(package)}" if version full_package = "#{package}-#{version}" cmd = "#{cmd} | grep -w -- #{Regexp.escape(full_package)}" end cmd end alias :check_is_installed_by_rpm :check_is_installed def get_version(package, opts=nil) "rpm -q --qf '%{VERSION}-%{RELEASE}' #{package}" end def install(package, version=nil, option='') if version full_package = "#{package}-#{version}" else full_package = package end cmd = "yum -y #{option} install #{escape(full_package)}" end def remove(package, option='') "yum -y #{option} remove #{package}" end end end specinfra-2.89.0/lib/specinfra/command/redhat/base/host.rb0000644000004100000410000000052514575463425023456 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Host < Specinfra::Command::Base::Host class << self def create(os_info=nil) release = (os_info || os)[:release].to_i # Dirty hack for Amazon Linux if release < 7 || release > 2000 self else Specinfra::Command::Redhat::V7::Host end end end end specinfra-2.89.0/lib/specinfra/command/redhat/base/iptables.rb0000644000004100000410000000015214575463425024300 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Iptables < Specinfra::Command::Linux::Base::Iptables end specinfra-2.89.0/lib/specinfra/command/redhat/base/yumrepo.rb0000644000004100000410000000103414575463425024175 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Yumrepo < Specinfra::Command::Linux::Base::Yumrepo class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 8 self else Specinfra::Command::Redhat::V8::Yumrepo end end def check_exists(repository) "yum repolist all -C | grep -qsE \"^[\\!\\*]?#{escape(repository)}\(\\s\|$\|\\/)\"" end def check_is_enabled(repository) "yum repolist enabled -C | grep -qs \"^[\\!\\*]\\?#{escape(repository)}\"" end end end specinfra-2.89.0/lib/specinfra/command/redhat/base/port.rb0000644000004100000410000000052514575463425023465 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Port < Specinfra::Command::Base::Port class << self def create(os_info=nil) release = (os_info || os)[:release].to_i # Dirty hack for Amazon Linux if release < 7 || release > 2000 self else Specinfra::Command::Redhat::V7::Port end end end end specinfra-2.89.0/lib/specinfra/command/redhat/v5/0000755000004100000410000000000014575463425021572 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/redhat/v5/iptables.rb0000644000004100000410000000045714575463425023730 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V5::Iptables < Specinfra::Command::Redhat::Base::Iptables class << self def check_has_rule(rule, table=nil, chain=nil) cmd = "iptables-save" cmd += " -t #{escape(table)}" if table cmd += " | grep -- #{escape(rule)}" cmd end end end specinfra-2.89.0/lib/specinfra/command/redhat/base.rb0000644000004100000410000000011514575463425022474 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/command/redhat/v5.rb0000644000004100000410000000011514575463425022114 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V5 < Specinfra::Command::Redhat::Base end specinfra-2.89.0/lib/specinfra/command/redhat/v7/0000755000004100000410000000000014575463425021574 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/redhat/v7/service.rb0000644000004100000410000000024414575463425023561 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V7::Service < Specinfra::Command::Redhat::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.89.0/lib/specinfra/command/redhat/v7/host.rb0000644000004100000410000000104014575463425023071 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V7::Host < Specinfra::Command::Redhat::Base::Host class << self def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -w #{escape(timeout)} -c 2 -n #{escape(host)}" else # RHEL7 comes with ncat which does no longer sport the -z option # hence this kludge "ncat -vvvv#{escape(proto[0].chr)} #{escape(host)} #{escape(port)} " + "-w #{escape(timeout)} -i #{escape(timeout)} 2>&1 | " + "grep -q SUCCESS" end end end end specinfra-2.89.0/lib/specinfra/command/redhat/v7/port.rb0000644000004100000410000000023114575463425023101 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V7::Port < Specinfra::Command::Redhat::Base::Port class << self include Specinfra::Command::Module::Ss end end specinfra-2.89.0/lib/specinfra/command/redhat/v8/0000755000004100000410000000000014575463425021575 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/redhat/v8/selinux_module.rb0000644000004100000410000000047414575463425025163 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V8::SelinuxModule < Specinfra::Command::Redhat::Base::SelinuxModule class << self def check_is_installed(name, version=nil) "semodule -l | grep $'^#{escape(name)}'" end def check_is_enabled(name) "semodule -l | grep $'^#{escape(name)}'" end end end specinfra-2.89.0/lib/specinfra/command/redhat/v8/yumrepo.rb0000644000004100000410000000056014575463425023623 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V8::Yumrepo < Specinfra::Command::Redhat::Base::Yumrepo class << self def check_exists(repository) "dnf repolist all | grep -qsE \"^[\\!\\*]?#{escape(repository)}\(\\s\|$\|\\/)\"" end def check_is_enabled(repository) "dnf repolist enabled | grep -qs \"^[\\!\\*]\\?#{escape(repository)}\"" end end end specinfra-2.89.0/lib/specinfra/command/fedora.rb0000644000004100000410000000004614575463425021556 0ustar www-datawww-dataclass Specinfra::Command::Fedora; end specinfra-2.89.0/lib/specinfra/command/solaris.rb0000644000004100000410000000004714575463425021773 0ustar www-datawww-dataclass Specinfra::Command::Solaris; end specinfra-2.89.0/lib/specinfra/command/neon.rb0000644000004100000410000000004414575463425021253 0ustar www-datawww-dataclass Specinfra::Command::Neon; end specinfra-2.89.0/lib/specinfra/command/eos.rb0000644000004100000410000000004314575463425021101 0ustar www-datawww-dataclass Specinfra::Command::Eos; end specinfra-2.89.0/lib/specinfra/command/guix/0000755000004100000410000000000014575463425020745 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/guix/base/0000755000004100000410000000000014575463425021657 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/guix/base/service.rb0000644000004100000410000000126714575463425023652 0ustar www-datawww-dataclass Specinfra::Command::Guix::Base::Service < Specinfra::Command::Linux::Base::Service class << self def check_is_enabled(service, level=nil) "herd status #{escape(service)} | grep 'It is enabled.'" end def check_is_running(service) "herd status #{escape(service)} | grep 'It is started.'" end def enable(service) "herd enable #{escape(service)}" end def disable(service) "herd disable #{escape(service)}" end def start(service) "herd start #{escape(service)}" end def stop(service) "herd stop #{escape(service)}" end def restart(service) "herd restart #{escape(service)}" end end end specinfra-2.89.0/lib/specinfra/command/guix/base.rb0000644000004100000410000000011314575463425022177 0ustar www-datawww-dataclass Specinfra::Command::Guix::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/command/alpine.rb0000644000004100000410000000004614575463425021566 0ustar www-datawww-dataclass Specinfra::Command::Alpine; end specinfra-2.89.0/lib/specinfra/command/amazon.rb0000644000004100000410000000004614575463425021603 0ustar www-datawww-dataclass Specinfra::Command::Amazon;end specinfra-2.89.0/lib/specinfra/command/gentoo/0000755000004100000410000000000014575463425021264 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/gentoo/base/0000755000004100000410000000000014575463425022176 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/gentoo/base/service.rb0000644000004100000410000000025314575463425024163 0ustar www-datawww-dataclass Specinfra::Command::Gentoo::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::OpenRC end end specinfra-2.89.0/lib/specinfra/command/gentoo/base/package.rb0000644000004100000410000000125014575463425024114 0ustar www-datawww-dataclass Specinfra::Command::Gentoo::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) "eix #{escape(package)} --installed | grep -v \"No matches found\"" end def get_version(package, opts=nil) "equery -q list #{package} | sed -e 's!^.*/?#{package}-!!'" end def install(package, version=nil, option='') if version full_package = "=#{package}-#{version}" else full_package = package end cmd = "emerge #{option} #{full_package}" end def remove(package, option='') cmd = "emerge --unmerge #{option} #{package}" end end end specinfra-2.89.0/lib/specinfra/command/gentoo/base.rb0000644000004100000410000000011514575463425022520 0ustar www-datawww-dataclass Specinfra::Command::Gentoo::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/command/opensuse.rb0000644000004100000410000000005014575463425022152 0ustar www-datawww-dataclass Specinfra::Command::Opensuse; end specinfra-2.89.0/lib/specinfra/command/aix.rb0000644000004100000410000000004314575463425021074 0ustar www-datawww-dataclass Specinfra::Command::Aix; end specinfra-2.89.0/lib/specinfra/command/freebsd/0000755000004100000410000000000014575463425021403 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/freebsd/v7.rb0000644000004100000410000000011614575463425022262 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V7 < Specinfra::Command::Freebsd::Base end specinfra-2.89.0/lib/specinfra/command/freebsd/v8.rb0000644000004100000410000000011614575463425022263 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V8 < Specinfra::Command::Freebsd::Base end specinfra-2.89.0/lib/specinfra/command/freebsd/base/0000755000004100000410000000000014575463425022315 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/freebsd/base/group.rb0000644000004100000410000000060714575463425024001 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Group < Specinfra::Command::Base::Group class << self def update_gid(group, gid) "pw groupmod #{escape(group)} -g #{escape(gid)}" end def add(group, options) command = %w[pw group add] command << escape(group) command << '-g' << escape(options[:gid]) if options[:gid] command.join(' ') end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/zfs.rb0000644000004100000410000000022314575463425023441 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Zfs < Specinfra::Command::Base::Zfs class << self include Specinfra::Command::Module::Zfs end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/process.rb0000644000004100000410000000073414575463425024324 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Process < Specinfra::Command::Base::Process class << self def get(process, opts) "ps -p `pgrep -xn #{escape(process)}` -o #{opts[:format]}" end def count(process) "pgrep #{escape(process)} | wc -l" end def check_is_running(process) "pgrep -q #{escape(process)}" end def check_count(process,count) "test `pgrep #{escape(process)} | wc -l` -eq #{escape(count)}" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/service.rb0000644000004100000410000000044414575463425024304 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Service < Specinfra::Command::Base::Service class << self def check_is_enabled(service, level=3) "service #{escape(service)} enabled" end def check_is_running(service) "service #{escape(service)} onestatus" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/interface.rb0000644000004100000410000000401614575463425024603 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Interface < Specinfra::Command::Base::Interface class << self def check_exists(name) "ifconfig #{name}" end def get_speed_of(name) "ifconfig #{name} | awk '/media:/{if(match($0,/[0-9]+/)){ print substr($0, RSTART, RLENGTH);}}'" end def get_mtu_of(name) "ifconfig #{name} | awk '/mtu /{print $NF}'" end def check_has_ipv4_address(interface, ip_address) ip_address = ip_address.dup if ip_address =~ /\/\d+$/ # remove the prefix - better would be to calculate the netmask ip_address.gsub!(/\/\d+$/, "") end ip_address << " " ip_address.gsub!(".", "\\.") "ifconfig #{interface} inet | grep 'inet #{ip_address}'" end def check_has_ipv6_address(interface, ip_address) ip_address = ip_address.dup (ip_address, prefixlen) = ip_address.split(/\//) ip_address.downcase! if ip_address =~ /^fe80::/i # link local needs the scope (interface) appended ip_address << "%#{interface}" end unless prefixlen.to_s.empty? # append prefixlen ip_address << " prefixlen #{prefixlen}" else ip_address << " " end "ifconfig #{interface} inet6 | grep 'inet6 #{ip_address}'" end def get_ipv4_address(interface) "ifconfig #{interface} inet | grep inet | awk '{print $2}'" end def get_ipv6_address(interface) # Awk refuses to print '/' even with using escapes or hex so workaround with sed employed here. "ifconfig #{interface} inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" end def get_link_state(interface) # Checks if interfaces is administratively up with the -u arg. # L1 check via status. Virtual interfaces like tapX missing the status will report up. # Emulates operstate in linux with exception of the unknown status. %Q{ifconfig -u #{interface} 2>&1 | awk -v s=up '/status:/ && $2 != "active" { s="down" }; END {print s}'} end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/user.rb0000644000004100000410000000325514575463425023625 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::User < Specinfra::Command::Base::User class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 7 Specinfra::Command::Freebsd::V6::User else self end end def get_minimum_days_between_password_change(user) 'echo 0' end def get_maximum_days_between_password_change(user) "pw usershow -n #{escape(user)} | cut -d':' -f 6" end def update_home_directory(user, directory) "pw user mod #{escape(user)} -d #{escape(directory)}" end def update_login_shell(user, shell) "pw user mod #{escape(user)} -s #{escape(shell)}" end def update_uid(user, uid) "pw user mod #{escape(user)} -u #{escape(uid)}" end def update_gid(user, gid) "pw user mod #{escape(user)} -g #{escape(gid)}" end def add(user, options) command = ['pw', 'user', 'add', escape(user)] command << '-g' << escape(options[:gid]) if options[:gid] command << '-d' << escape(options[:home_directory]) if options[:home_directory] command << '-s' << escape(options[:shell]) if options[:shell] command << '-m' if options[:create_home] command << '-u' << escape(options[:uid]) if options[:uid] if options[:password] command.concat(['&&', 'chpass', '-p', "\'#{options[:password]}\'", escape(user)]) end command.join(' ') end def update_encrypted_password(user, encrypted_password) "chpass -p \'#{encrypted_password}\' #{escape(user)}" end def get_encrypted_password(user) "getent passwd #{escape(user)} | awk -F: '{ print $2 }'" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/package.rb0000644000004100000410000000151714575463425024241 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) if version "pkg query %v #{escape(package)} | grep -- #{escape(version)}" else "pkg info -e #{escape(package)}" end end alias :check_is_installed_by_pkg :check_is_installed def check_is_installed_by_rpm(package, version=nil) cmd = "rpm -q #{escape(package)}" if version cmd = "#{cmd} | grep -w -- #{escape(package)}-#{escape(version)}" end cmd end alias :check_is_installed_by_yum :check_is_installed_by_rpm def install(package, version=nil, option='') "pkg install -y #{option} #{package}" end def get_version(package, opts=nil) "pkg query %v #{escape(package)}" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/host.rb0000644000004100000410000000166414575463425023626 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Host < Specinfra::Command::Base::Host class << self def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -t #{escape(timeout)} -c 2 -n #{escape(host)}" else "nc -vvvvz#{escape(proto[0].chr)} #{escape(host)} #{escape(port)} -w #{escape(timeout)}" end end def get_ipaddress(name) # getent hosts will return both the ipv6 and ipv4 record. # this will only pick the first one. (Linux behavior) "getent hosts #{escape(name)} | awk '{print $1; exit}'" end def get_ipv4_address(name) # May return multiple values pick the one matching ipv4 "getent hosts #{escape(name)} | awk '$1 ~ /^[0-9.]+$/ {print $1}'" end def get_ipv6_address(name) # May return multiple values pick the one matching ipv6 "getent hosts #{escape(name)} | awk 'tolower($1) ~ /^[0-9a-f:]+$/ {print $1}'" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/file.rb0000644000004100000410000000220214575463425023555 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::File < Specinfra::Command::Base::File class << self def check_is_grouped(file, group) regexp = "^#{group}$" "stat -f%Sg #{escape(file)} | grep -- #{escape(regexp)}" end def get_owner_group(file) "stat -f%Sg #{escape(file)}" end def check_is_owned_by(file, owner) regexp = "^#{owner}$" "stat -f%Su #{escape(file)} | grep -- #{escape(regexp)}" end def get_owner_user(file) "stat -f%Su #{escape(file)}" end def check_has_mode(file, mode) "test `stat -f%Mp%Lp #{escape(file)} | sed 's/^0*//'` -eq #{escape(mode)}" end def get_mode(file) "stat -f%Mp%Lp #{escape(file)} | sed 's/^0*//'" end def check_is_linked_to(link, target) "stat -f%Y #{escape(link)} | grep -- #{escape(target)}" end def get_mtime(file) "stat -f%m #{escape(file)}" end def get_size(file) "stat -f%z #{escape(file)}" end def get_sha256sum(file) "sha256 #{escape(file)} | cut -d ' ' -f 4" end def get_md5sum(file) "md5 #{escape(file)} | cut -d ' ' -f 4" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/port.rb0000644000004100000410000000036614575463425023633 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, options={}) regexp = ":#{port} " "sockstat -46l -p #{port} | grep -- #{escape(regexp)}" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/kernel_module.rb0000644000004100000410000000027514575463425025473 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::KernelModule < Specinfra::Command::Base::KernelModule class << self def check_is_loaded(name) "kldstat -q -m #{name}" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/inventory.rb0000644000004100000410000000103414575463425024675 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'false' end def get_cpu 'false' end def get_hostname 'hostname -s' end def get_domain 'hostname -f | ' + 'awk -v h=`hostname -s` \'$1 ~ h { sub(h".", "", $1); print $1 }\'' end def get_fqdn 'hostname -f' end def get_filesystem 'df -k' end def get_system_product_name 'kenv smbios.system.product' end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base/routing_table.rb0000644000004100000410000000045014575463425025477 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::RoutingTable < Specinfra::Command::Base::RoutingTable class << self def check_has_entry(destination) %Q{netstat -rnW | grep #{destination} | awk '{print $1, "via", $2, "dev", $6, " "}'} end alias :get_entry :check_has_entry end end specinfra-2.89.0/lib/specinfra/command/freebsd/v11/0000755000004100000410000000000014575463425022012 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/freebsd/v11/interface.rb0000644000004100000410000000056514575463425024305 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V11::Interface < Specinfra::Command::Freebsd::Base::Interface class << self def get_ipv4_address(interface) "ifconfig -f inet:cidr #{interface} inet | awk '/inet /{print $2}'" end def get_ipv6_address(interface) "ifconfig -f inet6:cidr #{interface} inet6 | awk '/inet6 /{print $2}' | tail -1" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/v6/0000755000004100000410000000000014575463425021736 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/freebsd/v6/service.rb0000644000004100000410000000032214575463425023720 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V6::Service < Specinfra::Command::Base::Service class << self def check_is_enabled(service, level=3) "service -e | grep -- /#{escape(service)}$" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/v6/user.rb0000644000004100000410000000114314575463425023240 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V6::User < Specinfra::Command::Freebsd::Base::User class << self def check_has_home_directory(user, path_to_home) "pw user show #{escape(user)} | cut -f 9 -d ':' | grep -w -- #{escape(path_to_home)}" end def check_has_login_shell(user, path_to_shell) "pw user show #{escape(user)} | cut -f 10 -d ':' | grep -w -- #{escape(path_to_shell)}" end def get_home_directory(user) "pw user show #{escape(user)} | cut -f 9 -d ':'" end def get_login_shell(user) "pw user show #{escape(user)} | cut -f 10 -d ':'" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/v6/package.rb0000644000004100000410000000103714575463425023657 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V6::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) if version "pkg_info -I #{escape(package)}-#{escape(version)}" else "pkg_info -Ix #{escape(package)}" end end def install(package, version=nil, option='') "pkg_add -r #{option} #{package}" end def get_version(package, opts=nil) "pkg_info -Ix #{escape(package)} | cut -f 1 -w | sed -n 's/^#{escape(package)}-//p'" end end end specinfra-2.89.0/lib/specinfra/command/freebsd/base.rb0000644000004100000410000000011014575463425022632 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/freebsd/v6.rb0000644000004100000410000000011614575463425022261 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V6 < Specinfra::Command::Freebsd::Base end specinfra-2.89.0/lib/specinfra/command/freebsd/v9.rb0000644000004100000410000000011614575463425022264 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V9 < Specinfra::Command::Freebsd::Base end specinfra-2.89.0/lib/specinfra/command/freebsd/v9/0000755000004100000410000000000014575463425021741 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/freebsd/v9/service.rb0000644000004100000410000000013614575463425023726 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V9::Service < Specinfra::Command::Freebsd::V8::Service end specinfra-2.89.0/lib/specinfra/command/freebsd/v9/package.rb0000644000004100000410000000013714575463425023662 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V9::Package < Specinfra::Command::Freebsd::V8::Package end specinfra-2.89.0/lib/specinfra/command/freebsd/v7/0000755000004100000410000000000014575463425021737 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/freebsd/v7/service.rb0000644000004100000410000000013614575463425023724 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V7::Service < Specinfra::Command::Freebsd::V6::Service end specinfra-2.89.0/lib/specinfra/command/freebsd/v7/package.rb0000644000004100000410000000013714575463425023660 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V7::Package < Specinfra::Command::Freebsd::V6::Package end specinfra-2.89.0/lib/specinfra/command/freebsd/v8/0000755000004100000410000000000014575463425021740 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/freebsd/v8/service.rb0000644000004100000410000000013614575463425023725 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V8::Service < Specinfra::Command::Freebsd::V7::Service end specinfra-2.89.0/lib/specinfra/command/freebsd/v8/package.rb0000644000004100000410000000332014575463425023656 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V8::Package < Specinfra::Command::Freebsd::Base::Package class << self def pkg_info_pattern(package) # allow portorigin (origin/portname) as package argument, so that we get # similar answers from either "pkg info" and "pkg_info" "^#{package.split('/', 2)[-1]}-[0-9][0-9a-zA-Z_\.,]*$" end def shell_check_pkgng # See manpage of pkg(8), the paragraph devoted to -N flag # https://www.freebsd.org/cgi/man.cgi?query=pkg 'TMPDIR=/dev/null ASSUME_ALWAYS_YES=1 PACKAGESITE=file:///nonexist ' \ 'pkg info -x \'pkg(-devel)?$\' > /dev/null 2>&1' end def shell_ifelse(cond, stmt_t, stmt_f) "if #{cond}; then #{stmt_t}; else #{stmt_f}; fi" end def check_is_installed(package, version = nil) if version shell_ifelse( shell_check_pkgng(), "pkg query %v #{escape(package)} | grep -- #{escape(version)}", "pkg_info -I #{escape(package)}-#{escape(version)}" ) else pattern = pkg_info_pattern(package) shell_ifelse( shell_check_pkgng(), "pkg info -e #{escape(package)}", "pkg_info -Ix #{escape(pattern)}" ) end end def install(package, _version = nil, option = '') shell_ifelse( shell_check_pkgng(), "pkg install -y #{option} #{package}", "pkg_add -r #{option} #{package}" ) end def get_version(package, _options = nil) pattern = pkg_info_pattern(package) shell_ifelse( shell_check_pkgng(), "pkg query %v #{escape(package)}", "pkg_info -Ix #{escape(pattern)} | cut -f 1 -w | sed -n 's/^#{escape(package)}-//p'" ) end end end specinfra-2.89.0/lib/specinfra/command/freebsd/v11.rb0000644000004100000410000000011714575463425022336 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V11 < Specinfra::Command::Freebsd::Base end specinfra-2.89.0/lib/specinfra/command/alpine/0000755000004100000410000000000014575463425021241 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/alpine/base/0000755000004100000410000000000014575463425022153 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/alpine/base/process.rb0000644000004100000410000000115214575463425024155 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base::Process < Specinfra::Command::Base class << self def get(process, opts) col = opts[:format].chomp('=') if col == 'args' "ps -o #{col} | grep #{escape(process)} | head -1" else "ps -o #{col},args | grep -E '\\s+#{process}' | awk '{ print $1 }' | head -1" end end def check_is_running(process) "ps -ocomm | grep -w -- #{escape(process)} | grep -qv grep" end def check_count(process, count) "test $(ps -ocomm | grep -w -- #{escape(process)} | grep -v grep | wc -l) -eq #{escape(count)}" end end end specinfra-2.89.0/lib/specinfra/command/alpine/base/service.rb0000644000004100000410000000024414575463425024140 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::OpenRC end end specinfra-2.89.0/lib/specinfra/command/alpine/base/package.rb0000644000004100000410000000130514575463425024072 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version = nil) if version.nil? then pkg = escape(package) "apk info -qe #{pkg}" else pkg = "#{package}-#{version}" "apk info -v | grep -w -- '^#{Regexp.escape(pkg)}'" end end alias_method :check_is_installed_by_apk, :check_is_installed def install(package, version = nil, _option = '') pkg = [escape(package), version].compact.join('=') "apk add -U #{pkg}" end def get_version(package, _opts = nil) "apk version #{package} | tail -n1 | awk '{ print $3; }'" end end end specinfra-2.89.0/lib/specinfra/command/alpine/base/host.rb0000644000004100000410000000060314575463425023454 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base::Host < Specinfra::Command::Base::Host class << self def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -w #{escape(timeout)} -c 2 -n #{escape(host)}" else "nc -w #{escape(timeout)} -vvvvz#{proto.downcase.start_with?('u') ? 'u' : ''} #{escape(host)} #{escape(port)}" end end end end specinfra-2.89.0/lib/specinfra/command/alpine/base.rb0000644000004100000410000000011514575463425022475 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/command/nixos/0000755000004100000410000000000014575463425021131 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/nixos/base/0000755000004100000410000000000014575463425022043 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/nixos/base/service.rb0000644000004100000410000000024414575463425024030 0ustar www-datawww-dataclass Specinfra::Command::Nixos::Base::Service < Specinfra::Command::Linux::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.89.0/lib/specinfra/command/nixos/base/package.rb0000644000004100000410000000106414575463425023764 0ustar www-datawww-dataclass Specinfra::Command::Nixos::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) if version "nix-store -q --references /var/run/current-system/sw | grep #{escape(package)}-#{escape(version)}" else "nix-store -q --references /var/run/current-system/sw | grep #{escape(package)}" end end alias :check_is_installed_by_nix :check_is_installed def install(package, version=nil, option='') "nix-env -i #{option} #{package}" end end end specinfra-2.89.0/lib/specinfra/command/nixos/base.rb0000644000004100000410000000011414575463425022364 0ustar www-datawww-dataclass Specinfra::Command::Nixos::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/command/plamo.rb0000644000004100000410000000004514575463425021425 0ustar www-datawww-dataclass Specinfra::Command::Plamo; end specinfra-2.89.0/lib/specinfra/command/darwin/0000755000004100000410000000000014575463425021255 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/darwin/base/0000755000004100000410000000000014575463425022167 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/darwin/base/group.rb0000644000004100000410000000141214575463425023646 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Group < Specinfra::Command::Base::Group class << self def get_gid(group) "dscl . -read /Groups/#{escape(group)} PrimaryGroupID | awk '{ print $2 }'" end def update_gid(group, gid) "dscl . -create /Groups/#{escape(group)} PrimaryGroupID #{escape(gid)}" end def add(group, options) group_name = escape(group) record_path = "/Groups/#{group_name}" dscl_create = "dscl . -create #{record_path}" command = [dscl_create] command << "#{dscl_create} PrimaryGroupID #{escape(options[:gid])}" if options[:gid] command << "#{dscl_create} RecordName #{escape(options[:groupname])}" if options[:groupname] command.join(' && ') end end end specinfra-2.89.0/lib/specinfra/command/darwin/base/process.rb0000644000004100000410000000040314575463425024167 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Process < Specinfra::Command::Base::Process class << self def get(process, opts) "ps -A -c -o #{opts[:format]},command | grep -E -m 1 ^\\ *[0-9]+\\ +#{escape(process)}$ | awk '{print $1}'" end end end specinfra-2.89.0/lib/specinfra/command/darwin/base/service.rb0000644000004100000410000000106314575463425024154 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Service < Specinfra::Command::Base::Service class << self def check_is_enabled(service, level=nil) "launchctl list | grep #{escape(service)}" end def check_is_enabled_under_homebrew(service) "brew services list | grep #{escape(service)}" end def check_is_running(service) "launchctl list | grep #{escape(service)} | grep -E '^[0-9]+'" end def check_is_running_under_homebrew(service) "brew services list | grep #{escape(service)} | grep 'started'" end end end specinfra-2.89.0/lib/specinfra/command/darwin/base/interface.rb0000644000004100000410000000345514575463425024463 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Interface < Specinfra::Command::Base::Interface class << self def check_exists(name) "ifconfig #{name}" end def check_has_ipv4_address(interface, ip_address) ip_address = ip_address.dup if ip_address =~ /\/\d+$/ # remove the prefix - better would be to calculate the netmask ip_address.gsub!(/\/\d+$/, "") end ip_address << " " ip_address.gsub!(".", "\\.") "ifconfig #{interface} inet | grep 'inet #{ip_address}'" end def check_has_ipv6_address(interface, ip_address) ip_address = ip_address.dup (ip_address, prefixlen) = ip_address.split(/\//) ip_address.downcase! if ip_address =~ /^fe80::/i # link local needs the scope (interface) appended ip_address << "%#{interface}" end unless prefixlen.to_s.empty? # append prefixlen ip_address << " prefixlen #{prefixlen}" else ip_address << " " end "ifconfig #{interface} inet6 | grep 'inet6 #{ip_address}'" end def get_ipv4_address(interface) "ifconfig #{interface} inet | grep inet | awk '{print $2}'" end def get_ipv6_address(interface) # Awk refuses to print '/' even with using escapes or hex so workaround with sed employed here. "ifconfig #{interface} inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" end def get_link_state(interface) # Checks if interfaces is administratively up with the -u arg. # L1 check via status. Virtual interfaces like tapX missing the status will report up. # Emulates operstate in linux with exception of the unknown status. %Q{ifconfig -u #{interface} 2>&1 | awk -v s=up '/status:/ && $2 != "active" { s="down" }; END {print s}'} end end end specinfra-2.89.0/lib/specinfra/command/darwin/base/user.rb0000644000004100000410000000366414575463425023503 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::User < Specinfra::Command::Base::User class << self def check_has_home_directory(user, path_to_home) "#{get_home_directory(user)} | grep -E '^#{escape(path_to_home)}$'" end def check_has_login_shell(user, path_to_shell) "finger #{escape(user)} | grep -E '^Directory' | awk '{ print $4 }' | grep -E '^#{escape(path_to_shell)}$'" end def get_home_directory(user) "finger #{escape(user)} | grep -E '^Directory' | awk '{ print $2 }'" end def update_home_directory(user, directory) "dscl . -create /Users/#{escape(user)} NFSHomeDirectory #{escape(directory)}" end def update_login_shell(user, shell) "dscl . -create /Users/#{escape(user)} UserShell #{escape(shell)}" end def update_encrypted_password(user, password) "dscl . passwd /Users/#{escape(user)} #{escape(password)}" end def update_gid(user, gid) "dscl . -create /Users/#{escape(user)} PrimaryGroupID #{escape(gid)}" end def add(user, options) user_name = escape(user) record_path = "/Users/#{user_name}" dscl_create = "dscl . -create #{record_path}" command = [dscl_create] command << "#{dscl_create} UserShell #{escape(options[:shell])}" if options[:shell] command << "#{dscl_create} UniqueID #{escape(options[:uid])}" if options[:uid] command << "#{dscl_create} PrimaryGroupID #{escape(options[:gid])}" if options[:gid] home_dir = if options[:home_directory] escape(options[:home_directory]) else record_path end command << "#{dscl_create} NFSHomeDirectory #{home_dir}" command << "dscl . passwd #{record_path} #{escape(options[:password])}" if options[:password] command << "createhomedir -b -u #{user_name}" if options[:create_home] command.join(' && ') end end end specinfra-2.89.0/lib/specinfra/command/darwin/base/package.rb0000644000004100000410000000344114575463425024111 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Package < Specinfra::Command::Base::Package class << self def check_is_installed(package, version=nil) escaped_package = escape(::File.basename(package)) if version cmd = %Q[brew info #{escaped_package} | grep -E "^$(brew --prefix)/Cellar/#{escaped_package}/#{escape(version)}"] else cmd = "#{brew_list} | grep -E '^#{escaped_package}$'" end cmd end alias :check_is_installed_by_homebrew :check_is_installed def check_is_installed_by_homebrew_cask(package, version=nil) escaped_package = escape(::File.basename(package)) if version cmd = "brew cask info #{escaped_package} | grep -E '^/opt/homebrew-cask/Caskroom/#{escaped_package}/#{escape(version)}'" else cmd = "#{brew_cask_list} | grep -E '^#{escaped_package}$'" end cmd end def check_is_installed_by_pkgutil(package, version=nil) cmd = "pkgutil --pkg-info #{package}" cmd = "#{cmd} | grep '^version: #{escape(version)}'" if version cmd end def install(package, version=nil, option='') # Homebrew doesn't support to install specific version. cmd = "brew install #{option} '#{package}'" end def remove(package, option='') cmd = "brew uninstall #{option} '#{package}'" end def get_version(package, opts=nil) %Q[ls -1 "$(brew --prefix)/Cellar/#{package}/" | tail -1] end def brew_list # Since `brew list` is slow, directly check Cellar directory 'ls -1 "$(brew --prefix)/Cellar/"' end def brew_cask_list # Since `brew cask list` is slow, directly check Caskroom directory # Brew cask can install in multiple directories "ls -1 /opt/homebrew-cask/Caskroom/ /usr/local/Caskroom" end end end specinfra-2.89.0/lib/specinfra/command/darwin/base/host.rb0000644000004100000410000000331114575463425023467 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Host < Specinfra::Command::Base::Host class << self def check_is_resolvable(name, type) if type == "dns" ## try to resolve either A or AAAA record; grep is used to return the appropriate exit code %Q{dig +search +short +time=1 -q #{escape(name)} a #{escape(name)} aaaa | grep -qie '^[0-9a-f:.]*$'} elsif type == "hosts" "sed 's/#.*$//' /etc/hosts | grep -w -- #{escape(name)}" else ## grep is required as dscacheutil always returns exit code 0 "dscacheutil -q host -a name #{escape(name)} | grep -q '_address:'" end end def check_is_reachable(host, port, proto, timeout) if port.nil? "ping -t #{escape(timeout)} -c 2 -n #{escape(host)}" else "nc -vvvvz#{escape(proto[0].chr)} #{escape(host)} #{escape(port)} -w #{escape(timeout)} -G #{escape(timeout)}" end end def get_ipaddress(name) # If the query returns multiple records the most likey match is returned. # Generally this means IPv6 wins over IPv4. %Q{dscacheutil -q host -a name #{escape(name)} | } + %Q{awk '/^ipv6_/{ ip = $2 }; /^$/{ exit }; /^ip_/{ ip = $2; exit}; END{ print ip }'} end def get_ipv4_address(name) ## With dscacheutil multiple IPs can be returned for IPv4 just pick the first one %Q{dscacheutil -q host -a name #{escape(name)} | awk '/^ip_/{ print $2; exit }'} end def get_ipv6_address(name) ## With dscacheutil multiple IPs can be returned. For IPv6 the link-local is displayed first ## hence the last entry is picked. %Q{dscacheutil -q host -a name #{escape(name)} | awk '/^ipv6_/{ ip = $2 } END{ print ip }'} end end end specinfra-2.89.0/lib/specinfra/command/darwin/base/file.rb0000644000004100000410000000236214575463425023436 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::File < Specinfra::Command::Base::File class << self def check_is_accessible_by_user(file, user, access) "sudo -u #{user} -s /bin/test -#{access} #{file}" end def get_md5sum(file) "openssl md5 #{escape(file)} | cut -d'=' -f2 | cut -c 2-" end def get_sha256sum(file) "ruby -e \"require 'digest'; puts Digest::SHA256.hexdigest File.read '#{escape(file)}'\"" end def check_is_linked_to(link, target) "stat -f %Y #{escape(link)} | grep -- #{escape(target)}" end def check_has_mode(file, mode) regexp = "^#{mode}$" "stat -f%Lp #{escape(file)} | grep -- #{escape(regexp)}" end def check_is_owned_by(file, owner) regexp = "^#{owner}$" "stat -f %Su #{escape(file)} | grep -- #{escape(regexp)}" end def check_is_grouped(file, group) regexp = "^#{group}$" "stat -f %Sg #{escape(file)} | grep -- #{escape(regexp)}" end def get_mode(file) "stat -f%Lp #{escape(file)}" end def get_size(file) "stat -f %z #{escape(file)}" end def get_owner_user(file) "stat -f %Su #{escape(file)}" end def get_owner_group(file) "stat -f %Sg #{escape(file)}" end end end specinfra-2.89.0/lib/specinfra/command/darwin/base/port.rb0000644000004100000410000000077314575463425023507 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, options={}) regexp = ":#{port} " protocol = options[:protocol] || 'tcp' protocol_options = case protocol when 'tcp' "-iTCP -sTCP:LISTEN" when 'tcp6' "-i6TCP -sTCP:LISTEN" when 'udp' "-iUDP" when 'udp6' "-i6UDP" end "lsof -nP #{protocol_options} | grep -- #{escape(regexp)}" end end end specinfra-2.89.0/lib/specinfra/command/darwin/base/inventory.rb0000644000004100000410000000077114575463425024556 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Inventory < Specinfra::Command::Base::Inventory class << self def get_memory 'false' end def get_cpu 'false' end def get_kernel 'false' end def get_hostname 'hostname -s' end def get_domain 'hostname -f | ' + 'awk -v h=`hostname -s` \'$1 ~ h { sub(h".", "", $1); print $1 }\'' end def get_fqdn 'hostname -f' end def get_filesystem 'df -k' end end end specinfra-2.89.0/lib/specinfra/command/darwin/base.rb0000644000004100000410000000010614575463425022511 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base < Specinfra::Command::Base end specinfra-2.89.0/lib/specinfra/command/fedora/0000755000004100000410000000000014575463425021231 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/fedora/v15/0000755000004100000410000000000014575463425021644 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/fedora/v15/service.rb0000644000004100000410000000024514575463425023632 0ustar www-datawww-dataclass Specinfra::Command::Fedora::V15::Service < Specinfra::Command::Fedora::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.89.0/lib/specinfra/command/fedora/base/0000755000004100000410000000000014575463425022143 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/fedora/base/service.rb0000644000004100000410000000043214575463425024127 0ustar www-datawww-dataclass Specinfra::Command::Fedora::Base::Service < Specinfra::Command::Redhat::Base::Service class << self def create(os_info=nil) if (os_info || os)[:release].to_i < 15 self else Specinfra::Command::Fedora::V15::Service end end end end specinfra-2.89.0/lib/specinfra/command/fedora/base.rb0000644000004100000410000000011614575463425022466 0ustar www-datawww-dataclass Specinfra::Command::Fedora::Base < Specinfra::Command::Redhat::Base end specinfra-2.89.0/lib/specinfra/command/fedora/v15.rb0000644000004100000410000000011514575463425022166 0ustar www-datawww-dataclass Specinfra::Command::Fedora::V15 < Specinfra::Command::Fedora::Base end specinfra-2.89.0/lib/specinfra/command/module/0000755000004100000410000000000014575463425021256 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/module/systemd.rb0000644000004100000410000000041714575463425023275 0ustar www-datawww-datamodule Specinfra module Command module Module module Systemd include Specinfra::Command::Module::Service::Systemd extend Specinfra::Command::Module::Service::Delegator def_delegator_service_under :systemd end end end end specinfra-2.89.0/lib/specinfra/command/module/zfs.rb0000644000004100000410000000112414575463425022403 0ustar www-datawww-datamodule Specinfra module Command module Module module Zfs def check_exists(zfs) "zfs list -H #{escape(zfs)}" end def check_has_property(zfs, property=nil) commands = [] property.sort.each do |key, value| regexp = "^#{value}$" commands << "zfs list -H -o #{escape(key)} #{escape(zfs)} | grep -- #{escape(regexp)}" end commands.join(' && ') end def get_property(zfs) "zfs get -Hp -o property,value all #{escape(zfs)}" end end end end end specinfra-2.89.0/lib/specinfra/command/module/openrc.rb0000644000004100000410000000041314575463425023067 0ustar www-datawww-datamodule Specinfra module Command module Module module OpenRC include Specinfra::Command::Module::Service::OpenRC extend Specinfra::Command::Module::Service::Delegator def_delegator_service_under :openrc end end end end specinfra-2.89.0/lib/specinfra/command/module/service/0000755000004100000410000000000014575463425022716 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/module/service/systemd.rb0000644000004100000410000000203314575463425024731 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Systemd def check_is_enabled_under_systemd(service, level=nil) "systemctl --quiet is-enabled #{escape(service)}" end def check_is_running_under_systemd(service) "systemctl is-active #{escape(service)}" end def enable_under_systemd(service) "systemctl enable #{escape(service)}" end def disable_under_systemd(service) "systemctl disable #{escape(service)}" end def start_under_systemd(service) "systemctl start #{escape(service)}" end def stop_under_systemd(service) "systemctl stop #{escape(service)}" end def restart_under_systemd(service) "systemctl restart #{escape(service)}" end def reload_under_systemd(service) "systemctl reload #{escape(service)}" end end end end end end specinfra-2.89.0/lib/specinfra/command/module/service/runit.rb0000644000004100000410000000060114575463425024401 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Runit def check_is_running_under_runit(service) "sv status #{escape(service)} | grep -E '^run: '" end def check_is_enabled_under_runit(service) "test ! -f /etc/sv/#{escape(service)}/down" end end end end end end specinfra-2.89.0/lib/specinfra/command/module/service/openrc.rb0000644000004100000410000000202614575463425024531 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module OpenRC def check_is_enabled_under_openrc(service, level=3) "rc-update show boot default | grep -w #{escape(service)}" end def check_is_running_under_openrc(service) "/etc/init.d/#{escape(service)} status" end def enable_under_openrc(service) "rc-update add #{escape(service)}" end def disable_under_openrc(service) "rc-update del #{escape(service)}" end def start_under_openrc(service) "rc-service #{escape(service)} start" end def stop_under_openrc(service) "rc-service #{escape(service)} stop" end def restart_under_openrc(service) "rc-service #{escape(service)} restart" end def reload_under_openrc(service) "/etc/init.d/#{escape(service)} reload" end end end end end end specinfra-2.89.0/lib/specinfra/command/module/service/monit.rb0000644000004100000410000000034214575463425024370 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Monit def check_is_monitored_by_monit(service) "monit status" end end end end end end specinfra-2.89.0/lib/specinfra/command/module/service/init.rb0000644000004100000410000000176114575463425024213 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Init def check_is_enabled_under_init(service, level=3) "chkconfig --list #{escape(service)} | grep #{level}:on" end def check_is_running_under_init(service) "service #{escape(service)} status" end def enable_under_init(service) "chkconfig #{escape(service)} on" end def disable_under_init(service) "chkconfig #{escape(service)} off" end def start_under_init(service) "service #{escape(service)} start" end def stop_under_init(service) "service #{escape(service)} stop" end def restart_under_init(service) "service #{escape(service)} restart" end def reload_under_init(service) "service #{escape(service)} reload" end end end end end end specinfra-2.89.0/lib/specinfra/command/module/service/upstart.rb0000644000004100000410000000041314575463425024743 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Upstart def check_is_running_under_upstart(service) "initctl status #{escape(service)} | grep running" end end end end end end specinfra-2.89.0/lib/specinfra/command/module/service/god.rb0000644000004100000410000000035714575463425024021 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module God def check_is_monitored_by_god(service) "god status #{escape(service)}" end end end end end end specinfra-2.89.0/lib/specinfra/command/module/service/daemontools.rb0000644000004100000410000000254314575463425025573 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Daemontools def check_is_enabled_under_daemontools(service) "test -L #{service_dir}/#{escape(service)} && test -f #{service_dir}/#{escape(service)}/run" end def check_is_running_under_daemontools(service) "svstat #{service_dir}/#{escape(service)} | grep -E 'up \\(pid [0-9]+\\)'" end def enable_under_daemontools(service, directory) "ln -snf #{escape(directory)} #{service_dir}/#{escape(service)}" end def disable_under_daemontools(service) "( cd #{service_dir}/#{escape(service)} && rm -f #{service_dir}/#{escape(service)} && svc -dx . log )" end def start_under_daemontools(service) "svc -u #{service_dir}/#{escape(service)}" end def stop_under_daemontools(service) "svc -d #{service_dir}/#{escape(service)}" end def restart_under_daemontools(service) "svc -t #{service_dir}/#{escape(service)}" end def reload_under_daemontools(service) "svc -h #{service_dir}/#{escape(service)}" end private def service_dir '$([ -d /service ] && echo /service || echo /etc/service)' end end end end end end specinfra-2.89.0/lib/specinfra/command/module/service/supervisor.rb0000644000004100000410000000042714575463425025467 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Supervisor def check_is_running_under_supervisor(service) "supervisorctl status #{escape(service)} | grep RUNNING" end end end end end end specinfra-2.89.0/lib/specinfra/command/module/service/delegator.rb0000644000004100000410000000155414575463425025216 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Delegator def def_delegator_service_under(under) self.send(:alias_method, :check_is_enabled, :"check_is_enabled_under_#{under}") self.send(:alias_method, :check_is_running, :"check_is_running_under_#{under}") self.send(:alias_method, :enable, :"enable_under_#{under}") self.send(:alias_method, :disable, :"disable_under_#{under}") self.send(:alias_method, :start, :"start_under_#{under}") self.send(:alias_method, :stop, :"stop_under_#{under}") self.send(:alias_method, :restart, :"restart_under_#{under}") self.send(:alias_method, :reload, :"reload_under_#{under}") end end end end end end specinfra-2.89.0/lib/specinfra/command/module/ss.rb0000644000004100000410000000275414575463425022240 0ustar www-datawww-datamodule Specinfra module Command module Module module Ss def check_is_listening(port, options={}) if options[:local_address] pattern = inaddr_any_to_asterisk(options[:local_address]).map { |l| " #{l}:#{port} " } pattern = pattern.join('|') else pattern = ":#{port} " end "ss #{command_options(options[:protocol])} | grep -E -- #{escape(pattern)}" end private # WORKAROUND: # Older ss versions display "*" instead of "0.0.0.0". # But serverspec validates IP address by `valid_ip_address?` method: # https://github.com/serverspec/serverspec/blob/master/lib/serverspec/type/port.rb def inaddr_any_to_asterisk(local_address) if local_address == '0.0.0.0' [ '\*' , '0\.0\.0\.0' ] else [ fix_format_if_ipv6(local_address) ] end end def fix_format_if_ipv6(local_address) if local_address =~ /.*:.*/ "\\[#{local_address}\\]" else local_address end end def command_options(protocol) case protocol.to_s when 'tcp' then "-tnl4" when 'tcp6' then "-tnl6" when 'udp' then "-unl4" when 'udp6' then "-unl6" when '' then "-tunl" else raise ArgumentError, "Unknown protocol [#{protocol}]" end end end end end end specinfra-2.89.0/lib/specinfra/command/nixos.rb0000644000004100000410000000004514575463425021455 0ustar www-datawww-dataclass Specinfra::Command::Nixos; end specinfra-2.89.0/lib/specinfra/command/suse.rb0000644000004100000410000000004414575463425021273 0ustar www-datawww-dataclass Specinfra::Command::Suse; end specinfra-2.89.0/lib/specinfra/command/debian.rb0000644000004100000410000000004614575463425021540 0ustar www-datawww-dataclass Specinfra::Command::Debian; end specinfra-2.89.0/lib/specinfra/command/openbsd.rb0000644000004100000410000000004714575463425021751 0ustar www-datawww-dataclass Specinfra::Command::Openbsd; end specinfra-2.89.0/lib/specinfra/command/opensuse/0000755000004100000410000000000014575463425021632 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/opensuse/base/0000755000004100000410000000000014575463425022544 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/opensuse/base/service.rb0000644000004100000410000000054114575463425024531 0ustar www-datawww-dataclass Specinfra::Command::Opensuse::Base::Service < Specinfra::Command::Suse::Base::Service class << self include Specinfra::Command::Module::Systemd def check_is_running(service) "service #{escape(service)} status" end def check_is_enabled(service, level=nil) "systemctl is-enabled #{escape(service)}" end end end specinfra-2.89.0/lib/specinfra/command/opensuse/base.rb0000644000004100000410000000011714575463425023070 0ustar www-datawww-dataclass Specinfra::Command::Opensuse::Base < Specinfra::Command::Suse::Base end specinfra-2.89.0/lib/specinfra/command/poky.rb0000644000004100000410000000004414575463425021276 0ustar www-datawww-dataclass Specinfra::Command::Poky; end specinfra-2.89.0/lib/specinfra/command/eos/0000755000004100000410000000000014575463425020557 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/eos/base.rb0000644000004100000410000000011314575463425022011 0ustar www-datawww-dataclass Specinfra::Command::Eos::Base < Specinfra::Command::Fedora::Base end specinfra-2.89.0/lib/specinfra/command/esxi.rb0000644000004100000410000000004414575463425021264 0ustar www-datawww-dataclass Specinfra::Command::Esxi; end specinfra-2.89.0/lib/specinfra/command/vyos.rb0000644000004100000410000000004314575463425021313 0ustar www-datawww-dataclass Specinfra::Command::Vyos; endspecinfra-2.89.0/lib/specinfra/command/raspbian.rb0000644000004100000410000000010514575463425022111 0ustar www-datawww-dataclass Specinfra::Command::Raspbian < Specinfra::Command::Debian; end specinfra-2.89.0/lib/specinfra/command/vyos/0000755000004100000410000000000014575463425020771 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/vyos/base.rb0000644000004100000410000000011314575463425022223 0ustar www-datawww-dataclass Specinfra::Command::Vyos::Base < Specinfra::Command::Debian::Base endspecinfra-2.89.0/lib/specinfra/command/ubuntu.rb0000644000004100000410000000004614575463425021640 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu; end specinfra-2.89.0/lib/specinfra/command/darwin.rb0000644000004100000410000000004614575463425021602 0ustar www-datawww-dataclass Specinfra::Command::Darwin; end specinfra-2.89.0/lib/specinfra/command/plamo/0000755000004100000410000000000014575463425021101 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/plamo/base/0000755000004100000410000000000014575463425022013 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/command/plamo/base/service.rb0000644000004100000410000000053514575463425024003 0ustar www-datawww-dataclass Specinfra::Command::Plamo::Base::Service < Specinfra::Command::Linux::Base::Service class << self def check_is_enabled(service, level=3) # This check is not necessarily detected whether service is enabled or not # TODO: check rc.inet2 $SERV variable "test -x /etc/rc.d/init.d/#{escape(service)}" end end end specinfra-2.89.0/lib/specinfra/command/plamo/base/package.rb0000644000004100000410000000061014575463425023730 0ustar www-datawww-dataclass Specinfra::Command::Plamo::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) cmd = "ls /var/log/packages/#{escape(package)}" if version cmd = "#{cmd} && grep -E \"PACKAGE NAME:.+#{escape(package)}-#{escape(version)}\" /var/log/packages/#{escape(package)}" end cmd end end end specinfra-2.89.0/lib/specinfra/command/plamo/base.rb0000644000004100000410000000011514575463425022335 0ustar www-datawww-dataclass Specinfra::Command::Plamo::Base < Specinfra::Command::Linux::Base end specinfra-2.89.0/lib/specinfra/backend/0000755000004100000410000000000014575463425017742 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/backend/cmd.rb0000644000004100000410000000450514575463425021036 0ustar www-datawww-datarequire 'open3' module Specinfra module Backend class Cmd < Base include PowerShell::ScriptHelper def os_info { :family => 'windows', :release => nil, :arch => nil, :cygwin => `echo $0`.include?("sh") } end def run_command(cmd, opts={}) script = create_script(cmd) psh = powershell if os_info[:cygwin] # convert c:\windows... to /cygdrive/c/windows... psh.gsub!("\\", "/") psh.sub!(":", "") psh = psh.prepend("/cygdrive/") end result = execute_script %Q{#{psh} -NoProfile -encodedCommand #{encode_script(script)}} if @example @example.metadata[:command] = script @example.metadata[:stdout] = result[:stdout] + result[:stderr] end CommandResult.new :stdout => result[:stdout], :stderr => result[:stderr], :exit_status => result[:status] end def execute_script script if Open3.respond_to? :capture3 stdout, stderr, status = Open3.capture3(script) # powershell still exits with 0 even if there are syntax errors, although it spits the error out into stderr # so we have to resort to return an error exit code if there is anything in the standard error status = 1 if status == 0 and !stderr.empty? { :stdout => stdout, :stderr => stderr, :status => status } else stdout = `#{script} 2>&1` { :stdout => stdout, :stderr => nil, :status => $? } end end def check_os # Dirty hack for specs 'Windows' end private def powershell architecture = if @example @example.metadata[:architecture] end architecture ||= get_config(:architecture) case architecture when :i386 then x86_powershell when :x86_64 then x64_powershell else raise ArgumentError, "invalid architecture [#{architecture}]" end end def x64_powershell find_powershell(%w(sysnative system32)) end def x86_powershell find_powershell(%w(syswow64 system32)) end def find_powershell(dirs) ( dirs.map { |dir| "#{ENV['WINDIR']}\\#{dir}\\WindowsPowerShell\\v1.0\\powershell.exe" } ).find { |exe| File.exist?(exe) } || 'powershell' end end end end specinfra-2.89.0/lib/specinfra/backend/shell_script.rb0000644000004100000410000000100014575463425022751 0ustar www-datawww-datarequire 'singleton' module Specinfra module Backend class ShellScript < Base def initialize(config = {}) super @lines = [ "#!/bin/sh", "" ] ObjectSpace.define_finalizer(self, Writer.new(@lines)) end def run_command(cmd, opts={}) @lines << cmd CommandResult.new end class Writer def initialize(lines) @lines = lines end def call(*args) puts @lines end end end end end specinfra-2.89.0/lib/specinfra/backend/lxd.rb0000644000004100000410000000203714575463425021060 0ustar www-datawww-data# frozen_string_literal: true require 'singleton' require 'fileutils' require 'shellwords' require 'sfl' if Specinfra.ruby_is_older_than?(1, 9, 0) module Specinfra module Backend # LXD transport class Lxd < Exec def build_command(cmd) lxc_cmd = %W[lxc exec #{instance}] lxc_cmd << '-t' if get_config(:interactive_shell) lxc_cmd << '--' (lxc_cmd << super(cmd)).join(' ') end def send_file(source, destination) flags = %w[--create-dirs] if File.directory?(source) flags << '--recursive' destination = Pathname.new(destination).dirname.to_s end cmd = %W[lxc file push #{source} #{instance}#{destination}] + flags spawn_command(cmd.join(' ')) end private def instance raise 'Please specify lxd_instance' unless (instance = get_config(:lxd_instance)) raise 'Please specify lxd_remote' unless (remote = get_config(:lxd_remote)) [remote, instance].compact.join(':') end end end end specinfra-2.89.0/lib/specinfra/backend/lxc.rb0000644000004100000410000000201214575463425021050 0ustar www-datawww-datamodule Specinfra module Backend class Lxc < Exec def initialize(config = {}) super begin require 'lxc/extra' unless defined?(::LXC::Extra) rescue LoadError fail "LXC client library is not available. Try installing `lxc-extra' gem" end end def run_command(cmd, opts={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) out, ret = ct.execute do out = `#{cmd} 2>&1` [out, $?.dup] end if @example @example.metadata[:command] = cmd @example.metadata[:stdout] = out end CommandResult.new :stdout => out, :exit_status => ret.exitstatus end def build_command(cmd) cmd end def add_pre_command(cmd) cmd end def send_file(from, to) FileUtils.cp(from, File.join(ct.config_item('lxc.rootfs'), to)) end def ct @ct ||= ::LXC::Container.new(get_config(:lxc)) end end end end specinfra-2.89.0/lib/specinfra/backend/docker.rb0000644000004100000410000000750414575463425021544 0ustar www-datawww-datamodule Specinfra module Backend class Docker < Exec def initialize(config = {}) super begin require 'docker' unless defined?(::Docker) rescue LoadError fail "Docker client library is not available. Try installing `docker-api' gem." end ::Docker.url = get_config(:docker_url) if image = get_config(:docker_image) @images = [] @base_image = get_or_pull_image(image) create_and_start_container ObjectSpace.define_finalizer(self, self.class.__send__(:finalizer_for, @container)) elsif container = get_config(:docker_container) @container = ::Docker::Container.get(container) else fail 'Please specify docker_image or docker_container.' end end class << self protected # Get a finalizer for given container. # # @param [::Docker::Container, nil] container # # @return [Proc] def finalizer_for(container) proc do # noinspection RubyNilAnalysis unless container.nil? container.stop container.delete end end end end def run_command(cmd, opts={}) cmd = build_command(cmd) run_pre_command(opts) docker_run!(cmd, opts) end def send_file(from, to) if @base_image @images << commit_container if @container @images << current_image.insert_local('localPath' => from, 'outputPath' => to) cleanup_container create_and_start_container elsif @container # This needs Docker >= 1.8 @container.archive_in(from, to) else fail 'Cannot call send_file without docker_image or docker_container.' end end def commit_container @container.commit end private def create_and_start_container opts = { 'Image' => current_image.id } if current_image.json["Config"]["Cmd"].nil? && current_image.json["Config"]["Entrypoint"].nil? opts.merge!({'Cmd' => ['/bin/sh']}) end opts.merge!({'OpenStdin' => true}) if path = get_config(:path) (opts['Env'] ||= []) << "PATH=#{path}" end env = get_config(:env).to_a.map { |v| v.join('=') } opts['Env'] = opts['Env'].to_a.concat(env) opts.merge!(get_config(:docker_container_create_options) || {}) @container = ::Docker::Container.create(opts) @container.start while @container.json['State'].key?('Health') && @container.json['State']['Health']['Status'] == "starting" do sleep 0.5 end end def cleanup_container self.class.__send__(:finalizer_for, @container).call end def current_image @images.last || @base_image end def docker_run!(cmd, opts={}) opts.merge!(get_config(:docker_container_exec_options) || {}) stdout, stderr, status = @container.exec(cmd.shellsplit, opts) CommandResult.new :stdout => stdout.join, :stderr => stderr.join, :exit_status => status rescue ::Docker::Error::DockerError => e raise rescue => e @container.kill err = stderr.nil? ? ([e.message] + e.backtrace) : stderr CommandResult.new :stdout => [stdout].join, :stderr => err.join, :exit_status => (status || 1) end def get_or_pull_image(name) begin ::Docker::Image.get(name) rescue ::Docker::Error::NotFoundError ::Docker::Image.create('fromImage' => name) end end def run_pre_command(opts) if get_config(:pre_command) cmd = build_command(get_config(:pre_command)) docker_run!(cmd, opts) end end end end end specinfra-2.89.0/lib/specinfra/backend/dockercli.rb0000644000004100000410000000154114575463425022227 0ustar www-datawww-data# frozen_string_literal: true module Specinfra module Backend # Docker command line transport class Dockercli < Exec def build_command(cmd) docker_cmd = %w[docker exec] docker_cmd << '--interactive' if get_config(:interactive_shell) docker_cmd << '--tty' if get_config(:request_pty) docker_cmd << instance (docker_cmd << super(cmd)).join(' ') end def send_file(from, to) to = Pathname.new(to).dirname.to_s if File.directory?(from) cmd = %W[docker cp #{from} #{instance}:#{to}] spawn_command(cmd.join(' ')) end def send_directory(from, to) send_file(from, to) end private def instance raise 'Please specify docker_container' unless (container = get_config(:docker_container)) container end end end end specinfra-2.89.0/lib/specinfra/backend/base.rb0000644000004100000410000000231114575463425021176 0ustar www-datawww-datarequire 'singleton' require 'specinfra/command_result' module Specinfra module Backend class Base def self.instance @instance ||= self.new end def self.clear @instance = nil end def initialize(config = {}) @config = config @example = nil end def get_config(key) @config[key] || Specinfra.configuration.send(key) end def set_config(key, value) @config[key] = value end def os_info return @os_info if @os_info Specinfra::Helper::DetectOs.subclasses.each do |klass| if @os_info = klass.new(self).detect @os_info[:arch] ||= self.run_command('uname -m').stdout.strip return @os_info end end raise NotImplementedError, 'OS detection failed.' end def command CommandFactory.new(os_info) end def host_inventory @inventory ||= HostInventory.new(self) end def set_example(e) @example = e end def stdout_handler=(block) @stdout_handler = block end def stderr_handler=(block) @stderr_handler = block end end end end specinfra-2.89.0/lib/specinfra/backend/telnet.rb0000644000004100000410000000506614575463425021571 0ustar www-datawww-data# -*- coding: utf-8 -*- require 'specinfra/backend/exec' require 'net/telnet' module Specinfra module Backend class Telnet < Exec def run_command(cmd, opt={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) ret = with_env do telnet_exec!(cmd) end if @example @example.metadata[:command] = cmd @example.metadata[:stdout] = ret[:stdout] end CommandResult.new ret end def build_command(cmd) cmd = super(cmd) cmd end private def prompt 'Login: ' end def with_env env = get_config(:env) || {} env[:LANG] ||= 'C' env.each do |key, value| key = key.to_s ENV["_SPECINFRA_#{key}"] = ENV[key]; ENV[key] = value end yield ensure env.each do |key, value| key = key.to_s ENV[key] = ENV.delete("_SPECINFRA_#{key}"); end end def add_pre_command(cmd) if get_config(:pre_command) pre_cmd = build_command(get_config(:pre_command)) "#{pre_cmd} && #{cmd}" else cmd end end def telnet_exec!( command ) stdout_data = '' stderr_data = '' exit_status = nil exit_signal = nil retry_prompt = /^Login: / if get_config(:telnet).nil? set_config(:telnet, create_telnet) end telnet = get_config(:telnet) re = [] unless telnet.nil? re = telnet.cmd( "#{command}; echo $?" ).split("\n")[0..-2] exit_status = re.last.to_i stdout_data = re[1..-2].join("\n") end { :stdout => stdout_data, :stderr => stderr_data, :exit_status => exit_status, :exit_signal => exit_signal } end def create_telnet tel = Net::Telnet.new( "Host" => get_config(:host) ) tel.login( "Name" => get_config(:telnet_options)[:user], "Password" => get_config(:telnet_options)[:pass] ) tel rescue return nil end def sudo if sudo_path = get_config(:sudo_path) sudo_path += '/sudo' else sudo_path = 'sudo' end sudo_options = get_config(:sudo_options) if sudo_options sudo_options = sudo_options.shelljoin if sudo_options.is_a?(Array) sudo_options = ' ' + sudo_options end "#{sudo_path.shellescape}#{sudo_options}" end def sudo? false end end end end specinfra-2.89.0/lib/specinfra/backend/exec.rb0000644000004100000410000001064514575463425021221 0ustar www-datawww-datarequire 'singleton' require 'fileutils' require 'shellwords' require 'sfl' if Specinfra.ruby_is_older_than?(1, 9, 0) module Specinfra module Backend class Exec < Base def run_command(cmd, opts={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) stdout, stderr, exit_status = with_env do spawn_command(cmd) end if @example @example.metadata[:command] = cmd @example.metadata[:stdout] = stdout end CommandResult.new :stdout => stdout, :stderr => stderr, :exit_status => exit_status end def send_file(from, to) FileUtils.cp(from, to) end def send_directory(from, to) FileUtils.cp_r(from, to) end def build_command(cmd) shell = get_config(:shell) || '/bin/sh' cmd = cmd.shelljoin if cmd.is_a?(Array) shell = shell.shellescape if get_config(:interactive_shell) shell << " -i" end if get_config(:login_shell) shell << " -l" end cmd = "#{shell} -c #{cmd.to_s.shellescape}" path = get_config(:path) if path cmd = %Q{env PATH="#{path}" #{cmd}} end cmd end private def spawn_command(cmd) stdout, stderr = '', '' begin quit_r, quit_w = IO.pipe out_r, out_w = IO.pipe err_r, err_w = IO.pipe th = Thread.new do output = { quit_r => "", out_r => "", err_r => "" } handlers = { quit_r => nil, out_r => @stdout_handler, err_r => @stderr_handler } begin loop do readable_ios, = IO.select(output.keys) readable_ios.each do |fd| loop do begin out = fd.read_nonblock(4096) output[fd] << out handlers[fd].call(out) if handlers[fd] rescue Errno::EAGAIN # Ruby 2.2 has more specific exception class IO::EAGAINWaitReadable break end end end break unless output[quit_r].empty? end rescue EOFError ensure # Consume remained stdout and stderr from buffer output.keys.each do |fd| loop do begin out = fd.read_nonblock(4096) output[fd] << out handlers[fd].call(out) if handlers[fd] rescue Errno::EAGAIN, EOFError # Ruby 2.2 has more specific exception class IO::EAGAINWaitReadable break end end end stdout = output[out_r] stderr = output[err_r] quit_r.close unless quit_r.closed? out_r.close unless out_r.closed? err_r.close unless err_r.closed? end end th.abort_on_exception = true pid = spawn(cmd, :out => out_w, :err => err_w) pid, stats = Process.waitpid2(pid) out_w.close err_w.close begin quit_w.syswrite 1 rescue Errno::EPIPE end th.value # wait ensure quit_w.close unless quit_w.closed? end return stdout, stderr, stats.exitstatus end def with_env keys = %w[BUNDLER_EDITOR BUNDLE_BIN_PATH BUNDLE_GEMFILE RUBYOPT GEM_HOME GEM_PATH GEM_CACHE] keys.each { |key| ENV["_SPECINFRA_#{key}"] = ENV[key] ; ENV.delete(key) } env = get_config(:env) || {} env[:LANG] ||= 'C' env.each do |key, value| key = key.to_s ENV["_SPECINFRA_#{key}"] = ENV[key]; ENV[key] = value end yield ensure keys.each { |key| ENV[key] = ENV.delete("_SPECINFRA_#{key}") } env.each do |key, value| key = key.to_s ENV[key] = ENV.delete("_SPECINFRA_#{key}"); end end def add_pre_command(cmd) if get_config(:pre_command) pre_cmd = build_command(get_config(:pre_command)) "#{pre_cmd} && #{cmd}" else cmd end end end end end specinfra-2.89.0/lib/specinfra/backend/winrm.rb0000644000004100000410000000236514575463425021431 0ustar www-datawww-datamodule Specinfra module Backend class Winrm < Base include PowerShell::ScriptHelper def os_info { :family => 'windows', :release => nil, :arch => nil } end def run_command(cmd, opts={}) script = create_script(cmd) winrm = get_config(:winrm) stdout, stderr = '' exitcode = 0 if Gem.loaded_specs['winrm'].version < Gem::Version.create('2.0') # Use winrm V1 API result = winrm.powershell(script) stdout, stderr = [:stdout, :stderr].map do |s| result[:data].select {|item| item.key? s}.map {|item| item[s]}.join end exitcode = result[:exitcode] else # Use winrm V2 API winrm.shell(:powershell) do |shell| result = shell.run(script) stdout = result.stdout.to_s stderr = result.stderr.to_s exitcode = result.exitcode end end exitcode = 1 if exitcode == 0 and !stderr.empty? if @example @example.metadata[:command] = script @example.metadata[:stdout] = stdout + stderr end CommandResult.new :stdout => stdout, :stderr => stderr, :exit_status => exitcode end end end end specinfra-2.89.0/lib/specinfra/backend/ssh.rb0000644000004100000410000001226114575463425021066 0ustar www-datawww-data# -*- coding: utf-8 -*- require 'specinfra/backend/exec' require 'net/ssh' require 'net/scp' module Specinfra module Backend class Ssh < Exec def run_command(cmd, opt={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) if get_config(:ssh_without_env) ret = ssh_exec!(cmd) else ret = with_env do ssh_exec!(cmd) end end ret[:stdout].gsub!(/\r\n/, "\n") ret[:stdout].gsub!(/\A\n/, "") if sudo? if @example @example.metadata[:command] = cmd @example.metadata[:stdout] = ret[:stdout] end CommandResult.new ret end def send_file(from, to) scp_upload!(from, to) end def send_directory(from, to) scp_upload!(from, to, :recursive => true) end def build_command(cmd) cmd = super(cmd) if sudo? cmd = "#{sudo} -p '#{prompt}' #{cmd}" end cmd end private def prompt 'Password: ' end def with_env env = get_config(:env) || {} env[:LANG] ||= 'C' ssh_options = get_config(:ssh_options) || {} ssh_options[:send_env] ||= [] env.each do |key, value| key = key.to_s ENV["_SPECINFRA_#{key}"] = ENV[key]; ENV[key] = value ssh_options[:send_env] << key end yield ensure env.each do |key, value| key = key.to_s ENV[key] = ENV.delete("_SPECINFRA_#{key}"); end end def create_ssh options = get_config(:ssh_options) if !Net::SSH::VALID_OPTIONS.include?(:strict_host_key_checking) options.delete(:strict_host_key_checking) end Net::SSH.start( get_config(:host), options[:user], options ) end def create_scp ssh = get_config(:ssh) if ssh.nil? ssh = create_ssh end Net::SCP.new(ssh) end def scp_upload!(from, to, opt={}) if get_config(:scp).nil? set_config(:scp, create_scp) end tmp = File.join('/tmp', File.basename(to)) scp = get_config(:scp) scp.upload!(from, tmp, opt) run_command(command.get(:move_file, tmp, to)) end def ssh_exec!(command) stdout_data = '' stderr_data = '' exit_status = nil exit_signal = nil retry_prompt = /^Sorry, try again/ if get_config(:ssh).nil? set_config(:ssh, create_ssh) end ssh = get_config(:ssh) ssh.open_channel do |channel| if get_config(:sudo_password) or get_config(:request_pty) channel.request_pty do |ch, success| abort "Could not obtain pty " if !success end end channel.exec("#{command}") do |ch, success| abort "FAILED: couldn't execute command (ssh.channel.exec)" if !success channel.on_data do |ch, data| if data.match retry_prompt abort "Wrong sudo password! Please confirm your password on #{get_config(:host)}." elsif data.match /^#{prompt}/ channel.send_data "#{get_config(:sudo_password)}\n" # When pty is allocated and the name of the target host # cannot be resolved, this error is injected into stdout. # So exclude this error message. elsif ! data.match /^sudo: unable to resolve host/ stdout_data += data @stdout_handler.call(data) if @stdout_handler end end channel.on_extended_data do |ch, type, data| if data.match /you must have a tty to run sudo/ abort 'Please write "set :request_pty, true" in your spec_helper.rb or other appropriate file.' end if data.match /^sudo: no tty present and no askpass program specified/ abort 'Please set sudo password to Specinfra.configuration.sudo_password.' else stderr_data += data @stderr_handler.call(data) if @stderr_handler end end channel.on_request("exit-status") do |ch, data| exit_status = data.read_long end channel.on_request("exit-signal") do |ch, data| exit_signal = data.read_long end end end ssh.loop { :stdout => stdout_data, :stderr => stderr_data, :exit_status => exit_status, :exit_signal => exit_signal } end def sudo if sudo_path = get_config(:sudo_path) sudo_path += '/sudo' else sudo_path = 'sudo' end sudo_options = get_config(:sudo_options) if sudo_options sudo_options = sudo_options.shelljoin if sudo_options.is_a?(Array) sudo_options = ' ' + sudo_options end "#{sudo_path.shellescape}#{sudo_options}" end def sudo? user = get_config(:ssh_options)[:user] disable_sudo = get_config(:disable_sudo) user != 'root' && !disable_sudo end end end end specinfra-2.89.0/lib/specinfra/backend/dockerfile.rb0000644000004100000410000000124014575463425022373 0ustar www-datawww-datamodule Specinfra module Backend class Dockerfile < Specinfra::Backend::Base def initialize(config = {}) super @lines = [] ObjectSpace.define_finalizer(self) { if get_config(:dockerfile_finalizer).nil? puts @lines else get_config(:dockerfile_finalizer).call(@lines) end } end def run_command(cmd, opts={}) @lines << "RUN #{cmd}" CommandResult.new end def send_file(from, to) @lines << "ADD #{from} #{to}" CommandResult.new end def from(base) @lines << "FROM #{base}" end end end end specinfra-2.89.0/lib/specinfra/backend/powershell/0000755000004100000410000000000014575463425022126 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/backend/powershell/script_helper.rb0000644000004100000410000000415114575463425025317 0ustar www-datawww-datarequire 'base64' module Specinfra module Backend module PowerShell module ScriptHelper def build_command(cmd) path = get_config(:path) if path cmd.strip! cmd = <<-EOF $env:path = "#{path};$env:path" #{cmd} EOF end cmd end def add_pre_command(cmd) path = get_config(:path) if get_config(:pre_command) cmd.strip! cmd = <<-EOF #{get_config(:pre_command)} #{cmd} EOF cmd = "$env:path = \"#{path};$env:path\"\n#{cmd}" if path end cmd end def encode_script script script_text = script.chars.to_a.join("\x00").chomp script_text << "\x00" unless script_text[-1].eql? "\x00" if script_text.respond_to?(:encode) script_text = script_text.encode('ASCII-8BIT') end if Base64.respond_to?(:strict_encode64) Base64.strict_encode64(script_text) else [ script_text ].pack("m").strip end end def create_script command if command.is_a? Command ps_functions = command.import_functions.map { |f| File.read(File.join(File.dirname(__FILE__), 'support', f)) } script = build_command(command.script) script = add_pre_command(script) <<-EOF $exitCode = 1 $ProgressPreference = "SilentlyContinue" try { #{ps_functions.join("\n")} $success = $(#{script}) if ($success -is [Boolean] -and $success) { $exitCode = 0 } } catch { Write-Output $_.Exception.Message } Write-Output "Exiting with code: $exitCode" exit $exitCode EOF else script = build_command(command.to_s) add_pre_command(script) end end def check_running(process) ret = run_command(commands.check_running(process)) # If the service is not registered, check the process if ret.exit_status == 1 ret = run_command(commands.check_process(process)) end ret.success? end end end end end specinfra-2.89.0/lib/specinfra/backend/powershell/command.rb0000644000004100000410000000154614575463425024077 0ustar www-datawww-datamodule Specinfra module Backend module PowerShell class Command attr_reader :import_functions, :script def initialize &block @import_functions = [] @script = "" instance_eval(&block) if block_given? end def using *functions functions.each { |f| import_functions << f } end def exec code @script = code end def convert_regexp(target) case target when Regexp target.source else target.to_s.gsub '(^\/|\/$)', '' end end def get_identity id raise "You must provide a specific Windows user/group" if id =~ /(owner|group|others)/ identity = id || 'Everyone' end def to_s @script end end end end end specinfra-2.89.0/lib/specinfra/backend/powershell/support/0000755000004100000410000000000014575463425023642 5ustar www-datawww-dataspecinfra-2.89.0/lib/specinfra/backend/powershell/support/find_user.ps10000644000004100000410000000041014575463425026240 0ustar www-datawww-datafunction FindUser { param($userName, $domain) if ($domain -eq $null) {$selectionCriteria = " and LocalAccount = true"} else {$selectionCriteria = " and Domain = '$domain'"} Get-WmiObject Win32_UserAccount -filter "Name = '$userName' $selectionCriteria" } specinfra-2.89.0/lib/specinfra/backend/powershell/support/find_installed_gem.ps10000644000004100000410000000067514575463425030106 0ustar www-datawww-datafunction FindInstalledGem { param($gemName, $gemVersion) $nameVer = $(Invoke-Expression "gem list --local" | Select-String "^$gemName").Line if ($nameVer.StartsWith($gemName)) { if ($gemVersion) { $versions = ($nameVer -split { $_ -eq "(" -or $_ -eq ")"})[1].split(", ") if ($versions.Contains($gemVersion)) { $true } else { $false } } else { $true } } else { $false } } specinfra-2.89.0/lib/specinfra/backend/powershell/support/find_scheduled_task.ps10000644000004100000410000000020014575463425030241 0ustar www-datawww-datafunction FindScheduledTask { param($name) $task = schtasks /query /v /fo csv /TN "$name" | ConvertFrom-CSV return $task }specinfra-2.89.0/lib/specinfra/backend/powershell/support/find_installed_application.ps10000644000004100000410000000242414575463425031633 0ustar www-datawww-datafunction FindInstalledApplication { param($appName, $appVersion) if ((Get-WmiObject win32_operatingsystem).OSArchitecture -notmatch '64') { $keys= (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*') $possible_path= 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' if (Test-Path $possible_path) { $keys+= (Get-ItemProperty $possible_path) } } else { $keys = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*') $possible_path= 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' if (Test-Path $possible_path) { $keys+= (Get-ItemProperty $possible_path) } $possible_path= 'HKCU:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' if (Test-Path $possible_path) { $keys+= (Get-ItemProperty $possible_path) } } if ($appVersion -eq $null) { @($keys | Where-Object {$_.DisplayName -like $appName -or $_.PSChildName -like $appName}).Length -gt 0 } else{ @($keys | Where-Object {$_.DisplayName -like $appName -or $_.PSChildName -like $appName } | Where-Object {$_.DisplayVersion -eq $appVersion} ).Length -gt 0 } } specinfra-2.89.0/lib/specinfra/backend/powershell/support/find_group.ps10000644000004100000410000000040414575463425026421 0ustar www-datawww-datafunction FindGroup { param($groupName, $domain) if ($domain -eq $null) {$selectionCriteria = " and LocalAccount = true"} else {$selectionCriteria = " and Domain = '$domain'"} Get-WmiObject Win32_Group -filter "Name = '$groupName' $selectionCriteria" }specinfra-2.89.0/lib/specinfra/backend/powershell/support/find_service.ps10000644000004100000410000000020514575463425026724 0ustar www-datawww-datafunction FindService { param($name) Get-WmiObject Win32_Service | Where-Object {$_.Name -eq $name -or $_.DisplayName -eq $name} }specinfra-2.89.0/lib/specinfra/backend/powershell/support/check_file_access_rules.ps10000644000004100000410000000055614575463425031104 0ustar www-datawww-datafunction CheckFileAccessRules { param($path, $identity, $rules) $accessRules = @((Get-Acl $path).access | Where-Object {$_.AccessControlType -eq 'Allow' -and $_.IdentityReference -eq $identity }) $match = @($accessRules | Where-Object {($_.FileSystemRights.ToString().Split(',') | % {$_.trim()} | ? {$rules -contains $_}) -ne $null}) $match.count -gt 0 } specinfra-2.89.0/lib/specinfra/backend/powershell/support/find_installed_hot_fix.ps10000644000004100000410000000052414575463425030767 0ustar www-datawww-datafunction FindInstalledHotFix { param($description, $hotFixId) Write-Host "Num Args:" $args.Length; foreach ($arg in $args) { Write-Host "Arg: $arg"; } Write-Host $description Write-Host $hotFixId $keys= (Get-WmiObject -Class WIN32_QuickFixEngineering) @($keys | Where-Object {$_.HotFixID -like $hotFixId}).Length -gt 0 } specinfra-2.89.0/lib/specinfra/backend/powershell/support/crop_text.ps10000644000004100000410000000047114575463425026300 0ustar www-datawww-datafunction CropText { param($text, $fromPattern, $toPattern) $from, $to = ([regex]::matches($text, $fromPattern)), ([regex]::matches($text, $toPattern)) if ($from.count -gt 0 -and $to.count -gt 0) { $text.substring($from[0].index, $to[0].index + $to[0].length - $from[0].index) } else { "" } } specinfra-2.89.0/lib/specinfra/backend/powershell/support/list_windows_features.ps10000644000004100000410000000364614575463425030723 0ustar www-datawww-datafunction ListWindowsFeatures { param( [string]$feature, [string]$provider="dism" ) $cachepath = "${env:temp}/ListWindowsFeatures-${provider}.xml" $maxAge = 2 $cache = Get-Item $cachepath -erroraction SilentlyContinue if($cache -ne $null -and ((get-date) - $cache.LastWriteTime).minutes -lt $maxage){ $features = Import-Clixml $cachepath | Select *| Where-Object {(($_.name -like $feature) -or ($_.displayName -like $feature)) -and (($_.installed -eq $true) -or ($_.state -eq "Enabled"))} return $features } else{ switch($provider) { "dism" { return features_dism | Select * | Where-Object {($_.name -eq $feature) -and ($_.state -eq "Enabled")} } "powershell" { return features_powershell | Select * | Where-Object {(($_.name -like $feature) -or ($_.displayName -like $feature)) -and ($_.installed -eq $true)} } default {throw "Unsupported provider"} } } } function features_dism{ try { $out = DISM /Online /Get-Features /Format:List | Where-Object {$_} if($LASTEXITCODE -ne 0) { Write-Error $out Break } $f = $out[4..($out.length-2)] $features = for($i=0; $i -lt $f.length;$i+=2) { $tmp = $f[$i],$f[$i+1] -replace '^([^:]+:\s)' New-Object PSObject -Property @{ Name = $tmp[0] State = $tmp[1] } } $features | Export-Clixml $cachepath return $features } catch { Throw } } function features_powershell{ $ProgressPreference = "SilentlyContinue" import-module servermanager $features = Get-WindowsFeature $features | Export-Clixml $cachepath return Get-WindowsFeature }specinfra-2.89.0/lib/specinfra/backend/powershell/support/find_usergroup.ps10000644000004100000410000000073514575463425027327 0ustar www-datawww-datafunction FindUserGroup { param($userName, $groupName, $userDomain, $groupDomain) $user = FindUser -userName $userName -domain $userDomain $group = FindGroup -groupName $groupName -domain $groupDomain if ($user -and $group) { Get-WmiObject Win32_GroupUser -filter ("GroupComponent = 'Win32_Group.Domain=`"" + $group.domain + "`",Name=`"" + $group.name + "`"' and PartComponent = 'Win32_UserAccount.Domain=`"" + $user.domain + "`",Name=`"" + $user.name + "`"'") } }specinfra-2.89.0/lib/specinfra/backend/powershell/support/is_port_listening.ps10000644000004100000410000000120014575463425030013 0ustar www-datawww-datafunction IsPortListening { param($portNumber, $protocol) $netstatOutput = netstat -an | Out-String $networkIPs = (Get-WmiObject Win32_NetworkAdapterConfiguration | ? {$_.IPEnabled}) | %{ $_.IPAddress[0] } [array] $networkIPs += "0.0.0.0" [array] $networkIPs += "127.0.0.1" [array] $networkIPs += "[::1]" [array] $networkIPs += "[::]" foreach ($ipaddress in $networkIPs) { $matchExpression = ("$ipaddress" + ":" + $portNumber + ".*(LISTENING|\*:\*)") if ($protocol) { $matchExpression = ($protocol.toUpper() + "\s+$matchExpression") } if ($netstatOutput -match $matchExpression) { return $true } } $false } specinfra-2.89.0/lib/specinfra/backend/powershell/support/is_remote_port_listening.ps10000644000004100000410000000267114575463425031403 0ustar www-datawww-datafunction IsRemotePortListening{ param( [string]$hostname, [string]$proto="tcp", [int]$port, [int]$timeout) If ($proto -eq "tcp") { $tcpobject = new-Object system.Net.Sockets.TcpClient $connect = $tcpobject.BeginConnect($hostname,$port,$null,$null) $wait = $connect.AsyncWaitHandle.WaitOne($timeout * 1000,$false) #If timeout If(!$wait) { $tcpobject.Close() return $false } else{ $result = $tcpobject.Connected $tcpobject.Close() return $result } } elseif ($proto -eq "udp") { $udpobject = new-Object system.Net.Sockets.Udpclient $udpobject.client.ReceiveTimeout = $timeout * 1000 $udpobject.Connect($hostname,$port) $a = new-object system.text.asciiencoding $byte = $a.GetBytes("$(Get-Date)") [void]$udpobject.Send($byte,$byte.length) $remoteendpoint = New-Object system.net.ipendpoint([system.net.ipaddress]::Any,0) try{ #Blocks until a message returns on this socket from a remote host. $receivebytes = $udpobject.Receive([ref]$remoteendpoint) [string]$returndata = $a.GetString($receivebytes) If ($returndata) { $udpobject.close() return $true } else{ return $false } } catch{ return $false } } else{ throw "Protocol ${proto} not supported" } } specinfra-2.89.0/lib/specinfra/backend/powershell/support/find_iis_component.ps10000644000004100000410000000373214575463425030142 0ustar www-datawww-datafunction FindIISWebsite { param($name) Import-Module WebAdministration Try { Get-Item "IIS:\Sites\$name" -Erroraction silentlycontinue } Catch [System.IO.FileNotFoundException] { Get-Item "IIS:\Sites\$name" -Erroraction silentlycontinue } } function FindIISAppPool { param($name) Import-Module WebAdministration Try { Get-Item "IIS:\AppPools\$name" -Erroraction silentlycontinue } Catch [System.IO.FileNotFoundException] { Get-Item "IIS:\AppPools\$name" -Erroraction silentlycontinue } } function FindSiteBindings { param($name, $protocol, $hostHeader, $port, $ipAddress) Import-Module WebAdministration Try { Get-WebBinding -Name $name -Protocol $protocol -HostHeader $hostHeader -Port $port -IPAddress $ipAddress } Catch [System.IO.FileNotFoundException] { Get-WebBinding -Name $name -Protocol $protocol -HostHeader $hostHeader -Port $port -IPAddress $ipAddress } } function FindSiteVirtualDir { param($name, $vdir, $path) Import-Module WebAdministration $webVirtDirPath = [string]::Format('IIS:\Sites\{0}\{1}',$name, $vdir); if (Test-Path $webVirtDirPath) { if ([string]::IsNullOrEmpty($path)) { $true } else { (Get-Item $webVirtDirPath).physicalPath -eq $path } } else { $false } } function FindSiteApplication { param($name, $app, $pool, $physicalPath) Import-Module WebAdministration $path = "IIS:\Sites\${name}\${app}" $result = $false if (Test-Path $path) { $result = $true if ([string]::IsNullOrEmpty($pool) -eq $false) { $result = $result -and (Get-Item $path).applicationPool -eq $pool } if ([string]::IsNullOrEmpty($physicalPath) -eq $false) { $result = $result -and (Get-Item $path).physicalPath -eq $physicalPath } } $result } specinfra-2.89.0/lib/specinfra/backend/jexec.rb0000644000004100000410000000216014575463425021364 0ustar www-datawww-datamodule Specinfra module Backend class Jexec < Exec def initialize(config = {}) super(config) jname = get_config(:jail_name) jroot = `jls -j #{jname} path`.strip fail 'fail to get jail path!' if jroot.to_s.empty? set_config(:jail_root, jroot) end def send_file(from, to) jroot = get_config(:jail_root) FileUtils.cp(from, "#{jroot}/#{to}") end def send_directory(from, to) jroot = get_config(:jail_root) FileUtils.cp_r(from, "#{jroot}/#{to}") end def build_command(cmd) shell = get_config(:shell) || '/bin/sh' cmd = cmd.shelljoin if cmd.is_a?(Array) shell = shell.shellescape if get_config(:interactive_shell) shell << " -i" end if get_config(:login_shell) shell << " -l" end cmd = "#{shell} -c #{cmd.to_s.shellescape}" path = get_config(:path) if path cmd = %Q{env PATH="#{path}" #{cmd}} end jname = get_config(:jail_name) "jexec #{jname} #{cmd}" end end end end specinfra-2.89.0/lib/specinfra/properties.rb0000644000004100000410000000035314575463425021075 0ustar www-datawww-datarequire 'singleton' module Specinfra class Properties include Singleton def initialize @prop = {} end def properties(prop=nil) if ! prop.nil? @prop = prop end @prop end end end specinfra-2.89.0/lib/specinfra/processor.rb0000644000004100000410000001703414575463425020724 0ustar www-datawww-datamodule Specinfra class Processor def self.check_service_is_running(service) cmd = Specinfra.command.get(:check_service_is_running, service) ret = Specinfra.backend.run_command(cmd) # In Ubuntu, some services are under upstart and "service foo status" returns # exit status 0 even though they are stopped. # So return false if stdout contains "stopped/waiting" or "stop/waiting". return false if ret.stdout =~ /stop(ped)?\/waiting/ # If the service is not registered, check by ps command if ret.exit_status == 1 && !Specinfra.configuration.no_service_process_fallback cmd = Specinfra.command.get(:check_process_is_running, service) ret = Specinfra.backend.run_command(cmd) end ret.success? end def self.check_service_is_monitored_by_monit(process) cmd = Specinfra.command.get(:check_service_is_monitored_by_monit, process) ret = Specinfra.backend.run_command(cmd) return false unless ret.stdout != nil && ret.success? retlines = ret.stdout.split(/[\r\n]+/).map(&:strip) proc_index = retlines.index("Process '#{process}'") return false unless proc_index retlines[proc_index+2].match(/\Amonitoring status\s+monitored\Z/i) != nil end def self.check_file_is_readable(file, by_whom) cmd = Specinfra.command.get(:get_file_mode, file) mode = sprintf('%04s',Specinfra.backend.run_command(cmd).stdout.strip) mode = mode.split('') mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1 case by_whom.to_s when '' mode_octal & 0444 != 0 when 'owner' mode_octal & 0400 != 0 when 'group' mode_octal & 0040 != 0 when 'others' mode_octal & 0004 != 0 end end def self.check_file_is_writable(file, by_whom) cmd = Specinfra.command.get(:get_file_mode, file) mode = sprintf('%04s',Specinfra.backend.run_command(cmd).stdout.strip) mode = mode.split('') mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1 case by_whom.to_s when '' mode_octal & 0222 != 0 when 'owner' mode_octal & 0200 != 0 when 'group' mode_octal & 0020 != 0 when 'others' mode_octal & 0002 != 0 end end def self.check_file_is_executable(file, by_whom) cmd = Specinfra.command.get(:get_file_mode, file) mode = sprintf('%04s',Specinfra.backend.run_command(cmd).stdout.strip) mode = mode.split('') mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1 case by_whom.to_s when '' mode_octal & 0111 != 0 when 'owner' mode_octal & 0100 != 0 when 'group' mode_octal & 0010 != 0 when 'others' mode_octal & 0001 != 0 end end def self.check_file_is_mounted(path, expected_attr, only_with) cmd = Specinfra.command.get(:check_file_is_mounted, path) ret = Specinfra.backend.run_command(cmd) if expected_attr.nil? || ret.failure? return ret.success? end mount = ret.stdout.scan(/\S+/) actual_attr = { } actual_attr[:device] = mount[0] # Output of mount depends on os: # a) proc on /proc type proc (rw,noexec,nosuid,nodev) # b) procfs on /proc (procfs, local) actual_attr[:type] = mount[4] if mount[3] == 'type' # case a. if match = ret.stdout.match(/\((.*)\)/) options = match[1].split(',') actual_attr[:type] ||= options.shift # case b. options.each do |option| name, val = option.split('=') if val.nil? actual_attr[name.strip.to_sym] = true else val = val.to_i if val.match(/^\d+$/) actual_attr[name.strip.to_sym] = val end end end if ! expected_attr[:options].nil? expected_attr.merge!(expected_attr[:options]) expected_attr.delete(:options) end if only_with actual_attr == expected_attr else expected_attr.each do |key, val| return false if actual_attr[key] != val end true end end def self.check_fstab_has_entry(expected_attr) return false unless expected_attr[:mount_point] cmd = Specinfra.command.get(:get_fstab_entry, expected_attr[:mount_point]) ret = Specinfra.backend.run_command(cmd) return false if ret.failure? fstab = ret.stdout.scan(/\S+/) actual_attr = { :device => fstab[0], :mount_point => fstab[1], :type => fstab[2], :dump => fstab[4].to_i, :pass => fstab[5].to_i } fstab[3].split(',').each do |option| name, val = option.split('=') if val.nil? actual_attr[name.to_sym] = true else val = val.to_i if val.match(/^\d+$/) actual_attr[name.to_sym] = val end end unless expected_attr[:options].nil? expected_attr.merge!(expected_attr[:options]) expected_attr.delete(:options) end expected_attr.each do |key, val| return false if actual_attr[key] != val end true end def self.check_routing_table_has_entry(expected_attr) return false if ! expected_attr[:destination] cmd = Specinfra.command.get(:get_routing_table_entry, expected_attr[:destination]) ret = Specinfra.backend.run_command(cmd) return false if ret.failure? ret.stdout.gsub!(/\r\n/, "\n") if os[:family] == 'openbsd' match = ret.stdout.match(/^(\S+)\s+(\S+).*?(\S+[0-9]+)(\s*)$/) actual_attr = { :destination => $1, :gateway => $2, :interface => expected_attr[:interface] ? $3 : nil } else matches = ret.stdout.scan(/^(\S+)(?: via (\S+))? dev (\S+).+\n|^(\S+).*\n|\s+nexthop via (\S+)\s+dev (\S+).+/) if matches.length > 1 # ECMP route destination = nil matches.each do |groups| if groups[3] destination = groups[3] next end next if expected_attr[:gateway] && expected_attr[:gateway] != groups[4] next if expected_attr[:interface] && expected_attr[:interface] != groups[5] actual_attr = { :destination => destination, :gateway => groups[4], :interface => groups[5] } end elsif matches.length == 1 # Non-ECMP route groups = matches[0] actual_attr = { :destination => groups[0], :gateway => groups[1] ? groups[1] : groups[3], :interface => expected_attr[:interface] ? groups[2] : nil } end end expected_attr.each do |key, val| return false if actual_attr[key] != val end true end def self.get_default_gateway(attr) cmd = Specinfra.command.get(:get_routing_table_entry, 'default') ret = Specinfra.backend.run_command(cmd) return false if ret.failure? ret.stdout.gsub!(/\r\n/, "\n") if os[:family] == 'openbsd' match = ret.stdout.match(/^(\S+)\s+(\S+).*?(\S+[0-9]+)(\s*)$/) if attr == :gateway $2 elsif attr == :interface $3 end else ret.stdout =~ /^(\S+)(?: via (\S+))? dev (\S+).+\n(?:default via (\S+))?/ if attr == :gateway $2 ? $2 : $4 elsif attr == :interface $3 end end end end end specinfra-2.89.0/LICENSE.txt0000644000004100000410000000206114575463425015455 0ustar www-datawww-dataCopyright (c) 2013 Gosuke Miyashita MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. specinfra-2.89.0/spec/0000755000004100000410000000000014575463425014565 5ustar www-datawww-dataspecinfra-2.89.0/spec/spec_helper.rb0000644000004100000410000000075614575463425017413 0ustar www-datawww-datarequire 'specinfra' require 'rspec/mocks/standalone' require 'rspec/its' require 'specinfra/helper/set' require 'specinfra/helper/host_inventory' include Specinfra::Helper::Set set :backend, :exec module Specinfra module Backend class Ssh def run_command(cmd, opts={}) CommandResult.new :stdout => nil, :exit_status => 0 end end end end module GetCommand def get_command(method, *args) Specinfra.command.get(method, *args) end end include GetCommand specinfra-2.89.0/spec/helper/0000755000004100000410000000000014575463425016044 5ustar www-datawww-dataspecinfra-2.89.0/spec/helper/os_spec.rb0000644000004100000410000000312714575463425020027 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'os', :order => :defined do def set_stub_chain(keys, value) allow(Specinfra).to receive_message_chain([:configuration, keys].flatten).and_return(value) end describe 'no ssh connection without cache' do before do property[:os] = nil set_stub_chain(:ssh, nil) set_stub_chain(:ssh_options, nil) set_stub_chain(:host, 'localhost') set_stub_chain(:os, :family => 'redhat') end it { expect(os[:family]).to eq 'redhat' } end describe 'no ssh connection with cache' do it { expect(property[:os]).to eq(:family => 'redhat') } end describe 'ssh_options without cache' do before do property[:os] = nil set_stub_chain(:ssh, nil) set_stub_chain(:ssh_options, :port => 22) set_stub_chain(:host, 'localhost') set_stub_chain(:os, :family => 'ubuntu') end it { expect(os[:family]).to eq 'ubuntu' } end describe 'ssh_options with cache' do it { expect(property[:os]).to eq(:family => 'ubuntu') } end describe 'ssh_connection without cache' do before do property[:os] = nil set_stub_chain([:ssh, :host], 'localhost') set_stub_chain([:ssh, :options], :port => 2222) set_stub_chain(:os, :family => 'nixos') end it { expect(os[:family]).to eq 'nixos' } end describe 'ssh_connection with cache' do before do set_stub_chain([:ssh, :host], 'localhost') set_stub_chain([:ssh, :options], :port => 2222) set_stub_chain(:os, :family => 'nixos') end it { expect(property[:os]).to eq(:family => 'nixos') } end end specinfra-2.89.0/spec/helper/detect_os/0000755000004100000410000000000014575463425020015 5ustar www-datawww-dataspecinfra-2.89.0/spec/helper/detect_os/guix_spec.rb0000644000004100000410000000130214575463425022324 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/guix' describe Specinfra::Helper::DetectOs::Guix do guix = Specinfra::Helper::DetectOs::Guix.new(:exec) it 'Should return guix when Guix is installed.' do allow(guix).to receive(:run_command) { CommandResult.new(:stdout => "NAME=\"Guix System\" \nID=guix\nPRETTY_NAME=\"Guix System\" \nLOGO=guix-icon\nHOME_URL=\"https://guix.gnu.org\" \nDOCUMENTATION_URL=\"https://guix.gnu.org/en/manual\" \nSUPPORT_URL=\"https://guix.gnu.org/en/help\" \nBUG_REPORT_URL=\"https://lists.gnu.org/mailman/listinfo/bug-guix\"", :exit_status => 0) } expect(guix.detect).to include( :family => 'guix', :release => nil ) end end specinfra-2.89.0/spec/helper/detect_os/darwin_spec.rb0000644000004100000410000000260614575463425022644 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/darwin' describe Specinfra::Helper::DetectOs::Darwin do darwin = Specinfra::Helper::DetectOs::Darwin.new(Specinfra.backend) it 'Should return darwin 13.4.0 when Mac OS X 10.9.5 (Mavericks) is installed.' do allow(darwin).to receive(:run_command) { CommandResult.new(:stdout => 'Darwin 13.4.0', :exit_status => 0) } expect(darwin.detect).to include( :family => 'darwin', :release => '13.4.0' ) end it 'Should return darwin 12.6.0 when Mac OS X 10.8.5 (Mountain Lion) is installed.' do allow(darwin).to receive(:run_command) { CommandResult.new(:stdout => 'Darwin 12.6.0', :exit_status => 0) } expect(darwin.detect).to include( :family => 'darwin', :release => '12.6.0' ) end it 'Should return darwin 11.4.2 when Mac OS X 10.7.5 (Lion) is installed.' do allow(darwin).to receive(:run_command) { CommandResult.new(:stdout => 'Darwin 11.4.2', :exit_status => 0) } expect(darwin.detect).to include( :family => 'darwin', :release => '11.4.2' ) end it 'Should return darwin nil when Darwin FooBar is installed.' do allow(darwin).to receive(:run_command) { CommandResult.new(:stdout => 'Darwin FooBar', :exit_status => 0) } expect(darwin.detect).to include( :family => 'darwin', :release => nil ) end end specinfra-2.89.0/spec/helper/detect_os/freebsd_spec.rb0000644000004100000410000000257114575463425022773 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/freebsd' describe Specinfra::Helper::DetectOs::Freebsd do freebsd = Specinfra::Helper::DetectOs::Freebsd.new(:exec) it 'Should return freebsd 10 when FreeBSD 10.1-RELEASE is installed.' do allow(freebsd).to receive(:run_command) { CommandResult.new(:stdout => 'FreeBSD 10.1--RELEASE', :exit_status => 0) } expect(freebsd.detect).to include( :family => 'freebsd', :release => '10' ) end it 'Should return freebsd 9 when FreeBSD 9.3-RELEASE is installed.' do allow(freebsd).to receive(:run_command) { CommandResult.new(:stdout => 'FreeBSD 9.3-RELEASE', :exit_status => 0) } expect(freebsd.detect).to include( :family => 'freebsd', :release => '9' ) end it 'Should return freebsd 8 when FreeBSD 8.2-RELEASE-p3 is installed.' do allow(freebsd).to receive(:run_command) { CommandResult.new(:stdout => 'FreeBSD 8.2-RELEASE-p3', :exit_status => 0) } expect(freebsd.detect).to include( :family => 'freebsd', :release => '8' ) end it 'Should return freebsd nil when FreeBSD FooBar is installed.' do allow(freebsd).to receive(:run_command) { CommandResult.new(:stdout => 'FreeBSD FooBar', :exit_status => 0) } expect(freebsd.detect).to include( :family => 'freebsd', :release => nil ) end end specinfra-2.89.0/spec/helper/detect_os/debian_spec.rb0000644000004100000410000000570614575463425022606 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/debian' describe Specinfra::Helper::DetectOs::Debian do debian = Specinfra::Helper::DetectOs::Debian.new(Specinfra.backend) it 'Should return debian 8.5 when jessie is installed.' do allow(debian).to receive(:run_command).with('cat /etc/debian_version') { CommandResult.new(:stdout => "8.5\n", :exit_status => 0) } allow(debian).to receive(:run_command).with('lsb_release -ir') { CommandResult.new(:stdout => "8.5\n", :exit_status => 1) } allow(debian).to receive(:run_command).with('cat /etc/lsb-release') { CommandResult.new(:stdout => "8.5\n", :exit_status => 1) } expect(debian.detect).to include( :family => 'debian', :release => '8.5' ) end it 'Should return ubuntu 16.10 when yakkety is installed.' do allow(debian).to receive(:run_command).with('cat /etc/debian_version') { CommandResult.new(:stdout => "stretch/sid", :exit_status => 0) } allow(debian).to receive(:run_command).with('lsb_release -ir') { CommandResult.new(:stdout => "Distributor ID:Ubuntu\nRelease:16.10\n", :exit_status => 0) } allow(debian).to receive(:run_command).with('cat /etc/lsb-release') { CommandResult.new(:stdout => "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=16.10\nDISTRIB_CODENAME=yakkety\nDISTRIB_DESCRIPTION=\"Ubuntu 16.10\"", :exit_status => 0) } expect(debian.detect).to include( :family => 'ubuntu', :release => '16.10' ) end it 'Should return ubuntu 16.04 when xenial is installed.' do allow(debian).to receive(:run_command).with('cat /etc/debian_version') { CommandResult.new(:stdout => "stretch/sid", :exit_status => 0) } allow(debian).to receive(:run_command).with('lsb_release -ir') { CommandResult.new(:stdout => "Distributor ID:Ubuntu\nRelease:16.04\n", :exit_status => 0) } allow(debian).to receive(:run_command).with('cat /etc/lsb-release') { CommandResult.new(:stdout => "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=16.04\nDISTRIB_CODENAME=xenial\nDISTRIB_DESCRIPTION=\"Ubuntu 16.04.2 LTS\"", :exit_status => 0) } expect(debian.detect).to include( :family => 'ubuntu', :release => '16.04' ) end it 'Should return ubuntu 16.04 when xenial is installed in docker.' do allow(debian).to receive(:run_command).with('cat /etc/debian_version') { CommandResult.new(:stdout => "stretch/sid", :exit_status => 0) } allow(debian).to receive(:run_command).with('lsb_release -ir') { CommandResult.new(:stdout => 'lsb-release is not installed in docker image by default', :exit_status => 1) } allow(debian).to receive(:run_command).with('cat /etc/lsb-release') { CommandResult.new(:stdout => "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=16.04\nDISTRIB_CODENAME=xenial\nDISTRIB_DESCRIPTION=\"Ubuntu 16.04.2 LTS\"", :exit_status => 0) } expect(debian.detect).to include( :family => 'ubuntu', :release => '16.04' ) end end specinfra-2.89.0/spec/helper/detect_os/openbsd_spec.rb0000644000004100000410000000253514575463425023013 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/openbsd' describe Specinfra::Helper::DetectOs::Openbsd do openbsd = Specinfra::Helper::DetectOs::Openbsd.new(:exec) it 'Should return (fictional) openbsd 10.11 when OpenBSD 10.11 is installed.' do allow(openbsd).to receive(:run_command) { CommandResult.new(:stdout => 'OpenBSD 10.11', :exit_status => 0) } expect(openbsd.detect).to include( :family => 'openbsd', :release => '10.11' ) end it 'Should return openbsd 5.7 when OpenBSD 5.7 is installed.' do allow(openbsd).to receive(:run_command) { CommandResult.new(:stdout => 'OpenBSD 5.7', :exit_status => 0) } expect(openbsd.detect).to include( :family => 'openbsd', :release => '5.7' ) end it 'Should return openbsd 5.6 when OpenBSD 5.6 is installed.' do allow(openbsd).to receive(:run_command) { CommandResult.new(:stdout => 'OpenBSD 5.6', :exit_status => 0) } expect(openbsd.detect).to include( :family => 'openbsd', :release => '5.6' ) end it 'Should return openbsd nil when OpenBSD FooBar is installed.' do allow(openbsd).to receive(:run_command) { CommandResult.new(:stdout => 'OpenBSD FooBar', :exit_status => 0) } expect(openbsd.detect).to include( :family => 'openbsd', :release => nil ) end end specinfra-2.89.0/spec/helper/detect_os/aix_spec.rb0000644000004100000410000000371114575463425022137 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/aix' describe Specinfra::Helper::DetectOs::Aix do aix = Specinfra::Helper::DetectOs::Aix.new(:exec) it 'Should return aix 10.11 powerpc when (fictional) AIX 10.11 is installed.' do allow(aix).to receive(:run_command).with('uname -s') { CommandResult.new(:stdout => 'AIX', :exit_status => 0) } allow(aix).to receive(:run_command).with('uname -rvp') { CommandResult.new(:stdout => '11 10 powerpc', :exit_status => 0) } expect(aix.detect).to include( :family => 'aix', :release => '10.11', :arch => 'powerpc' ) end it 'Should return aix 7.1 powerpc when AIX 7.1 is installed.' do allow(aix).to receive(:run_command).with('uname -s') { CommandResult.new(:stdout => 'AIX', :exit_status => 0) } allow(aix).to receive(:run_command).with('uname -rvp') { CommandResult.new(:stdout => '1 7 powerpc', :exit_status => 0) } expect(aix.detect).to include( :family => 'aix', :release => '7.1', :arch => 'powerpc' ) end it 'Should return aix 6.1 powerpc when AIX 6.1 is installed.' do allow(aix).to receive(:run_command).with('uname -s') { CommandResult.new(:stdout => 'AIX', :exit_status => 0) } allow(aix).to receive(:run_command).with('uname -rvp') { CommandResult.new(:stdout => '1 6 powerpc', :exit_status => 0) } expect(aix.detect).to include( :family => 'aix', :release => '6.1', :arch => 'powerpc' ) end it 'Should return aix nil nil when AIX FooBar is installed.' do allow(aix).to receive(:run_command).with('uname -s') { CommandResult.new(:stdout => 'AIX', :exit_status => 0) } allow(aix).to receive(:run_command).with('uname -rvp') { CommandResult.new(:stdout => 'Foo Bar batz', :exit_status => 1) } expect(aix.detect).to include( :family => 'aix', :release => nil, :arch => nil ) end end specinfra-2.89.0/spec/helper/detect_os/esxi_spec.rb0000644000004100000410000000130514575463425022323 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/esxi' describe Specinfra::Helper::DetectOs::Esxi do esxi = Specinfra::Helper::DetectOs::Esxi.new(:exec) it 'Should return esxi when esxi is installed.' do allow(esxi).to receive(:run_command) { CommandResult.new(:stdout => 'VMware ESXi 5.0.0 build-123445', :exit_status => 0) } expect(esxi.detect).to include( :family => 'esxi', :release => '5.0.0 build-123445' ) end it 'Should not return esxi when VMware Workstation is installed.' do allow(esxi).to receive(:run_command) { CommandResult.new(:stdout => 'VMware Workstation', :exit_status => 0) } expect(esxi.detect).to be_nil end end specinfra-2.89.0/spec/helper/detect_os/clearlinux_spec.rb0000644000004100000410000000152614575463425023526 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/clearlinux' describe Specinfra::Helper::DetectOs::Clearlinux do clearlinux = Specinfra::Helper::DetectOs::Clearlinux.new(:exec) it 'Should return clearlinux & release when clearlinux is installed.' do allow(clearlinux).to receive(:run_command) { CommandResult.new(:stdout => 'Installed version: 30340', :exit_status => 0) } expect(clearlinux.detect).to include( :family => 'clearlinux', :release => '30340' ) end it 'Should return clearlinux but not the release when the command returns the wrong line' do allow(clearlinux).to receive(:run_command) { CommandResult.new(:stdout => 'Foobar version: 30340', :exit_status => 0) } expect(clearlinux.detect).to include( :family => 'clearlinux', :release => nil ) end endspecinfra-2.89.0/spec/helper/detect_os/suse_spec.rb0000644000004100000410000000430014575463425022330 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/suse' describe Specinfra::Helper::DetectOs::Suse do suse = Specinfra::Helper::DetectOs::Suse.new(:exec) it 'Should return opensuse 42.2 when openSUSE 42.2 is installed.' do allow(suse).to receive(:run_command) { CommandResult.new(:stdout => "NAME=\"openSUSE Leap\"\nVERSION=\"42.2\"\nID=opensuse\nID_LIKE=\"suse\"\nVERSION_ID=\"42.2\"\nPRETTY_NAME=\"openSUSE Leap 42.2\"\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:opensuse:leap:42.2\"\nBUG_REPORT_URL=\"https://bugs.opensuse.org\"\nHOME_URL=\"https://www.opensuse.org/\"\n", :exit_status => 0) } expect(suse.detect).to include( :family => 'opensuse', :release => '42.2' ) end it 'Should return opensuse 13.2 when openSUSE 13.2 is installed.' do allow(suse).to receive(:run_command) { CommandResult.new(:stdout => "NAME=openSUSE\nVERSION=\"13.2 (Harlequin)\"\nVERSION_ID=\"13.2\"\nPRETTY_NAME=\"openSUSE 13.2 (Harlequin) (x86_64)\"\nID=opensuse\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:opensuse:opensuse:13.2\"\nBUG_REPORT_URL=\"https://bugs.opensuse.org\"\nHOME_URL=\"https://opensuse.org/\"\nID_LIKE=\"suse\"\n", :exit_status => 0) } expect(suse.detect).to include( :family => 'opensuse', :release => '13.2' ) end it 'Should return sles 12.2 when SUSE Linux Enterprise Server 12.2 is installed.' do allow(suse).to receive(:run_command) { CommandResult.new(:stdout => "NAME=\"SLES\"\nVERSION=\"12.2\"\nVERSION_ID=\"12.2\"\nPRETTY_NAME=\"SUSE Linux Enterprise Server 12\"\nID=\"sles\"\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:suse:sles:12\"\n", :exit_status => 0) } expect(suse.detect).to include( :family => 'sles', :release => '12.2' ) end it 'Should return sles 11.4 when SUSE Linux Enterprise Server 11.4 is installed.' do allow(suse).to receive(:run_command) { CommandResult.new(:stdout => "NAME=\"SLES\"\nVERSION=\"11.4\"\nVERSION_ID=\"11.4\"\nPRETTY_NAME=\"SUSE Linux Enterprise Server 11 SP4\"\nID=\"sles\"\nANSI_COLOR=\"0;32\"\nCPE_NAME=\"cpe:/o:suse:sles:11:4\"", :exit_status => 0) } expect(suse.detect).to include( :family => 'sles', :release => '11.4' ) end end specinfra-2.89.0/spec/helper/detect_os/eos_spec.rb0000644000004100000410000000214014575463425022137 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/eos' describe Specinfra::Helper::DetectOs::Eos do eos = Specinfra::Helper::DetectOs::Eos.new(:exec) it 'Should return eos family and the correct version.' do allow(eos).to receive(:run_command).with('ls /etc/Eos-release') { CommandResult.new(:stdout => '/etc/Eos-release', :exit_status => 0) } allow(eos).to receive(:run_command).with('cat /etc/Eos-release') { CommandResult.new(:stdout => 'Arista Networks EOS 4.15.3F', :exit_status => 0) } expect(eos.detect).to include( :family => 'eos', :release => '4.15.3F' ) end it 'Should return eos nil when a non-conforming EOS version is installed.' do allow(eos).to receive(:run_command).with('ls /etc/Eos-release') { CommandResult.new(:stdout => '/etc/Eos-release', :exit_status => 0) } allow(eos).to receive(:run_command).with('cat /etc/Eos-release') { CommandResult.new(:stdout => 'Arista Networks EOS foo', :exit_status => 0) } expect(eos.detect).to include( :family => 'eos', :release => nil ) end end specinfra-2.89.0/spec/helper/properties_spec.rb0000644000004100000410000000033314575463425021576 0ustar www-datawww-datarequire 'spec_helper' include Specinfra::Helper::Properties describe 'Properties Helper' do before :all do set_property :role => 'proxy' end subject { property } it { should include :role => 'proxy' } end specinfra-2.89.0/spec/helper/set_spec.rb0000644000004100000410000000073414575463425020202 0ustar www-datawww-datarequire 'spec_helper' describe 'set method set value to Specinfra.configuration' do it 'set method handle string value correctly' do set :host, 'localhost' expect(Specinfra.configuration.host).to eq 'localhost' end it 'set method handle hash value correctly' do set :ssh_options, :password => 'password', :port => 2222 ssh_options = { :password => 'password', :port => 2222 } expect(Specinfra.configuration.ssh_options).to eq ssh_options end end specinfra-2.89.0/spec/host_inventory/0000755000004100000410000000000014575463425017657 5ustar www-datawww-dataspecinfra-2.89.0/spec/host_inventory/solaris/0000755000004100000410000000000014575463425021333 5ustar www-datawww-dataspecinfra-2.89.0/spec/host_inventory/solaris/virtualization_spec.rb0000644000004100000410000000161114575463425025755 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::HostInventory::Virtualization do before :all do set :os, { :family => 'solaris' } end virt = Specinfra::HostInventory::Virtualization.new(host_inventory) let(:host_inventory) { nil } it 'OpenIndiana on KVM should return :system => "kvm"' do ret = virt.parse_system_product_name("System Configuration: Red Hat KVM") expect(ret).to include('kvm') end let(:host_inventory) { nil } it 'OpenIndiana on VMware should return :system => "vmware"' do ret = virt.parse_system_product_name("System Configuration: VMware, Inc. VMware Virtual Platform\n") expect(ret).to include('vmware') end let(:host_inventory) { nil } it 'OpenIndiana on VirtualBox should return :system => "vbox"' do ret = virt.parse_system_product_name("System Configuration: innotek GmbH VirtualBox\n") expect(ret).to include('vbox') end end specinfra-2.89.0/spec/host_inventory/solaris/filesystem_spec.rb0000644000004100000410000001110214575463425025051 0ustar www-datawww-datarequire 'spec_helper' # Output from df -k | nawk -v i=0 '$1 == "swap" { $1=$1i; i++ }; NF == 1 { printf($1); next }; { print }' str = <<-EOH Filesystem kbytes used avail capacity Mounted on / 32769183 5637051 27132132 18% / /dev 32769183 5637051 27132132 18% /dev proc 0 0 0 0% /proc ctfs 0 0 0 0% /system/contract mnttab 0 0 0 0% /etc/mnttab objfs 0 0 0 0% /system/object swap0 8664048 312 8663736 1% /etc/svc/volatile /platform/sun4v/lib/libc_psr/libc_psr_hwcap3.so.1 32769183 5637051 27132132 18% /platform/sun4v/lib/libc_psr.so.1 /platform/sun4v/lib/sparc9/libc_psr/lib_psr_hwcap3.so.1 32769183 5637051 27132132 18% /platform/sun4v/lib/sparcv9/libc_psr.so.1 fd 0 0 0 0% /dev/fd swap1 2097152 160 2096992 1% /tmp swap2 8663784 48 8663736 1% /var/run EOH ## Houston we have problem! ## there are multiple entries called 'swap' in Solaris ## with the current parser they are not getting reported correctly ## only the last entry is being reported! describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example of Solaris 10' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "/" do expect(ret["/"]).to include( "kb_available" => "27132132", "kb_size" => "32769183", "kb_used" => "5637051", "mount" => "/", "percent_used" => "18%" ) end example "/dev" do expect(ret["/dev"]).to include( "kb_available" => "27132132", "kb_size" => "32769183", "kb_used" => "5637051", "mount" => "/dev", "percent_used" => "18%" ) end example "/platform/sun4v/lib/libc_psr/libc_psr_hwcap3.so.1" do expect(ret["/platform/sun4v/lib/libc_psr/libc_psr_hwcap3.so.1"]).to include( "kb_available" => "27132132", "kb_size" => "32769183", "kb_used" => "5637051", "mount" => "/platform/sun4v/lib/libc_psr.so.1", "percent_used" => "18%" ) end example "/platform/sun4v/lib/sparc9/libc_psr/lib_psr_hwcap3.so.1" do expect(ret["/platform/sun4v/lib/sparc9/libc_psr/lib_psr_hwcap3.so.1"]).to include( "kb_available" => "27132132", "kb_size" => "32769183", "kb_used" => "5637051", "mount" => "/platform/sun4v/lib/sparcv9/libc_psr.so.1", "percent_used" => "18%" ) end example "ctfs" do expect(ret["ctfs"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/system/contract", "percent_used" => "0%" ) end example "fd" do expect(ret["fd"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/dev/fd", "percent_used" => "0%" ) end example "mnttab" do expect(ret["mnttab"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/etc/mnttab", "percent_used" => "0%" ) end example "objfs" do expect(ret["objfs"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/system/object", "percent_used" => "0%" ) end example "proc" do expect(ret["proc"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/proc", "percent_used" => "0%" ) end example "swap0" do expect(ret["swap0"]).to include( "kb_available" => "8663736", "kb_size" => "8664048", "kb_used" => "312", "mount" => "/etc/svc/volatile", "percent_used" => "1%" ) end example "swap1" do expect(ret["swap1"]).to include( "kb_available" => "2096992", "kb_size" => "2097152", "kb_used" => "160", "mount" => "/tmp", "percent_used" => "1%" ) end example "swap2" do expect(ret["swap2"]).to include( "kb_available" => "8663736", "kb_size" => "8663784", "kb_used" => "48", "mount" => "/var/run", "percent_used" => "1%" ) end end end specinfra-2.89.0/spec/host_inventory/base/0000755000004100000410000000000014575463425020571 5ustar www-datawww-dataspecinfra-2.89.0/spec/host_inventory/base/user_spec.rb0000644000004100000410000001247414575463425023116 0ustar www-datawww-datarequire 'spec_helper' str = <<-EOH root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin systemd-network:x:998:996:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:997:995:User for polkitd:/:/sbin/nologin tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin hoge:x:1000:1000::/home/hoge:/bin/bash saslauth:x:499:76:Saslauthd user:/run/saslauthd:/sbin/nologin apache:x:48:48:Apache:/opt/rh/httpd24/root/usr/share/httpd:/sbin/nologin postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash EOH describe Specinfra::HostInventory::User do let(:host_inventory) { nil } describe 'Example of CentOS Linux release 7.2.1511' do ret = Specinfra::HostInventory::User.new(host_inventory).parse(str) example do expect(ret).to include( 'root' => {'name' => 'root', 'uid' => '0', 'gid' => '0', 'gecos' => 'root', 'directory' => '/root', 'shell' => '/bin/root'}, 'adm' => {'name'=>'adm', 'uid'=>'3', 'gid'=>'4', 'gecos'=>'adm', 'directory'=>'/var/adm', 'shell'=>'/sbin/nologin'}, 'apache' => {'name'=>'apache', 'uid'=>'48', 'gid'=>'48', 'gecos'=>'Apache', 'directory'=>'/opt/rh/httpd24/root/usr/share/httpd', 'shell'=>'/sbin/nologin'}, 'avahi-autoipd' => {'name'=>'avahi-autoipd', 'uid'=>'170', 'gid'=>'170', 'gecos'=>'Avahi IPv4LL Stack', 'directory'=>'/var/lib/avahi-autoipd', 'shell'=>'/sbin/nologin'}, 'bin' => {'name'=>'bin', 'uid'=>'1', 'gid'=>'1', 'gecos'=>'bin', 'directory'=>'/bin', 'shell'=>'/sbin/nologin'}, 'daemon' => {'name'=>'daemon', 'uid'=>'2', 'gid'=>'2', 'gecos'=>'daemon', 'directory'=>'/sbin', 'shell'=>'/sbin/nologin'}, 'dbus' => {'name'=>'dbus', 'uid'=>'81', 'gid'=>'81', 'gecos'=>'System message bus', 'directory'=>'/', 'shell'=>'/sbin/nologin'}, 'ftp' => {'name'=>'ftp', 'uid'=>'14', 'gid'=>'50', 'gecos'=>'FTP User', 'directory'=>'/var/ftp', 'shell'=>'/sbin/nologin'}, 'games' => {'name'=>'games', 'uid'=>'12', 'gid'=>'100', 'gecos'=>'games', 'directory'=>'/usr/games', 'shell'=>'/sbin/nologin'}, 'halt' => {'name'=>'halt', 'uid'=>'7', 'gid'=>'0', 'gecos'=>'halt', 'directory'=>'/sbin', 'shell'=>'/sbin/halt'}, 'hoge' => {'name'=>'hoge', 'uid'=>'1000', 'gid'=>'1000', 'gecos'=>'', 'directory'=>'/home/hoge', 'shell'=>'/bin/bash'}, 'lp' => {'name'=>'lp', 'uid'=>'4', 'gid'=>'7', 'gecos'=>'lp', 'directory'=>'/var/spool/lpd', 'shell'=>'/sbin/nologin'}, 'mail' => {'name'=>'mail', 'uid'=>'8', 'gid'=>'12', 'gecos'=>'mail', 'directory'=>'/var/spool/mail', 'shell'=>'/sbin/nologin'}, 'nobody' => {'name'=>'nobody', 'uid'=>'99', 'gid'=>'99', 'gecos'=>'Nobody', 'directory'=>'/', 'shell'=>'/sbin/nologin'}, 'ntp' => {'name'=>'ntp', 'uid'=>'38', 'gid'=>'38', 'gecos'=>'', 'directory'=>'/etc/ntp', 'shell'=>'/sbin/nologin'}, 'operator' => {'name'=>'operator', 'uid'=>'11', 'gid'=>'0', 'gecos'=>'operator', 'directory'=>'/root', 'shell'=>'/sbin/nologin'}, 'polkitd' => {'name'=>'polkitd', 'uid'=>'997', 'gid'=>'995', 'gecos'=>'User for polkitd', 'directory'=>'/', 'shell'=>'/sbin/nologin'}, 'postfix' => {'name'=>'postfix', 'uid'=>'89', 'gid'=>'89', 'gecos'=>'', 'directory'=>'/var/spool/postfix', 'shell'=>'/sbin/nologin'}, 'postgres' => {'name'=>'postgres', 'uid'=>'26', 'gid'=>'26', 'gecos'=>'PostgreSQL Server', 'directory'=>'/var/lib/pgsql', 'shell'=>'/bin/bash'}, 'root' => {'name'=>'root', 'uid'=>'0', 'gid'=>'0', 'gecos'=>'root', 'directory'=>'/root', 'shell'=>'/bin/bash'}, 'saslauth' => {'name'=>'saslauth', 'uid'=>'499', 'gid'=>'76', 'gecos'=>'Saslauthd user', 'directory'=>'/run/saslauthd', 'shell'=>'/sbin/nologin'}, 'shutdown' => {'name'=>'shutdown', 'uid'=>'6', 'gid'=>'0', 'gecos'=>'shutdown', 'directory'=>'/sbin', 'shell'=>'/sbin/shutdown'}, 'sshd' => {'name'=>'sshd', 'uid'=>'74', 'gid'=>'74', 'gecos'=>'Privilege-separated SSH', 'directory'=>'/var/empty/sshd', 'shell'=>'/sbin/nologin'}, 'sync' => {'name'=>'sync', 'uid'=>'5', 'gid'=>'0', 'gecos'=>'sync', 'directory'=>'/sbin', 'shell'=>'/bin/sync'}, 'systemd-bus-proxy' => {'name'=>'systemd-bus-proxy', 'uid'=>'999', 'gid'=>'997', 'gecos'=>'systemd Bus Proxy', 'directory'=>'/', 'shell'=>'/sbin/nologin'}, 'systemd-network' => {'name'=>'systemd-network', 'uid'=>'998', 'gid'=>'996', 'gecos'=>'systemd Network Management', 'directory'=>'/', 'shell'=>'/sbin/nologin'}, 'tss' => {'name'=>'tss', 'uid'=>'59', 'gid'=>'59', 'gecos'=>'Account used by the trousers package to sandbox the tcsd daemon', 'directory'=>'/dev/null', 'shell'=>'/sbin/nologin'} ) end end end specinfra-2.89.0/spec/host_inventory/base/group_spec.rb0000644000004100000410000000703714575463425023273 0ustar www-datawww-datarequire 'spec_helper' str = <<-EOH root:x:0: bin:x:1: daemon:x:2: sys:x:3: adm:x:4: tty:x:5: disk:x:6: lp:x:7: mem:x:8: kmem:x:9: wheel:x:10:hoge cdrom:x:11: mail:x:12:postfix man:x:15: dialout:x:18: floppy:x:19: games:x:20: tape:x:30: video:x:39: ftp:x:50: lock:x:54: audio:x:63: nobody:x:99: users:x:100: avahi-autoipd:x:170: utmp:x:22: utempter:x:35: ssh_keys:x:999: input:x:998: systemd-journal:x:190: systemd-bus-proxy:x:997: systemd-network:x:996: dbus:x:81: polkitd:x:995: dip:x:40: tss:x:59: postdrop:x:90: postfix:x:89: sshd:x:74: ntp:x:38: hoge:x:1000: EOH describe Specinfra::HostInventory::Group do let(:host_inventory) { nil } describe 'Example of CentOS Linux release 7.2.1511' do ret = Specinfra::HostInventory::Group.new(host_inventory).parse(str) example do expect(ret).to include( 'adm' => {'name'=>'adm', 'gid'=>'4', 'members'=>[]}, 'audio' => {'name'=>'audio', 'gid'=>'63', 'members'=>[]}, 'avahi-autoipd' => {'name'=>'avahi-autoipd', 'gid'=>'170', 'members'=>[]}, 'bin' => {'name'=>'bin', 'gid'=>'1', 'members'=>[]}, 'cdrom' => {'name'=>'cdrom', 'gid'=>'11', 'members'=>[]}, 'daemon' => {'name'=>'daemon', 'gid'=>'2', 'members'=>[]}, 'dbus' => {'name'=>'dbus', 'gid'=>'81', 'members'=>[]}, 'dialout' => {'name'=>'dialout', 'gid'=>'18', 'members'=>[]}, 'dip' => {'name'=>'dip', 'gid'=>'40', 'members'=>[]}, 'disk' => {'name'=>'disk', 'gid'=>'6', 'members'=>[]}, 'floppy' => {'name'=>'floppy', 'gid'=>'19', 'members'=>[]}, 'ftp' => {'name'=>'ftp', 'gid'=>'50', 'members'=>[]}, 'games' => {'name'=>'games', 'gid'=>'20', 'members'=>[]}, 'hoge' => {'name'=>'hoge', 'gid'=>'1000', 'members'=>[]}, 'input' => {'name'=>'input', 'gid'=>'998', 'members'=>[]}, 'kmem' => {'name'=>'kmem', 'gid'=>'9', 'members'=>[]}, 'lock' => {'name'=>'lock', 'gid'=>'54', 'members'=>[]}, 'lp' => {'name'=>'lp', 'gid'=>'7', 'members'=>[]}, 'mail' => {'name'=>'mail', 'gid'=>'12', 'members'=>['postfix']}, 'man' => {'name'=>'man', 'gid'=>'15', 'members'=>[]}, 'mem' => {'name'=>'mem', 'gid'=>'8', 'members'=>[]}, 'nobody' => {'name'=>'nobody', 'gid'=>'99', 'members'=>[]}, 'ntp' => {'name'=>'ntp', 'gid'=>'38', 'members'=>[]}, 'polkitd' => {'name'=>'polkitd', 'gid'=>'995', 'members'=>[]}, 'postdrop' => {'name'=>'postdrop', 'gid'=>'90', 'members'=>[]}, 'postfix' => {'name'=>'postfix', 'gid'=>'89', 'members'=>[]}, 'root' => {'name'=>'root', 'gid'=>'0', 'members'=>[]}, 'ssh_keys' => {'name'=>'ssh_keys', 'gid'=>'999', 'members'=>[]}, 'sshd' => {'name'=>'sshd', 'gid'=>'74', 'members'=>[]}, 'sys' => {'name'=>'sys', 'gid'=>'3', 'members'=>[]}, 'systemd-bus-proxy' => {'name'=>'systemd-bus-proxy', 'gid'=>'997', 'members'=>[]}, 'systemd-journal' => {'name'=>'systemd-journal', 'gid'=>'190', 'members'=>[]}, 'systemd-network' => {'name'=>'systemd-network', 'gid'=>'996', 'members'=>[]}, 'tape' => {'name'=>'tape', 'gid'=>'30', 'members'=>[]}, 'tss' => {'name'=>'tss', 'gid'=>'59', 'members'=>[]}, 'tty' => {'name'=>'tty', 'gid'=>'5', 'members'=>[]}, 'users' => {'name'=>'users', 'gid'=>'100', 'members'=>[]}, 'utempter' => {'name'=>'utempter', 'gid'=>'35', 'members'=>[]}, 'utmp' => {'name'=>'utmp', 'gid'=>'22', 'members'=>[]}, 'video' => {'name'=>'video', 'gid'=>'39', 'members'=>[]}, 'wheel' => {'name'=>'wheel', 'gid'=>'10', 'members'=>['hoge']} ) end end end specinfra-2.89.0/spec/host_inventory/aix/0000755000004100000410000000000014575463425020440 5ustar www-datawww-dataspecinfra-2.89.0/spec/host_inventory/aix/filesystem_spec.rb0000644000004100000410000000650214575463425024166 0ustar www-datawww-datarequire 'spec_helper' # Output from 'df -kP' str = <<-EOH Filesystem 1024-blocks Used Available Capacity Mounted on /dev/hd4 524288 67328 456960 13% / /dev/hd2 4194304 3077768 1116536 74% /usr /dev/hd9var 3145728 96588 3049140 4% /var /dev/hd3 2097152 128588 1968564 7% /tmp /dev/hd1 65536 380 65156 1% /home /dev/hd11admin 131072 364 130708 1% /admin /proc - - - - /proc /dev/hd10opt 4194304 725280 3469024 18% /opt /dev/livedump 1572864 568 1572296 1% /var/adm/ras/livedump /dev/fslv00 1048576 127848 920728 13% /audit EOH describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example of AIX 7.1' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "/dev/fslv00" do expect(ret["/dev/fslv00"]).to include( "kb_available" => "920728", "kb_size" => "1048576", "kb_used" => "127848", "mount" => "/audit", "percent_used" => "13%" ) end example "/dev/hd1" do expect(ret["/dev/hd1"]).to include( "kb_available" => "65156", "kb_size" => "65536", "kb_used" => "380", "mount" => "/home", "percent_used" => "1%" ) end example "/dev/hd2" do expect(ret["/dev/hd2"]).to include( "kb_available" => "1116536", "kb_used" => "3077768", "kb_size" => "4194304", "mount" => "/usr", "percent_used" => "74%" ) end example "/dev/hd3" do expect(ret["/dev/hd3"]).to include( "kb_available" => "1968564", "kb_size" => "2097152", "kb_used" => "128588", "mount" => "/tmp", "percent_used" => "7%" ) end example "/dev/hd4" do expect(ret["/dev/hd4"]).to include( "kb_available" => "456960", "kb_size" => "524288", "kb_used" => "67328", "mount" => "/", "percent_used" => "13%" ) end example "/dev/hd9var" do expect(ret["/dev/hd9var"]).to include( "kb_available" => "3049140", "kb_size" => "3145728", "kb_used" => "96588", "mount" => "/var", "percent_used" => "4%" ) end example "/dev/hd10opt" do expect(ret["/dev/hd10opt"]).to include( "kb_available" => "3469024", "kb_size" => "4194304", "kb_used" => "725280", "mount" => "/opt", "percent_used" => "18%" ) end example "/dev/hd11admin" do expect(ret["/dev/hd11admin"]).to include( "kb_available" => "130708", "kb_used" => "364", "kb_size" => "131072", "mount" => "/admin", "percent_used" => "1%" ) end example "/dev/livedump" do expect(ret["/dev/livedump"]).to include( "kb_available" => "1572296", "kb_size" => "1572864", "kb_used" => "568", "mount" => "/var/adm/ras/livedump", "percent_used" => "1%" ) end example "/proc" do expect(ret).to_not include( "/proc" ) end end end specinfra-2.89.0/spec/host_inventory/linux/0000755000004100000410000000000014575463425021016 5ustar www-datawww-dataspecinfra-2.89.0/spec/host_inventory/linux/block_device_spec.rb0000644000004100000410000000245014575463425024767 0ustar www-datawww-datarequire 'spec_helper' ## Output from: # # for f in $(ls /sys/block/*/{size,removable,device/{model,rev,state,timeout,vendor},queue/rotational}); do # echo -e "${f}\t$(cat ${f})" # done str = <<-EOH /sys/block/loop0/queue/rotational 1 /sys/block/loop0/removable 0 /sys/block/loop0/size 0 /sys/block/sda/device/model HARDDISK /sys/block/sda/device/rev 1.0 /sys/block/sda/device/state running /sys/block/sda/device/timeout 30 /sys/block/sda/device/vendor ATA /sys/block/sda/queue/rotational 1 /sys/block/sda/removable 0 /sys/block/sda/size 40960000 EOH describe Specinfra::HostInventory::BlockDevice do let(:host_inventory) { nil } describe 'Example of CentOS 6.6 Kernel version 2.6.32-504.23.4.el6.i686' do ret = Specinfra::HostInventory::BlockDevice.new(host_inventory).parse(str) example "/sys/block/loop0" do expect(ret["loop0"]).to include( "rotational" => "1", "removable" => "0", "size" => "0" ) end example "/sys/block/sda" do expect(ret["sda"]).to include( "model" => "HARDDISK", "rev" => "1.0", "state" => "running", "timeout" => "30", "vendor" => "ATA", "rotational" => "1", "removable" => "0", "size" => "40960000" ) end end end specinfra-2.89.0/spec/host_inventory/linux/kernel_spec.rb0000644000004100000410000000160714575463425023641 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::HostInventory::Kernel do describe 'Example of CentOS 6.6 Kernel version 2.6.32-504.30.3.el6.x86_64' do str = 'Linux 2.6.32-504.30.3.el6.x86_64' let(:host_inventory) { nil } ret = Specinfra::HostInventory::Kernel.new(host_inventory).parse_uname(str) example "name" do expect(ret["name"]).to eq("Linux") end example "release" do expect(ret["release"]).to eq("2.6.32-504.30.3.el6.x86_64") end example "version" do expect(ret["version"]).to eq("2.6.32") end example "major" do expect(ret["version_major"]).to eq("2.6") end end describe 'Example of unparseable output' do str = 'unparseable output' let(:host_inventory) { nil } ret = Specinfra::HostInventory::Kernel.new(host_inventory).parse_uname(str) example 'is nil' do expect(ret).to be(nil) end end end specinfra-2.89.0/spec/host_inventory/linux/cpu_spec.rb0000644000004100000410000000573414575463425023155 0ustar www-datawww-datarequire 'spec_helper' str = <<-EOH processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 60 model name : Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz stepping : 3 microcode : 0x19 cpu MHz : 3132.076 cache size : 6144 KB physical id : 0 siblings : 2 core id : 0 cpu cores : 2 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 5 wp : yes flags : fpu vme de pse bogomips : 6264.15 clflush size : 64 cache_alignment : 64 address sizes : 39 bits physical, 48 bits virtual power management: processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 60 model name : Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz stepping : 3 microcode : 0x19 cpu MHz : 3132.076 cache size : 6144 KB physical id : 0 siblings : 2 core id : 1 cpu cores : 2 apicid : 1 initial apicid : 1 fpu : yes fpu_exception : yes cpuid level : 5 wp : yes flags : fpu vme de bogomips : 6264.15 clflush size : 64 cache_alignment : 64 address sizes : 39 bits physical, 48 bits virtual power management: EOH describe Specinfra::HostInventory::Cpu do let(:host_inventory) { nil } describe 'Example of Ubuntu 14.04.1 LTS Kernel version 3.13.11' do ret = Specinfra::HostInventory::Cpu.new(host_inventory).parse(str) example do expect(ret["0"]).to include( "vendor_id" => "GenuineIntel", "cpu_family" => "6", "model" => "60", "model_name" => "Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz", "stepping" => "3", "microcode" => "0x19", "cpu_mhz" => "3132.076", "cache_size" => "6144KB", "physical_id" => "0", "siblings" => "2", "core_id" => "0", "cpu_cores" => "2", "apicid" => "0", "initial_apicid" => "0", "fpu" => "yes", "fpu_exception" => "yes", "cpuid_level" => "5", "wp" => "yes", "flags" => ["fpu", "vme", "de", "pse"], "bogomips" => "6264.15", "clflush_size" => "64", "cache_alignment" => "64", "address_sizes" => "39 bits physical, 48 bits virtual", "power_management" => "" ) end example do expect(ret["1"]).to include( "vendor_id" => "GenuineIntel", "cpu_family" => "6", "model" => "60", "model_name" => "Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz", "stepping" => "3", "microcode" => "0x19", "cpu_mhz" => "3132.076", "cache_size" => "6144KB", "physical_id" => "0", "siblings" => "2", "core_id" => "1", "cpu_cores" => "2", "apicid" => "1", "initial_apicid" => "1", "fpu" => "yes", "fpu_exception" => "yes", "cpuid_level" => "5", "wp" => "yes", "flags" => ["fpu", "vme", "de"], "bogomips" => "6264.15", "clflush_size" => "64", "cache_alignment" => "64", "address_sizes" => "39 bits physical, 48 bits virtual", "power_management" => "" ) end example do expect(ret["total"]).to eq "2" end end end specinfra-2.89.0/spec/host_inventory/linux/memory_spec.rb0000644000004100000410000001004714575463425023667 0ustar www-datawww-datarequire 'spec_helper' str = <<-EOH MemTotal: 1019392 kB MemFree: 88248 kB Buffers: 26016 kB Cached: 312856 kB SwapCached: 87708 kB Active: 396664 kB Inactive: 444580 kB Active(anon): 242816 kB Inactive(anon): 308412 kB Active(file): 153848 kB Inactive(file): 136168 kB Unevictable: 16 kB Mlocked: 16 kB HighTotal: 131912 kB HighFree: 312 kB LowTotal: 887480 kB LowFree: 87936 kB SwapTotal: 2064380 kB SwapFree: 1760500 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 473868 kB Mapped: 68192 kB Shmem: 48856 kB Slab: 57696 kB SReclaimable: 14152 kB SUnreclaim: 43544 kB KernelStack: 3240 kB PageTables: 12144 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 2574076 kB Committed_AS: 2517964 kB VmallocTotal: 122880 kB VmallocUsed: 11204 kB VmallocChunk: 95432 kB AnonHugePages: 92160 kB HugePages_Total: 189440 HugePages_Free: 189440 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 907256 kB DirectMap2M: 0 kB EOH describe Specinfra::HostInventory::Memory do let(:host_inventory) { nil } describe 'Example of CentOS 6.6 Kernel version 2.6.32-504.23.4.el6.i686' do ret = Specinfra::HostInventory::Memory.new(host_inventory).parse(str) example "active" do expect(ret["active"]).to include("396664kB") end example "anon_pages" do expect(ret["anon_pages"]).to include("473868kB") end example "bounce" do expect(ret["bounce"]).to include("0kB") end example "buffers" do expect(ret["buffers"]).to include("26016kB") end example "cached" do expect(ret["cached"]).to include("312856kB") end example "commited_as" do expect(ret["committed_as"]).to include("2517964kB") end example "commit_limit" do expect(ret["commit_limit"]).to include("2574076kB") end example "dirty" do expect(ret["dirty"]).to include("0kB") end example "free" do expect(ret["free"]).to include("88248kB") end example "inactive" do expect(ret["inactive"]).to include("444580kB") end example "mapped" do expect(ret["mapped"]).to include("68192kB") end example "nfs_unstable" do expect(ret["nfs_unstable"]).to include("0kB") end example "page_tables" do expect(ret["page_tables"]).to include("12144kB") end example "slab" do expect(ret["slab"]).to include("57696kB") end example "slab_reclaimable" do expect(ret["slab_reclaimable"]).to include("14152kB") end example "slab_unreclaim" do expect(ret["slab_unreclaim"]).to include("43544kB") end example "swap" do expect(ret["swap"]).to include( "free" => "1760500kB", "total" => "2064380kB", "cached" => "87708kB" ) end example "total" do expect(ret["total"]).to include("1019392kB") end example "vmalloc_chunk" do expect(ret["vmalloc_chunk"]).to include("95432kB") end example "vmalloc_total" do expect(ret["vmalloc_total"]).to include("122880kB") end example "vmalloc_used" do expect(ret["vmalloc_used"]).to include("11204kB") end example "writeback" do expect(ret["writeback"]).to include("0kB") end example "annon_huge_pages" do expect(ret["annon_huge_pages"]).to include("92160kB") end example "huge_pages_total" do expect(ret["huge_pages_total"]).to include("189440") end example "huge_pages_free" do expect(ret["huge_pages_free"]).to include("189440") end example "huge_pages_rsvd" do expect(ret["huge_pages_rsvd"]).to include("0") end example "huge_pages_surp" do expect(ret["huge_pages_surp"]).to include("0") end example "huge_page_size" do expect(ret["huge_page_size"]).to include("2048kB") end end end specinfra-2.89.0/spec/host_inventory/linux/virtualization_spec.rb0000644000004100000410000000466314575463425025452 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::HostInventory::Virtualization do before :all do set :os, { :family => 'linux' } end virt = Specinfra::HostInventory::Virtualization.new(host_inventory) let(:host_inventory) { nil } it 'Docker Image should return :system => "docker"' do allow(virt.backend).to receive(:run_command).with('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit') do CommandResult.new(:stdout => '', :exit_status => 0) end expect(virt.get).to include(:system => 'docker') end let(:host_inventory) { nil } it 'Debian Wheezy on OpenVZ should return :system => "openvz"' do allow(virt.backend).to receive(:run_command).with('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit') do CommandResult.new(:stdout => '', :exit_status => 2) end allow(virt.backend).to receive(:run_command).with('test -d /proc/vz -a ! -d /proc/bc') do CommandResult.new(:stdout => '', :exit_status => 0) end expect(virt.get).to include(:system => 'openvz') end it 'Debian on QEMU KVM should return :system => "kvm"' do allow(virt.backend).to receive(:run_command).with('grep -Eqa \'docker(/|-[0-9a-f]+)\' /proc/1/cgroup||test -e /.dockerinit') do CommandResult.new(:stdout => '', :exit_status => 1) end allow(virt.backend).to receive(:run_command).with('test -d /proc/vz -a ! -d /proc/bc') do CommandResult.new(:stdout => '', :exit_status => 1) end allow(virt.backend).to receive(:run_command).with('dmidecode -s system-product-name') do CommandResult.new(:stdout => "Standard PC (Q35 + ICH9, 2009)\n", :exit_status => 0) end allow(virt.backend).to receive(:run_command).with('systemd-detect-virt') do CommandResult.new(:stdout => "kvm\n", :exit_status => 0) end expect(virt.get).to include(:system => 'kvm') end let(:host_inventory) { nil } it 'Debian Jessie on KVM should return :system => "kvm"' do ret = virt.parse_system_product_name("KVM\n") expect(ret).to include('kvm') end let(:host_inventory) { nil } it 'CentOS 6.7 on VMware should return :system => "vmware"' do ret = virt.parse_system_product_name("VMware Virtual Platform\n") expect(ret).to include('vmware') end let(:host_inventory) { nil } it 'Ubuntu 14.04 on VirtualBox should return :system => "vbox"' do ret = virt.parse_system_product_name("VirtualBox\n") expect(ret).to include('vbox') end end specinfra-2.89.0/spec/host_inventory/linux/filesystem_spec.rb0000644000004100000410000000346014575463425024544 0ustar www-datawww-datarequire 'spec_helper' ## Output from 'df -P' str = <<-EOH Filesystem 1024-blocks Used Available Capacity Mounted on /dev/mapper/vg_idefix-lv_root 51475068 8840540 40013088 19% / tmpfs 509696 872 508824 1% /dev/shm /dev/sdb3 487652 124828 337224 28% /boot /dev/mapper/vg_idefix-lv_home 20857444 17905852 1885404 91% /home EOH describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example of CentOS 6.6 Kernel version 2.6.32-504.23.4.el6.i686' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "/dev/mapper/vg_idefix-lv_home" do expect(ret["/dev/mapper/vg_idefix-lv_home"]).to include( "kb_used" => "17905852", "kb_size" => "20857444", "kb_available" => "1885404", "mount" => "/home", "percent_used" => "91%" ) end example "/dev/mapper/vg_idefix-lv_root" do expect(ret["/dev/mapper/vg_idefix-lv_root"]).to include( "kb_used" => "8840540", "kb_size" => "51475068", "kb_available" => "40013088", "mount" => "/", "percent_used" => "19%" ) end example "/dev/sdb3" do expect(ret["/dev/sdb3"]).to include( "kb_used" => "124828", "kb_size" => "487652", "kb_available" => "337224", "mount" => "/boot", "percent_used" => "28%" ) end example "tmpfs" do expect(ret["tmpfs"]).to include( "kb_used" => "872", "kb_size" => "509696", "kb_available" => "508824", "mount" => "/dev/shm", "percent_used" => "1%" ) end end end specinfra-2.89.0/spec/host_inventory/openbsd/0000755000004100000410000000000014575463425021311 5ustar www-datawww-dataspecinfra-2.89.0/spec/host_inventory/openbsd/virtualization_spec.rb0000644000004100000410000000144614575463425025741 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::HostInventory::Virtualization do before :all do set :os, { :family => 'openbsd' } end virt = Specinfra::HostInventory::Virtualization.new(host_inventory) let(:host_inventory) { nil } it 'OpenBSD 5.7 on KVM should return :system => "kvm"' do ret = virt.parse_system_product_name("KVM\n") expect(ret).to include('kvm') end let(:host_inventory) { nil } it 'OpenBSD 5.7 on VMware should return :system => "vmware"' do ret = virt.parse_system_product_name("VMware Virtual Platform\n") expect(ret).to include('vmware') end let(:host_inventory) { nil } it 'OpenBSD 5.7 on VirtualBox should return :system => "vbox"' do ret = virt.parse_system_product_name("VirtualBox\n") expect(ret).to include('vbox') end end specinfra-2.89.0/spec/host_inventory/openbsd/filesystem_spec.rb0000644000004100000410000000240614575463425025036 0ustar www-datawww-datarequire 'spec_helper' ## Output from 'df -kP' str = <<-EOH Filesystem 1024-blocks Used Available Capacity Mounted on /dev/sd0a 1013006 58408 903948 6% / /dev/sd0e 1822574 18 1731428 0% /home /dev/sd0d 3093230 372244 2566326 13% /usr EOH describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example OpenBSD release 5.7' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "/dev/sd0a" do expect(ret["/dev/sd0a"]).to include( "kb_available" => "903948", "kb_size" => "1013006", "kb_used" => "58408", "mount" => "/", "percent_used" => "6%" ) end example "/dev/sd0d" do expect(ret["/dev/sd0d"]).to include( "kb_available" => "2566326", "kb_size" => "3093230", "kb_used" => "372244", "mount" => "/usr", "percent_used" => "13%" ) end example "/dev/sd0e" do expect(ret["/dev/sd0e"]).to include( "kb_available" => "1731428", "kb_size" => "1822574", "kb_used" => "18", "mount" => "/home", "percent_used" => "0%" ) end end end specinfra-2.89.0/spec/host_inventory/guix/0000755000004100000410000000000014575463425020633 5ustar www-datawww-dataspecinfra-2.89.0/spec/host_inventory/guix/filesystem_spec.rb0000644000004100000410000000327714575463425024367 0ustar www-datawww-datarequire 'spec_helper' ## Output from 'df -k' str = <<-EOH Filesystem 1K-blocks Used Available Use% Mounted on none 4015168 0 4015168 0% /dev /dev/sda3 235797392 184584640 39162064 83% / /dev/sda1 523248 3640 519608 1% /boot/efi tmpfs 4025296 1052 4024244 1% /dev/shm none 4025292 44 4025248 1% /run/systemd none 4025292 0 4025292 0% /run/user cgroup 4025292 0 4025292 0% /sys/fs/cgroup none 4025292 0 4025292 0% /var/cache/fontconfig none 4025292 684 4024608 1% /var/lib/gdm tmpfs 805056 44 805012 1% /run/user/1000 EOH describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example of Guix' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "/dev/sda3" do expect(ret["/dev/sda3"]).to include( "kb_available" => "39162064", "kb_size" => "235797392", "mount" => "/", "percent_used" => "83%", "kb_used" => "184584640" ) end example "/dev/sda1" do expect(ret["/dev/sda1"]).to include( "kb_available" => "519608", "kb_size" => "523248", "mount" => "/boot/efi", "percent_used" => "1%", "kb_used" => "3640" ) end example "cgroup" do expect(ret["cgroup"]).to include( "kb_available" => "4025292", "kb_size" => "4025292", "mount" => "/sys/fs/cgroup", "percent_used" => "0%", "kb_used" => "0" ) end end end specinfra-2.89.0/spec/host_inventory/freebsd/0000755000004100000410000000000014575463425021271 5ustar www-datawww-dataspecinfra-2.89.0/spec/host_inventory/freebsd/filesystem_spec.rb0000644000004100000410000000765714575463425025033 0ustar www-datawww-datarequire 'spec_helper' ## Output from 'df -k' str = <<-EOH Filesystem 1024-blocks Used Avail Capacity Mounted on zroot/ROOT/default 2500692 1345720 1154972 54% / devfs 1 1 0 100% /dev zroot/tmp 1155148 176 1154972 0% /tmp zroot/usr/home 1353676 198704 1154972 15% /usr/home zroot/usr/ports 2306832 1151860 1154972 50% /usr/ports zroot/usr/src 1155116 144 1154972 0% /usr/src zroot/var 1361412 206440 1154972 15% /var zroot/var/crash 1155120 148 1154972 0% /var/crash zroot/var/log 1156184 1212 1154972 0% /var/log zroot/var/mail 1155168 196 1154972 0% /var/mail zroot/var/tmp 1188108 33136 1154972 3% /var/tmp EOH describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example of FreeBSD 9.3 amd64' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "devfs" do expect(ret["devfs"]).to include( "kb_available" => "0", "kb_size" => "1", "mount" => "/dev", "percent_used" => "100%", "kb_used" => "1" ) end example "zroot/ROOT/default" do expect(ret["zroot/ROOT/default"]).to include( "kb_available" => "1154972", "kb_size" => "2500692", "mount" => "/", "percent_used" => "54%", "kb_used" => "1345720" ) end example "zroot/tmp" do expect(ret["zroot/tmp"]).to include( "kb_available" => "1154972", "kb_size" => "1155148", "mount" => "/tmp", "percent_used" => "0%", "kb_used" => "176" ) end example "zroot/usr/home" do expect(ret["zroot/usr/home"]).to include( "kb_available" => "1154972", "kb_size" => "1353676", "mount" => "/usr/home", "percent_used" => "15%", "kb_used" => "198704" ) end example "zroot/usr/ports" do expect(ret["zroot/usr/ports"]).to include( "kb_available" => "1154972", "kb_size" => "2306832", "mount" => "/usr/ports", "percent_used" => "50%", "kb_used" => "1151860" ) end example "zroot/usr/src" do expect(ret["zroot/usr/src"]).to include( "kb_available" => "1154972", "kb_size" => "1155116", "mount" => "/usr/src", "percent_used" => "0%", "kb_used" => "144" ) end example "zroot/var" do expect(ret["zroot/var"]).to include( "kb_available" => "1154972", "kb_size" => "1361412", "mount" => "/var", "percent_used" => "15%", "kb_used" => "206440" ) end example "zroot/var/crash" do expect(ret["zroot/var/crash"]).to include( "kb_available" => "1154972", "kb_size" => "1155120", "mount" => "/var/crash", "percent_used" => "0%", "kb_used" => "148" ) end example "zroot/var/mail" do expect(ret["zroot/var/mail"]).to include( "kb_available" => "1154972", "kb_size" => "1155168", "mount" => "/var/mail", "percent_used" => "0%", "kb_used" => "196" ) end example "zroot/var/log" do expect(ret["zroot/var/log"]).to include( "kb_available" => "1154972", "kb_size" => "1156184", "mount" => "/var/log", "percent_used" => "0%", "kb_used" => "1212" ) end example "zroot/var/tmp" do expect(ret["zroot/var/tmp"]).to include( "kb_available" => "1154972", "kb_size" => "1188108", "mount" => "/var/tmp", "percent_used" => "3%", "kb_used" => "33136" ) end end end specinfra-2.89.0/spec/host_inventory/darwin/0000755000004100000410000000000014575463425021143 5ustar www-datawww-dataspecinfra-2.89.0/spec/host_inventory/darwin/kernel_spec.rb0000644000004100000410000000114614575463425023764 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::HostInventory::Kernel do describe "get" do let(:host_inventory) { Specinfra::HostInventory.instance } let(:command_class) { Specinfra::Command::Darwin::Base } let(:error_message) { "get_kernel is not implemented in #{command_class}" } let(:kernel_inventory) { Specinfra::HostInventory::Kernel.new(host_inventory) } let(:result) { kernel_inventory.get } example "it includes the value of os_info[:arch] in the key 'machine'" do expect(result).to include( "machine" => host_inventory.backend.os_info[:arch] ) end end end specinfra-2.89.0/spec/host_inventory/darwin/filesystem_spec.rb0000644000004100000410000000413414575463425024670 0ustar www-datawww-datarequire 'spec_helper' ## Output from 'df -k' str = <<-EOH Filesystem 1024-blocks Used Available Capacity Mounted on /dev/disk0s2 243358976 213852680 29250296 88% / devfs 126 126 0 100% /dev map -hosts 0 0 0 100% /net map auto_home 0 0 0 100% /home localhost:/zbXdxUd1sN5zY6jeNUAx8l 243358976 243358976 0 100% /Volumes/MobileBackups EOH describe Specinfra::HostInventory::Filesystem do let(:host_inventory) { nil } describe 'Example Darwin (MacOS X) release 11.4.2' do ret = Specinfra::HostInventory::Filesystem.new(host_inventory).parse(str) example "/dev/disk0s2" do expect(ret["/dev/disk0s2"]).to include( "kb_available" => "29250296", "kb_size" => "243358976", "kb_used" => "213852680", "mount" => "/", "percent_used" => "88%" ) end example "map -hosts" do expect(ret["map -hosts"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/net", "percent_used" => "100%" ) end example "map auto_home" do expect(ret["map auto_home"]).to include( "kb_available" => "0", "kb_size" => "0", "kb_used" => "0", "mount" => "/home", "percent_used" => "100%" ) end example "devfs" do expect(ret["devfs"]).to include( "kb_available" => "0", "kb_size" => "126", "kb_used" => "126", "mount" => "/dev", "percent_used" => "100%" ) end example "localhost:/zbXdxUd1sN5zY6jeNUAx8l" do expect(ret["localhost:/zbXdxUd1sN5zY6jeNUAx8l"]).to include( "kb_available" => "0", "kb_size" => "243358976", "kb_used" => "243358976", "mount" => "/Volumes/MobileBackups", "percent_used" => "100%" ) end end end specinfra-2.89.0/spec/processor_spec.rb0000644000004100000410000001203314575463425020142 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Processor do describe 'check_file_is_mounted' do let(:path) { '/proc' } let(:cmd) { Specinfra.command.get(:check_file_is_mounted, path) } def mock_output(stdout) Specinfra::CommandResult.new :stdout => stdout end context 'freebsd' do before do allow(Specinfra.backend).to receive(:run_command).with(cmd) { mock_output 'procfs on /proc (procfs, local)' } end it 'true when fs type matches' do expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'procfs'}, false)).to eq(true) end it 'false when fs type is different' do expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'ufs'}, false)).to eq(false) end it 'true when option matches' do expect(Specinfra::Processor.check_file_is_mounted(path, {:local => true}, false)).to eq(true) end it 'false when option is different' do expect(Specinfra::Processor.check_file_is_mounted(path, {:async => true}, false)).to eq(false) end context 'only_with' do it 'false when extra options present' do expect(Specinfra::Processor.check_file_is_mounted(path, {:local => true, :async => true}, true)).to eq(false) end it 'true when all options met' do expect(Specinfra::Processor.check_file_is_mounted(path, {:device => "procfs", :type => "procfs", :local => true}, true)).to eq(true) end end end context 'linux' do before do allow(Specinfra.backend).to receive(:run_command).with(cmd) { mock_output 'proc on /proc type proc (rw,noexec,nosuid,nodev)' } end it 'true when fs type matches' do expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'proc'}, false)).to eq(true) end it 'false when fs type is different' do expect(Specinfra::Processor.check_file_is_mounted(path, {:type => 'ufs'}, false)).to eq(false) end it 'true when option matches' do expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :nosuid => true}, false)).to eq(true) end it 'false when option is different' do expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :unknown => true}, false)).to eq(false) end context 'only_with' do it 'false when extra options present' do expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :nosuid => true}, true)).to eq(false) end it 'true when all options are same' do expect(Specinfra::Processor.check_file_is_mounted(path, {:noexec => true, :nosuid => true, :nodev => true, :rw => true, :device => "proc", :type => "proc"}, true)).to eq(true) end end end end describe 'check_service_is_running' do let(:service_command) { Specinfra.command.get(:check_service_is_running, 'service_name') } let(:process_command) { Specinfra.command.get(:check_process_is_running, 'service_name') } context 'default settings' do it 'does not fall back to process checking if service checking succeeds' do allow(Specinfra.backend).to receive(:run_command).with(service_command) { CommandResult.new :exit_status => 0 } expect(Specinfra::Processor.check_service_is_running('service_name')).to eq(true) end context 'when service checking fails' do it 'falls back to checking by process and returns true if that succeeds' do allow(Specinfra.backend).to receive(:run_command).with(service_command) { CommandResult.new :exit_status => 1 } expect(Specinfra.backend).to receive(:run_command).with(process_command) { CommandResult.new :exit_status => 0 } expect(Specinfra::Processor.check_service_is_running('service_name')).to eq(true) end it 'falls back to checking by process and returns false if that fails' do allow(Specinfra.backend).to receive(:run_command).with(service_command) { CommandResult.new :exit_status => 1 } expect(Specinfra.backend).to receive(:run_command).with(process_command) { CommandResult.new :exit_status => 1 } expect(Specinfra::Processor.check_service_is_running('service_name')).to eq(false) end end end context 'no_service_process_fallback set to true' do it 'does not fall back to checking processes if service checking succeeds' do Specinfra.configuration.no_service_process_fallback(true) allow(Specinfra.backend).to receive(:run_command).with(service_command) { CommandResult.new :exit_status => 0 } expect(Specinfra::Processor.check_service_is_running('service_name')).to eq(true) end it 'does not fall back to checking processes if service checking fails' do Specinfra.configuration.no_service_process_fallback(true) allow(Specinfra.backend).to receive(:run_command).with(service_command) { CommandResult.new :exit_status => 1 } expect(Specinfra::Processor.check_service_is_running('service_name')).to eq(false) end end end end specinfra-2.89.0/spec/command/0000755000004100000410000000000014575463425016203 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/clearlinux/0000755000004100000410000000000014575463425020351 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/clearlinux/package_spec.rb0000644000004100000410000000064114575463425023304 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, { :family => 'clearlinux' } describe get_command(:check_package_is_installed, 'vim') do it { should eq "swupd bundle-list --quiet | grep -w vim" } end describe get_command(:install_package, 'vim') do it { should eq "swupd bundle-add --quiet vim" } end describe get_command(:remove_package, 'vim') do it { should eq "swupd bundle-remove --quiet vim" } endspecinfra-2.89.0/spec/command/windows/0000755000004100000410000000000014575463425017675 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/windows/service_spec.rb0000644000004100000410000000321114575463425022671 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe Specinfra::Command::Windows::Base::Service do before :all do property[:os] = nil set :os, :family => 'windows' end let(:service_name) { "Power" } let(:property_map) {{"StartName"=>"Local System","State"=>"Running","StartMode"=>"Auto"}} describe "#check_service_is_running" do it "" do command = get_command(:check_service_is_running, service_name) expect(command.script).to eq("(FindService -name 'Power').State -eq 'Running'") end end describe "#check_service_is_enabled" do it "" do command = get_command(:check_service_is_enabled, service_name) expect(command.script).to eq ("(FindService -name 'Power').StartMode -eq 'Auto'") end end describe "#has_property" do it "includes (FindService -name 'Power').StartName -eq 'Local System" do command = get_command(:check_service_has_property, service_name,property_map) expect(command.script).to include ("(FindService -name 'Power').StartName -eq 'Local System'") end it "includes (FindService -name 'Power').State -eq 'Running" do command = get_command(:check_service_has_property, service_name,property_map) expect(command.script).to include ("(FindService -name 'Power').State -eq 'Running'") end it "includes (FindService -name 'Power').StartMode -eq 'Auto" do command = get_command(:check_service_has_property, service_name,property_map) expect(command.script).to include ("(FindService -name 'Power').StartMode -eq 'Auto'") end end end specinfra-2.89.0/spec/command/windows/registry_key_spec.rb0000644000004100000410000000225314575463425023756 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe Specinfra::Command::Windows::Base::RegistryKey do let(:key_path) { "HKLM\\Software\\Microsoft\\Windows" } def stub_exec (command) expect(described_class).to receive(:create_command).with(command) end describe 'has_property?' do it { stub_exec "(Get-Item 'Registry::#{key_path}') -ne $null" described_class.check_exists(key_path) } end [:type_dword, :type_dword_converted].each do |reg_type| it "has_property_value #{reg_type}" do prop = {:name => 'CurrentVersion', :type => reg_type} stub_exec "(Get-Item 'Registry::#{key_path}').GetValueKind('CurrentVersion') -eq 'DWord'" described_class.check_has_property key_path, prop end end [:type_dword, :type_dword_converted].each do |reg_type| describe 'check_has_value' do it { value = reg_type == :type_dword_converted ? "23" : "17" prop = {:name => 'CurrentVersion', :type => reg_type, :value => value} cmd = "(Compare-Object (Get-Item 'Registry::#{key_path}').GetValue('CurrentVersion') 23) -eq $null" stub_exec cmd described_class.check_has_value key_path, prop } end end end specinfra-2.89.0/spec/command/factory_spec.rb0000644000004100000410000000163014575463425021211 0ustar www-datawww-datarequire 'spec_helper' describe 'create_command_class work correctly' do before do property[:os] = nil end context 'family: base, release: nil' do before do set :os, :family => 'base' end it { expect(Specinfra.command.send(:create_command_class, 'file')).to eq Specinfra::Command::Base::File } end context 'family: redhat, release: nil' do before do set :os, :family => 'redhat' end it { expect(Specinfra.command.send(:create_command_class, 'file')).to eq Specinfra::Command::Redhat::Base::File } it { expect(Specinfra.command.send(:create_command_class, 'selinux')).to eq Specinfra::Command::Linux::Base::Selinux } end context 'family: redhat, release: 7' do before do set :os, :family => 'redhat', :release => 7 end it { expect(Specinfra.command.send(:create_command_class, 'file')).to eq Specinfra::Command::Redhat::V7::File } end end specinfra-2.89.0/spec/command/debiantesting/0000755000004100000410000000000014575463425021023 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/debiantesting/service_spec.rb0000644000004100000410000000041514575463425024022 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian', :release => 'testing' describe get_command(:check_service_is_enabled, 'apache') do it { should eq 'systemctl --quiet is-enabled apache||ls /etc/rc[S5].d/S??apache >/dev/null 2>/dev/null' } end specinfra-2.89.0/spec/command/debiantesting/port_spec.rb0000644000004100000410000000031514575463425023345 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian', :release => 'testing' describe get_command(:check_port_is_listening, '80') do it { should eq 'ss -tunl | grep -E -- :80\ ' } end specinfra-2.89.0/spec/command/debian/0000755000004100000410000000000014575463425017425 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/debian/service_spec.rb0000644000004100000410000000126014575463425022423 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian' describe get_command(:enable_service, 'apache2') do it { should eq 'update-rc.d apache2 defaults' } end describe get_command(:disable_service, 'apache2') do it { should eq 'update-rc.d -f apache2 remove' } end describe get_command(:start_service, 'apache2') do it { should eq 'service apache2 start' } end describe get_command(:stop_service, 'apache2') do it { should eq 'service apache2 stop' } end describe get_command(:restart_service, 'apache2') do it { should eq 'service apache2 restart' } end describe get_command(:reload_service, 'apache2') do it { should eq 'service apache2 reload' } end specinfra-2.89.0/spec/command/debian/package_spec.rb0000644000004100000410000000277614575463425022373 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian' describe get_command(:check_package_is_installed, 'telnet') do it { should eq "dpkg-query -f '${Status}' -W telnet | grep -E '^(install|hold) ok installed$'" } end describe get_command(:check_package_is_installed, 'telnet', '0.17-36build2') do it { should eq "dpkg-query -f '${Status} ${Version}' -W telnet | grep -E '^(install|hold) ok installed 0\\.17\\-36build2$'" } end describe get_command(:check_package_is_installed, 'linux-headers-$(uname -r)') do it 'should be escaped (that is, command substitution should not work)' do should eq "dpkg-query -f '${Status}' -W linux-headers-\\$\\(uname\\ -r\\) | grep -E '^(install|hold) ok installed$'" end end describe get_command(:install_package, 'telnet') do it { should eq "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install telnet" } end describe get_command(:install_package, 'telnet', '0.17-36build2') do it { should eq "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install telnet\\=0.17-36build2" } end describe get_command(:install_package, 'linux-headers-$(uname -r)') do it 'should be escaped (that is, command substitution should not work)' do should eq "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install linux-headers-\\$\\(uname\\ -r\\)" end end specinfra-2.89.0/spec/command/debian/port_spec.rb0000644000004100000410000000027114575463425021750 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian' describe get_command(:check_port_is_listening, '80') do it { should eq 'netstat -tunl | grep -- :80\ ' } end specinfra-2.89.0/spec/command/debianunstable/0000755000004100000410000000000014575463425021163 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/debianunstable/service_spec.rb0000644000004100000410000000041614575463425024163 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian', :release => 'unstable' describe get_command(:check_service_is_enabled, 'apache') do it { should eq 'systemctl --quiet is-enabled apache||ls /etc/rc[S5].d/S??apache >/dev/null 2>/dev/null' } end specinfra-2.89.0/spec/command/debianunstable/port_spec.rb0000644000004100000410000000031614575463425023506 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian', :release => 'unstable' describe get_command(:check_port_is_listening, '80') do it { should eq 'ss -tunl | grep -E -- :80\ ' } end specinfra-2.89.0/spec/command/base/0000755000004100000410000000000014575463425017115 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/base/package_spec.rb0000644000004100000410000000116614575463425022053 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:check_package_is_installed_by_gem, 'serverspec', '2.0.0') do it { should eq 'gem list --local | grep -iw -- \\^serverspec\\ | grep -w -- "[( ]2.0.0[,)]"' } end describe get_command(:check_package_is_installed_by_td_agent_gem, 'fluent-plugin-forest', '0.3.0') do it { should eq '/usr/sbin/td-agent-gem list --local | grep -iw -- \\^fluent-plugin-forest\\ | grep -w -- "[( ]0.3.0[,)]"' } end describe get_command(:check_package_is_installed_by_rvm, 'rbx', '2.4.1') do it { should eq 'rvm list strings | grep -iw -- \\^rbx | grep -w -- 2.4.1' } end specinfra-2.89.0/spec/command/base/file_spec.rb0000644000004100000410000000707614575463425021405 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:check_file_is_directory, '/tmp') do it { should eq 'test -d /tmp' } end describe get_command(:check_file_is_symlink, '/tmp') do it { should eq 'test -L /tmp' } end describe get_command(:change_file_mode, '/tmp', '0644') do it { should eq 'chmod 0644 /tmp' } end describe get_command(:change_file_mode, '/tmp', '0644', :recursive => true) do it { should eq 'chmod -R 0644 /tmp' } end describe get_command(:change_file_owner, '/tmp', 'root') do it { should eq 'chown root /tmp' } end describe get_command(:change_file_owner, '/tmp', 'root', 'root') do it { should eq 'chown root:root /tmp' } end describe get_command(:change_file_owner, '/tmp', 'root', 'Domain Users') do it { should eq 'chown root:Domain\\ Users /tmp' } end describe get_command(:change_file_owner, '/tmp', 'root', 'root', :recursive => true) do it { should eq 'chown -R root:root /tmp' } end describe get_command(:change_file_group, '/tmp', 'root') do it { should eq 'chgrp root /tmp' } end describe get_command(:change_file_group, '/tmp', 'Domain Users') do it { should eq 'chgrp Domain\ Users /tmp' } end describe get_command(:change_file_group, '/tmp', 'root', :recursive => true) do it { should eq 'chgrp -R root /tmp' } end describe get_command(:create_file_as_directory, '/tmp') do it { should eq 'mkdir -p /tmp' } end describe get_command(:get_file_owner_user, '/tmp') do it { should eq 'stat -c %U /tmp' } end describe get_command(:get_file_owner_group, '/tmp') do it { should eq 'stat -c %G /tmp' } end describe get_command(:copy_file, '/src', '/dest') do it { should eq 'cp -p /src /dest' } end describe get_command(:copy_file, '/src', '/dest', :recursive => true) do it { should eq 'cp -pR /src /dest' } end describe get_command(:move_file, '/src', '/dest') do it { should eq 'mv /src /dest' } end describe get_command(:link_file_to, '/link', '/target') do it { should eq 'ln -s /target /link' } end describe get_command(:link_file_to, '/link', '/target', :force => true) do it { should eq 'ln -sf /target /link' } end describe get_command(:link_file_to, '/link', '/target', :no_dereference => true) do it { should eq 'ln -sn /target /link' } end describe get_command(:link_file_to, '/link', '/target', :force => true, :no_dereference => true) do it { should eq 'ln -sfn /target /link' } end describe get_command(:remove_file, '/tmp') do it { should eq 'rm -rf /tmp' } end describe get_command(:check_file_is_link, '/tmp') do it { should eq 'test -L /tmp' } end describe get_command(:check_file_is_pipe, '/tmp') do it { should eq 'test -p /tmp' } end describe get_command(:check_file_is_block_device, '/tmp') do it { should eq 'test -b /tmp' } end describe get_command(:check_file_is_character_device, '/tmp') do it { should eq 'test -c /tmp' } end describe get_command(:get_file_link_target, '/tmp') do it { should eq 'readlink /tmp' } end describe get_command(:get_file_link_realpath, '/tmp') do it { should eq 'readlink -e /tmp' } end describe get_command(:check_file_is_dereferenceable, '/tmp') do it { should eq 'test -n "$(readlink -e /tmp)"' } end describe get_command(:check_file_exists, '/tmp') do it { should eq 'test -e /tmp' } end describe get_command(:get_file_mtime, '/tmp') do it { should eq 'stat -c %Y /tmp' } end describe get_command(:get_file_size, '/tmp') do it { should eq 'stat -c %s /tmp' } end describe get_command(:download_file, 'http://example.com/sample_file', '/tmp/sample_file') do it { should eq 'curl -sSL http://example.com/sample_file -o /tmp/sample_file' } end specinfra-2.89.0/spec/command/base/mail_alias_spec.rb0000644000004100000410000000110014575463425022537 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:check_mail_alias_is_aliased_to, 'pink', '|/pony') do it do should eq %Q{getent aliases pink | } + %Q{egrep -- \\\[\\\[:space:\\\]\\\]\\\(\\\[\\\"\\'\\\]\\?\\)\\\\\\|/pony\\\\1\\\(,\\\|\\\$\\\)} end end describe get_command(:check_mail_alias_is_aliased_to, 'pink', '|/pony, |/unicorn') do it do should eq %Q{getent aliases pink | } + %Q{egrep -- \\\[\\\[:space:\\\]\\\]\\\(\\\[\\\"\\'\\\]\\?\\)\\\\\\|/pony,\\\ \\\\\\|/unicorn\\\\1\\\(,\\\|\\\$\\\)} end end specinfra-2.89.0/spec/command/base/host_spec.rb0000644000004100000410000000144214575463425021432 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:check_host_is_reachable, 'pink.unicorn.com', nil, 'tcp', 10) do it { should eq "ping -w 10 -c 2 -n pink.unicorn.com" } end describe get_command(:check_host_is_reachable, 'pink.unicorn.com', '53', 'udp', 2) do it { should eq "nc -w 2 -vvvvzu pink.unicorn.com 53" } end describe get_command(:get_host_ipaddress, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '{print $1}'" } end describe get_command(:get_host_ipv4_address, 'pink.unicorn.com') do it { should eq "getent ahostsv4 pink.unicorn.com | awk '{print $1; exit}'" } end describe get_command(:get_host_ipv6_address, 'pink.unicorn.com') do it { should eq "getent ahostsv6 pink.unicorn.com | awk '{print $1; exit}'" } end specinfra-2.89.0/spec/command/base/user_spec.rb0000644000004100000410000000446614575463425021444 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:get_user_uid, 'foo') do it { should eq 'id -u foo' } end describe get_command(:get_user_gid, 'foo') do it { should eq 'id -g foo' } end describe get_command(:get_user_home_directory, 'foo') do it { should eq "getent passwd foo | cut -f 6 -d ':'" } end describe get_command(:update_user_home_directory, 'user', 'dir') do it { should eq "usermod -d dir user" } end describe get_command(:update_user_uid, 'foo', 100) do it { should eq 'usermod -u 100 foo' } end describe get_command(:update_user_gid, 'foo', 100) do it { should eq 'usermod -g 100 foo' } end describe get_command(:add_user, 'foo', :home_directory => '/home/foo', :password => '$6$foo/bar', :shell => '/bin/tcsh', :create_home => true) do it { should eq 'useradd -d /home/foo -p \$6\$foo/bar -s /bin/tcsh -m foo' } end describe get_command(:update_user_encrypted_password, 'foo', 'xxxxxxxx') do it { should eq 'echo foo:xxxxxxxx | chpasswd -e' } end describe get_command(:get_user_encrypted_password, 'foo') do it { should eq "getent shadow foo | cut -f 2 -d ':'" } end describe get_command(:check_user_has_login_shell, 'foo', '/bin/sh') do it { should eq "getent passwd foo | cut -f 7 -d ':' | grep -w -- /bin/sh" } end describe get_command(:get_user_minimum_days_between_password_change, 'foo') do it { should eq "chage -l foo | sed -n 's/^Minimum.*: //p'" } end describe get_command(:get_user_maximum_days_between_password_change, 'foo') do it { should eq "chage -l foo | sed -n 's/^Maximum.*: //p'" } end describe get_command(:get_user_login_shell, 'foo') do it { should eq "getent passwd foo | cut -f 7 -d ':'" } end describe get_command(:update_user_login_shell, 'foo', '/bin/bash') do it { should eq 'usermod -s /bin/bash foo' } end describe get_command(:check_user_is_system_user, 'foo') do it { should eq "getent passwd foo > /dev/null 2>&1 && test \"$(getent passwd foo | cut -f 3 -d ':')\" -ge \"$(awk 'BEGIN{sys_uid_min=101} {if($1~/^SYS_UID_MIN/){sys_uid_min=$2}} END{print sys_uid_min}' /etc/login.defs)\" && test \"$(getent passwd foo | cut -f 3 -d ':')\" -le \"$(awk 'BEGIN{sys_uid_max=0;uid_min=1000} {if($1~/^SYS_UID_MAX/){sys_uid_max=$2}if($1~/^UID_MIN/){uid_min=$2}} END{if(sys_uid_max!=0){print sys_uid_max}else{print uid_min-1}}' /etc/login.defs)\"" } end specinfra-2.89.0/spec/command/base/process_spec.rb0000644000004100000410000000025314575463425022132 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:count_process, 'foo') do it { should eq 'ps aux | grep -w -- foo | grep -v grep | wc -l' } end specinfra-2.89.0/spec/command/base/localhost_spec.rb0000644000004100000410000000027314575463425022446 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:check_localhost_is_ec2_instance) do it { should eq 'curl --connect-timeout=1 http://169.254.169.254:80/' } end specinfra-2.89.0/spec/command/base/group_spec.rb0000644000004100000410000000176614575463425021622 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => nil } describe get_command(:get_group_gid, 'foo') do it { should eq "getent group foo | cut -f 3 -d ':'" } end describe get_command(:update_group_gid, 'foo', 1234) do it { should eq "groupmod -g 1234 foo" } end describe get_command(:add_group, 'foo', :gid => 1234) do it { should eq 'groupadd -g 1234 foo' } end describe get_command(:add_group, 'foo', :system_group => true) do it { should eq 'groupadd -r foo' } end describe get_command(:check_group_is_system_group, 'foo') do it { should eq "getent group foo > /dev/null 2>&1 && test \"$(getent group foo | cut -f 3 -d ':')\" -ge \"$(awk 'BEGIN{sys_gid_min=101} {if($1~/^SYS_GID_MIN/){sys_gid_min=$2}} END{print sys_gid_min}' /etc/login.defs)\" && test \"$(getent group foo | cut -f 3 -d ':')\" -le \"$(awk 'BEGIN{sys_gid_max=0;gid_min=1000} {if($1~/^SYS_GID_MAX/){sys_gid_max=$2}if($1~/^GID_MIN/){gid_min=$2}} END{if(sys_gid_max!=0){print sys_gid_max}else{print gid_min-1}}' /etc/login.defs)\"" } end specinfra-2.89.0/spec/command/linux/0000755000004100000410000000000014575463425017342 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/linux/selinux_spec.rb0000644000004100000410000000167214575463425022376 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_selinux_has_mode, 'disabled') do it do should eq %Q{test ! -f /etc/selinux/config || ( ( (} + %Q{getenforce | grep -i -- disabled) ||} + %Q{ (getenforce | grep -i -- permissive) )} + %Q{ && grep -iE -- '^\\s*SELINUX=disabled\\>' /etc/selinux/config)} end end describe get_command(:check_selinux_has_mode, 'permissive', nil) do it do should eq %Q{(getenforce | grep -i -- permissive)} + %Q{ && grep -iE -- '^\\s*SELINUX=permissive\\>' /etc/selinux/config} end end describe get_command(:check_selinux_has_mode, 'enforcing', 'targeted') do it do should eq %Q{(getenforce | grep -i -- enforcing)} + %Q{ && grep -iE -- '^\\s*SELINUX=enforcing\\>' /etc/selinux/config} + %Q{ && grep -iE -- '^\\s*SELINUXTYPE=targeted\\>' /etc/selinux/config} end end specinfra-2.89.0/spec/command/linux/file_spec.rb0000644000004100000410000000053414575463425021622 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_file_is_immutable, 'some_file') do it { should eq "lsattr -d some_file 2>&1 | awk '$1~/^[A-Za-z-]+$/ && $1~/i/ {exit 0} {exit 1}'" } end describe get_command(:get_file_selinuxlabel, 'some_file') do it { should eq 'stat -c %C some_file' } end specinfra-2.89.0/spec/command/linux/ip6tables_spec.rb0000644000004100000410000000030514575463425022570 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe get_command(:check_ip6tables_has_rule, 'rule') do it { should eq 'ip6tables -S | grep -- rule || ip6tables-save | grep -- rule' } end specinfra-2.89.0/spec/command/linux/interface_spec.rb0000644000004100000410000000250514575463425022643 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_interface_has_ipv6_address, 'eth0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee') do it { should eq "ip -6 addr show eth0 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/'" } end describe get_command(:check_interface_has_ipv6_address, 'eth0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/64') do it { should eq "ip -6 addr show eth0 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/64 '" } end describe get_command(:check_interface_has_ipv4_address, 'eth0', '192.168.0.123') do it { should eq "ip -4 addr show eth0 | grep 'inet 192\\.168\\.0\\.123/'" } end describe get_command(:check_interface_has_ipv4_address, 'eth0', '192.168.0.123/24') do it { should eq "ip -4 addr show eth0 | grep 'inet 192\\.168\\.0\\.123/24 '" } end describe get_command(:get_interface_ipv4_address, 'eth0') do it { should eq "ip -4 addr show eth0 | grep eth0$ | awk '{print $2}'" } end describe get_command(:get_interface_ipv6_address, 'eth0') do it { should eq "ip -6 addr show eth0 | grep inet6 | awk '{print $2}'" } end describe get_command(:get_interface_link_state, 'eth0') do it { should eq "cat /sys/class/net/eth0/operstate" } end describe get_command(:get_interface_mtu_of, 'eth0') do it { should eq "cat /sys/class/net/eth0/mtu" } end specinfra-2.89.0/spec/command/linux/inventory_spec.rb0000644000004100000410000000111714575463425022736 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe get_command(:get_inventory_memory) do it { should eq 'cat /proc/meminfo' } end describe get_command(:get_inventory_cpu) do it { should eq 'cat /proc/cpuinfo' } end describe get_command(:get_inventory_kernel) do it { should eq 'uname -s -r' } end describe get_command(:get_inventory_block_device) do block_device_dirs = '/sys/block/*/{size,removable,device/{model,rev,state,timeout,vendor},queue/rotational}' it { should eq %Q[bash -c 'for f in $(ls #{block_device_dirs}); do echo -e "${f}\t$(cat ${f})"; done'] } end specinfra-2.89.0/spec/command/linux/bond_spec.rb0000644000004100000410000000047314575463425021627 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_bond_exists, 'bond0') do it { should eq "ip link show bond0" } end describe get_command(:check_bond_has_interface, 'br0', 'eth0') do it { should eq "grep -o 'Slave Interface: eth0' /proc/net/bonding/br0" } end specinfra-2.89.0/spec/command/linux/selinux_module_spec.rb0000644000004100000410000000056214575463425023740 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_selinux_module_is_installed, 'dnsmasq') do it { should eq "semodule -l | grep $'^dnsmasq\\t'" } end describe get_command(:check_selinux_module_is_enabled, 'dnsmasq') do it { should eq "semodule -l | grep $'^dnsmasq\\t' | grep -v $'^dnsmasq\\t.*\\tDisabled$'" } end specinfra-2.89.0/spec/command/linux/bridge_spec.rb0000644000004100000410000000044314575463425022136 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_bridge_exists, 'br0') do it { should eq "ip link show br0" } end describe get_command(:check_bridge_has_interface, 'br0', 'eth0') do it { should eq "brctl show br0 | grep -o eth0" } end specinfra-2.89.0/spec/command/openbsd57/0000755000004100000410000000000014575463425020011 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/openbsd57/service_spec.rb0000644000004100000410000000156714575463425023021 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd', :release => '5.7' describe get_command(:check_service_is_enabled, 'httpd') do it { should eq 'rcctl get httpd status' } end describe get_command(:check_service_is_running, 'httpd') do it { should eq 'rcctl check httpd' } end describe get_command(:enable_service, 'httpd') do it { should eq 'rcctl set httpd status on' } end describe get_command(:disable_service, 'httpd') do it { should eq 'rcctl set httpd status off' } end describe get_command(:start_service, 'httpd') do it { should eq 'rcctl start httpd' } end describe get_command(:stop_service, 'httpd') do it { should eq 'rcctl stop httpd' } end describe get_command(:restart_service, 'httpd') do it { should eq 'rcctl restart httpd' } end describe get_command(:reload_service, 'httpd') do it { should eq 'rcctl reload httpd' } end specinfra-2.89.0/spec/command/debian8/0000755000004100000410000000000014575463425017515 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/debian8/port_spec.rb0000644000004100000410000000030714575463425022040 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian', :release => '8' describe get_command(:check_port_is_listening, '80') do it { should eq 'ss -tunl | grep -E -- :80\ ' } end specinfra-2.89.0/spec/command/amazon/0000755000004100000410000000000014575463425017470 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/amazon/service_spec.rb0000644000004100000410000000121014575463425022461 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'amazon' describe get_command(:enable_service, 'httpd') do it { should eq 'chkconfig httpd on' } end describe get_command(:disable_service, 'httpd') do it { should eq 'chkconfig httpd off' } end describe get_command(:start_service, 'httpd') do it { should eq 'service httpd start' } end describe get_command(:stop_service, 'httpd') do it { should eq 'service httpd stop' } end describe get_command(:restart_service, 'httpd') do it { should eq 'service httpd restart' } end describe get_command(:reload_service, 'httpd') do it { should eq 'service httpd reload' } end specinfra-2.89.0/spec/command/amazon/package_spec.rb0000644000004100000410000000023614575463425022423 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => 'amazon' } describe get_command(:check_package_is_installed, 'httpd') do it { should eq 'rpm -q httpd' } end specinfra-2.89.0/spec/command/amazon/interface_spec.rb0000644000004100000410000000037114575463425022770 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, { :family => 'amazon', :release => nil } describe Specinfra.command.send(:create_command_class, 'interface') do it { should be_an_instance_of(Specinfra::Command::Linux::Base::Interface) } end specinfra-2.89.0/spec/command/esxi/0000755000004100000410000000000014575463425017153 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/esxi/package_spec.rb0000644000004100000410000000055314575463425022110 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, { :family => 'esxi' } describe get_command(:check_package_is_installed, 'httpd') do it { should eq 'esxcli software vib list | grep -w -- httpd' } end describe get_command(:check_package_is_installed, 'httpd', '2.0') do it { should eq 'esxcli software vib list | grep -w -- httpd | grep -w -- 2.0'} end specinfra-2.89.0/spec/command/cumulus/0000755000004100000410000000000014575463425017700 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/cumulus/ppa_cumuluslinux_spec.rb0000644000004100000410000000036114575463425024654 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'cumuluslinux' describe get_command(:check_ppa_exists, 'git') do it { should eq 'find /etc/apt/ -name *.list | xargs grep -o "deb +http://repo.cumulusnetworks.com/git"' } end specinfra-2.89.0/spec/command/cumulus/ppa_cumulusnetworks_spec.rb0000644000004100000410000000036414575463425025374 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'cumulusnetworks' describe get_command(:check_ppa_exists, 'git') do it { should eq 'find /etc/apt/ -name *.list | xargs grep -o "deb +http://repo.cumulusnetworks.com/git"' } end specinfra-2.89.0/spec/command/redhat8/0000755000004100000410000000000014575463425017542 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/redhat8/selinux_spec.rb0000644000004100000410000000052714575463425022574 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat', :release => '8' describe get_command(:check_selinux_module_is_installed, 'dnsmasq') do it { should eq "semodule -l | grep $'^dnsmasq'" } end describe get_command(:check_selinux_module_is_enabled, 'dnsmasq') do it { should eq "semodule -l | grep $'^dnsmasq'" } end specinfra-2.89.0/spec/command/redhat8/yumrepo_spec.rb0000644000004100000410000000056214575463425022604 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat', :release => '8' describe get_command(:check_yumrepo_exists, 'epel') do it { should eq "dnf repolist all | grep -qsE \"^[\\!\\*]?epel\(\\s\|$\|\\/)\"" } end describe get_command(:check_yumrepo_is_enabled, 'epel') do it { should eq "dnf repolist enabled | grep -qs \"^[\\!\\*]\\?epel\"" } end specinfra-2.89.0/spec/command/amazon2/0000755000004100000410000000000014575463425017552 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/amazon2/service_spec.rb0000644000004100000410000000143014575463425022547 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'amazon', :release => '2' describe get_command(:enable_service, 'httpd') do it { should eq 'systemctl enable httpd' } end describe get_command(:disable_service, 'httpd') do it { should eq 'systemctl disable httpd' } end describe get_command(:start_service, 'httpd') do it { should eq 'systemctl start httpd' } end describe get_command(:stop_service, 'httpd') do it { should eq 'systemctl stop httpd' } end describe get_command(:restart_service, 'httpd') do it { should eq 'systemctl restart httpd' } end describe get_command(:reload_service, 'httpd') do it { should eq 'systemctl reload httpd' } end describe get_command(:enable_service, 'sshd.socket') do it { should eq 'systemctl enable sshd.socket' } end specinfra-2.89.0/spec/command/amazon2/port_spec.rb0000644000004100000410000000030714575463425022075 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'amazon', :release => '2' describe get_command(:check_port_is_listening, '80') do it { should eq 'ss -tunl | grep -E -- :80\ ' } end specinfra-2.89.0/spec/command/openbsd/0000755000004100000410000000000014575463425017635 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/openbsd/service_spec.rb0000644000004100000410000000044214575463425022634 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd' describe get_command(:check_service_is_enabled, 'httpd') do it { should eq '/etc/rc.d/httpd status' } end describe get_command(:check_service_is_running, 'httpd') do it { should eq '/etc/rc.d/httpd check' } end specinfra-2.89.0/spec/command/openbsd/file_spec.rb0000644000004100000410000000037614575463425022121 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd' describe get_command(:get_file_mtime, '/tmp') do it { should eq 'stat -f %m /tmp' } end describe get_command(:get_file_size, '/tmp') do it { should eq 'stat -f %z /tmp' } end specinfra-2.89.0/spec/command/openbsd/mail_alias_spec.rb0000644000004100000410000000117514575463425023273 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => 'openbsd' } describe get_command(:check_mail_alias_is_aliased_to, 'pink', '|/pony') do it do should eq %Q{egrep ^pink:.*\\(\\[\\[:space:\\]\\]\\|,\\)\\[\\\"\\'\\]\\?} + %Q{\\\\\\|/pony\\[\\\"\\'\\]\\?\\(,\\|\\$\\) } + %Q{/etc/mail/aliases} end end describe get_command(:check_mail_alias_is_aliased_to, 'pink', '|/pony, |/unicorn') do it do should eq %Q{egrep ^pink:.*\\(\\[\\[:space:\\]\\]\\|,\\)\\[\\\"\\'\\]\\?} + %Q{\\\\\\|/pony,\\\\\\ \\\\\\|/unicorn\\[\\\"\\'\\]\\?\\(,\\|\\$\\) } + %Q{/etc/mail/aliases} end end specinfra-2.89.0/spec/command/openbsd/interface_spec.rb0000644000004100000410000000364114575463425023140 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd' describe get_command(:get_interface_speed_of, 'vio0') do it { should eq "ifconfig vio0 | grep 'media\:' | perl -pe 's|.*media\:.*\\((.*?)\\)|\\1|'" } end describe get_command(:check_interface_has_ipv6_address, 'vio0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee') do it { should eq "ifconfig vio0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee '" } end describe get_command(:check_interface_has_ipv6_address, 'vio0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/64') do it { should eq "ifconfig vio0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'vio0', 'fe80::5054:ff:fe01:10ee/64') do it { should eq "ifconfig vio0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%vio0 prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'vio0', 'fe80::5054:ff:fe01:10ee') do it { should eq "ifconfig vio0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%vio0 '" } end describe get_command(:check_interface_has_ipv4_address, 'vio0', '192.168.0.123') do it { should eq "ifconfig vio0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:check_interface_has_ipv4_address, 'vio0', '192.168.0.123/24') do it { should eq "ifconfig vio0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:get_interface_ipv4_address, 'vio0') do it { should eq "ifconfig vio0 inet | grep inet | awk '{print $2}'" } end describe get_command(:get_interface_ipv6_address, 'vio0') do it { should eq "ifconfig vio0 inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" } end describe get_command(:get_interface_link_state, 'vio0') do it do should eq %Q{ifconfig vio0 2>&1 | awk -v s=down -F '[:<>,]' } + %Q{'NR == 1 && $3 == "UP" { s="up" }; /status:/ && $2 != " active" { s="down" }; END{ print s }'} end end specinfra-2.89.0/spec/command/openbsd/host_spec.rb0000644000004100000410000000152714575463425022156 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd' describe get_command(:check_host_is_reachable, 'pink.unicorn.com', nil, 'tcp', 10) do it { should eq "ping -w 10 -c 2 -n pink.unicorn.com"} end describe get_command(:check_host_is_reachable, 'pink.unicorn.com', 53, 'udp', 66) do it { should eq "nc -w 66 -vvvvzu pink.unicorn.com 53" } end describe get_command(:get_host_ipaddress, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '{print $1; exit}'" } end describe get_command(:get_host_ipv4_address, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '$1 ~ /^[0-9.]+$/ {print $1}'" } end describe get_command(:get_host_ipv6_address, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk 'tolower($1) ~ /^[0-9a-f:]+$/ {print $1}'" } end specinfra-2.89.0/spec/command/openbsd/port_spec.rb0000644000004100000410000000100214575463425022151 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'openbsd' describe get_command(:check_port_is_listening, '80') do it { should eq "netstat -nat -f inet | egrep '((tcp|udp).*.80.*LISTEN$)'" } end describe get_command(:check_port_is_listening, '22', :protocol => 'tcp') do it { should eq "netstat -nat -f inet | egrep '(tcp.*.22.*LISTEN$)'" } end describe get_command(:check_port_is_listening, '514', :protocol => 'udp') do it { should eq "netstat -nat -f inet | egrep '(udp.*.514.*$)'" } end specinfra-2.89.0/spec/command/amazon2022/0000755000004100000410000000000014575463425017776 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/amazon2022/service_spec.rb0000644000004100000410000000143314575463425022776 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'amazon', :release => '2022' describe get_command(:enable_service, 'httpd') do it { should eq 'systemctl enable httpd' } end describe get_command(:disable_service, 'httpd') do it { should eq 'systemctl disable httpd' } end describe get_command(:start_service, 'httpd') do it { should eq 'systemctl start httpd' } end describe get_command(:stop_service, 'httpd') do it { should eq 'systemctl stop httpd' } end describe get_command(:restart_service, 'httpd') do it { should eq 'systemctl restart httpd' } end describe get_command(:reload_service, 'httpd') do it { should eq 'systemctl reload httpd' } end describe get_command(:enable_service, 'sshd.socket') do it { should eq 'systemctl enable sshd.socket' } end specinfra-2.89.0/spec/command/amazon2022/package_spec.rb0000644000004100000410000000204714575463425022733 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'amazon', :release => '2022' describe get_command(:check_package_is_installed, 'telnet') do it { should eq 'rpm -q telnet' } end describe get_command(:check_package_is_installed, 'telnet', '0.17-48.el6.x86_64') do it { should eq 'rpm -q telnet | grep -w -- telnet\\-0\\.17\\-48\\.el6\\.x86_64' } end describe get_command(:check_package_is_installed, 'linux-headers-$(uname -r)') do it 'should be escaped (that is, command substitution should not work' do should eq 'rpm -q linux-headers-\\$\\(uname\\ -r\\)' end end describe get_command(:install_package, 'telnet') do it { should eq "dnf -y install telnet" } end describe get_command(:install_package, 'telnet', '0.17-48.el6.x86_64') do it { should eq "dnf -y install telnet-0.17-48.el6.x86_64" } end describe get_command(:install_package, 'linux-headers-$(uname -r)') do it 'should be escaped (that is, command substitution should no work)' do should eq "dnf -y install linux-headers-\\$\\(uname\\ -r\\)" end end specinfra-2.89.0/spec/command/amazon2022/port_spec.rb0000644000004100000410000000031214575463425022315 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'amazon', :release => '2022' describe get_command(:check_port_is_listening, '80') do it { should eq 'ss -tunl | grep -E -- :80\ ' } end specinfra-2.89.0/spec/command/amazon2022/yumrepo_spec.rb0000644000004100000410000000056514575463425023043 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'amazon', :release => '2022' describe get_command(:check_yumrepo_exists, 'epel') do it { should eq "dnf repolist all | grep -qsE \"^[\\!\\*]?epel\(\\s\|$\|\\/)\"" } end describe get_command(:check_yumrepo_is_enabled, 'epel') do it { should eq "dnf repolist enabled | grep -qs \"^[\\!\\*]\\?epel\"" } end specinfra-2.89.0/spec/command/ubuntu/0000755000004100000410000000000014575463425017525 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/ubuntu/ppa_spec.rb0000644000004100000410000000070114575463425021642 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'ubuntu' describe get_command(:check_ppa_exists, 'nginx/stable') do it { should eq %(find /etc/apt/ -name *.list | xargs grep -o -E "deb +[\\\"']?http://ppa.launchpad.net/nginx/stable") } end describe get_command(:check_ppa_is_enabled, 'nginx/stable') do it { should eq %(find /etc/apt/ -name *.list | xargs grep -o -E "^deb +[\\\"']?http://ppa.launchpad.net/nginx/stable") } end specinfra-2.89.0/spec/command/redhat/0000755000004100000410000000000014575463425017452 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/redhat/service_spec.rb0000644000004100000410000000121014575463425022443 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat' describe get_command(:enable_service, 'httpd') do it { should eq 'chkconfig httpd on' } end describe get_command(:disable_service, 'httpd') do it { should eq 'chkconfig httpd off' } end describe get_command(:start_service, 'httpd') do it { should eq 'service httpd start' } end describe get_command(:stop_service, 'httpd') do it { should eq 'service httpd stop' } end describe get_command(:restart_service, 'httpd') do it { should eq 'service httpd restart' } end describe get_command(:reload_service, 'httpd') do it { should eq 'service httpd reload' } end specinfra-2.89.0/spec/command/redhat/package_spec.rb0000644000004100000410000000202714575463425022405 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, { :family => 'redhat' } describe get_command(:check_package_is_installed, 'telnet') do it { should eq 'rpm -q telnet' } end describe get_command(:check_package_is_installed, 'telnet', '0.17-48.el6.x86_64') do it { should eq 'rpm -q telnet | grep -w -- telnet\\-0\\.17\\-48\\.el6\\.x86_64' } end describe get_command(:check_package_is_installed, 'linux-headers-$(uname -r)') do it 'should be escaped (that is, command substitution should not work' do should eq 'rpm -q linux-headers-\\$\\(uname\\ -r\\)' end end describe get_command(:install_package, 'telnet') do it { should eq "yum -y install telnet" } end describe get_command(:install_package, 'telnet', '0.17-48.el6.x86_64') do it { should eq "yum -y install telnet-0.17-48.el6.x86_64" } end describe get_command(:install_package, 'linux-headers-$(uname -r)') do it 'should be escaped (that is, command substitution should no work)' do should eq "yum -y install linux-headers-\\$\\(uname\\ -r\\)" end end specinfra-2.89.0/spec/command/debian9/0000755000004100000410000000000014575463425017516 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/debian9/service_spec.rb0000644000004100000410000000041014575463425022510 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian', :release => '9' describe get_command(:check_service_is_enabled, 'apache') do it { should eq 'systemctl --quiet is-enabled apache||ls /etc/rc[S5].d/S??apache >/dev/null 2>/dev/null' } end specinfra-2.89.0/spec/command/debian9/port_spec.rb0000644000004100000410000000031014575463425022033 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'debian', :release => '9' describe get_command(:check_port_is_listening, '80') do it { should eq 'ss -tunl | grep -E -- :80\ ' } end specinfra-2.89.0/spec/command/guix/0000755000004100000410000000000014575463425017157 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/guix/service_spec.rb0000644000004100000410000000103214575463425022152 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'guix' describe get_command(:enable_service, 'nginx') do it { should eq 'herd enable nginx' } end describe get_command(:disable_service, 'nginx') do it { should eq 'herd disable nginx' } end describe get_command(:start_service, 'nginx') do it { should eq 'herd start nginx' } end describe get_command(:stop_service, 'nginx') do it { should eq 'herd stop nginx' } end describe get_command(:restart_service, 'nginx') do it { should eq 'herd restart nginx' } end specinfra-2.89.0/spec/command/solaris11/0000755000004100000410000000000014575463425020021 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/solaris11/user_spec.rb0000644000004100000410000000065614575463425022345 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'solaris', :release => '11' describe get_command(:get_user_minimum_days_between_password_change, 'foo') do it { should eq "passwd -s foo | sed 's/ \\{1,\\}/%/g' | tr '%' '\n' | sed '4q;d'" } end describe get_command(:get_user_maximum_days_between_password_change, 'foo') do it { should eq "passwd -s foo | sed 's/ \\{1,\\}/%/g' | tr '%' '\n' | sed '5q;d'" } endspecinfra-2.89.0/spec/command/freebsd/0000755000004100000410000000000014575463425017615 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/freebsd/service_spec.rb0000644000004100000410000000610514575463425022616 0ustar www-datawww-datarequire 'spec_helper' describe 'command/freebsd/service works correctly' do before do property[:os] = nil end describe 'check_service_is_enabled' do context 'freebsd-base' do before do set :os, :family => 'freebsd' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service httpd enabled' } end end context 'freebsd-6' do before do set :os, :family => 'freebsd', :release => '6' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service -e | grep -- /httpd$' } end end context 'freebsd-7' do before do set :os, :family => 'freebsd', :release => '7' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service -e | grep -- /httpd$' } end end context 'freebsd-8' do before do set :os, :family => 'freebsd', :release => '8' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service -e | grep -- /httpd$' } end end context 'freebsd-9' do before do set :os, :family => 'freebsd', :release => '9' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service -e | grep -- /httpd$' } end end context 'freebsd-10' do before do set :os, :family => 'freebsd', :release => '10' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service httpd enabled' } end end context 'freebsd-11' do before do set :os, :family => 'freebsd', :release => '11' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service httpd enabled' } end end context 'freebsd-12' do before do set :os, :family => 'freebsd', :release => '12' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service httpd enabled' } end end context 'freebsd-13' do before do set :os, :family => 'freebsd', :release => '13' end describe 'get_command(:check_service_is_enabled, "httpd")' do it { expect(get_command(:check_service_is_enabled, 'httpd')).to eq 'service httpd enabled' } end end end describe 'check_service_is_running' do before do set :os, :family => 'freebsd' end describe 'get_command(:check_service_is_running, "foobar")' do it { expect(get_command(:check_service_is_running, 'foobar')).to eq 'service foobar onestatus' } end end end specinfra-2.89.0/spec/command/freebsd/package_spec.rb0000644000004100000410000001500414575463425022547 0ustar www-datawww-datarequire 'spec_helper' describe 'command/freebsd/package works correctly' do before do property[:os] = nil end context 'freebsd-base' do before do set :os, :family => 'freebsd' end describe 'get_command(:check_package_is_installed, "figlet")' do it { expect(get_command(:check_package_is_installed, 'figlet')).to match /^pkg +info +-e +figlet$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')).to match /^pkg +query +%v +figlet *\| *grep -- 1.2.3$/ } end describe 'get_command(:install_package, "figlet")' do it { expect(get_command(:install_package, 'figlet')).to match /^pkg +install +-y +figlet$/ } end end context 'freebsd-6' do before do set :os, :family => 'freebsd', :release => '6' end describe 'get_command(:check_package_is_installed, "figlet")' do it { expect(get_command(:check_package_is_installed, 'figlet')).to match /^pkg_info +-Ix +figlet$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')).to match /^pkg_info +-I +figlet-1.2.3$/ } end describe 'get_command(:install_package, "figlet")' do it { expect(get_command(:install_package, 'figlet')).to match /^pkg_add +-r +figlet$/ } end end context 'freebsd-7' do before do set :os, :family => 'freebsd', :release => '7' end describe 'get_command(:check_package_is_installed, "figlet")' do it { expect(get_command(:check_package_is_installed, 'figlet')).to match /^pkg_info +-Ix +figlet$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')).to match /^pkg_info +-I +figlet-1.2.3$/ } end describe 'get_command(:install_package, "figlet")' do it { expect(get_command(:install_package, 'figlet')).to match /^pkg_add +-r +figlet$/ } end end context 'freebsd-8' do before do set :os, :family => 'freebsd', :release => '8' end let(:cond) do %r{TMPDIR=/dev/null +ASSUME_ALWAYS_YES=1 +PACKAGESITE=file:///nonexist +pkg +info +-x +'pkg\(-devel\)\?\$' *> */dev/null +2>&1} end describe 'get_command(:check_package_is_installed, "figlet")' do st = /pkg +info +-e +figlet/ sf = /pkg_info +-Ix +\\\^figlet-\\\[0-9\\\]\\\[0-9a-zA-Z_\.,\\\]\\\*\\\$/ it { expect(get_command(:check_package_is_installed, 'figlet')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do st = /pkg +query +%v +figlet *\| *grep -- 1.2.3/ sf = /pkg_info +-I +figlet-1.2.3/ it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:install_package, "figlet")' do st = /pkg +install +-y +figlet/ sf = /pkg_add +-r +figlet/ it { expect(get_command(:install_package, 'figlet')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:get_package_version, "figlet")' do st = /pkg +query +%v +figlet/ sf = /pkg_info +-Ix +\\\^figlet-\\\[0-9\\\]\\\[0-9a-zA-Z_\.,\\\]\\\*\\\$ *\| *cut +-f +1 +-w *\| *sed +-n +'s\/\^figlet-\/\/p'/ it { expect(get_command(:get_package_version, 'figlet')). to match /if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi/ } end end context 'freebsd-9' do before do set :os, :family => 'freebsd', :release => '9' end let(:cond) do %r{TMPDIR=/dev/null +ASSUME_ALWAYS_YES=1 +PACKAGESITE=file:///nonexist +pkg +info +-x +'pkg\(-devel\)\?\$' *> */dev/null +2>&1} end describe 'get_command(:check_package_is_installed, "figlet")' do st = /pkg +info +-e +figlet/ sf = /pkg_info +-Ix +\\\^figlet-\\\[0-9\\\]\\\[0-9a-zA-Z_\.,\\\]\\\*\\\$/ it { expect(get_command(:check_package_is_installed, 'figlet')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do st = /pkg +query +%v +figlet *\| *grep -- 1.2.3/ sf = /pkg_info +-I +figlet-1.2.3/ it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:install_package, "figlet")' do st = /pkg +install +-y +figlet/ sf = /pkg_add +-r +figlet/ it { expect(get_command(:install_package, 'figlet')). to match /^if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi$/ } end describe 'get_command(:get_package_version, "figlet")' do st = /pkg +query +%v +figlet/ sf = /pkg_info +-Ix +\\\^figlet-\\\[0-9\\\]\\\[0-9a-zA-Z_\.,\\\]\\\*\\\$ *\| *cut +-f +1 +-w *\| *sed +-n +'s\/\^figlet-\/\/p'/ it { expect(get_command(:get_package_version, 'figlet')). to match /if +#{cond} *; *then +#{st} *; *else +#{sf} *; *fi/ } end end context 'freebsd-10' do before do set :os, :family => 'freebsd', :release => '10' end describe 'get_command(:check_package_is_installed, "figlet")' do it { expect(get_command(:check_package_is_installed, 'figlet')).to match /^pkg +info +-e +figlet$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')).to match /^pkg +query +%v +figlet *\| *grep -- 1.2.3$/ } end describe 'get_command(:install_package, "figlet")' do it { expect(get_command(:install_package, 'figlet')).to match /^pkg +install +-y +figlet$/ } end end context 'freebsd-11' do before do set :os, :family => 'freebsd', :release => '11' end describe 'get_command(:check_package_is_installed, "figlet")' do it { expect(get_command(:check_package_is_installed, 'figlet')).to match /^pkg +info +-e +figlet$/ } end describe 'get_command(:check_package_is_installed, "figlet", "1.2.3")' do it { expect(get_command(:check_package_is_installed, 'figlet', '1.2.3')).to match /^pkg +query +%v +figlet *\| *grep -- 1.2.3$/ } end describe 'get_command(:install_package, "figlet")' do it { expect(get_command(:install_package, 'figlet')).to match /^pkg +install +-y +figlet$/ } end end end specinfra-2.89.0/spec/command/freebsd/file_spec.rb0000644000004100000410000000051214575463425022071 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'freebsd' describe get_command(:check_file_is_owned_by, '/tmp', 'root') do it { should eq 'stat -f%Su /tmp | grep -- \\^root\\$' } end describe get_command(:check_file_is_grouped, '/tmp', 'wheel') do it { should eq 'stat -f%Sg /tmp | grep -- \\^wheel\\$' } end specinfra-2.89.0/spec/command/freebsd/interface_spec.rb0000644000004100000410000000401714575463425023116 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'freebsd' describe get_command(:check_interface_has_ipv6_address, 'vtnet0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee') do it { should eq "ifconfig vtnet0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee '" } end describe get_command(:check_interface_has_ipv6_address, 'vtnet0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/64') do it { should eq "ifconfig vtnet0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'vtnet0', 'fe80::5054:ff:fe01:10ee/64') do it { should eq "ifconfig vtnet0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%vtnet0 prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'vtnet0', 'fe80::5054:ff:fe01:10ee') do it { should eq "ifconfig vtnet0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%vtnet0 '" } end describe get_command(:check_interface_has_ipv4_address, 'vtnet0', '192.168.0.123') do it { should eq "ifconfig vtnet0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:check_interface_has_ipv4_address, 'vtnet0', '192.168.0.123/24') do it { should eq "ifconfig vtnet0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:get_interface_ipv4_address, 'vtnet0') do it { should eq "ifconfig vtnet0 inet | grep inet | awk '{print $2}'" } end describe get_command(:get_interface_ipv6_address, 'vtnet0') do it { should eq "ifconfig vtnet0 inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" } end describe get_command(:get_interface_link_state, 'vtnet0') do it { should eq %Q{ifconfig -u vtnet0 2>&1 | awk -v s=up '/status:/ && $2 != "active" { s="down" }; END {print s}'} } end describe get_command(:get_interface_speed_of, 'vtnet0') do it { should eq "ifconfig vtnet0 | awk '/media:/{if(match($0,/[0-9]+/)){ print substr($0, RSTART, RLENGTH);}}'" } end describe get_command(:get_interface_mtu_of, 'vtnet0') do it { should eq "ifconfig vtnet0 | awk '/mtu /{print $NF}'" } end specinfra-2.89.0/spec/command/freebsd/host_spec.rb0000644000004100000410000000152714575463425022136 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'freebsd' describe get_command(:check_host_is_reachable, 'pink.unicorn.com', nil, 'tcp', 10) do it { should eq "ping -t 10 -c 2 -n pink.unicorn.com"} end describe get_command(:check_host_is_reachable, 'pink.unicorn.com', 53, 'udp', 66) do it { should eq "nc -vvvvzu pink.unicorn.com 53 -w 66" } end describe get_command(:get_host_ipaddress, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '{print $1; exit}'" } end describe get_command(:get_host_ipv4_address, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '$1 ~ /^[0-9.]+$/ {print $1}'" } end describe get_command(:get_host_ipv6_address, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk 'tolower($1) ~ /^[0-9a-f:]+$/ {print $1}'" } end specinfra-2.89.0/spec/command/alpine/0000755000004100000410000000000014575463425017453 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/alpine/service_spec.rb0000644000004100000410000000106114575463425022450 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'alpine' describe get_command(:enable_service, 'nginx') do it { should eq 'rc-update add nginx' } end describe get_command(:disable_service, 'nginx') do it { should eq 'rc-update del nginx' } end describe get_command(:start_service, 'nginx') do it { should eq 'rc-service nginx start' } end describe get_command(:stop_service, 'nginx') do it { should eq 'rc-service nginx stop' } end describe get_command(:restart_service, 'nginx') do it { should eq 'rc-service nginx restart' } end specinfra-2.89.0/spec/command/darwin/0000755000004100000410000000000014575463425017467 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/darwin/file_spec.rb0000644000004100000410000000077314575463425021754 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'darwin' describe get_command(:get_file_sha256sum, '/etc/services') do it { should eq 'ruby -e "require \'digest\'; puts Digest::SHA256.hexdigest File.read \'/etc/services\'"' } end describe get_command(:check_file_is_owned_by, '/tmp', 'root') do it { should eq 'stat -f %Su /tmp | grep -- \\^root\\$' } end describe get_command(:check_file_is_grouped, '/tmp', 'wheel') do it { should eq 'stat -f %Sg /tmp | grep -- \\^wheel\\$' } end specinfra-2.89.0/spec/command/darwin/interface_spec.rb0000644000004100000410000000340214575463425022765 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'darwin' describe get_command(:check_interface_exists, 'en0') do it { should eq "ifconfig en0" } end describe get_command(:check_interface_has_ipv6_address, 'en0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee') do it { should eq "ifconfig en0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee '" } end describe get_command(:check_interface_has_ipv6_address, 'en0', '2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/64') do it { should eq "ifconfig en0 inet6 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'en0', 'fe80::5054:ff:fe01:10ee/64') do it { should eq "ifconfig en0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%en0 prefixlen 64'" } end describe get_command(:check_interface_has_ipv6_address, 'en0', 'fe80::5054:ff:fe01:10ee') do it { should eq "ifconfig en0 inet6 | grep 'inet6 fe80::5054:ff:fe01:10ee%en0 '" } end describe get_command(:check_interface_has_ipv4_address, 'en0', '192.168.0.123') do it { should eq "ifconfig en0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:check_interface_has_ipv4_address, 'en0', '192.168.0.123/24') do it { should eq "ifconfig en0 inet | grep 'inet 192\\.168\\.0\\.123 '" } end describe get_command(:get_interface_ipv4_address, 'en0') do it { should eq "ifconfig en0 inet | grep inet | awk '{print $2}'" } end describe get_command(:get_interface_ipv6_address, 'en0') do it { should eq "ifconfig en0 inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit" } end describe get_command(:get_interface_link_state, 'en0') do it { should eq %Q{ifconfig -u en0 2>&1 | awk -v s=up '/status:/ && $2 != "active" { s="down" }; END {print s}'} } end specinfra-2.89.0/spec/command/darwin/host_spec.rb0000644000004100000410000000274614575463425022014 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'darwin' describe get_command(:check_host_is_resolvable, 'pink.unicorn.com', 'dns') do it { should eq "dig +search +short +time=1 -q pink.unicorn.com a pink.unicorn.com aaaa | grep -qie '^[0-9a-f:.]*$'" } end describe get_command(:check_host_is_resolvable, 'pink.unicorn.com', 'hosts') do it { should eq "sed 's/#.*$//' /etc/hosts | grep -w -- pink.unicorn.com" } end describe get_command(:check_host_is_resolvable, 'pink.unicorn.com', nil) do it { should eq "dscacheutil -q host -a name pink.unicorn.com | grep -q '_address:'" } end describe get_command(:check_host_is_reachable, 'pink.unicorn.com', nil, 'tcp', 10) do it { should eq "ping -t 10 -c 2 -n pink.unicorn.com"} end describe get_command(:check_host_is_reachable, 'pink.unicorn.com', 53, 'udp', 66) do it { should eq "nc -vvvvzu pink.unicorn.com 53 -w 66 -G 66" } end describe get_command(:get_host_ipaddress, 'pink.unicorn.com') do it do should eq "dscacheutil -q host -a name pink.unicorn.com | " + "awk '/^ipv6_/{ ip = $2 }; /^$/{ exit }; /^ip_/{ ip = $2; exit}; END{ print ip }'" end end describe get_command(:get_host_ipv4_address, 'pink.unicorn.com') do it { should eq "dscacheutil -q host -a name pink.unicorn.com | awk '/^ip_/{ print $2; exit }'" } end describe get_command(:get_host_ipv6_address, 'pink.unicorn.com') do it { should eq "dscacheutil -q host -a name pink.unicorn.com | awk '/^ipv6_/{ ip = $2 } END{ print ip }'" } end specinfra-2.89.0/spec/command/darwin/port_spec.rb0000644000004100000410000000051314575463425022011 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'darwin' describe get_command(:check_port_is_listening, '80') do it { should eq 'lsof -nP -iTCP -sTCP:LISTEN | grep -- :80\ ' } end describe get_command(:check_port_is_listening, '80', :protocol => 'udp') do it { should eq 'lsof -nP -iUDP | grep -- :80\ ' } end specinfra-2.89.0/spec/command/darwin/user_spec.rb0000644000004100000410000000267714575463425022020 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => 'darwin' } describe get_command(:check_user_has_home_directory, 'foo', '/Users/foo') do it { should eq "finger foo | grep -E '^Directory' | awk '{ print $2 }' | grep -E '^/Users/foo$'" } end describe get_command(:check_user_has_login_shell, 'foo', '/bin/bash') do it { should eq "finger foo | grep -E '^Directory' | awk '{ print $4 }' | grep -E '^/bin/bash$'" } end describe get_command(:get_user_home_directory, 'foo') do it { should eq "finger foo | grep -E '^Directory' | awk '{ print $2 }'" } end describe get_command(:update_user_home_directory, 'user', 'dir') do it { should eq "dscl . -create /Users/user NFSHomeDirectory dir" } end describe get_command(:update_user_login_shell, 'user', '/bin/bash') do it { should eq "dscl . -create /Users/user UserShell /bin/bash" } end describe get_command(:update_user_encrypted_password, 'user', 'pass') do it { should eq "dscl . passwd /Users/user pass" } end describe get_command(:update_user_gid, 'user', '100') do it { should eq "dscl . -create /Users/user PrimaryGroupID 100" } end describe get_command(:add_user, 'foo', :home_directory => '/Users/foo', :password => '$6$foo/bar', :shell => '/bin/zsh', :create_home => true) do it { should eq 'dscl . -create /Users/foo && dscl . -create /Users/foo UserShell /bin/zsh && dscl . -create /Users/foo NFSHomeDirectory /Users/foo && dscl . passwd /Users/foo \$6\$foo/bar && createhomedir -b -u foo' } end specinfra-2.89.0/spec/command/darwin/process_spec.rb0000644000004100000410000000036714575463425022512 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => 'darwin' } describe get_command(:get_process, 'Google Chrome', :format => 'pid=') do it { should eq "ps -A -c -o pid=,command | grep -E -m 1 ^\\ *[0-9]+\\ +Google\\ Chrome$ | awk '{print $1}'" } end specinfra-2.89.0/spec/command/darwin/group_spec.rb0000644000004100000410000000104114575463425022156 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => 'darwin' } describe get_command(:get_group_gid, 'foo') do it { should eq "dscl . -read /Groups/foo PrimaryGroupID | awk '{ print $2 }'" } end describe get_command(:update_group_gid, 'foo', 1234) do it { should eq "dscl . -create /Groups/foo PrimaryGroupID 1234" } end describe get_command(:add_group, 'foo', :gid => 1234, :groupname => 'bar') do it { should eq 'dscl . -create /Groups/foo && dscl . -create /Groups/foo PrimaryGroupID 1234 && dscl . -create /Groups/foo RecordName bar' } end specinfra-2.89.0/spec/command/module/0000755000004100000410000000000014575463425017470 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/module/zfs_spec.rb0000644000004100000410000000053414575463425021633 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Solaris::Base::Zfs do let(:klass) { Specinfra::Command::Solaris::Base::Zfs } it { expect(klass.check_exists('rpool')).to eq "zfs list -H rpool" } it { expect(klass.check_has_property('rpool', {'mountpoint' => '/rpool' })).to eq "zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end specinfra-2.89.0/spec/command/module/service/0000755000004100000410000000000014575463425021130 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/module/service/daemontools_spec.rb0000644000004100000410000000320214575463425025010 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Module::Service::Daemontools do class Specinfra::Command::Module::Service::Daemontools::Test < Specinfra::Command::Base extend Specinfra::Command::Module::Service::Daemontools end let(:klass) { Specinfra::Command::Module::Service::Daemontools::Test } it { expect(klass.check_is_enabled_under_daemontools('httpd')).to eq "test -L $([ -d /service ] && echo /service || echo /etc/service)/httpd && test -f $([ -d /service ] && echo /service || echo /etc/service)/httpd/run" } it { expect(klass.check_is_running_under_daemontools('httpd')).to eq "svstat $([ -d /service ] && echo /service || echo /etc/service)/httpd | grep -E 'up \\(pid [0-9]+\\)'" } it { expect(klass.enable_under_daemontools('httpd', '/tmp/service/httpd')).to eq 'ln -snf /tmp/service/httpd $([ -d /service ] && echo /service || echo /etc/service)/httpd' } it { expect(klass.disable_under_daemontools('httpd')).to eq '( cd $([ -d /service ] && echo /service || echo /etc/service)/httpd && rm -f $([ -d /service ] && echo /service || echo /etc/service)/httpd && svc -dx . log )' } it { expect(klass.start_under_daemontools('httpd')).to eq 'svc -u $([ -d /service ] && echo /service || echo /etc/service)/httpd' } it { expect(klass.stop_under_daemontools('httpd')).to eq 'svc -d $([ -d /service ] && echo /service || echo /etc/service)/httpd' } it { expect(klass.restart_under_daemontools('httpd')).to eq 'svc -t $([ -d /service ] && echo /service || echo /etc/service)/httpd' } it { expect(klass.reload_under_daemontools('httpd')).to eq 'svc -h $([ -d /service ] && echo /service || echo /etc/service)/httpd' } end specinfra-2.89.0/spec/command/module/service/systemd_spec.rb0000644000004100000410000000176514575463425024170 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Module::Service::Systemd do class Specinfra::Command::Module::Service::Systemd::Test < Specinfra::Command::Base extend Specinfra::Command::Module::Service::Systemd end let(:klass) { Specinfra::Command::Module::Service::Systemd::Test } it { expect(klass.check_is_enabled_under_systemd('httpd')).to eq "systemctl --quiet is-enabled httpd" } it { expect(klass.check_is_running_under_systemd('httpd')).to eq 'systemctl is-active httpd' } it { expect(klass.enable_under_systemd('httpd')).to eq 'systemctl enable httpd' } it { expect(klass.disable_under_systemd('httpd')).to eq 'systemctl disable httpd' } it { expect(klass.start_under_systemd('httpd')).to eq 'systemctl start httpd' } it { expect(klass.stop_under_systemd('httpd')).to eq 'systemctl stop httpd' } it { expect(klass.restart_under_systemd('httpd')).to eq 'systemctl restart httpd' } it { expect(klass.reload_under_systemd('httpd')).to eq 'systemctl reload httpd' } end specinfra-2.89.0/spec/command/module/service/init_spec.rb0000644000004100000410000000167614575463425023444 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Module::Service::Init do class Specinfra::Command::Module::Service::Init::Test < Specinfra::Command::Base extend Specinfra::Command::Module::Service::Init end let(:klass) { Specinfra::Command::Module::Service::Init::Test } it { expect(klass.check_is_enabled_under_init('httpd')).to eq "chkconfig --list httpd | grep 3:on" } it { expect(klass.check_is_running_under_init('httpd')).to eq 'service httpd status' } it { expect(klass.enable_under_init('httpd')).to eq 'chkconfig httpd on' } it { expect(klass.disable_under_init('httpd')).to eq 'chkconfig httpd off' } it { expect(klass.start_under_init('httpd')).to eq 'service httpd start' } it { expect(klass.stop_under_init('httpd')).to eq 'service httpd stop' } it { expect(klass.restart_under_init('httpd')).to eq 'service httpd restart' } it { expect(klass.reload_under_init('httpd')).to eq 'service httpd reload' } end specinfra-2.89.0/spec/command/module/systemd_spec.rb0000644000004100000410000000124314575463425022517 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Redhat::V7::Service do let(:klass) { Specinfra::Command::Redhat::V7::Service } it { expect(klass.check_is_enabled('httpd')).to eq "systemctl --quiet is-enabled httpd" } it { expect(klass.check_is_enabled('httpd', 'multi-user.target')).to eq "systemctl --quiet is-enabled httpd" } it { expect(klass.check_is_enabled('httpd.service')).to eq "systemctl --quiet is-enabled httpd.service" } it { expect(klass.check_is_enabled('sshd.socket')).to eq "systemctl --quiet is-enabled sshd.socket" } it { expect(klass.check_is_enabled('logrotate.timer')).to eq "systemctl --quiet is-enabled logrotate.timer" } end specinfra-2.89.0/spec/command/module/ss_spec.rb0000644000004100000410000000505414575463425021460 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Command::Module::Ss do class Specinfra::Command::Module::Ss::Test < Specinfra::Command::Base extend Specinfra::Command::Module::Ss end let(:klass) { Specinfra::Command::Module::Ss::Test } it { expect(klass.check_is_listening('80')).to eq 'ss -tunl | grep -E -- :80\ ' } it { expect(klass.check_is_listening('80', options={:protocol => 'tcp'})).to eq 'ss -tnl4 | grep -E -- :80\ ' } it { expect(klass.check_is_listening('80', options={:protocol => 'tcp6'})).to eq 'ss -tnl6 | grep -E -- :80\ ' } it { expect(klass.check_is_listening('80', options={:protocol => 'udp'})).to eq 'ss -unl4 | grep -E -- :80\ ' } it { expect(klass.check_is_listening('80', options={:protocol => 'udp6'})).to eq 'ss -unl6 | grep -E -- :80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '0.0.0.0'})).to eq 'ss -tunl | grep -E -- \ \\\\\*:80\ \\|\\ 0\\\\.0\\\\.0\\\\.0:80\\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '0.0.0.0', :protocol => 'tcp'})).to eq 'ss -tnl4 | grep -E -- \ \\\\\*:80\ \\|\\ 0\\\\.0\\\\.0\\\\.0:80\\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '::', :protocol => 'tcp6'})).to eq 'ss -tnl6 | grep -E -- \ \\\\\\[::\\\\\\]:80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '0.0.0.0', :protocol => 'udp'})).to eq 'ss -unl4 | grep -E -- \ \\\\\*:80\ \\|\\ 0\\\\.0\\\\.0\\\\.0:80\\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '::', :protocol => 'udp6'})).to eq 'ss -unl6 | grep -E -- \ \\\\\\[::\\\\\\]:80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '1.2.3.4'})).to eq 'ss -tunl | grep -E -- \ 1.2.3.4:80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '1.2.3.4', :protocol => 'tcp'})).to eq 'ss -tnl4 | grep -E -- \\ 1.2.3.4:80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '2001:db8:dead:beef::1', :protocol => 'tcp6'})).to eq 'ss -tnl6 | grep -E -- \ \\\\\\[2001:db8:dead:beef::1\\\\\\]:80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '1.2.3.4', :protocol => 'udp'})).to eq 'ss -unl4 | grep -E -- \ 1.2.3.4:80\ ' } it { expect(klass.check_is_listening('80', options={:local_address => '2001:db8:dead:beef::1', :protocol => 'udp6'})).to eq 'ss -unl6 | grep -E -- \ \\\\\\[2001:db8:dead:beef::1\\\\\\]:80\ ' } it { expect{klass.check_is_listening('80', options={:protocol => 'bad_proto'})}.to raise_error(ArgumentError, 'Unknown protocol [bad_proto]') } end specinfra-2.89.0/spec/command/sles15/0000755000004100000410000000000014575463425017317 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/sles15/service_spec.rb0000644000004100000410000000032114575463425022312 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'sles', :release => '15' describe get_command(:check_service_is_enabled, 'httpd') do it { should eq 'systemctl --quiet is-enabled httpd' } end specinfra-2.89.0/spec/command/redhat7/0000755000004100000410000000000014575463425017541 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/redhat7/service_spec.rb0000644000004100000410000000143014575463425022536 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat', :release => '7' describe get_command(:enable_service, 'httpd') do it { should eq 'systemctl enable httpd' } end describe get_command(:disable_service, 'httpd') do it { should eq 'systemctl disable httpd' } end describe get_command(:start_service, 'httpd') do it { should eq 'systemctl start httpd' } end describe get_command(:stop_service, 'httpd') do it { should eq 'systemctl stop httpd' } end describe get_command(:restart_service, 'httpd') do it { should eq 'systemctl restart httpd' } end describe get_command(:reload_service, 'httpd') do it { should eq 'systemctl reload httpd' } end describe get_command(:enable_service, 'sshd.socket') do it { should eq 'systemctl enable sshd.socket' } end specinfra-2.89.0/spec/command/redhat7/interface_spec.rb0000644000004100000410000000036714575463425023046 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, { :family => 'redhat', :release => 7 } describe Specinfra.command.send(:create_command_class, 'interface') do it { should be_an_instance_of(Specinfra::Command::Linux::Base::Interface) } end specinfra-2.89.0/spec/command/redhat7/host_spec.rb0000644000004100000410000000155314575463425022061 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat', :release => '7' describe get_command(:check_host_is_reachable, 'example.jp', '53', 'udp', 2) do it { should eq "ncat -vvvvu example.jp 53 -w 2 -i 2 2>&1 | grep -q SUCCESS" } end describe get_command(:check_host_is_reachable, 'example.jp', '80', 'tcp', 3) do it { should eq "ncat -vvvvt example.jp 80 -w 3 -i 3 2>&1 | grep -q SUCCESS" } end describe get_command(:get_host_ipaddress, 'pink.unicorn.com') do it { should eq "getent hosts pink.unicorn.com | awk '{print $1}'" } end describe get_command(:get_host_ipv4_address, 'pink.unicorn.com') do it { should eq "getent ahostsv4 pink.unicorn.com | awk '{print $1; exit}'" } end describe get_command(:get_host_ipv6_address, 'pink.unicorn.com') do it { should eq "getent ahostsv6 pink.unicorn.com | awk '{print $1; exit}'" } end specinfra-2.89.0/spec/command/redhat7/port_spec.rb0000644000004100000410000000030714575463425022064 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'redhat', :release => '7' describe get_command(:check_port_is_listening, '80') do it { should eq 'ss -tunl | grep -E -- :80\ ' } end specinfra-2.89.0/spec/command/sles11/0000755000004100000410000000000014575463425017313 5ustar www-datawww-dataspecinfra-2.89.0/spec/command/sles11/user_spec.rb0000644000004100000410000000065614575463425021637 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'sles', :release => '11' describe get_command(:get_user_minimum_days_between_password_change, 'foo') do it { should eq "chage -l foo | sed -n 's/^Minimum://p' | sed 's|^[[:blank:]]*||g'" } end describe get_command(:get_user_maximum_days_between_password_change, 'foo') do it { should eq "chage -l foo | sed -n 's/^Maximum://p' | sed 's|^[[:blank:]]*||g'" } end specinfra-2.89.0/spec/backend/0000755000004100000410000000000014575463425016154 5ustar www-datawww-dataspecinfra-2.89.0/spec/backend/exec/0000755000004100000410000000000014575463425017100 5ustar www-datawww-dataspecinfra-2.89.0/spec/backend/exec/env_spec.rb0000644000004100000410000000063714575463425021235 0ustar www-datawww-datarequire 'spec_helper' set :backend, :exec describe Specinfra.backend.run_command('echo $LANG').stdout.strip do it { should eq 'C' } end describe do before do set :backend, :exec ENV['LANG'] = 'C' set :env, :LANG => 'ja_JP.UTF-8' end let(:lang) { Specinfra.backend.run_command('echo $LANG').stdout.strip } it { expect(lang).to eq 'ja_JP.UTF-8' } it { expect(ENV['LANG']).to eq 'C' } end specinfra-2.89.0/spec/backend/exec/consume_exited_process_spec.rb0000644000004100000410000000264314575463425025215 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'exec backend' do before :all do set :backend, :exec end context 'when executed process had exited before read stdout and stderr,' do let(:backend) { Specinfra::Backend::Exec.new } it 'can consume stdout and stderr from buffer' do allow(IO).to receive(:select).and_wrap_original { |m, *args| sleep 1; m.call(*args) } result = backend.run_command("ruby -e 'STDOUT.puts \"stdout\"; STDERR.puts \"stderr\"'") expect(result.stdout.chomp).to eq('stdout') expect(result.stderr.chomp).to eq('stderr') end end context 'when executed process has exited between reading stdout and stderr,' do let(:backend) { Specinfra::Backend::Exec.new } it 'can consume stdout and stderr from buffer' do backend.stdout_handler = proc { |o| sleep 1 } result = backend.run_command("ruby -e 'STDOUT.puts \"stdout\"; STDOUT.close; STDERR.puts \"stderr\"'") expect(result.stdout.chomp).to eq('stdout') expect(result.stderr.chomp).to eq('stderr') end end context 'Output of stderr_handler' do let(:backend) { Specinfra::Backend::Exec.new } subject(:stderr) do allow(IO).to receive(:select).and_wrap_original { |m, *args| sleep 1; m.call(*args) } err = '' backend.stderr_handler = proc { |e| err += e } backend.run_command('echo foo 1>&2') err end it { expect(stderr).to eq "foo\n" } end end specinfra-2.89.0/spec/backend/exec/read_noblock_spec.rb0000644000004100000410000000247214575463425023066 0ustar www-datawww-datarequire 'spec_helper' def command(cmd) Specinfra::Runner.run_command(cmd) end shared_examples "IO checks" do let (:generator) { "seq 1 #{max}" } let (:expected) { (1..max).map { |x| x.to_s }.join("\n") << "\n" } it "stdout only" do out = command(generator).stdout expect(out).to eq expected end it "stderr only" do out = command("#{generator} >&2" ).stderr expect(out).to eq expected end it "stdout then stderr" do cmd = command("#{generator}; #{generator} >&2" ) expect(cmd.stdout).to eq expected expect(cmd.stderr).to eq expected end it "stderr then stdout" do cmd = command("#{generator} >&2; #{generator}" ) expect(cmd.stdout).to eq expected expect(cmd.stderr).to eq expected end it "stdout and stderr" do cmd = command("(#{generator} &); #{generator} >&2; sleep 2" ) expect(cmd.stdout).to eq expected expect(cmd.stderr).to eq expected end end describe "buffer overflow problem" do before :all do set :backend, :exec end context "with small output amount" do let (:max) { 10 } include_examples "IO checks" end context "with huge output amount" do let (:max) { 999999 } include_examples "IO checks" end end specinfra-2.89.0/spec/backend/exec/child_process_spec.rb0000644000004100000410000000127714575463425023267 0ustar www-datawww-data# Ref: https://github.com/sorah/infra_operator/blob/6259aada3fdd9d4bed5759115d39bd1df25a81f2/spec/backends/exec_spec.rb#L36 require 'spec_helper' context "when executed process launches child process like a daemon, and the daemon doesn't close stdout,err" do before :all do set :backend, :exec end subject(:result) { Specinfra::Runner.run_command("ruby -e 'pid = fork { sleep 10; puts :bye }; Process.detach(pid); puts pid'") } it "doesn't block" do a = Time.now result # exec b = Time.now expect((b-a) < 3).to be_truthy expect(result.stderr).to be_empty expect(result.stdout.chomp).to match(/\A\d+\z/) Process.kill :TERM, result.stdout.chomp.to_i end end specinfra-2.89.0/spec/backend/exec/stdxxx_handler_spec.rb0000644000004100000410000000077514575463425023507 0ustar www-datawww-datarequire 'spec_helper' backend = Specinfra::Backend::Exec.new context 'Output of stdout_handler' do subject(:stdout) do out = '' backend.stdout_handler = Proc.new {|o| out += o } backend.run_command('echo foo') out end it { expect(stdout).to eq "foo\n" } end context 'Output of stderr_handler' do subject(:stderr) do err = '' backend.stderr_handler = Proc.new {|e| err += e } backend.run_command('echo foo 1>&2') err end it { expect(stderr).to eq "foo\n" } end specinfra-2.89.0/spec/backend/exec/build_command_spec.rb0000644000004100000410000001473614575463425023247 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Backend::Exec do before :all do set :backend, :exec end describe '#build_command' do context 'with simple command' do it 'should escape spaces' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd' end end context 'with complex command' do it 'should escape special chars' do expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq '/bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)' end it 'should escape quotes' do if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.7') expect(Specinfra.backend.build_command(%Q{find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"})).to eq('/bin/sh -c find\ /etc/apt/\ -name\ \*.list\ \|\ xargs\ grep\ -o\ -E\ \"\^deb\ \+\[\\\\\"\\\'\]\?http://ppa.launchpad.net/gluster/glusterfs-3.7\"') else # Since Ruby 2.7, `+` is not escaped. expect(Specinfra.backend.build_command(%Q{find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"})).to eq('/bin/sh -c find\ /etc/apt/\ -name\ \*.list\ \|\ xargs\ grep\ -o\ -E\ \"\^deb\ +\[\\\\\"\\\'\]\?http://ppa.launchpad.net/gluster/glusterfs-3.7\"') end end end context 'with custom shell' do before do RSpec.configure {|c| c.shell = '/usr/local/bin/tcsh' } end after do RSpec.configure {|c| c.shell = nil } end it 'should use custom shell' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/usr/local/bin/tcsh -c test\ -f\ /etc/passwd' end end context 'with custom shell that needs escaping' do before do RSpec.configure {|c| c.shell = '/usr/test & spec/bin/sh' } end after do RSpec.configure {|c| c.shell = nil } end it 'should use custom shell' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/usr/test\ \&\ spec/bin/sh -c test\ -f\ /etc/passwd' end end context 'with an interactive shell' do before do RSpec.configure {|c| c.interactive_shell = true } end after do RSpec.configure {|c| c.interactive_shell = nil } end it 'should emulate an interactive shell' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -i -c test\ -f\ /etc/passwd' end end context 'with an login shell' do before do RSpec.configure {|c| c.login_shell = true } end after do RSpec.configure {|c| c.login_shell = nil } end it 'should emulate an login shell' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -l -c test\ -f\ /etc/passwd' end end context 'with custom path' do before do RSpec.configure {|c| c.path = '/opt/bin:/opt/foo/bin:$PATH' } end after do RSpec.configure {|c| c.path = nil } end it 'should use custom path' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq 'env PATH="/opt/bin:/opt/foo/bin:$PATH" /bin/sh -c test\ -f\ /etc/passwd' end end context 'with custom path that needs escaping' do before do RSpec.configure {|c| c.path = '/opt/bin:/opt/test & spec/bin:$PATH' } end after do RSpec.configure {|c| c.path = nil } end it 'should use custom path' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq 'env PATH="/opt/bin:/opt/test & spec/bin:$PATH" /bin/sh -c test\ -f\ /etc/passwd' end end end end describe 'os' do before do # clear os information cache property[:os] = nil Specinfra.configuration.instance_variable_set(:@os, nil) Specinfra.backend.instance_variable_set(:@os_info, nil) end context 'test ubuntu with lsb_release command' do before do allow(Specinfra.backend).to receive(:run_command) do |args| if ['cat /etc/debian_version', 'lsb_release -ir'].include? args double( :run_command_response, :success? => true, :stdout => "Distributor ID:\tUbuntu\nRelease:\t12.04\n" ) elsif args == 'uname -m' double :run_command_response, :success? => true, :stdout => "x86_64\n" else double :run_command_response, :success? => false, :stdout => nil end end end subject! { os } it do expect(Specinfra.backend).to have_received(:run_command).at_least(1).times should eq({:family => 'ubuntu', :release => '12.04', :arch => 'x86_64' }) end end context 'test ubuntu with /etc/lsb-release' do before do allow(Specinfra.backend).to receive(:run_command) do |args| if ['cat /etc/debian_version', 'cat /etc/lsb-release'].include? args double( :run_command_response, :success? => true, :stdout => <<-EOF DISTRIB_ID=Ubuntu DISTRIB_RELEASE=12.04 DISTRIB_CODENAME=precise DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS" EOF ) elsif args == 'uname -m' double :run_command_response, :success? => true, :stdout => "x86_64\n" else double :run_command_response, :success? => false, :stdout => nil end end end subject! { os } it do expect(Specinfra.backend).to have_received(:run_command).at_least(1).times should eq({:family => 'ubuntu', :release => '12.04', :arch => 'x86_64' }) end end context 'test debian (no lsb_release or lsb-release)' do before do allow(Specinfra.backend).to receive(:run_command) do |args| if args == 'cat /etc/debian_version' double :run_command_response, :success? => true, :stdout => "8.5\n" elsif args == 'uname -m' double :run_command_response, :success? => true, :stdout => "x86_64\n" else double :run_command_response, :success? => false, :stdout => nil end end end subject! { os } it do expect(Specinfra.backend).to have_received(:run_command).at_least(1).times should eq({:family => 'debian', :release => '8.5', :arch => 'x86_64' }) end end end specinfra-2.89.0/spec/backend/dockercli/0000755000004100000410000000000014575463425020113 5ustar www-datawww-dataspecinfra-2.89.0/spec/backend/dockercli/build_command_spec.rb0000644000004100000410000001025614575463425024253 0ustar www-datawww-data# frozen_string_literal: true require 'spec_helper' require 'shellwords' describe Specinfra::Backend::Dockercli do let(:interactive_shell) { false } let(:login_shell) { false } let(:request_pty) { false } let(:shell) { '/bin/sh' } let(:docker_container) { 'instance' } let(:path) { nil } let(:docker_exec) do cmd = %w[docker exec] cmd << '--interactive' if interactive_shell cmd << '--tty' if request_pty cmd << docker_container cmd << "env PATH=\"#{path}\"" if path cmd << shell.shellescape cmd << '-i' if interactive_shell cmd << '-l' if login_shell cmd << '-c' cmd.join(' ') end before(:each) do set :backend, :dockercli RSpec.configure do |c| c.request_pty = request_pty c.interactive_shell = interactive_shell c.docker_container = docker_container c.path = path end end after(:each) do Specinfra::Backend::Dockercli.clear end describe '#build_command' do context 'without required docker_container set' do let(:docker_container) { nil } it { expect { subject.build_command('true') }.to raise_error(RuntimeError, /docker_container/) } end context 'with simple command' do it 'should escape spaces' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd" end end context 'with complex command' do it 'should escape special chars' do expect(subject.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')) .to eq "#{docker_exec} test\\ \\!\\ -f\\ /etc/selinux/config\\ \\|\\|\\ \\(getenforce\\ \\|\\ grep\\ -i\\ --\\ disabled\\ \\&\\&\\ grep\\ -i\\ --\\ \\^SELINUX\\=disabled\\$\\ /etc/selinux/config\\)" end it 'should escape quotes' do if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.7') expect(subject.build_command(%Q(find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"))).to eq("#{docker_exec} find\\ /etc/apt/\\ -name\\ \\*.list\\ \\|\\ xargs\\ grep\\ -o\\ -E\\ \\\"\\^deb\\ \\+\\[\\\\\\\"\\'\\]\\?http://ppa.launchpad.net/gluster/glusterfs-3.7\\\"") else # Since Ruby 2.7, `+` is not escaped. expect(subject.build_command(%Q(find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"))).to eq("#{docker_exec} find\\ /etc/apt/\\ -name\\ \\*.list\\ \\|\\ xargs\\ grep\\ -o\\ -E\\ \\\"\\^deb\\ +\\[\\\\\\\"\\'\\]\\?http://ppa.launchpad.net/gluster/glusterfs-3.7\\\"") end end end context 'with custom shell' do let(:shell) { '/usr/local/bin/tcsh' } it 'should use custom shell' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd" end end context 'with custom shell that needs escaping' do let(:shell) { '/usr/test & spec/bin/sh' } it 'should use custom shell' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd" end end context 'with an interactive shell' do let(:interactive_shell) { true } it 'should emulate an interactive shell' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd" end end context 'with an login shell' do let(:login_shell) { true } it 'should emulate an login shell' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd" end end context 'with custom path' do let(:path) { '/opt/bin:/opt/foo/bin:$PATH' } it 'should use custom path' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd" end end context 'with custom path that needs escaping' do let(:path) { '/opt/bin:/opt/test & spec/bin:$PATH' } it 'should use custom path' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd" end end end end specinfra-2.89.0/spec/backend/lxd/0000755000004100000410000000000014575463425016743 5ustar www-datawww-dataspecinfra-2.89.0/spec/backend/lxd/build_command_spec.rb0000644000004100000410000001117614575463425023105 0ustar www-datawww-data# frozen_string_literal: true require 'spec_helper' describe Specinfra::Backend::Lxd do let(:lxd_instance) { 'instance' } let(:lxd_remote) { 'remote' } let(:lxc_exec) { "lxc exec #{lxd_remote}:#{lxd_instance}" } before(:each) do set :backend, :lxd RSpec.configure do |c| c.lxd_instance = lxd_instance c.lxd_remote = lxd_remote end end after(:each) do Specinfra::Backend::Lxd.clear end describe '#build_command' do context 'without required lxd_instance set' do let(:lxd_instance) { nil } it { expect { subject.build_command('true') }.to raise_error(RuntimeError, /lxd_instance/) } end context 'without required lxd_remote set' do let(:lxd_remote) { nil } it { expect { subject.build_command('true') }.to raise_error(RuntimeError, /lxd_remote/) } end context 'with simple command' do it 'should escape spaces' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- /bin/sh -c test\\ -f\\ /etc/passwd" end end context 'with complex command' do it 'should escape special chars' do expect(subject.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')) .to eq "lxc exec #{lxd_remote}:#{lxd_instance} -- /bin/sh -c test\\ \\!\\ -f\\ /etc/selinux/config\\ \\|\\|\\ \\(getenforce\\ \\|\\ grep\\ -i\\ --\\ disabled\\ \\&\\&\\ grep\\ -i\\ --\\ \\^SELINUX\\=disabled\\$\\ /etc/selinux/config\\)" end it 'should escape quotes' do if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.7') expect(subject.build_command(%Q(find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"))).to eq("#{lxc_exec} -- /bin/sh -c find\\ /etc/apt/\\ -name\\ \\*.list\\ \\|\\ xargs\\ grep\\ -o\\ -E\\ \\\"\\^deb\\ \\+\\[\\\\\\\"\\'\\]\\?http://ppa.launchpad.net/gluster/glusterfs-3.7\\\"") else # Since Ruby 2.7, `+` is not escaped. expect(subject.build_command(%Q(find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"))).to eq("#{lxc_exec} -- /bin/sh -c find\\ /etc/apt/\\ -name\\ \\*.list\\ \\|\\ xargs\\ grep\\ -o\\ -E\\ \\\"\\^deb\\ +\\[\\\\\\\"\\'\\]\\?http://ppa.launchpad.net/gluster/glusterfs-3.7\\\"") end end end context 'with custom shell' do before { RSpec.configure { |c| c.shell = '/usr/local/bin/tcsh' } } after { RSpec.configure { |c| c.shell = nil } } it 'should use custom shell' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- /usr/local/bin/tcsh -c test\\ -f\\ /etc/passwd" end end context 'with custom shell that needs escaping' do before { RSpec.configure { |c| c.shell = '/usr/test & spec/bin/sh' } } after { RSpec.configure { |c| c.shell = nil } } it 'should use custom shell' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- /usr/test\\ \\&\\ spec/bin/sh -c test\\ -f\\ /etc/passwd" end end context 'with an interactive shell' do before { RSpec.configure { |c| c.interactive_shell = true } } after { RSpec.configure { |c| c.interactive_shell = nil } } it 'should emulate an interactive shell' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -t -- /bin/sh -i -c test\\ -f\\ /etc/passwd" end end context 'with an login shell' do before { RSpec.configure { |c| c.login_shell = true } } after { RSpec.configure { |c| c.login_shell = nil } } it 'should emulate an login shell' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- /bin/sh -l -c test\\ -f\\ /etc/passwd" end end context 'with custom path' do before { RSpec.configure { |c| c.path = '/opt/bin:/opt/foo/bin:$PATH' } } after { RSpec.configure { |c| c.path = nil } } it 'should use custom path' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- env PATH=\"/opt/bin:/opt/foo/bin:$PATH\" /bin/sh -c test\\ -f\\ /etc/passwd" end end context 'with custom path that needs escaping' do before { RSpec.configure { |c| c.path = '/opt/bin:/opt/test & spec/bin:$PATH' } } after { RSpec.configure { |c| c.path = nil } } it 'should use custom path' do expect(subject.build_command('test -f /etc/passwd')).to eq "#{lxc_exec} -- env PATH=\"/opt/bin:/opt/test & spec/bin:$PATH\" /bin/sh -c test\\ -f\\ /etc/passwd" end end end end specinfra-2.89.0/spec/backend/ssh/0000755000004100000410000000000014575463425016751 5ustar www-datawww-dataspecinfra-2.89.0/spec/backend/ssh/build_command_spec.rb0000644000004100000410000001170014575463425023104 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Backend::Ssh do before(:all) do set :backend, :ssh end after(:all) do if Specinfra.configuration.instance_variable_defined?(:@ssh_options) Specinfra.configuration.instance_variable_set(:@ssh_options, nil) end end describe '#build_command' do context 'with root user' do before do RSpec.configure do |c| set :ssh_options, :user => 'root' c.ssh = double(:ssh, Specinfra.configuration.ssh_options) end end after do RSpec.configure do |c| c.ssh = nil end end it 'should not prepend sudo' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd' end it 'should escape special characters' do expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq '/bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)' end end context 'with non-root user' do before do RSpec.configure do |c| set :ssh_options, :user => 'foo' c.ssh = double(:ssh, Specinfra.configuration.ssh_options) end end after do RSpec.configure do |c| c.ssh = nil end end it 'should prepend sudo' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq %q{sudo -p 'Password: ' /bin/sh -c test\ -f\ /etc/passwd} end it 'should escape special characters' do expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq %q{sudo -p 'Password: ' /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)} end end context 'with custom sudo path' do before do RSpec.configure do |c| set :ssh_options, :user => 'foo' c.ssh = double(:ssh, Specinfra.configuration.ssh_options) c.sudo_path = '/usr/local/bin' end end after do RSpec.configure do |c| c.ssh = nil c.sudo_path = nil end end it 'command pattern 1a' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq %q{/usr/local/bin/sudo -p 'Password: ' /bin/sh -c test\ -f\ /etc/passwd} end it 'command pattern 2a' do expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq %q{/usr/local/bin/sudo -p 'Password: ' /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)} end end context 'without sudo' do before do RSpec.configure do |c| set :ssh_options, :user => 'foo' c.ssh = double(:ssh, Specinfra.configuration.ssh_options) c.disable_sudo = true end end after do RSpec.configure do |c| c.ssh = nil c.disable_sudo = false end end it 'command pattern 1b' do expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd' end it 'command pattern 2b' do expect(Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq '/bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)' end end context 'with sudo on alternative path' do before do RSpec.configure do |c| set :ssh_options, :user => 'foo' c.ssh = double(:ssh, Specinfra.configuration.ssh_options) c.sudo_path = nil end end after do RSpec.configure do |c| c.ssh = nil c.sudo_options = nil end end context 'command pattern 1a' do subject { Specinfra.backend.build_command('test -f /etc/passwd') } it { should eq %q{sudo -p 'Password: ' /bin/sh -c test\ -f\ /etc/passwd} } end context 'command pattern 2a' do subject { Specinfra.backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') } it { should eq %q{sudo -p 'Password: ' /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)} } end end end end specinfra-2.89.0/spec/configuration_spec.rb0000644000004100000410000000105614575463425020775 0ustar www-datawww-datarequire 'spec_helper' describe 'RSpec.configuration.path' do before do RSpec.configure do |c| c.path = 'foo' end end after do RSpec.configure do |c| c.path = nil end end subject { RSpec.configuration.path } it { should eq Specinfra.configuration.path } end Specinfra.configuration.os = 'foo' describe Specinfra.configuration.os do it { should eq 'foo' } end Specinfra.configuration.instance_variable_set(:@os, nil) RSpec.configuration.os = nil describe Specinfra.configuration.os do it { should be_nil } end specinfra-2.89.0/Rakefile0000644000004100000410000000223414575463425015301 0ustar www-datawww-datarequire "bundler/gem_tasks" begin require "rspec/core/rake_task" require "octorelease" rescue LoadError end if defined?(RSpec) task :spec => 'spec:all' task :default => 'spec:all' namespace :spec do task :all => [ :helper, :backend, :configuration, :processor, :command, :host_inventory ] RSpec::Core::RakeTask.new(:helper) do |t| t.pattern = "spec/helper/**/*_spec.rb" end task :backend => 'backend:all' namespace :backend do backends = Dir.glob("spec/backend/*").map { |path| File.basename(path) } task :all => backends backends.each do |backend| RSpec::Core::RakeTask.new(backend) do |t| t.pattern = "spec/backend/#{backend}/*_spec.rb" end end end RSpec::Core::RakeTask.new(:configuration) do |t| t.pattern = "spec/configuration_spec.rb" end RSpec::Core::RakeTask.new(:processor) do |t| t.pattern = "spec/processor_spec.rb" end RSpec::Core::RakeTask.new(:command) do |t| t.pattern = "spec/command/**/*.rb" end RSpec::Core::RakeTask.new(:host_inventory) do |t| t.pattern = "spec/host_inventory/**/*_spec.rb" end end end specinfra-2.89.0/Gemfile0000644000004100000410000000136414575463425015132 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in specinfra.gemspec gemspec ruby_version = Gem::Version.new(RUBY_VERSION.dup) if ruby_version < Gem::Version.new('2.0.0') # net-ssh 3.x dropped Ruby 1.8 and 1.9 support. gem 'net-ssh', '~> 2.7' end if ruby_version < Gem::Version.new('1.9.3') # pry 0.11 dropped Ruby 1.8 support gem 'pry', '0.10.4' # listen 2.0 dropped Ruby 1.8 support gem 'listen', '< 2.0' # hitimes 1.2.3 dropped Ruby 1.8 support gem 'hitimes', '< 1.2.3' elsif ruby_version < Gem::Version.new('2.0.0') # listen 3.0 dropped Ruby 1.8 and 1.9 support gem 'listen', '< 3.0' elsif ruby_version < Gem::Version.new('2.2.3') # listen 3.1 dropped support for Ruby 2.1 and lower gem 'listen', '< 3.1' end specinfra-2.89.0/specinfra.gemspec0000644000004100000410000000256214575463425017157 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'specinfra/version' Gem::Specification.new do |spec| spec.name = "specinfra" spec.version = Specinfra::VERSION spec.authors = ["Gosuke Miyashita"] spec.email = ["gosukenator@gmail.com"] spec.description = %q{Common layer for serverspec and itamae} spec.summary = %q{Common layer for serverspec and itamae} spec.homepage = 'https://github.com/mizzy/specinfra' spec.license = "MIT" spec.files = %w{LICENSE.txt README.md} + `git ls-files`.split("\n").select { |f| f =~ %r{^(?:lib/)}i } spec.test_files = %w{Gemfile specinfra.gemspec Rakefile} + `git ls-files`.split("\n").select { |f| f =~ %r{^(?:spec/)}i } spec.require_paths = ["lib"] # TODO: at some point pin to a minumum version of ruby to reduce support burden in a major version bump # spec.required_ruby_version = '>= 2.3.0' spec.add_runtime_dependency "net-scp" spec.add_runtime_dependency "net-ssh", ">= 2.7" spec.add_runtime_dependency "net-telnet" # intentionally version-unspecified for Ruby older than 2.3.0 spec.add_runtime_dependency "sfl" # required for Ruby older than 1.9.0 spec.add_development_dependency "rake" spec.add_development_dependency "rspec" spec.add_development_dependency "rspec-its" end specinfra-2.89.0/README.md0000644000004100000410000000262614575463425015120 0ustar www-datawww-data# Specinfra TODO: Write a gem description ## Installation Add this line to your application's Gemfile: gem 'specinfra' And then execute: ``` bundle ``` Or install it yourself as: ``` gem install specinfra ``` For Ruby versions older than 2.3.0, pin net-telnet to version 0.1.1 in your `Gemfile` or `*.gemspec`. See also [pin net-telnet dependency to keep ruby support for < 2.3 #665][issue665]. [issue665]: https://github.com/mizzy/specinfra/pull/665 ## Running tests ``` bundle exec rake ``` ## Usage TODO: Write usage instructions here ---- ## Maintenance policy of Serverspec/Specinfra * The person who found a bug should fix the bug by themself. * If you find a bug and cannot fix it by yourself, send a pull request and attach test code to reproduce the bug, please. * The person who want a new feature should implement it by themself. * For above reasons, I accept pull requests only and disable issues. * If you'd like to discuss about a new feature before implement it, make an empty commit and send [a WIP pull request](http://ben.straub.cc/2015/04/02/wip-pull-request/). But It is better that the WIP PR has some code than an empty commit. ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request