Class: SpecInfra::Command::OpenBSD

Inherits:
Base
  • Object
show all
Defined in:
lib/specinfra/command/openbsd.rb

Instance Method Summary collapse

Methods inherited from Base

#check_access_by_user, #check_authorized_key, #check_belonging_group, #check_container, #check_cotainer_running, #check_cron_entry, #check_directory, #check_file, #check_file_checksum, #check_file_contain, #check_file_contain_lines, #check_file_contain_with_fixed_strings, #check_file_contain_with_regexp, #check_file_contain_within, #check_gid, #check_group, #check_installed_by_cpan, #check_installed_by_gem, #check_installed_by_npm, #check_installed_by_pear, #check_installed_by_pecl, #check_installed_by_pip, #check_ipfilter_rule, #check_ipnat_rule, #check_iptables_rule, #check_kernel_module_loaded, #check_listening_with_protocol, #check_monitored_by_god, #check_monitored_by_monit, #check_process, #check_reachable, #check_resolvable, #check_routing_table, #check_running_under_supervisor, #check_running_under_upstart, #check_selinux, #check_service_installed, #check_service_start_mode, #check_socket, #check_svcprop, #check_svcprops, #check_uid, #check_user, #check_yumrepo, #check_yumrepo_enabled, #check_zfs, #escape, #get_file_content, #get_ipaddress_of_host, #get_package_version, #get_process

Instance Method Details

#check_enabled(service, level = 3) ⇒ Object



4
5
6
# File 'lib/specinfra/command/openbsd.rb', line 4

def check_enabled(service, level=3)
  "egrep '(#{escape(service)}_flags=|^pkg_scripts=\"(.*)#{escape(service)}(.*)\")' /etc/rc.conf.local | grep -v \=NO"
end

#check_file_md5checksum(file, expected) ⇒ Object



8
9
10
11
# File 'lib/specinfra/command/openbsd.rb', line 8

def check_file_md5checksum(file, expected)
  regexp = "^#{expected}"
  "cksum -qa md5 #{escape(file)} | grep -w #{escape(regexp)}"
end

#check_file_sha256checksum(file, expected) ⇒ Object



13
14
15
16
# File 'lib/specinfra/command/openbsd.rb', line 13

def check_file_sha256checksum(file, expected)
  regexp = "^#{expected}"
  "cksum -qa sha256 #{escape(file)} | grep -w #{escape(regexp)}"
end

#check_grouped(file, group) ⇒ Object



64
65
66
67
# File 'lib/specinfra/command/openbsd.rb', line 64

def check_grouped(file, group)
  regexp = "^#{group}$"
  "stat -f %Sg #{escape(file)} | grep -- #{escape(regexp)}"
end

#check_home_directory(user, path_to_home) ⇒ Object



22
23
24
# File 'lib/specinfra/command/openbsd.rb', line 22

def check_home_directory(user, path_to_home)
  "getent passwd #{escape(user)} | cut -f 6 -d ':' | grep #{escape(path_to_home)}"
end

#check_installed(package, version = nil) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/specinfra/command/openbsd.rb', line 26

def check_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

#check_ipv4_address(interface, ip_address) ⇒ Object



38
39
40
# File 'lib/specinfra/command/openbsd.rb', line 38

def check_ipv4_address(interface, ip_address)
  "ifconfig #{interface} | grep -w inet | cut -d ' ' -f 2"
end


50
51
52
# File 'lib/specinfra/command/openbsd.rb', line 50

def check_link(link, target)
  "stat -f %Y #{escape(link)} | grep -- #{escape(target)}"
end

#check_listening(port) ⇒ Object



42
43
44
# File 'lib/specinfra/command/openbsd.rb', line 42

def check_listening(port)
  "netstat -nat -f inet | egrep '((tcp|udp).*\.#{port}.*LISTEN$)'"
end

#check_login_shell(user, path_to_shell) ⇒ Object



18
19
20
# File 'lib/specinfra/command/openbsd.rb', line 18

def (user, path_to_shell)
  "getent passwd #{escape(user)} | cut -f 7 -d ':' | grep #{escape(path_to_shell)}"
end

#check_mail_alias(recipient, target) ⇒ Object



46
47
48
# File 'lib/specinfra/command/openbsd.rb', line 46

def check_mail_alias(recipient, target)
  "egrep '^#{escape(recipient)}:.*#{escape(target)}' /etc/mail/aliases"
end

#check_mode(file, mode) ⇒ Object



54
55
56
57
# File 'lib/specinfra/command/openbsd.rb', line 54

def check_mode(file, mode)
  regexp = "^#{mode}$"
  "stat -f%Lp #{escape(file)} | grep #{escape(regexp)}"
end

#check_mounted(path) ⇒ Object



69
70
71
72
# File 'lib/specinfra/command/openbsd.rb', line 69

def check_mounted(path)
  regexp = "on #{path} "
  "mount | grep #{escape(regexp)}"
end

#check_owner(file, owner) ⇒ Object



59
60
61
62
# File 'lib/specinfra/command/openbsd.rb', line 59

def check_owner(file, owner)
  regexp = "^#{owner}$"
  "stat -f %Su #{escape(file)} | grep -- #{escape(regexp)}"
end

#check_running(service) ⇒ Object

def check_routing_table(destination)

  "route -n show -gateway | egrep '(^default|#{destination})' | head -1"
end


78
79
80
# File 'lib/specinfra/command/openbsd.rb', line 78

def check_running(service)
  "/etc/rc.d/#{escape(service)} status"
end

#get_interface_speed_of(name) ⇒ Object



34
35
36
# File 'lib/specinfra/command/openbsd.rb', line 34

def get_interface_speed_of(name)
  "ifconfig #{name} | grep 'media\:' | perl -pe 's|.*media\:.*\\((.*?)\\)|\\1|'"
end

#get_mode(file) ⇒ Object



82
83
84
# File 'lib/specinfra/command/openbsd.rb', line 82

def get_mode(file)
  "stat -f%Lp #{escape(file)}"
end

#install(package) ⇒ Object



86
87
88
# File 'lib/specinfra/command/openbsd.rb', line 86

def install(package)
  "pkg_add #{package}"
end