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.
-
#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.
132 133 134 135 136 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 132 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}@global >/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 |
#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.
124 125 126 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 124 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
112 113 114 115 116 117 118 |
# File 'lib/capistrano/ext/capstrap/core.rb', line 112 def update_cmd if cookbooks_rake_update %{rake update} else %{git submodule init && git submodule update} end end |