Top Level Namespace
Defined Under Namespace
Modules: Capstrap
Instance Method Summary collapse
-
#apt_install(pkg, check = false) ⇒ Object
Installs a package via apt-get.
-
#apt_update ⇒ Object
Updates package repository via apt-get.
-
#banner(msg) ⇒ Object
Prints a message intended to catch attention.
-
#chef_installed? ⇒ Boolean
Checks if the chef gem is installed on the remote host.
-
#cmd_if(test, rvm = false) ⇒ true, false
Runs a remote if condition and returns true/false.
-
#cmd_test(test, rvm = false) ⇒ true, false
Runs a remote if test condition and returns true/false.
-
#config_repo_installed? ⇒ Boolean
Checks if chef config repo is installed on the remote host.
-
#cookbooks_repo_installed? ⇒ Boolean
Checks if chef cookbook repo is installed on the remote host.
-
#fetch_primary_ip_address ⇒ Object
Retrieve the primary IP address of the host.
-
#fqdn_correct?(host_name, domain_name, ip_addr) ⇒ Boolean
Checks if the full qualified domain name is current and correct.
-
#hostname_correct?(host_name) ⇒ Boolean
Checks if the hostname is current and correct.
-
#info(msg) ⇒ Object
Prints an information message.
-
#pkg_installed?(pkg) ⇒ true, false
Checks if a package is installed on the remote host.
-
#ruby_installed?(ruby) ⇒ Boolean
Checks if an RVM ruby is installed on the remote host.
- #rvm_env ⇒ Object
-
#rvm_installed? ⇒ Boolean
Checks if RVM is installed on the remote host.
-
#rvm_run(cmd) ⇒ Object
Runs a remote command in an RVM aware bubble.
- #update_cmd ⇒ Object
Instance Method Details
#apt_install(pkg, check = false) ⇒ Object
Installs a package via apt-get.
41 42 43 44 45 46 47 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 41 def apt_install(pkg, check=false) if check && pkg_installed?(pkg) info %{Package "#{pkg}" is already installed, skipping.} else run %{apt-get install -y #{pkg}} end end |
#apt_update ⇒ Object
Updates package repository via apt-get.
51 52 53 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 51 def apt_update run %{apt-get update -y} end |
#banner(msg) ⇒ Object
Prints a message intended to catch attention.
161 162 163 164 165 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 161 def (msg) puts "\n #{'*' * (msg.size + 6)}" puts " * #{msg} *" puts " #{'*' * (msg.size + 6)}\n" end |
#chef_installed? ⇒ Boolean
Checks if the chef gem is installed on the remote host.
85 86 87 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 85 def chef_installed? cmd_if %{rvm use #{ruby} >/dev/null && gem list --no-versions | grep -q "^chef$" >/dev/null}, true end |
#cmd_if(test, rvm = false) ⇒ true, false
Runs a remote if condition and returns true/false.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 6 def cmd_if(test, rvm=false) load_rvm = "" load_rvm = "#{rvm_env} " if rvm r = capture %{#{load_rvm}if #{test} ; then echo true; else echo false; fi}, :shell => "bash" puts " * Result is: #{r.to_s}" if r.to_s =~ /true/ true else false end end |
#cmd_test(test, rvm = false) ⇒ true, false
Runs a remote if test condition and returns true/false
24 25 26 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 24 def cmd_test(test, rvm=false) cmd_if %{[ #{test} ]}, rvm end |
#config_repo_installed? ⇒ Boolean
Checks if chef config repo is installed on the remote host.
100 101 102 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 100 def config_repo_installed? cmd_test %{-d "#{config_path}"} end |
#cookbooks_repo_installed? ⇒ Boolean
Checks if chef cookbook repo is installed on the remote host.
93 94 95 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 93 def cookbooks_repo_installed? cmd_test %{-d "#{cookbooks_path}"} end |
#fetch_primary_ip_address ⇒ Object
Retrieve the primary IP address of the host.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 125 def fetch_primary_ip_address capture(<<-GETADDR, :shell => "bash").chomp _if="$(netstat -nr | grep ^0\.0\.0\.0 | awk '{print $8}')"; _ip="$(/sbin/ifconfig $_if | \ grep '^[[:space:]]*inet ' | awk '{print $2}' | \ awk -F':' '{print $2}')"; if [ -z "$_ip" -o "$_ip" == "" ] ; then echo ""; return 10; else echo $_ip; fi GETADDR end |
#fqdn_correct?(host_name, domain_name, ip_addr) ⇒ Boolean
Checks if the full qualified domain name is current and correct.
118 119 120 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 118 def fqdn_correct?(host_name, domain_name, ip_addr) cmd_if %{egrep -q '^#{ip_addr}[[:space:]]+#{host_name}.#{domain_name}' /etc/hosts >/dev/null} end |
#hostname_correct?(host_name) ⇒ Boolean
Checks if the hostname is current and correct.
108 109 110 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 108 def hostname_correct?(host_name) host_name == capture(%{hostname}).chomp end |
#info(msg) ⇒ Object
Prints an information message.
153 154 155 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 153 def info(msg) puts "\n ==> #{msg}" end |
#pkg_installed?(pkg) ⇒ true, false
Checks if a package is installed on the remote host.
33 34 35 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 33 def pkg_installed?(pkg) cmd_if %{dpkg-query --showformat='${Essential}\n' --show '#{pkg}' > /dev/null 2>&1} end |
#ruby_installed?(ruby) ⇒ Boolean
Checks if an RVM ruby is installed on the remote host.
78 79 80 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 78 def ruby_installed?(ruby) cmd_if %{rvm list strings | grep -q "#{ruby}" >/dev/null}, true end |
#rvm_env ⇒ Object
55 56 57 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 55 def rvm_env %{[[ -s "/usr/local/lib/rvm" ]] && source /usr/local/lib/rvm; } end |
#rvm_installed? ⇒ Boolean
Checks if RVM is installed on the remote host.
70 71 72 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 70 def rvm_installed? cmd_test %{-s "/usr/local/lib/rvm"} end |
#rvm_run(cmd) ⇒ Object
Runs a remote command in an RVM aware bubble.
63 64 65 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 63 def rvm_run(cmd) run %{#{rvm_env} rvm #{cmd}}, :shell => "bash" end |
#update_cmd ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 141 def update_cmd if cookbooks_rake_update %{rake update} else %{git submodule init && git submodule update} end end |