specinfra-2.35.1/0000755000004100000410000000000012537123500013602 5ustar www-datawww-dataspecinfra-2.35.1/Rakefile0000644000004100000410000000172612537123500015255 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' namespace :spec do task :all => [ :helper, :backend, :configuration, :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 = %w[exec ssh] 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(: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.35.1/Gemfile0000644000004100000410000000013612537123500015075 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in specinfra.gemspec gemspec specinfra-2.35.1/examples/0000755000004100000410000000000012537123500015420 5ustar www-datawww-dataspecinfra-2.35.1/examples/multiple_backends.rb0000644000004100000410000000267712537123500021446 0ustar www-datawww-datarequire 'specinfra' require 'pp' a = Specinfra::Backend::Exec.new ssh_options = Net::SSH::Config.for(ENV['SSH_HOST'], [ENV['SSH_CONFIG']]) b = Specinfra::Backend::Ssh.new( :host => ssh_options[:host_name], :ssh_options => ssh_options, ) threads = [a, b].map do |backend| Thread.start(backend) do |backend| result = [] result << backend.run_command("uname -a") result << backend.command result << backend.command.get(:install_package, 'dstat') result end end threads.each(&:join) threads.each do |t| pp t.value end # example: # [#, # #"darwin", :release=>nil, :arch=>"x86_64"}>, # "/usr/local/bin/brew install 'dstat'"] # [#, # #"ubuntu", :release=>"14.04", :arch=>"x86_64"}>, # "DEBIAN_FRONTEND='noninteractive' apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install dstat"] specinfra-2.35.1/appveyor.yml0000644000004100000410000000320112537123500016166 0ustar www-datawww-dataversion: "{build}" os: Windows Server 2012 platform: - x64 environment: bundle_gemfile: integration-test/Gemfile.winrm bundler_url: https://rubygems.org/downloads/bundler-1.9.9.gem matrix: - ruby_version: "193" - ruby_version: "200" - ruby_version: "21" - ruby_version: "22" matrix: allow_failures: - ruby_version: "22" # waiting for net-ssh update clone_depth: 5 cache: - C:\Ruby193\lib\ruby\gems\1.9.1 - C:\Ruby193\bin - C:\Ruby200\lib\ruby\gems\2.0.0 - C:\Ruby200\bin - C:\Ruby21\lib\ruby\gems\2.1.0 - C:\Ruby21\bin - C:\Ruby22\lib\ruby\gems\2.2.0 - C:\Ruby22\bin install: - git submodule update --init --recursive - ps: Enable-PSRemoting -Force - ps: Set-ExecutionPolicy RemoteSigned - winrm quickconfig -q - winrm set winrm/config/client @{TrustedHosts="*"} - winrm set winrm/config/client/auth @{Basic="true"} - winrm set winrm/config/service/auth @{Basic="true"} - winrm set winrm/config/service @{AllowUnencrypted="true"} - SET PATH=C:\Ruby%ruby_version%\bin;%PATH% - echo %PATH% - ruby --version - gem --version - appveyor DownloadFile -Url %bundler_url% -FileName bundler.gem - gem install --local bundler.gem --no-ri --no-rdoc ## appveyor often stops `gem install bundler`..? build_script: - ruby -rfileutils -e 'FileUtils.rm_r(File.join(Gem.dir, "cache", "bundler")) if Dir.exists?(File.join(Gem.dir, "cache", "bundler"))' - bundle install --jobs 3 --retry 3 - net user - net localgroup test_script: - net user appveyor %WINDOWS_PASSWORD% # set by webui - bundle exec rspec -fd --backtrace -r .\integration-test\winrm\spec_helper.rb .\integration-test\winrm specinfra-2.35.1/LICENSE.txt0000644000004100000410000000206112537123500015424 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.35.1/spec/0000755000004100000410000000000012537123500014534 5ustar www-datawww-dataspecinfra-2.35.1/spec/host_inventory/0000755000004100000410000000000012537123500017626 5ustar www-datawww-dataspecinfra-2.35.1/spec/host_inventory/cpu_spec.rb0000644000004100000410000000573412537123500021765 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.35.1/spec/spec_helper.rb0000644000004100000410000000075612537123500017362 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.35.1/spec/command/0000755000004100000410000000000012537123500016152 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/base/0000755000004100000410000000000012537123500017064 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/base/group_spec.rb0000644000004100000410000000055712537123500021566 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 specinfra-2.35.1/spec/command/base/package_spec.rb0000644000004100000410000000061112537123500022014 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_rvm, 'rbx', '2.4.1') do it { should eq 'rvm list strings | grep -iw -- \\^rbx | grep -w -- 2.4.1' } end specinfra-2.35.1/spec/command/base/user_spec.rb0000644000004100000410000000351512537123500021405 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 | awk -F: '{ print $6 }'" } 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 | awk -F: '{ print $2 }'" } 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 | grep '^Minimum.*:' | awk -F ': ' '{print $2}'" } end describe get_command(:get_user_maximum_days_between_password_change, 'foo') do it { should eq "chage -l foo | grep '^Maximum.*:' | awk -F ': ' '{print $2}'" } 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 specinfra-2.35.1/spec/command/base/file_spec.rb0000644000004100000410000000361512537123500021347 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_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_group, '/tmp', 'root') do it { should eq 'chgrp 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(: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(: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(:check_file_exists, '/tmp') do it { should eq 'test -e /tmp' } end specinfra-2.35.1/spec/command/base/localhost_spec.rb0000644000004100000410000000027312537123500022415 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.35.1/spec/command/windows/0000755000004100000410000000000012537123500017644 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/windows/registry_key_spec.rb0000644000004100000410000000225312537123500023725 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.35.1/spec/command/factory_spec.rb0000644000004100000410000000163012537123500021160 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.35.1/spec/command/freebsd/0000755000004100000410000000000012537123500017564 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/freebsd/file_spec.rb0000644000004100000410000000051212537123500022040 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.35.1/spec/command/module/0000755000004100000410000000000012537123500017437 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/module/zfs_spec.rb0000644000004100000410000000053412537123500021602 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.35.1/spec/command/module/systemd_spec.rb0000644000004100000410000000161312537123500022467 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 --plain list-dependencies multi-user.target | grep '\\(^\\| \\)httpd.service$'" } it { expect(klass.check_is_enabled('httpd', 'multi-user.target')).to eq "systemctl --plain list-dependencies multi-user.target | grep '\\(^\\| \\)httpd.service$'" } it { expect(klass.check_is_enabled('httpd', 3)).to eq "systemctl --plain list-dependencies runlevel3.target | grep '\\(^\\| \\)httpd.service$'" } it { expect(klass.check_is_enabled('httpd', '3')).to eq "systemctl --plain list-dependencies runlevel3.target | grep '\\(^\\| \\)httpd.service$'" } it { expect(klass.check_is_enabled('sshd.socket')).to eq "systemctl --plain list-dependencies multi-user.target | grep '\\(^\\| \\)sshd.socket$'" } end specinfra-2.35.1/spec/command/module/service/0000755000004100000410000000000012537123500021077 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/module/service/systemd_spec.rb0000644000004100000410000000205312537123500024126 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 --plain list-dependencies multi-user.target | grep '\\(^\\| \\)httpd.service$'" } 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.35.1/spec/command/module/service/daemontools_spec.rb0000644000004100000410000000320212537123500024757 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.35.1/spec/command/module/service/init_spec.rb0000644000004100000410000000167612537123500023413 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.35.1/spec/command/redhat7/0000755000004100000410000000000012537123500017510 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/redhat7/service_spec.rb0000644000004100000410000000143012537123500022505 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.35.1/spec/command/debian/0000755000004100000410000000000012537123500017374 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/debian/service_spec.rb0000644000004100000410000000126012537123500022372 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.35.1/spec/command/linux/0000755000004100000410000000000012537123500017311 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/linux/inventory_spec.rb0000644000004100000410000000034612537123500022710 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 specinfra-2.35.1/spec/command/linux/interface_spec.rb0000644000004100000410000000062012537123500022606 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 addr show eth0 | grep 'inet6 2001:0db8:bd05:01d2:288a:1fc0:0001:10ee/'" } end describe get_command(:get_interface_link_state, 'eth0') do it { should eq "cat /sys/class/net/eth0/operstate" } end specinfra-2.35.1/spec/command/linux/ip6tables_spec.rb0000644000004100000410000000030512537123500022537 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.35.1/spec/command/linux/file_spec.rb0000644000004100000410000000026312537123500021570 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:get_file_selinuxlabel, 'some_file') do it { should eq 'stat -c %C some_file' } end specinfra-2.35.1/spec/command/linux/selinux_module_spec.rb0000644000004100000410000000056212537123500023707 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.35.1/spec/command/linux/selinux_spec.rb0000644000004100000410000000042712537123500022342 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, :family => 'linux' describe get_command(:check_selinux_has_mode, 'disabled') do it { should eq 'test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)' } end specinfra-2.35.1/spec/command/linux/bond_spec.rb0000644000004100000410000000047312537123500021576 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.35.1/spec/command/linux/bridge_spec.rb0000644000004100000410000000044312537123500022105 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.35.1/spec/command/darwin/0000755000004100000410000000000012537123500017436 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/darwin/user_spec.rb0000644000004100000410000000105312537123500021752 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 specinfra-2.35.1/spec/command/darwin/file_spec.rb0000644000004100000410000000077312537123500021723 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.35.1/spec/command/ubuntu/0000755000004100000410000000000012537123500017474 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/ubuntu/ppa_spec.rb0000644000004100000410000000065712537123500021623 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.35.1/spec/command/redhat/0000755000004100000410000000000012537123500017421 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/redhat/service_spec.rb0000644000004100000410000000121012537123500022412 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.35.1/spec/command/redhat/interface_spec.rb0000644000004100000410000000036712537123500022726 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.35.1/spec/command/redhat/package_spec.rb0000644000004100000410000000023612537123500022354 0ustar www-datawww-datarequire 'spec_helper' set :os, { :family => 'redhat' } describe get_command(:check_package_is_installed, 'httpd') do it { should eq 'rpm -q httpd' } end specinfra-2.35.1/spec/command/esxi/0000755000004100000410000000000012537123500017122 5ustar www-datawww-dataspecinfra-2.35.1/spec/command/esxi/package_spec.rb0000644000004100000410000000031112537123500022047 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 httpd' } end specinfra-2.35.1/spec/configuration_spec.rb0000644000004100000410000000040512537123500020741 0ustar www-datawww-datarequire 'spec_helper' RSpec.configure do |c| c.path = 'foo' end describe RSpec.configuration.path do it { should eq Specinfra.configuration.path } end Specinfra.configuration.os = 'foo' describe Specinfra.configuration.os do it { should eq 'foo' } end specinfra-2.35.1/spec/helper/0000755000004100000410000000000012537123500016013 5ustar www-datawww-dataspecinfra-2.35.1/spec/helper/detect_os/0000755000004100000410000000000012537123500017764 5ustar www-datawww-dataspecinfra-2.35.1/spec/helper/detect_os/esxi_spec.rb0000644000004100000410000000133312537123500022273 0ustar www-datawww-datarequire 'spec_helper' require 'specinfra/helper/detect_os/esxi' describe Specinfra::Helper::DetectOs::Esxi do it 'Should return esxi when esxi is installed.' do allow(Specinfra::Helper::DetectOs::Esxi).to receive(:run_command) { CommandResult.new(:stdout => 'VMware ESXi 5.0.0 build-123445', :exit_status => 0) } expect(Specinfra::Helper::DetectOs::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(Specinfra::Helper::DetectOs::Esxi).to receive(:run_command) { CommandResult.new(:stdout => 'VMware Workstation', :exit_status => 0) } expect(Specinfra::Helper::DetectOs::Esxi.detect).to be_nil end endspecinfra-2.35.1/spec/helper/set_spec.rb0000644000004100000410000000073412537123500020151 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.35.1/spec/helper/os_spec.rb0000644000004100000410000000271312537123500017776 0ustar www-datawww-datarequire 'spec_helper' 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 wit 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 specinfra-2.35.1/spec/helper/properties_spec.rb0000644000004100000410000000033312537123500021545 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.35.1/spec/backend/0000755000004100000410000000000012537123500016123 5ustar www-datawww-dataspecinfra-2.35.1/spec/backend/exec/0000755000004100000410000000000012537123500017047 5ustar www-datawww-dataspecinfra-2.35.1/spec/backend/exec/env_spec.rb0000644000004100000410000000056112537123500021200 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra.backend.run_command('echo $LANG').stdout.strip do it { should eq 'C' } end describe do before do 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.35.1/spec/backend/exec/build_command_spec.rb0000644000004100000410000001113312537123500023202 0ustar www-datawww-datarequire 'spec_helper' describe Specinfra::Backend::Exec do 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 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 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_by_host] = {} end context 'test ubuntu with lsb_release command' do subject { os } it do expect(Specinfra.backend).to receive(:run_command).at_least(1).times do |args| if ['ls /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 should eq({:family => 'ubuntu', :release => '12.04', :arch => 'x86_64' }) end end context 'test ubuntu with /etc/lsb-release' do before do property[:os] = nil end subject { os } it do expect(Specinfra.backend).to receive(:run_command).at_least(1).times do |args| if ['ls /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 should eq({:family => 'ubuntu', :release => '12.04', :arch => 'x86_64' }) end end context 'test debian (no lsb_release or lsb-release)' do before do property[:os] = nil end subject { os } it do expect(Specinfra.backend).to receive(:run_command).at_least(1).times do |args| if args == 'ls /etc/debian_version' double :run_command_response, :success? => true, :stdout => nil 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 should eq({:family => 'debian', :release => nil, :arch => 'x86_64' }) end end end specinfra-2.35.1/spec/backend/ssh/0000755000004100000410000000000012537123500016720 5ustar www-datawww-dataspecinfra-2.35.1/spec/backend/ssh/build_command_spec.rb0000644000004100000410000001077312537123500023064 0ustar www-datawww-datarequire 'spec_helper' set :backend, :ssh describe Specinfra::Backend::Ssh do 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 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 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.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.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.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.35.1/.travis.yml0000644000004100000410000000056512537123500015721 0ustar www-datawww-datalanguage: ruby rvm: - 1.8.7 - 1.9.3 - 2.0.0 - 2.1.1 before_install: - gem update bundler script: - bundle exec rake spec sudo: false cache: bundler notifications: slack: secure: OhClKo2Gn26gevN773CRR2NAHzmkrzGrVTHsAKm4dgNFqnaBVZGNv2kzjAFsy0CEjZJw3433NtaJdrWpLozdHFA5g7fhOTqB2y7Oh+8PsoS4qWsosKcjtCYt7BmNbEFkGaHKAdQjO/vGFml7tAOk/DtVRnfX6QgVUBjky2ao7XM= specinfra-2.35.1/lib/0000755000004100000410000000000012537123500014350 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra.rb0000644000004100000410000000251212537123500016647 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 :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.35.1/lib/specinfra/0000755000004100000410000000000012537123500016322 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/helper.rb0000644000004100000410000000033012537123500020122 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.35.1/lib/specinfra/configuration.rb0000644000004100000410000000300112537123500021510 0ustar www-datawww-datamodule Specinfra module Configuration class << self VALID_OPTIONS_KEYS = [ :backend, :env, :path, :shell, :pre_command, :stdout, :stderr, :exit_status, :sudo_path, :disable_sudo, :sudo_options, :docker_container_create_options, :docker_image, :docker_url, :lxc, :request_pty, :ssh_options, :ssh_without_env, :dockerfile_finalizer, :telnet_options, ].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 Helpet::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 key.gsub!(/=$/, '') ret = nil begin if ! val.nil? instance_variable_set("@#{key}", val) RSpec.configuration.send(:"#{key}=", val) if defined?(RSpec) end ret = instance_variable_get("@#{key}") 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.35.1/lib/specinfra/host_inventory/0000755000004100000410000000000012537123500021414 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/host_inventory/cpu.rb0000644000004100000410000000523412537123500022534 0ustar www-datawww-datamodule Specinfra class HostInventory class Cpu < Base def get cmd = backend.command.get(:get_inventory_cpu) ret = backend.run_command(cmd).stdout parse(ret) 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.35.1/lib/specinfra/host_inventory/domain.rb0000644000004100000410000000032012537123500023203 0ustar www-datawww-datamodule Specinfra class HostInventory class Domain < Base def get cmd = backend.command.get(:get_inventory_domain) backend.run_command(cmd).stdout.strip end end end end specinfra-2.35.1/lib/specinfra/host_inventory/hostname.rb0000644000004100000410000000032412537123500023556 0ustar www-datawww-datamodule Specinfra class HostInventory class Hostname < Base def get cmd = backend.command.get(:get_inventory_hostname) backend.run_command(cmd).stdout.strip end end end end specinfra-2.35.1/lib/specinfra/host_inventory/platform_version.rb0000644000004100000410000000023212537123500025327 0ustar www-datawww-datamodule Specinfra class HostInventory class PlatformVersion < Base def get backend.os_info[:release] end end end end specinfra-2.35.1/lib/specinfra/host_inventory/virtualization.rb0000644000004100000410000000036712537123500025033 0ustar www-datawww-datamodule Specinfra class HostInventory class Virtualization < Base def get res = {} if backend.run_command('ls /.dockerinit').success? res[:system] = 'docker' end res end end end end specinfra-2.35.1/lib/specinfra/host_inventory/ec2.rb0000644000004100000410000000030012537123500022403 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.35.1/lib/specinfra/host_inventory/fqdn.rb0000644000004100000410000000031412537123500022667 0ustar www-datawww-datamodule Specinfra class HostInventory class Fqdn < Base def get cmd = backend.command.get(:get_inventory_fqdn) backend.run_command(cmd).stdout.strip end end end end specinfra-2.35.1/lib/specinfra/host_inventory/memory.rb0000644000004100000410000000470712537123500023261 0ustar www-datawww-datamodule Specinfra class HostInventory class Memory < Base def get cmd = backend.command.get(:get_inventory_memory) ret = backend.run_command(cmd).stdout 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}" end end memory end end end end specinfra-2.35.1/lib/specinfra/host_inventory/platform.rb0000644000004100000410000000021412537123500023562 0ustar www-datawww-datamodule Specinfra class HostInventory class Platform < Base def get backend.os_info[:family] end end end end specinfra-2.35.1/lib/specinfra/host_inventory/kernel.rb0000644000004100000410000000030012537123500023212 0ustar www-datawww-datamodule Specinfra class HostInventory class Kernel < Base def get kernel = {} kernel['machine'] = backend.os_info[:arch] kernel end end end end specinfra-2.35.1/lib/specinfra/host_inventory/base.rb0000644000004100000410000000033612537123500022655 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.35.1/lib/specinfra/host_inventory/filesystem.rb0000644000004100000410000000131112537123500024121 0ustar www-datawww-datamodule Specinfra class HostInventory class Filesystem < Base def get cmd = backend.command.get(:get_inventory_filesystem) filesystem = {} backend.run_command(cmd).stdout.lines 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.35.1/lib/specinfra/command_factory.rb0000644000004100000410000000455112537123500022021 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 command_class.create end def breakdown(meth) # Somtimes `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.35.1/lib/specinfra/ext.rb0000644000004100000410000000007512537123500017451 0ustar www-datawww-datarequire 'specinfra/ext/class' require 'specinfra/ext/string' specinfra-2.35.1/lib/specinfra/command.rb0000644000004100000410000002303212537123500020265 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/systemd' require 'specinfra/command/module/zfs' # 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/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 (inhefit 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/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/file' require 'specinfra/command/redhat/base/iptables' require 'specinfra/command/redhat/base/package' 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/service' # 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' # 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/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/package' require 'specinfra/command/alpine/base/process' # Arch (inherit Linux) require 'specinfra/command/arch' require 'specinfra/command/arch/base' require 'specinfra/command/arch/base/file' require 'specinfra/command/arch/base/service' require 'specinfra/command/arch/base/package' # 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/service' require 'specinfra/command/darwin/base/package' require 'specinfra/command/darwin/base/port' require 'specinfra/command/darwin/base/user' # 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/service' # Debian V8 (inherit Debian) require 'specinfra/command/debian/v8' require 'specinfra/command/debian/v8/service' # Ubuntu (inherit Debian) require 'specinfra/command/ubuntu' require 'specinfra/command/ubuntu/base' require 'specinfra/command/ubuntu/base/ppa' require 'specinfra/command/ubuntu/base/service' # 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' # Gentoo (inherit Linux) require 'specinfra/command/gentoo' require 'specinfra/command/gentoo/base' require 'specinfra/command/gentoo/base/package' require 'specinfra/command/gentoo/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' # FreeBSD (inherit Base) require 'specinfra/command/freebsd' require 'specinfra/command/freebsd/base' require 'specinfra/command/freebsd/base/file' require 'specinfra/command/freebsd/base/package' require 'specinfra/command/freebsd/base/port' require 'specinfra/command/freebsd/base/service' # FreeBSD V10 (inherit FreeBSD) require 'specinfra/command/freebsd/v10' require 'specinfra/command/freebsd/v10/package' # 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/interface' 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' # 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/ipfilter' require 'specinfra/command/solaris/base/ipnat' 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' # 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' specinfra-2.35.1/lib/specinfra/command/0000755000004100000410000000000012537123500017740 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/base/0000755000004100000410000000000012537123500020652 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/base/yumrepo.rb0000644000004100000410000000011012537123500022667 0ustar www-datawww-dataclass Specinfra::Command::Base::Yumrepo < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/interface.rb0000644000004100000410000000011112537123500023130 0ustar www-datawww-dataclass Specinfra::Command::Base::Interface < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/ppa.rb0000644000004100000410000000010312537123500021751 0ustar www-datawww-dataclass Specinfra::Command::Base::Ppa < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/selinux.rb0000644000004100000410000000010712537123500022664 0ustar www-datawww-dataclass Specinfra::Command::Base::Selinux < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/routing_table.rb0000644000004100000410000000036112537123500024035 0ustar www-datawww-dataclass Specinfra::Command::Base::RoutingTable < Specinfra::Command::Base class << self def check_has_entry(destination) "ip route show #{destination} | grep #{destination}" end alias :get_entry :check_has_entry end end specinfra-2.35.1/lib/specinfra/command/base/bond.rb0000644000004100000410000000010412537123500022114 0ustar www-datawww-dataclass Specinfra::Command::Base::Bond < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/lxc_container.rb0000644000004100000410000000011412537123500024023 0ustar www-datawww-dataclass Specinfra::Command::Base::LxcContainer < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/selinux_module.rb0000644000004100000410000000011512537123500024230 0ustar www-datawww-dataclass Specinfra::Command::Base::SelinuxModule < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/process.rb0000644000004100000410000000067012537123500022660 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 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.35.1/lib/specinfra/command/base/bridge.rb0000644000004100000410000000010612537123500022430 0ustar www-datawww-dataclass Specinfra::Command::Base::Bridge < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/iptables.rb0000644000004100000410000000011012537123500022772 0ustar www-datawww-dataclass Specinfra::Command::Base::Iptables < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/user.rb0000644000004100000410000000547612537123500022171 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)} | awk '{print $3}' | grep -- #{escape(group)}" end def check_belongs_to_primary_group(user, group) "id -gn #{escape(user)}| grep ^#{escape(group)}$" 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)} | grep '^Minimum.*:' | awk -F ': ' '{print $2}'" end def get_maximum_days_between_password_change(user) "chage -l #{escape(user)} | grep '^Maximum.*:' | awk -F ': ' '{print $2}'" 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)} | awk -F: '{ print $6 }'" 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)} | awk -F: '{ print $2 }'" end end end specinfra-2.35.1/lib/specinfra/command/base/file.rb0000644000004100000410000001101012537123500022107 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) "stat -c %N #{escape(link)} | egrep -e \"-> .#{escape(target)}.\"" end def check_is_link(link) "test -L #{escape(link)}" end def get_link_target(link) "readlink #{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) "chmod #{mode} #{escape(file)}" end def change_owner(file, owner, group=nil) owner = "#{owner}:#{group}" if group "chown #{owner} #{escape(file)}" end def change_group(file, group) "chgrp #{group} #{escape(file)}" end def create_as_directory(file) "mkdir -p #{escape(file)}" end def copy(src, dest) "cp #{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] "ln #{option} #{escape(target)} #{escape(link)}" end def remove(file) "rm -rf #{escape(file)}" end end end specinfra-2.35.1/lib/specinfra/command/base/fstab.rb0000644000004100000410000000010512537123500022272 0ustar www-datawww-dataclass Specinfra::Command::Base::Fstab < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/cron.rb0000644000004100000410000000066712537123500022151 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(/\]/, '\\]') 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 end end specinfra-2.35.1/lib/specinfra/command/base/host.rb0000644000004100000410000000152412537123500022156 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 -vvvvz#{escape(proto[0].chr)} #{escape(host)} #{escape(port)} -w #{escape(timeout)}" end end def get_ipaddress(name) "getent hosts #{escape(name)} | awk '{print $1}'" end end end specinfra-2.35.1/lib/specinfra/command/base/kernel_module.rb0000644000004100000410000000011412537123500024020 0ustar www-datawww-dataclass Specinfra::Command::Base::KernelModule < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/package.rb0000644000004100000410000000310512537123500022571 0ustar www-datawww-dataclass Specinfra::Command::Base::Package < Specinfra::Command::Base class << self def check_is_installed_by_gem(name, version=nil) regexp = "^#{name}" cmd = "gem list --local | grep -iw -- #{escape(regexp)}" cmd = %Q!#{cmd} | grep -w -- "[( ]#{escape(version)}[,)]"! if version cmd 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_cpan(name, version=nil) regexp = "^#{name}" cmd = "cpan -l | grep -iw -- #{escape(regexp)}" cmd = "#{cmd} | grep -w -- #{escape(version)}" if version cmd end end end specinfra-2.35.1/lib/specinfra/command/base/group.rb0000644000004100000410000000127312537123500022336 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) regexp = "^#{group}" "getent group | grep -w -- #{escape(regexp)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}" 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 << escape(group) command.join(' ') end end end specinfra-2.35.1/lib/specinfra/command/base/mail_alias.rb0000644000004100000410000000060412537123500023272 0ustar www-datawww-dataclass Specinfra::Command::Base::MailAlias < Specinfra::Command::Base class << self def check_is_aliased_to(mail_alias, recipient) 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.35.1/lib/specinfra/command/base/ipfilter.rb0000644000004100000410000000011012537123500023005 0ustar www-datawww-dataclass Specinfra::Command::Base::Ipfilter < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/port.rb0000644000004100000410000000057512537123500022172 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.35.1/lib/specinfra/command/base/localhost.rb0000644000004100000410000000030112537123500023161 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.35.1/lib/specinfra/command/base/ipnat.rb0000644000004100000410000000010512537123500022306 0ustar www-datawww-dataclass Specinfra::Command::Base::Ipnat < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/inventory.rb0000644000004100000410000000011112537123500023225 0ustar www-datawww-dataclass Specinfra::Command::Base::Inventory < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/zfs.rb0000644000004100000410000000010412537123500021774 0ustar www-datawww-dataclass Specinfra::Command::Base::Zfs < Specinfra::Command::Base; end specinfra-2.35.1/lib/specinfra/command/base/ip6tables.rb0000644000004100000410000000011112537123500023061 0ustar www-datawww-dataclass Specinfra::Command::Base::Ip6tables < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/base/service.rb0000644000004100000410000000120312537123500022633 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.35.1/lib/specinfra/command/fedora/0000755000004100000410000000000012537123500021200 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/fedora/base/0000755000004100000410000000000012537123500022112 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/fedora/base/service.rb0000644000004100000410000000040012537123500024071 0ustar www-datawww-dataclass Specinfra::Command::Fedora::Base::Service < Specinfra::Command::Redhat::Base::Service class << self def create if os[:release].to_i < 15 self else Specinfra::Command::Fedora::V15::Service end end end end specinfra-2.35.1/lib/specinfra/command/fedora/v15.rb0000644000004100000410000000011512537123500022135 0ustar www-datawww-dataclass Specinfra::Command::Fedora::V15 < Specinfra::Command::Fedora::Base end specinfra-2.35.1/lib/specinfra/command/fedora/v15/0000755000004100000410000000000012537123500021613 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/fedora/v15/service.rb0000644000004100000410000000024512537123500023601 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.35.1/lib/specinfra/command/fedora/base.rb0000644000004100000410000000011612537123500022435 0ustar www-datawww-dataclass Specinfra::Command::Fedora::Base < Specinfra::Command::Redhat::Base end specinfra-2.35.1/lib/specinfra/command/windows/0000755000004100000410000000000012537123500021432 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/windows/base/0000755000004100000410000000000012537123500022344 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/windows/base/iis_app_pool.rb0000644000004100000410000000420012537123500025342 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.35.1/lib/specinfra/command/windows/base/process.rb0000644000004100000410000000174112537123500024352 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.35.1/lib/specinfra/command/windows/base/registry_key.rb0000644000004100000410000000337612537123500025422 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.35.1/lib/specinfra/command/windows/base/hot_fix.rb0000644000004100000410000000114412537123500024331 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.35.1/lib/specinfra/command/windows/base/user.rb0000644000004100000410000000156512537123500023656 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.35.1/lib/specinfra/command/windows/base/file.rb0000644000004100000410000000712212537123500023612 0ustar www-datawww-dataclass Specinfra::Command::Windows::Base::File < Specinfra::Command::Windows::Base class << self 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}") | Out-String! 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){ 0 } else { 1 })" 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.35.1/lib/specinfra/command/windows/base/host.rb0000644000004100000410000000170012537123500023644 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.35.1/lib/specinfra/command/windows/base/package.rb0000644000004100000410000000066312537123500024271 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 end end specinfra-2.35.1/lib/specinfra/command/windows/base/group.rb0000644000004100000410000000057512537123500024034 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.35.1/lib/specinfra/command/windows/base/feature.rb0000644000004100000410000000074212537123500024327 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.35.1/lib/specinfra/command/windows/base/iis_website.rb0000644000004100000410000000413012537123500025175 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.35.1/lib/specinfra/command/windows/base/port.rb0000644000004100000410000000102612537123500023654 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.35.1/lib/specinfra/command/windows/base/scheduled_task.rb0000644000004100000410000000050012537123500025646 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.35.1/lib/specinfra/command/windows/base/service.rb0000644000004100000410000000170712537123500024336 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 end end specinfra-2.35.1/lib/specinfra/command/windows/base.rb0000644000004100000410000000066012537123500022673 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.35.1/lib/specinfra/command/redhat.rb0000644000004100000410000000004512537123500021533 0ustar www-datawww-dataclass Specinfra::Command::Redhat;end specinfra-2.35.1/lib/specinfra/command/smartos/0000755000004100000410000000000012537123500021430 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/smartos/base/0000755000004100000410000000000012537123500022342 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/smartos/base/file.rb0000644000004100000410000000054112537123500023606 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.35.1/lib/specinfra/command/smartos/base/package.rb0000644000004100000410000000064012537123500024262 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.35.1/lib/specinfra/command/smartos/base/service.rb0000644000004100000410000000057612537123500024337 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.35.1/lib/specinfra/command/smartos/base.rb0000644000004100000410000000012112537123500022661 0ustar www-datawww-dataclass Specinfra::Command::Smartos::Base < Specinfra::Command::Solaris::Base end specinfra-2.35.1/lib/specinfra/command/cumulus/0000755000004100000410000000000012537123500021435 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/cumulus/base/0000755000004100000410000000000012537123500022347 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/cumulus/base/ppa.rb0000644000004100000410000000102512537123500023452 0ustar www-datawww-dataclass Specinfra::Command::Cumulusnetworks::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 specinfra-2.35.1/lib/specinfra/command/cumulus/base/service.rb0000644000004100000410000000041112537123500024330 0ustar www-datawww-dataclass Specinfra::Command::Cumulusnetworks::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 specinfra-2.35.1/lib/specinfra/command/cumulus/base.rb0000644000004100000410000000012712537123500022674 0ustar www-datawww-dataclass Specinfra::Command::Cumulusnetworks::Base < Specinfra::Command::Debian::Base end specinfra-2.35.1/lib/specinfra/command/nixos/0000755000004100000410000000000012537123500021100 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/nixos/base/0000755000004100000410000000000012537123500022012 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/nixos/base/package.rb0000644000004100000410000000106412537123500023733 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.35.1/lib/specinfra/command/nixos/base/service.rb0000644000004100000410000000024412537123500023777 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.35.1/lib/specinfra/command/nixos/base.rb0000644000004100000410000000011412537123500022333 0ustar www-datawww-dataclass Specinfra::Command::Nixos::Base < Specinfra::Command::Linux::Base end specinfra-2.35.1/lib/specinfra/command/debian.rb0000644000004100000410000000004612537123500021507 0ustar www-datawww-dataclass Specinfra::Command::Debian; end specinfra-2.35.1/lib/specinfra/command/openbsd.rb0000644000004100000410000000004712537123500021720 0ustar www-datawww-dataclass Specinfra::Command::Openbsd; end specinfra-2.35.1/lib/specinfra/command/plamo.rb0000644000004100000410000000004512537123500021374 0ustar www-datawww-dataclass Specinfra::Command::Plamo; end specinfra-2.35.1/lib/specinfra/command/plamo/0000755000004100000410000000000012537123500021050 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/plamo/base/0000755000004100000410000000000012537123500021762 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/plamo/base/package.rb0000644000004100000410000000061012537123500023677 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.35.1/lib/specinfra/command/plamo/base/service.rb0000644000004100000410000000053512537123500023752 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.35.1/lib/specinfra/command/plamo/base.rb0000644000004100000410000000011512537123500022304 0ustar www-datawww-dataclass Specinfra::Command::Plamo::Base < Specinfra::Command::Linux::Base end specinfra-2.35.1/lib/specinfra/command/freebsd/0000755000004100000410000000000012537123500021352 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/freebsd/base/0000755000004100000410000000000012537123500022264 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/freebsd/base/file.rb0000644000004100000410000000174512537123500023537 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 check_is_owned_by(file, owner) regexp = "^#{owner}$" "stat -f%Su #{escape(file)} | grep -- #{escape(regexp)}" end def check_has_mode(file, mode) regexp = "^#{mode}$" "stat -f%Lp #{escape(file)} | grep -- #{escape(regexp)}" end def get_mode(file) "stat -f%Lp #{escape(file)}" 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.35.1/lib/specinfra/command/freebsd/base/package.rb0000644000004100000410000000105112537123500024201 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_info -I #{escape(package)}-#{escape(version)}" else "pkg_info -Ix #{escape(package)}" end end def install(package, version=nil, option='') "pkg_add -r #{option} install #{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.35.1/lib/specinfra/command/freebsd/base/port.rb0000644000004100000410000000036612537123500023602 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.35.1/lib/specinfra/command/freebsd/base/service.rb0000644000004100000410000000053612537123500024255 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base::Service < Specinfra::Command::Base::Service class << self def check_is_enabled(service, level=3) "service -e | grep -- #{escape(service)}" end def check_is_running_under_daemontools(service) "svstat /var/service/#{escape(service)} | grep -E 'up \\(pid [0-9]+\\)'" end end end specinfra-2.35.1/lib/specinfra/command/freebsd/v10/0000755000004100000410000000000012537123500021760 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/freebsd/v10/package.rb0000644000004100000410000000100112537123500023670 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V10::Package < Specinfra::Command::Freebsd::Base::Package class << self def check_is_installed(package, version=nil) if version "pkg query %v #{escape(package)} | grep -- #{escape(version)}" else "pkg info #{escape(package)}" end end 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.35.1/lib/specinfra/command/freebsd/v10.rb0000644000004100000410000000011712537123500022304 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::V10 < Specinfra::Command::Freebsd::Base end specinfra-2.35.1/lib/specinfra/command/freebsd/base.rb0000644000004100000410000000011012537123500022601 0ustar www-datawww-dataclass Specinfra::Command::Freebsd::Base < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/suse/0000755000004100000410000000000012537123500020717 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/suse/base/0000755000004100000410000000000012537123500021631 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/suse/base/package.rb0000644000004100000410000000110512537123500023546 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.35.1/lib/specinfra/command/suse/base/service.rb0000644000004100000410000000035412537123500023620 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.35.1/lib/specinfra/command/suse/base.rb0000644000004100000410000000011312537123500022151 0ustar www-datawww-dataclass Specinfra::Command::Suse::Base < Specinfra::Command::Linux::Base end specinfra-2.35.1/lib/specinfra/command/ubuntu.rb0000644000004100000410000000006012537123500021603 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu; end specinfra-2.35.1/lib/specinfra/command/module/0000755000004100000410000000000012537123500021225 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/module/systemd.rb0000644000004100000410000000041712537123500023244 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.35.1/lib/specinfra/command/module/service/0000755000004100000410000000000012537123500022665 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/module/service/runit.rb0000644000004100000410000000040612537123500024353 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 end end end end end specinfra-2.35.1/lib/specinfra/command/module/service/upstart.rb0000644000004100000410000000041312537123500024712 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.35.1/lib/specinfra/command/module/service/god.rb0000644000004100000410000000035712537123500023770 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.35.1/lib/specinfra/command/module/service/init.rb0000644000004100000410000000176112537123500024162 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.35.1/lib/specinfra/command/module/service/delegator.rb0000644000004100000410000000155412537123500025165 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.35.1/lib/specinfra/command/module/service/daemontools.rb0000644000004100000410000000254312537123500025542 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.35.1/lib/specinfra/command/module/service/monit.rb0000644000004100000410000000034212537123500024337 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.35.1/lib/specinfra/command/module/service/systemd.rb0000644000004100000410000000245712537123500024712 0ustar www-datawww-datamodule Specinfra module Command module Module module Service module Systemd def check_is_enabled_under_systemd(service, level="multi-user.target") if level.to_s =~ /^\d+$/ level = "runlevel#{level}.target" end unless service.match(/\.(service|mount|device|socket)$/) service += '.service' end "systemctl --plain list-dependencies #{level} | grep '\\(^\\| \\)#{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.35.1/lib/specinfra/command/module/service/supervisor.rb0000644000004100000410000000042712537123500025436 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.35.1/lib/specinfra/command/module/zfs.rb0000644000004100000410000000112412537123500022352 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.35.1/lib/specinfra/command/smartos.rb0000644000004100000410000000004712537123500021756 0ustar www-datawww-dataclass Specinfra::Command::Smartos; end specinfra-2.35.1/lib/specinfra/command/coreos/0000755000004100000410000000000012537123500021232 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/coreos/base/0000755000004100000410000000000012537123500022144 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/coreos/base/service.rb0000644000004100000410000000024512537123500024132 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.35.1/lib/specinfra/command/coreos/base.rb0000644000004100000410000000011512537123500022466 0ustar www-datawww-dataclass Specinfra::Command::Coreos::Base < Specinfra::Command::Linux::Base end specinfra-2.35.1/lib/specinfra/command/solaris/0000755000004100000410000000000012537123500021414 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/solaris/base/0000755000004100000410000000000012537123500022326 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/solaris/base/user.rb0000644000004100000410000000101412537123500023625 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.35.1/lib/specinfra/command/solaris/base/file.rb0000644000004100000410000000166612537123500023603 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.35.1/lib/specinfra/command/solaris/base/cron.rb0000644000004100000410000000062012537123500023612 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(/\]/, '\\]') if user.nil? "crontab -l | grep -- #{escape(entry_escaped)}" else "crontab -l #{escape(user)} | grep -- #{escape(entry_escaped)}" end end end end specinfra-2.35.1/lib/specinfra/command/solaris/base/host.rb0000644000004100000410000000055112537123500023631 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.35.1/lib/specinfra/command/solaris/base/package.rb0000644000004100000410000000050212537123500024243 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.35.1/lib/specinfra/command/solaris/base/group.rb0000644000004100000410000000042012537123500024003 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.35.1/lib/specinfra/command/solaris/base/ipfilter.rb0000644000004100000410000000032112537123500024465 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.35.1/lib/specinfra/command/solaris/base/port.rb0000644000004100000410000000071512537123500023642 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.35.1/lib/specinfra/command/solaris/base/ipnat.rb0000644000004100000410000000035312537123500023767 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.35.1/lib/specinfra/command/solaris/base/zfs.rb0000644000004100000410000000023312537123500023453 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base::Zfs < Specinfra::Command::Base::Zfs class << self include Specinfra::Command::Module::Zfs end end specinfra-2.35.1/lib/specinfra/command/solaris/base/service.rb0000644000004100000410000000130112537123500024306 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.35.1/lib/specinfra/command/solaris/v10/0000755000004100000410000000000012537123500022022 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/solaris/v10/user.rb0000644000004100000410000000063712537123500023333 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.35.1/lib/specinfra/command/solaris/v10/file.rb0000644000004100000410000000306312537123500023270 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.35.1/lib/specinfra/command/solaris/v10/host.rb0000644000004100000410000000064312537123500023327 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.35.1/lib/specinfra/command/solaris/v10/package.rb0000644000004100000410000000046612537123500023750 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.35.1/lib/specinfra/command/solaris/v10/group.rb0000644000004100000410000000031212537123500023477 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.35.1/lib/specinfra/command/solaris/v10.rb0000644000004100000410000000011712537123500022346 0ustar www-datawww-dataclass Specinfra::Command::Solaris::V10 < Specinfra::Command::Solaris::Base end specinfra-2.35.1/lib/specinfra/command/solaris/base.rb0000644000004100000410000000010712537123500022651 0ustar www-datawww-dataclass Specinfra::Command::Solaris::Base < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/module.rb0000644000004100000410000000010712537123500021550 0ustar www-datawww-datamodule Specinfra module Command module Module end end end specinfra-2.35.1/lib/specinfra/command/freebsd.rb0000644000004100000410000000004712537123500021700 0ustar www-datawww-dataclass Specinfra::Command::Freebsd; end specinfra-2.35.1/lib/specinfra/command/linux.rb0000644000004100000410000000004512537123500021423 0ustar www-datawww-dataclass Specinfra::Command::Linux; end specinfra-2.35.1/lib/specinfra/command/fedora.rb0000644000004100000410000000004612537123500021525 0ustar www-datawww-dataclass Specinfra::Command::Fedora; end specinfra-2.35.1/lib/specinfra/command/solaris.rb0000644000004100000410000000004712537123500021742 0ustar www-datawww-dataclass Specinfra::Command::Solaris; end specinfra-2.35.1/lib/specinfra/command/opensuse.rb0000644000004100000410000000005012537123500022121 0ustar www-datawww-dataclass Specinfra::Command::Opensuse; end specinfra-2.35.1/lib/specinfra/command/opensuse/0000755000004100000410000000000012537123500021601 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/opensuse/base/0000755000004100000410000000000012537123500022513 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/opensuse/base/service.rb0000644000004100000410000000054112537123500024500 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.35.1/lib/specinfra/command/opensuse/base.rb0000644000004100000410000000011712537123500023037 0ustar www-datawww-dataclass Specinfra::Command::Opensuse::Base < Specinfra::Command::Suse::Base end specinfra-2.35.1/lib/specinfra/command/aix/0000755000004100000410000000000012537123500020521 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/aix/base/0000755000004100000410000000000012537123500021433 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/aix/base/user.rb0000644000004100000410000000112012537123500022730 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.35.1/lib/specinfra/command/aix/base/file.rb0000644000004100000410000000125412537123500022701 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) raise NotImplementedError.new('check_has_mode is not implemented in Specinfra::Command::AIX::Base::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.35.1/lib/specinfra/command/aix/base/host.rb0000644000004100000410000000105512537123500022736 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.35.1/lib/specinfra/command/aix/base/package.rb0000644000004100000410000000050212537123500023350 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.35.1/lib/specinfra/command/aix/base/group.rb0000644000004100000410000000041712537123500023116 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base::Group < Specinfra::Command::Base::Group class << self def check_has_gid(group, gid) regexp = "^#{group}" "cat etc/group | grep -w -- #{escape(regexp)} | cut -f 3 -d ':' | grep -w -- #{escape(gid)}" end end end specinfra-2.35.1/lib/specinfra/command/aix/base/port.rb0000644000004100000410000000037212537123500022746 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.35.1/lib/specinfra/command/aix/base/service.rb0000644000004100000410000000046412537123500023424 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.35.1/lib/specinfra/command/aix/base.rb0000644000004100000410000000010312537123500021752 0ustar www-datawww-dataclass Specinfra::Command::Aix::Base < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/openbsd/0000755000004100000410000000000012537123500021372 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/openbsd/base/0000755000004100000410000000000012537123500022304 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/openbsd/base/interface.rb0000644000004100000410000000104612537123500024572 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) "ifconfig #{interface} | grep -w inet | cut -d ' ' -f 2" end def check_has_ipv6_address(interface, ip_address) "ifconfig #{interface} | grep -w inet6 | cut -d ' ' -f 2" end end end specinfra-2.35.1/lib/specinfra/command/openbsd/base/routing_table.rb0000644000004100000410000000042012537123500025463 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.35.1/lib/specinfra/command/openbsd/base/bond.rb0000644000004100000410000000041312537123500023551 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.35.1/lib/specinfra/command/openbsd/base/bridge.rb0000644000004100000410000000041712537123500024067 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.35.1/lib/specinfra/command/openbsd/base/user.rb0000644000004100000410000000062112537123500023606 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.35.1/lib/specinfra/command/openbsd/base/file.rb0000644000004100000410000000173412537123500023555 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 end end specinfra-2.35.1/lib/specinfra/command/openbsd/base/fstab.rb0000644000004100000410000000043512537123500023732 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.35.1/lib/specinfra/command/openbsd/base/package.rb0000644000004100000410000000070612537123500024227 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 end end specinfra-2.35.1/lib/specinfra/command/openbsd/base/mail_alias.rb0000644000004100000410000000036612537123500024731 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::MailAlias < Specinfra::Command::Base::MailAlias class << self def check_is_aliased_to(recipient, target) "egrep '^#{escape(recipient)}:.*#{escape(target)}' /etc/mail/aliases" end end end specinfra-2.35.1/lib/specinfra/command/openbsd/base/port.rb0000644000004100000410000000034212537123500023614 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, opts={}) "netstat -nat -f inet | egrep '((tcp|udp).*\.#{port}.*LISTEN$)'" end end end specinfra-2.35.1/lib/specinfra/command/openbsd/base/service.rb0000644000004100000410000000044612537123500024275 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base::Service < Specinfra::Command::Base::Service class << self 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.35.1/lib/specinfra/command/openbsd/base.rb0000644000004100000410000000011112537123500022622 0ustar www-datawww-dataclass Specinfra::Command::Openbsd::Base < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/arch/0000755000004100000410000000000012537123500020655 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/arch/base/0000755000004100000410000000000012537123500021567 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/arch/base/file.rb0000644000004100000410000000036612537123500023040 0ustar www-datawww-dataclass Specinfra::Command::Arch::Base::File < Specinfra::Command::Linux::Base::File class << self def check_is_accessible_by_user(file, user, access) "runuser -s /bin/sh -c \"test -#{access} #{file}\" #{user}" end end end specinfra-2.35.1/lib/specinfra/command/arch/base/package.rb0000644000004100000410000000155412537123500023514 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)}" 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.35.1/lib/specinfra/command/arch/base/service.rb0000644000004100000410000000024312537123500023553 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.35.1/lib/specinfra/command/arch/base.rb0000644000004100000410000000012412537123500022111 0ustar www-datawww-dataclass Specinfra::Command::Arch::Base < Specinfra::Command::Linux::Base end specinfra-2.35.1/lib/specinfra/command/debian/0000755000004100000410000000000012537123500021162 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/debian/base/0000755000004100000410000000000012537123500022074 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/debian/base/ppa.rb0000644000004100000410000000012712537123500023201 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base::Ppa < Specinfra::Command::Linux::Base::Ppa end specinfra-2.35.1/lib/specinfra/command/debian/base/package.rb0000644000004100000410000000221712537123500024016 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 #{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 #{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.35.1/lib/specinfra/command/debian/base/service.rb0000644000004100000410000000144412537123500024064 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base::Service < Specinfra::Command::Linux::Base::Service class << self 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 '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.35.1/lib/specinfra/command/debian/v8/0000755000004100000410000000000012537123500021517 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/debian/v8/service.rb0000644000004100000410000000024412537123500023504 0ustar www-datawww-dataclass Specinfra::Command::Debian::V8::Service < Specinfra::Command::Debian::Base::Service class << self include Specinfra::Command::Module::Systemd end end specinfra-2.35.1/lib/specinfra/command/debian/v8.rb0000644000004100000410000000011412537123500022040 0ustar www-datawww-dataclass Specinfra::Command::Debian::V8 < Specinfra::Command::Debian::Base end specinfra-2.35.1/lib/specinfra/command/debian/base.rb0000644000004100000410000000012612537123500022420 0ustar www-datawww-dataclass Specinfra::Command::Debian::Base < Specinfra::Command::Linux::Base end specinfra-2.35.1/lib/specinfra/command/alpine.rb0000644000004100000410000000004612537123500021535 0ustar www-datawww-dataclass Specinfra::Command::Alpine; end specinfra-2.35.1/lib/specinfra/command/linux/0000755000004100000410000000000012537123500021077 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/linux/base/0000755000004100000410000000000012537123500022011 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/linux/base/yumrepo.rb0000644000004100000410000000012712537123500024036 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Yumrepo < Specinfra::Command::Base::Yumrepo end specinfra-2.35.1/lib/specinfra/command/linux/base/interface.rb0000644000004100000410000000164112537123500024300 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 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 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 addr show #{interface} | grep 'inet6 #{ip_address}'" end def get_link_state(name) "cat /sys/class/net/#{name}/operstate" end end end specinfra-2.35.1/lib/specinfra/command/linux/base/ppa.rb0000644000004100000410000000011712537123500023115 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Ppa < Specinfra::Command::Base::Ppa end specinfra-2.35.1/lib/specinfra/command/linux/base/selinux.rb0000644000004100000410000000063612537123500024032 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Selinux < Specinfra::Command::Base::Selinux class << self def check_has_mode(mode) cmd = "" cmd += "test ! -f /etc/selinux/config || (" if mode == "disabled" cmd += "getenforce | grep -i -- #{escape(mode)} " cmd += "&& grep -i -- ^SELINUX=#{escape(mode)}$ /etc/selinux/config" cmd += ")" if mode == "disabled" cmd end end end specinfra-2.35.1/lib/specinfra/command/linux/base/bond.rb0000644000004100000410000000044712537123500023265 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.35.1/lib/specinfra/command/linux/base/lxc_container.rb0000644000004100000410000000047312537123500025172 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)}" end def check_is_running(container) "lxc-info -n #{escape(container)} -s | grep -w RUNNING" end end end specinfra-2.35.1/lib/specinfra/command/linux/base/selinux_module.rb0000644000004100000410000000074512537123500025400 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.35.1/lib/specinfra/command/linux/base/bridge.rb0000644000004100000410000000042312537123500023571 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.35.1/lib/specinfra/command/linux/base/iptables.rb0000644000004100000410000000053712537123500024146 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.35.1/lib/specinfra/command/linux/base/file.rb0000644000004100000410000000101512537123500023252 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::File < Specinfra::Command::Base::File class << self def check_is_accessible_by_user(file, user, access) "su -s /bin/sh -c \"test -#{access} #{file}\" #{user}" end def check_is_immutable(file) check_attribute(file, 'i') end def check_attribute(file, attribute) "lsattr -d #{escape(file)} 2>&1 | awk '$1~/^-*#{escape(attribute)}-*$/ {exit 0} {exit 1}'" end def get_selinuxlabel(file) "stat -c %C #{escape(file)}" end end end specinfra-2.35.1/lib/specinfra/command/linux/base/fstab.rb0000644000004100000410000000043312537123500023435 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.35.1/lib/specinfra/command/linux/base/kernel_module.rb0000644000004100000410000000027312537123500025165 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.35.1/lib/specinfra/command/linux/base/package.rb0000644000004100000410000000012712537123500023731 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Package < Specinfra::Command::Base::Package end specinfra-2.35.1/lib/specinfra/command/linux/base/inventory.rb0000644000004100000410000000063112537123500024373 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 end end specinfra-2.35.1/lib/specinfra/command/linux/base/zfs.rb0000644000004100000410000000022112537123500023133 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Zfs < Specinfra::Command::Base::Zfs class << self include Specinfra::Command::Module::Zfs end end specinfra-2.35.1/lib/specinfra/command/linux/base/ip6tables.rb0000644000004100000410000000073312537123500024232 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.35.1/lib/specinfra/command/linux/base/service.rb0000644000004100000410000000012712537123500023776 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base::Service < Specinfra::Command::Base::Service end specinfra-2.35.1/lib/specinfra/command/linux/base.rb0000644000004100000410000000010512537123500022332 0ustar www-datawww-dataclass Specinfra::Command::Linux::Base < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/darwin/0000755000004100000410000000000012537123500021224 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/darwin/base/0000755000004100000410000000000012537123500022136 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/darwin/base/user.rb0000644000004100000410000000102212537123500023434 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 end end specinfra-2.35.1/lib/specinfra/command/darwin/base/file.rb0000644000004100000410000000225612537123500023407 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_owner_user(file) "stat -f %Su #{escape(file)}" end def get_owner_group(file) "stat -f %Sg #{escape(file)}" end end end specinfra-2.35.1/lib/specinfra/command/darwin/base/host.rb0000644000004100000410000000055512537123500023445 0ustar www-datawww-dataclass Specinfra::Command::Darwin::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 end end specinfra-2.35.1/lib/specinfra/command/darwin/base/package.rb0000644000004100000410000000275512537123500024067 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(package) if version cmd = "/usr/local/bin/brew info #{escaped_package} | grep -E '^\/usr\/local\/Cellar\/#{escaped_package}\/#{escape(version)}'" else cmd = "/usr/local/bin/brew list -1 | 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(package) if version cmd = "/usr/local/bin/brew cask info #{escaped_package} | grep -E '^\/opt\/homebrew-cask\/Caskroom\/#{escaped_package}\/#{escape(version)}'" else cmd = "/usr/local/bin/brew cask list -1 | 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 = "/usr/local/bin/brew install #{option} '#{package}'" end def get_version(package, opts=nil) "basename $((/usr/local/bin/brew info #{package} | grep '\*$' || /usr/local/bin/brew info #{package} | grep '^/usr/local/Cellar' | tail -1) | awk '{print $1}')" end end end specinfra-2.35.1/lib/specinfra/command/darwin/base/port.rb0000644000004100000410000000037012537123500023447 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base::Port < Specinfra::Command::Base::Port class << self def check_is_listening(port, options={}) regexp = ":#{port} " "lsof -nP -iTCP -sTCP:LISTEN | grep -- #{escape(regexp)}" end end end specinfra-2.35.1/lib/specinfra/command/darwin/base/service.rb0000644000004100000410000000050412537123500024122 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_running(service) "launchctl list | grep #{escape(service)} | grep -E '^[0-9]+'" end end end specinfra-2.35.1/lib/specinfra/command/darwin/base.rb0000644000004100000410000000010612537123500022460 0ustar www-datawww-dataclass Specinfra::Command::Darwin::Base < Specinfra::Command::Base end specinfra-2.35.1/lib/specinfra/command/gentoo/0000755000004100000410000000000012537123500021233 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/gentoo/base/0000755000004100000410000000000012537123500022145 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/gentoo/base/package.rb0000644000004100000410000000037112537123500024066 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 end end specinfra-2.35.1/lib/specinfra/command/gentoo/base/service.rb0000644000004100000410000000056012537123500024133 0ustar www-datawww-dataclass Specinfra::Command::Gentoo::Base::Service < Specinfra::Command::Linux::Base::Service class << self def check_is_enabled(service, level=3) regexp = /\s*#{service}\s*\|\s*(boot|default)/ "rc-update show | grep -- #{escape(regexp)}" end def check_is_running(service) "/etc/init.d/#{escape(service)} status" end end end specinfra-2.35.1/lib/specinfra/command/gentoo/base.rb0000644000004100000410000000011512537123500022467 0ustar www-datawww-dataclass Specinfra::Command::Gentoo::Base < Specinfra::Command::Linux::Base end specinfra-2.35.1/lib/specinfra/command/ubuntu/0000755000004100000410000000000012537123500021262 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/ubuntu/base/0000755000004100000410000000000012537123500022174 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/ubuntu/base/ppa.rb0000644000004100000410000000100412537123500023274 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.35.1/lib/specinfra/command/ubuntu/base/service.rb0000644000004100000410000000040012537123500024153 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 | grep 'running'" end end end specinfra-2.35.1/lib/specinfra/command/ubuntu/base.rb0000644000004100000410000000011612537123500022517 0ustar www-datawww-dataclass Specinfra::Command::Ubuntu::Base < Specinfra::Command::Debian::Base end specinfra-2.35.1/lib/specinfra/command/aix.rb0000644000004100000410000000004312537123500021043 0ustar www-datawww-dataclass Specinfra::Command::Aix; end specinfra-2.35.1/lib/specinfra/command/gentoo.rb0000644000004100000410000000004612537123500021560 0ustar www-datawww-dataclass Specinfra::Command::Gentoo; end specinfra-2.35.1/lib/specinfra/command/base.rb0000644000004100000410000000055212537123500021201 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.35.1/lib/specinfra/command/windows.rb0000644000004100000410000000004712537123500021760 0ustar www-datawww-dataclass Specinfra::Command::Windows; end specinfra-2.35.1/lib/specinfra/command/redhat/0000755000004100000410000000000012537123500021207 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/redhat/base/0000755000004100000410000000000012537123500022121 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/redhat/base/yumrepo.rb0000644000004100000410000000053112537123500024145 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Yumrepo < Specinfra::Command::Linux::Base::Yumrepo class << self def check_exists(repository) "yum repolist all -C | grep ^#{escape(repository)}" end def check_is_enabled(repository) "yum repolist enabled -C | grep -qs \"^[\\!\\*]\\?#{escape(repository)}\"" end end end specinfra-2.35.1/lib/specinfra/command/redhat/base/iptables.rb0000644000004100000410000000015212537123500024247 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Iptables < Specinfra::Command::Linux::Base::Iptables end specinfra-2.35.1/lib/specinfra/command/redhat/base/file.rb0000644000004100000410000000041112537123500023361 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::File < Specinfra::Command::Linux::Base::File class << self def check_is_accessible_by_user(file, user, access) # Redhat-specific "runuser -s /bin/sh -c \"test -#{access} #{file}\" #{user}" end end end specinfra-2.35.1/lib/specinfra/command/redhat/base/package.rb0000644000004100000410000000146112537123500024043 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 cmd = "#{cmd} | grep -w -- #{escape(package)}-#{escape(version)}" end cmd end alias :check_is_installed_by_rpm :check_is_installed def get_version(package, opts=nil) "rpm -qi #{package} | grep Version | awk '{print $3}'" end def install(package, version=nil, option='') if version full_package = "#{package}-#{version}" else full_package = package end cmd = "yum -y #{option} install #{full_package}" end def remove(package, option='') "yum -y #{option} remove #{package}" end end end specinfra-2.35.1/lib/specinfra/command/redhat/base/service.rb0000644000004100000410000000013712537123500024107 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base::Service < Specinfra::Command::Linux::Base::Service end specinfra-2.35.1/lib/specinfra/command/redhat/v7.rb0000644000004100000410000000011512537123500022065 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V7 < Specinfra::Command::Redhat::Base end specinfra-2.35.1/lib/specinfra/command/redhat/v5/0000755000004100000410000000000012537123500021541 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/redhat/v5/iptables.rb0000644000004100000410000000045712537123500023677 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.35.1/lib/specinfra/command/redhat/v5.rb0000644000004100000410000000011512537123500022063 0ustar www-datawww-dataclass Specinfra::Command::Redhat::V5 < Specinfra::Command::Redhat::Base end specinfra-2.35.1/lib/specinfra/command/redhat/base.rb0000644000004100000410000000011512537123500022443 0ustar www-datawww-dataclass Specinfra::Command::Redhat::Base < Specinfra::Command::Linux::Base end specinfra-2.35.1/lib/specinfra/command/redhat/v7/0000755000004100000410000000000012537123500021543 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/redhat/v7/service.rb0000644000004100000410000000024412537123500023530 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.35.1/lib/specinfra/command/alpine/0000755000004100000410000000000012537123500021210 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/alpine/base/0000755000004100000410000000000012537123500022122 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/alpine/base/process.rb0000644000004100000410000000115212537123500024124 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.35.1/lib/specinfra/command/alpine/base/package.rb0000644000004100000410000000113312537123500024040 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version = nil) pkg = [escape(package), version].compact.join('=') "apk info -qe #{pkg}" 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 $1; }' | cut -d- -f2-" end end end specinfra-2.35.1/lib/specinfra/command/alpine/base.rb0000644000004100000410000000011512537123500022444 0ustar www-datawww-dataclass Specinfra::Command::Alpine::Base < Specinfra::Command::Linux::Base end specinfra-2.35.1/lib/specinfra/command/esxi/0000755000004100000410000000000012537123500020710 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/esxi/base/0000755000004100000410000000000012537123500021622 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/command/esxi/base/package.rb0000644000004100000410000000034712537123500023546 0ustar www-datawww-dataclass Specinfra::Command::Esxi::Base::Package < Specinfra::Command::Linux::Base::Package class << self def check_is_installed(package, version=nil) "esxcli software vib list | grep #{escape(package)}" end end end specinfra-2.35.1/lib/specinfra/command/esxi/base.rb0000644000004100000410000000011312537123500022142 0ustar www-datawww-dataclass Specinfra::Command::Esxi::Base < Specinfra::Command::Linux::Base end specinfra-2.35.1/lib/specinfra/command/coreos.rb0000644000004100000410000000004612537123500021557 0ustar www-datawww-dataclass Specinfra::Command::Coreos; end specinfra-2.35.1/lib/specinfra/command/suse.rb0000644000004100000410000000004412537123500021242 0ustar www-datawww-dataclass Specinfra::Command::Suse; end specinfra-2.35.1/lib/specinfra/command/cumulus.rb0000644000004100000410000000007112537123500021760 0ustar www-datawww-dataclass Specinfra::Command::Cumulusnetworks; end specinfra-2.35.1/lib/specinfra/command/arch.rb0000644000004100000410000000004412537123500021200 0ustar www-datawww-dataclass Specinfra::Command::Arch; end specinfra-2.35.1/lib/specinfra/command/nixos.rb0000644000004100000410000000004512537123500021424 0ustar www-datawww-dataclass Specinfra::Command::Nixos; end specinfra-2.35.1/lib/specinfra/command/darwin.rb0000644000004100000410000000004612537123500021551 0ustar www-datawww-dataclass Specinfra::Command::Darwin; end specinfra-2.35.1/lib/specinfra/command/esxi.rb0000644000004100000410000000004412537123500021233 0ustar www-datawww-dataclass Specinfra::Command::Esxi; end specinfra-2.35.1/lib/specinfra/properties.rb0000644000004100000410000000035312537123500021044 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.35.1/lib/specinfra/processor.rb0000644000004100000410000001600312537123500020666 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". return false if ret.stdout =~ /stopped\/waiting/ # If the service is not registered, check by ps command if ret.exit_status == 1 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 = { :device => mount[0], :type => mount[4] } mount[5].gsub(/\(|\)/, '').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 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 else next unless expected_attr[:interface] == groups[5] end 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.35.1/lib/specinfra/version.rb0000644000004100000410000000005212537123500020331 0ustar www-datawww-datamodule Specinfra VERSION = "2.35.1" end specinfra-2.35.1/lib/specinfra/core.rb0000644000004100000410000000062212537123500017577 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.35.1/lib/specinfra/runner.rb0000644000004100000410000000145612537123500020166 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.35.1/lib/specinfra/command_result.rb0000644000004100000410000000114312537123500021662 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.35.1/lib/specinfra/helper/0000755000004100000410000000000012537123500017601 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/helper/configuration.rb0000644000004100000410000000237412537123500023003 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 Specinfra::Configuration.instance_variable_set("@#{c}", value) end end end end end specinfra-2.35.1/lib/specinfra/helper/detect_os.rb0000644000004100000410000000175012537123500022102 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/coreos' require 'specinfra/helper/detect_os/darwin' require 'specinfra/helper/detect_os/debian' require 'specinfra/helper/detect_os/esxi' require 'specinfra/helper/detect_os/freebsd' require 'specinfra/helper/detect_os/gentoo' require 'specinfra/helper/detect_os/nixos' require 'specinfra/helper/detect_os/openbsd' require 'specinfra/helper/detect_os/plamo' require 'specinfra/helper/detect_os/redhat' require 'specinfra/helper/detect_os/solaris' require 'specinfra/helper/detect_os/suse' specinfra-2.35.1/lib/specinfra/helper/set.rb0000644000004100000410000000023612537123500020722 0ustar www-datawww-datamodule Specinfra module Helper module Set def set(param, *value) Specinfra.configuration.send(param, *value) end end end end specinfra-2.35.1/lib/specinfra/helper/docker.rb0000644000004100000410000000042012537123500021371 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.35.1/lib/specinfra/helper/detect_os/0000755000004100000410000000000012537123500021552 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/helper/detect_os/redhat.rb0000644000004100000410000000144212537123500023347 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? { :family => 'redhat', :release => nil } # Amazon Linux end end end specinfra-2.35.1/lib/specinfra/helper/detect_os/debian.rb0000644000004100000410000000167412537123500023331 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Debian < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/debian_version').success? distro = nil release = nil lsb_release = run_command("lsb_release -ir") if 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 lsb_release = run_command("cat /etc/lsb-release") if 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 end end distro ||= 'debian' release ||= nil { :family => distro.gsub(/[^[:alnum:]]/, '').downcase, :release => release } end end end specinfra-2.35.1/lib/specinfra/helper/detect_os/openbsd.rb0000644000004100000410000000031412537123500023527 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Openbsd < Specinfra::Helper::DetectOs def detect if run_command('uname -s').stdout =~ /OpenBSD/i { :family => 'openbsd', :release => nil } end end end specinfra-2.35.1/lib/specinfra/helper/detect_os/plamo.rb0000644000004100000410000000031512537123500023206 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.35.1/lib/specinfra/helper/detect_os/freebsd.rb0000644000004100000410000000050212537123500023506 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 =~ /10./ { :family => 'freebsd', :release => 10 } else { :family => 'freebsd', :release => nil } end end end end specinfra-2.35.1/lib/specinfra/helper/detect_os/solaris.rb0000644000004100000410000000106112537123500023551 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 SmartOS /etc/release').success? { :family => 'smartos', :release => nil } else { :family => 'solaris', :release => nil } end end end end specinfra-2.35.1/lib/specinfra/helper/detect_os/alpine.rb0000644000004100000410000000041612537123500023350 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.35.1/lib/specinfra/helper/detect_os/aix.rb0000644000004100000410000000030012537123500022651 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Aix < Specinfra::Helper::DetectOs def detect if run_command('uname -s').stdout =~ /AIX/i { :family => 'aix', :release => nil } end end end specinfra-2.35.1/lib/specinfra/helper/detect_os/gentoo.rb0000644000004100000410000000031412537123500023370 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.35.1/lib/specinfra/helper/detect_os/coreos.rb0000644000004100000410000000117612537123500023376 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 = line.split('=').last.strip if line =~ /^DISTRIB_ID=/ 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.35.1/lib/specinfra/helper/detect_os/suse.rb0000644000004100000410000000071712537123500023063 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Suse < Specinfra::Helper::DetectOs def detect if run_command('ls /etc/SuSE-release').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.35.1/lib/specinfra/helper/detect_os/arch.rb0000644000004100000410000000030612537123500023013 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.35.1/lib/specinfra/helper/detect_os/nixos.rb0000644000004100000410000000032112537123500023233 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.35.1/lib/specinfra/helper/detect_os/darwin.rb0000644000004100000410000000031112537123500023356 0ustar www-datawww-dataclass Specinfra::Helper::DetectOs::Darwin < Specinfra::Helper::DetectOs def detect if run_command('uname -s').stdout =~ /Darwin/i { :family => 'darwin', :release => nil } end end end specinfra-2.35.1/lib/specinfra/helper/detect_os/esxi.rb0000644000004100000410000000042712537123500023052 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.35.1/lib/specinfra/helper/properties.rb0000644000004100000410000000042712537123500022325 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.35.1/lib/specinfra/helper/lxc.rb0000644000004100000410000000041712537123500020716 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.35.1/lib/specinfra/helper/host_inventory.rb0000644000004100000410000000027612537123500023225 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.35.1/lib/specinfra/helper/os.rb0000644000004100000410000000157212537123500020554 0ustar www-datawww-datarequire 'specinfra/helper/detect_os' module Specinfra module Helper module Os def os property[:os] = {} if ! property[:os] if ! property[:os].include?(:family) property[:os] = detect_os end property[:os] end private def detect_os return Specinfra.configuration.os if Specinfra.configuration.os backend = Specinfra.configuration.backend if backend == :cmd || backend == :winrm return { :family => 'windows', :release => nil, :arch => nil } end Specinfra::Helper::DetectOs.subclasses.each do |c| res = c.detect if res res[:arch] ||= Specinfra.backend.run_command('uname -m').stdout.strip return res end end raise NotImplementedError, "Specinfra failed os detection." end end end end specinfra-2.35.1/lib/specinfra/host_inventory.rb0000644000004100000410000000235312537123500021744 0ustar www-datawww-datamodule Specinfra class HostInventory KEYS = %w{ memory ec2 hostname domain fqdn platform platform_version filesystem cpu virtualization kernel } 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.35.1/lib/specinfra/ec2_metadata.rb0000644000004100000410000000344012537123500021161 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 @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.35.1/lib/specinfra/backend.rb0000644000004100000410000000067612537123500020247 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/lxc' require 'specinfra/backend/winrm' require 'specinfra/backend/shell_script' require 'specinfra/backend/dockerfile' require 'specinfra/backend/telnet' specinfra-2.35.1/lib/specinfra/backend/0000755000004100000410000000000012537123500017711 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/backend/ssh.rb0000644000004100000410000001123712537123500021037 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 Net::SSH.start( get_config(:host), get_config(:ssh_options)[:user], get_config(:ssh_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.' elsif data.match /^#{prompt}/ channel.send_data "#{get_config(:sudo_password)}\n" else stdout_data += data 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 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.35.1/lib/specinfra/backend/docker.rb0000644000004100000410000000554012537123500021511 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, proc { cleanup_container }) elsif container = get_config(:docker_container) @container = ::Docker::Container.get(container) else fail 'Please specify docker_image or docker_container.' end end def run_command(cmd, opts={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) docker_run!(cmd) end def build_command(cmd) cmd end def add_pre_command(cmd) cmd end def send_file(from, to) if @base_image.nil? fail 'Cannot call send_file without docker_image.' end @images << current_image.insert_local('localPath' => from, 'outputPath' => to) cleanup_container create_and_start_container 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? 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 end def cleanup_container @container.stop @container.delete end def current_image @images.last || @base_image end def docker_run!(cmd, opts={}) stdout, stderr, status = @container.exec(['/bin/sh', '-c', cmd]) 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 end end end specinfra-2.35.1/lib/specinfra/backend/exec.rb0000644000004100000410000000374012537123500021166 0ustar www-datawww-datarequire 'singleton' require 'fileutils' require 'shellwords' module Specinfra module Backend class Exec < Base def run_command(cmd, opts={}) cmd = build_command(cmd) cmd = add_pre_command(cmd) stdout = with_env do `#{build_command(cmd)} 2>&1` end # In ruby 1.9, it is possible to use Open3.capture3, but not in 1.8 # stdout, stderr, status = Open3.capture3(cmd) if @example @example.metadata[:command] = cmd @example.metadata[:stdout] = stdout end CommandResult.new :stdout => stdout, :exit_status => $?.exitstatus 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) cmd = "#{shell.shellescape} -c #{cmd.to_s.shellescape}" path = get_config(:path) if path cmd = %Q{env PATH="#{path}" #{cmd}} end cmd end private 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.35.1/lib/specinfra/backend/shell_script.rb0000644000004100000410000000100012537123500022720 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.35.1/lib/specinfra/backend/lxc.rb0000644000004100000410000000201212537123500021017 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.35.1/lib/specinfra/backend/winrm.rb0000644000004100000410000000146712537123500021402 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) result = winrm.powershell(script) stdout, stderr = [:stdout, :stderr].map do |s| result[:data].select {|item| item.key? s}.map {|item| item[s]}.join end result[:exitcode] = 1 if result[: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 => result[:exitcode] end end end end specinfra-2.35.1/lib/specinfra/backend/cmd.rb0000644000004100000410000000400312537123500020776 0ustar www-datawww-datarequire 'open3' module Specinfra module Backend class Cmd < Base include PowerShell::ScriptHelper def os_info { :family => 'windows', :release => nil, :arch => nil } end def run_command(cmd, opts={}) script = create_script(cmd) result = execute_script %Q{#{powershell} -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 = @example.metadata[: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.exists?(exe) } || 'powershell' end end end end specinfra-2.35.1/lib/specinfra/backend/telnet.rb0000644000004100000410000000506612537123500021540 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.35.1/lib/specinfra/backend/dockerfile.rb0000644000004100000410000000124012537123500022342 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.35.1/lib/specinfra/backend/base.rb0000644000004100000410000000164712537123500021160 0ustar www-datawww-datarequire 'singleton' require 'specinfra/command_result' module Specinfra module Backend class Base def self.instance @instance ||= self.new end def initialize(config = {}) @config = config 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 end def command CommandFactory.new(os_info) end def host_inventory @inventory ||= HostInventory.new(self) end def set_example(e) @example = e end end end end specinfra-2.35.1/lib/specinfra/backend/powershell/0000755000004100000410000000000012537123500022075 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/backend/powershell/command.rb0000644000004100000410000000153512537123500024044 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.35.1/lib/specinfra/backend/powershell/script_helper.rb0000644000004100000410000000416312537123500025271 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 if (#{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.35.1/lib/specinfra/backend/powershell/support/0000755000004100000410000000000012537123500023611 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/backend/powershell/support/find_installed_hot_fix.ps10000644000004100000410000000052412537123500030736 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.35.1/lib/specinfra/backend/powershell/support/list_windows_features.ps10000644000004100000410000000364612537123500030672 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.35.1/lib/specinfra/backend/powershell/support/find_user.ps10000644000004100000410000000041012537123500026207 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.35.1/lib/specinfra/backend/powershell/support/find_usergroup.ps10000644000004100000410000000073512537123500027276 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.35.1/lib/specinfra/backend/powershell/support/crop_text.ps10000644000004100000410000000047112537123500026247 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.35.1/lib/specinfra/backend/powershell/support/find_installed_application.ps10000644000004100000410000000242412537123500031602 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.35.1/lib/specinfra/backend/powershell/support/find_group.ps10000644000004100000410000000040412537123500026370 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.35.1/lib/specinfra/backend/powershell/support/find_service.ps10000644000004100000410000000020512537123500026673 0ustar www-datawww-datafunction FindService { param($name) Get-WmiObject Win32_Service | Where-Object {$_.Name -eq $name -or $_.DisplayName -eq $name} }specinfra-2.35.1/lib/specinfra/backend/powershell/support/is_remote_port_listening.ps10000644000004100000410000000267112537123500031352 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.35.1/lib/specinfra/backend/powershell/support/is_port_listening.ps10000644000004100000410000000100212537123500027762 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" foreach ($ipaddress in $networkIPs) { $matchExpression = ("$ipaddress" + ":" + $portNumber) if ($protocol) { $matchExpression = ($protocol.toUpper() + "\s+$matchExpression") } if ($netstatOutput -match $matchExpression) { return $true } } $false } specinfra-2.35.1/lib/specinfra/backend/powershell/support/find_scheduled_task.ps10000644000004100000410000000020012537123500030210 0ustar www-datawww-datafunction FindScheduledTask { param($name) $task = schtasks /query /v /fo csv /TN "$name" | ConvertFrom-CSV return $task }specinfra-2.35.1/lib/specinfra/backend/powershell/support/check_file_access_rules.ps10000644000004100000410000000055612537123500031053 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.35.1/lib/specinfra/backend/powershell/support/find_iis_component.ps10000644000004100000410000000373212537123500030111 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.35.1/lib/specinfra/ext/0000755000004100000410000000000012537123500017122 5ustar www-datawww-dataspecinfra-2.35.1/lib/specinfra/ext/string.rb0000644000004100000410000000045612537123500020762 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.35.1/lib/specinfra/ext/class.rb0000644000004100000410000000022212537123500020550 0ustar www-datawww-dataclass Class def subclasses result = [] ObjectSpace.each_object(Class) do |k| result << k if k < self end result end end specinfra-2.35.1/metadata.yml0000644000004100000410000004320412537123500016110 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: specinfra version: !ruby/object:Gem::Version version: 2.35.1 platform: ruby authors: - Gosuke Miyashita autorequire: bindir: bin cert_chain: [] date: 2015-06-10 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: net-ssh requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: net-scp requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: bundler requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 10.1.1 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 10.1.1 - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rspec-its requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' description: Common layer for serverspec and itamae email: - gosukenator@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - ".gitignore" - ".gitmodules" - ".travis.yml" - Gemfile - Guardfile - LICENSE.txt - README.md - Rakefile - appveyor.yml - examples/multiple_backends.rb - lib/specinfra.rb - lib/specinfra/backend.rb - lib/specinfra/backend/base.rb - lib/specinfra/backend/cmd.rb - lib/specinfra/backend/docker.rb - lib/specinfra/backend/dockerfile.rb - lib/specinfra/backend/exec.rb - lib/specinfra/backend/lxc.rb - lib/specinfra/backend/powershell/command.rb - lib/specinfra/backend/powershell/script_helper.rb - lib/specinfra/backend/powershell/support/check_file_access_rules.ps1 - lib/specinfra/backend/powershell/support/crop_text.ps1 - lib/specinfra/backend/powershell/support/find_group.ps1 - lib/specinfra/backend/powershell/support/find_iis_component.ps1 - lib/specinfra/backend/powershell/support/find_installed_application.ps1 - lib/specinfra/backend/powershell/support/find_installed_hot_fix.ps1 - lib/specinfra/backend/powershell/support/find_scheduled_task.ps1 - lib/specinfra/backend/powershell/support/find_service.ps1 - lib/specinfra/backend/powershell/support/find_user.ps1 - lib/specinfra/backend/powershell/support/find_usergroup.ps1 - lib/specinfra/backend/powershell/support/is_port_listening.ps1 - lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1 - lib/specinfra/backend/powershell/support/list_windows_features.ps1 - lib/specinfra/backend/shell_script.rb - lib/specinfra/backend/ssh.rb - lib/specinfra/backend/telnet.rb - lib/specinfra/backend/winrm.rb - lib/specinfra/command.rb - lib/specinfra/command/aix.rb - lib/specinfra/command/aix/base.rb - lib/specinfra/command/aix/base/file.rb - lib/specinfra/command/aix/base/group.rb - lib/specinfra/command/aix/base/host.rb - lib/specinfra/command/aix/base/package.rb - lib/specinfra/command/aix/base/port.rb - lib/specinfra/command/aix/base/service.rb - lib/specinfra/command/aix/base/user.rb - lib/specinfra/command/alpine.rb - lib/specinfra/command/alpine/base.rb - lib/specinfra/command/alpine/base/package.rb - lib/specinfra/command/alpine/base/process.rb - lib/specinfra/command/arch.rb - lib/specinfra/command/arch/base.rb - lib/specinfra/command/arch/base/file.rb - lib/specinfra/command/arch/base/package.rb - lib/specinfra/command/arch/base/service.rb - lib/specinfra/command/base.rb - lib/specinfra/command/base/bond.rb - lib/specinfra/command/base/bridge.rb - lib/specinfra/command/base/cron.rb - lib/specinfra/command/base/file.rb - lib/specinfra/command/base/fstab.rb - lib/specinfra/command/base/group.rb - lib/specinfra/command/base/host.rb - lib/specinfra/command/base/interface.rb - lib/specinfra/command/base/inventory.rb - lib/specinfra/command/base/ip6tables.rb - lib/specinfra/command/base/ipfilter.rb - lib/specinfra/command/base/ipnat.rb - lib/specinfra/command/base/iptables.rb - lib/specinfra/command/base/kernel_module.rb - lib/specinfra/command/base/localhost.rb - lib/specinfra/command/base/lxc_container.rb - lib/specinfra/command/base/mail_alias.rb - lib/specinfra/command/base/package.rb - lib/specinfra/command/base/port.rb - lib/specinfra/command/base/ppa.rb - lib/specinfra/command/base/process.rb - lib/specinfra/command/base/routing_table.rb - lib/specinfra/command/base/selinux.rb - lib/specinfra/command/base/selinux_module.rb - lib/specinfra/command/base/service.rb - lib/specinfra/command/base/user.rb - lib/specinfra/command/base/yumrepo.rb - lib/specinfra/command/base/zfs.rb - lib/specinfra/command/coreos.rb - lib/specinfra/command/coreos/base.rb - lib/specinfra/command/coreos/base/service.rb - lib/specinfra/command/cumulus.rb - lib/specinfra/command/cumulus/base.rb - lib/specinfra/command/cumulus/base/ppa.rb - lib/specinfra/command/cumulus/base/service.rb - lib/specinfra/command/darwin.rb - lib/specinfra/command/darwin/base.rb - lib/specinfra/command/darwin/base/file.rb - lib/specinfra/command/darwin/base/host.rb - lib/specinfra/command/darwin/base/package.rb - lib/specinfra/command/darwin/base/port.rb - lib/specinfra/command/darwin/base/service.rb - lib/specinfra/command/darwin/base/user.rb - lib/specinfra/command/debian.rb - lib/specinfra/command/debian/base.rb - lib/specinfra/command/debian/base/package.rb - lib/specinfra/command/debian/base/ppa.rb - lib/specinfra/command/debian/base/service.rb - lib/specinfra/command/debian/v8.rb - lib/specinfra/command/debian/v8/service.rb - lib/specinfra/command/esxi.rb - lib/specinfra/command/esxi/base.rb - lib/specinfra/command/esxi/base/package.rb - lib/specinfra/command/fedora.rb - lib/specinfra/command/fedora/base.rb - lib/specinfra/command/fedora/base/service.rb - lib/specinfra/command/fedora/v15.rb - lib/specinfra/command/fedora/v15/service.rb - lib/specinfra/command/freebsd.rb - lib/specinfra/command/freebsd/base.rb - lib/specinfra/command/freebsd/base/file.rb - lib/specinfra/command/freebsd/base/package.rb - lib/specinfra/command/freebsd/base/port.rb - lib/specinfra/command/freebsd/base/service.rb - lib/specinfra/command/freebsd/v10.rb - lib/specinfra/command/freebsd/v10/package.rb - lib/specinfra/command/gentoo.rb - lib/specinfra/command/gentoo/base.rb - lib/specinfra/command/gentoo/base/package.rb - lib/specinfra/command/gentoo/base/service.rb - lib/specinfra/command/linux.rb - lib/specinfra/command/linux/base.rb - lib/specinfra/command/linux/base/bond.rb - lib/specinfra/command/linux/base/bridge.rb - lib/specinfra/command/linux/base/file.rb - lib/specinfra/command/linux/base/fstab.rb - lib/specinfra/command/linux/base/interface.rb - lib/specinfra/command/linux/base/inventory.rb - lib/specinfra/command/linux/base/ip6tables.rb - lib/specinfra/command/linux/base/iptables.rb - lib/specinfra/command/linux/base/kernel_module.rb - lib/specinfra/command/linux/base/lxc_container.rb - lib/specinfra/command/linux/base/package.rb - lib/specinfra/command/linux/base/ppa.rb - lib/specinfra/command/linux/base/selinux.rb - lib/specinfra/command/linux/base/selinux_module.rb - lib/specinfra/command/linux/base/service.rb - lib/specinfra/command/linux/base/yumrepo.rb - lib/specinfra/command/linux/base/zfs.rb - lib/specinfra/command/module.rb - lib/specinfra/command/module/service/daemontools.rb - lib/specinfra/command/module/service/delegator.rb - lib/specinfra/command/module/service/god.rb - lib/specinfra/command/module/service/init.rb - lib/specinfra/command/module/service/monit.rb - lib/specinfra/command/module/service/runit.rb - lib/specinfra/command/module/service/supervisor.rb - lib/specinfra/command/module/service/systemd.rb - lib/specinfra/command/module/service/upstart.rb - lib/specinfra/command/module/systemd.rb - lib/specinfra/command/module/zfs.rb - lib/specinfra/command/nixos.rb - lib/specinfra/command/nixos/base.rb - lib/specinfra/command/nixos/base/package.rb - lib/specinfra/command/nixos/base/service.rb - lib/specinfra/command/openbsd.rb - lib/specinfra/command/openbsd/base.rb - lib/specinfra/command/openbsd/base/bond.rb - lib/specinfra/command/openbsd/base/bridge.rb - lib/specinfra/command/openbsd/base/file.rb - lib/specinfra/command/openbsd/base/fstab.rb - lib/specinfra/command/openbsd/base/interface.rb - lib/specinfra/command/openbsd/base/mail_alias.rb - lib/specinfra/command/openbsd/base/package.rb - lib/specinfra/command/openbsd/base/port.rb - lib/specinfra/command/openbsd/base/routing_table.rb - lib/specinfra/command/openbsd/base/service.rb - lib/specinfra/command/openbsd/base/user.rb - lib/specinfra/command/opensuse.rb - lib/specinfra/command/opensuse/base.rb - lib/specinfra/command/opensuse/base/service.rb - lib/specinfra/command/plamo.rb - lib/specinfra/command/plamo/base.rb - lib/specinfra/command/plamo/base/package.rb - lib/specinfra/command/plamo/base/service.rb - lib/specinfra/command/redhat.rb - lib/specinfra/command/redhat/base.rb - lib/specinfra/command/redhat/base/file.rb - lib/specinfra/command/redhat/base/iptables.rb - lib/specinfra/command/redhat/base/package.rb - lib/specinfra/command/redhat/base/service.rb - lib/specinfra/command/redhat/base/yumrepo.rb - lib/specinfra/command/redhat/v5.rb - lib/specinfra/command/redhat/v5/iptables.rb - lib/specinfra/command/redhat/v7.rb - lib/specinfra/command/redhat/v7/service.rb - lib/specinfra/command/smartos.rb - lib/specinfra/command/smartos/base.rb - lib/specinfra/command/smartos/base/file.rb - lib/specinfra/command/smartos/base/package.rb - lib/specinfra/command/smartos/base/service.rb - lib/specinfra/command/solaris.rb - lib/specinfra/command/solaris/base.rb - lib/specinfra/command/solaris/base/cron.rb - lib/specinfra/command/solaris/base/file.rb - lib/specinfra/command/solaris/base/group.rb - lib/specinfra/command/solaris/base/host.rb - lib/specinfra/command/solaris/base/ipfilter.rb - lib/specinfra/command/solaris/base/ipnat.rb - lib/specinfra/command/solaris/base/package.rb - lib/specinfra/command/solaris/base/port.rb - lib/specinfra/command/solaris/base/service.rb - lib/specinfra/command/solaris/base/user.rb - lib/specinfra/command/solaris/base/zfs.rb - lib/specinfra/command/solaris/v10.rb - lib/specinfra/command/solaris/v10/file.rb - lib/specinfra/command/solaris/v10/group.rb - lib/specinfra/command/solaris/v10/host.rb - lib/specinfra/command/solaris/v10/package.rb - lib/specinfra/command/solaris/v10/user.rb - lib/specinfra/command/suse.rb - lib/specinfra/command/suse/base.rb - lib/specinfra/command/suse/base/package.rb - lib/specinfra/command/suse/base/service.rb - lib/specinfra/command/ubuntu.rb - lib/specinfra/command/ubuntu/base.rb - lib/specinfra/command/ubuntu/base/ppa.rb - lib/specinfra/command/ubuntu/base/service.rb - lib/specinfra/command/windows.rb - lib/specinfra/command/windows/base.rb - lib/specinfra/command/windows/base/feature.rb - lib/specinfra/command/windows/base/file.rb - lib/specinfra/command/windows/base/group.rb - lib/specinfra/command/windows/base/host.rb - lib/specinfra/command/windows/base/hot_fix.rb - lib/specinfra/command/windows/base/iis_app_pool.rb - lib/specinfra/command/windows/base/iis_website.rb - lib/specinfra/command/windows/base/package.rb - lib/specinfra/command/windows/base/port.rb - lib/specinfra/command/windows/base/process.rb - lib/specinfra/command/windows/base/registry_key.rb - lib/specinfra/command/windows/base/scheduled_task.rb - lib/specinfra/command/windows/base/service.rb - lib/specinfra/command/windows/base/user.rb - lib/specinfra/command_factory.rb - lib/specinfra/command_result.rb - lib/specinfra/configuration.rb - lib/specinfra/core.rb - lib/specinfra/ec2_metadata.rb - lib/specinfra/ext.rb - lib/specinfra/ext/class.rb - lib/specinfra/ext/string.rb - lib/specinfra/helper.rb - lib/specinfra/helper/configuration.rb - lib/specinfra/helper/detect_os.rb - lib/specinfra/helper/detect_os/aix.rb - lib/specinfra/helper/detect_os/alpine.rb - lib/specinfra/helper/detect_os/arch.rb - lib/specinfra/helper/detect_os/coreos.rb - lib/specinfra/helper/detect_os/darwin.rb - lib/specinfra/helper/detect_os/debian.rb - lib/specinfra/helper/detect_os/esxi.rb - lib/specinfra/helper/detect_os/freebsd.rb - lib/specinfra/helper/detect_os/gentoo.rb - lib/specinfra/helper/detect_os/nixos.rb - lib/specinfra/helper/detect_os/openbsd.rb - lib/specinfra/helper/detect_os/plamo.rb - lib/specinfra/helper/detect_os/redhat.rb - lib/specinfra/helper/detect_os/solaris.rb - lib/specinfra/helper/detect_os/suse.rb - lib/specinfra/helper/docker.rb - lib/specinfra/helper/host_inventory.rb - lib/specinfra/helper/lxc.rb - lib/specinfra/helper/os.rb - lib/specinfra/helper/properties.rb - lib/specinfra/helper/set.rb - lib/specinfra/host_inventory.rb - lib/specinfra/host_inventory/base.rb - lib/specinfra/host_inventory/cpu.rb - lib/specinfra/host_inventory/domain.rb - lib/specinfra/host_inventory/ec2.rb - lib/specinfra/host_inventory/filesystem.rb - lib/specinfra/host_inventory/fqdn.rb - lib/specinfra/host_inventory/hostname.rb - lib/specinfra/host_inventory/kernel.rb - lib/specinfra/host_inventory/memory.rb - lib/specinfra/host_inventory/platform.rb - lib/specinfra/host_inventory/platform_version.rb - lib/specinfra/host_inventory/virtualization.rb - lib/specinfra/processor.rb - lib/specinfra/properties.rb - lib/specinfra/runner.rb - lib/specinfra/version.rb - spec/backend/exec/build_command_spec.rb - spec/backend/exec/env_spec.rb - spec/backend/ssh/build_command_spec.rb - spec/command/base/file_spec.rb - spec/command/base/group_spec.rb - spec/command/base/localhost_spec.rb - spec/command/base/package_spec.rb - spec/command/base/user_spec.rb - spec/command/darwin/file_spec.rb - spec/command/darwin/user_spec.rb - spec/command/debian/service_spec.rb - spec/command/esxi/package_spec.rb - spec/command/factory_spec.rb - spec/command/freebsd/file_spec.rb - spec/command/linux/bond_spec.rb - spec/command/linux/bridge_spec.rb - spec/command/linux/file_spec.rb - spec/command/linux/interface_spec.rb - spec/command/linux/inventory_spec.rb - spec/command/linux/ip6tables_spec.rb - spec/command/linux/selinux_module_spec.rb - spec/command/linux/selinux_spec.rb - spec/command/module/service/daemontools_spec.rb - spec/command/module/service/init_spec.rb - spec/command/module/service/systemd_spec.rb - spec/command/module/systemd_spec.rb - spec/command/module/zfs_spec.rb - spec/command/redhat/interface_spec.rb - spec/command/redhat/package_spec.rb - spec/command/redhat/service_spec.rb - spec/command/redhat7/service_spec.rb - spec/command/ubuntu/ppa_spec.rb - spec/command/windows/registry_key_spec.rb - spec/configuration_spec.rb - spec/helper/detect_os/esxi_spec.rb - spec/helper/os_spec.rb - spec/helper/properties_spec.rb - spec/helper/set_spec.rb - spec/host_inventory/cpu_spec.rb - spec/spec_helper.rb - specinfra.gemspec homepage: '' licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.2.2 signing_key: specification_version: 4 summary: Common layer for serverspec and itamae test_files: - spec/backend/exec/build_command_spec.rb - spec/backend/exec/env_spec.rb - spec/backend/ssh/build_command_spec.rb - spec/command/base/file_spec.rb - spec/command/base/group_spec.rb - spec/command/base/localhost_spec.rb - spec/command/base/package_spec.rb - spec/command/base/user_spec.rb - spec/command/darwin/file_spec.rb - spec/command/darwin/user_spec.rb - spec/command/debian/service_spec.rb - spec/command/esxi/package_spec.rb - spec/command/factory_spec.rb - spec/command/freebsd/file_spec.rb - spec/command/linux/bond_spec.rb - spec/command/linux/bridge_spec.rb - spec/command/linux/file_spec.rb - spec/command/linux/interface_spec.rb - spec/command/linux/inventory_spec.rb - spec/command/linux/ip6tables_spec.rb - spec/command/linux/selinux_module_spec.rb - spec/command/linux/selinux_spec.rb - spec/command/module/service/daemontools_spec.rb - spec/command/module/service/init_spec.rb - spec/command/module/service/systemd_spec.rb - spec/command/module/systemd_spec.rb - spec/command/module/zfs_spec.rb - spec/command/redhat/interface_spec.rb - spec/command/redhat/package_spec.rb - spec/command/redhat/service_spec.rb - spec/command/redhat7/service_spec.rb - spec/command/ubuntu/ppa_spec.rb - spec/command/windows/registry_key_spec.rb - spec/configuration_spec.rb - spec/helper/detect_os/esxi_spec.rb - spec/helper/os_spec.rb - spec/helper/properties_spec.rb - spec/helper/set_spec.rb - spec/host_inventory/cpu_spec.rb - spec/spec_helper.rb specinfra-2.35.1/specinfra.gemspec0000644000004100000410000000206112537123500017120 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 = "" spec.license = "MIT" spec.files = `git ls-files`.split($/) spec.files.delete('wercker.yml') spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] spec.add_runtime_dependency "net-ssh" spec.add_runtime_dependency "net-scp" spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "rake", "~> 10.1.1" spec.add_development_dependency "rspec" spec.add_development_dependency "rspec-its" end specinfra-2.35.1/.gitignore0000644000004100000410000000030312537123500015566 0ustar www-datawww-data*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp .idea/ .ruby-gemset .ruby-version .rvmrc specinfra-2.35.1/README.md0000644000004100000410000000076712537123500015073 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 ## Usage TODO: Write usage instructions here ## 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 specinfra-2.35.1/.gitmodules0000644000004100000410000000017512537123500015762 0ustar www-datawww-data[submodule "integration-test"] path = integration-test url = https://github.com/serverspec/serverspec-integration-test.git specinfra-2.35.1/Guardfile0000644000004100000410000000025212537123500015426 0ustar www-datawww-data# A sample Guardfile # More info at https://github.com/guard/guard#readme guard :rspec do watch(%r{^spec/.+_spec\.rb$}) watch('spec/spec_helper.rb') { 'spec' } end