Top Level Namespace
Defined Under Namespace
Modules: Mina
Instance Method Summary collapse
- #add_user(u) ⇒ Object
- #append_template(source, destination) ⇒ Object
- #apt_get(package) ⇒ Object
- #brew_install(package) ⇒ Object
- #check_exec_and_ownership(u, g, destination) ⇒ Object
- #check_exists(destination) ⇒ Object
- #check_file_exist?(file) ⇒ Boolean
- #check_ownership(u, g, destination) ⇒ Object
- #check_response ⇒ Object
- #check_symlink(destination) ⇒ Object
- #command_echo(s) ⇒ Object
- #custom_conf?(conf) ⇒ Boolean
- #custom_conf_path(conf) ⇒ Object
- #extra_echo(desc) ⇒ Object
- #extra_echo!(desc) ⇒ Object
- #gem_install(package, options = nil) ⇒ Object
- #mv_config(source, destination) ⇒ Object
- #parse_template(file) ⇒ Object
- #scp_file(desc, source, destination) ⇒ Object
- #upload_default_template(tpl, destination) ⇒ Object
- #upload_file(filename, destination) ⇒ Object
- #upload_shared_file(filename) ⇒ Object
- #upload_shared_folder(folder, base) ⇒ Object
- #upload_template(source, destination) ⇒ Object
Instance Method Details
#add_user(u) ⇒ Object
8 9 10 11 |
# File 'lib/mina/extras/ubuntu.rb', line 8 def add_user(u) invoke :sudo command "adduser #{u}" end |
#append_template(source, destination) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/mina/extras/methods.rb', line 48 def append_template(source, destination) desc = File.basename(destination) if source =~ /erb$/ contents = parse_template(source) else contents = File.read(source) end extra_echo("Put #{desc} file to #{destination}") script = <<EOF script=$(cat <<'EOFF' #{contents} EOFF ) EOF command %{#{script}} command %{echo "$script" >> #{destination}} command check_exists(destination) end |
#apt_get(package) ⇒ Object
3 4 5 |
# File 'lib/mina/extras/apt.rb', line 3 def apt_get(package) command "sudo apt-get install #{package} -y" end |
#brew_install(package) ⇒ Object
1 2 3 |
# File 'lib/mina/extras/brew.rb', line 1 def brew_install(package) command "sudo brew install #{package} -y" end |
#check_exec_and_ownership(u, g, destination) ⇒ Object
148 149 150 151 152 153 |
# File 'lib/mina/extras/methods.rb', line 148 def check_exec_and_ownership(u, g, destination) %{ file_info=(`ls -l #{destination}`) if [[ -s "#{destination}" ]] && [[ -x "#{destination}" ]] && [[ ${file_info[2]} == '#{u}' ]] && [[ ${file_info[3]} == '#{g}' ]]; #{check_response} } end |
#check_exists(destination) ⇒ Object
137 138 139 |
# File 'lib/mina/extras/methods.rb', line 137 def check_exists(destination) %{if [[ -s "#{destination}" ]]; #{check_response}} end |
#check_file_exist?(file) ⇒ Boolean
192 193 194 |
# File 'lib/mina/extras/methods.rb', line 192 def check_file_exist?(file) File.exist?(file) end |
#check_ownership(u, g, destination) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/mina/extras/methods.rb', line 141 def check_ownership(u, g, destination) %{ file_info=(`ls -l #{destination}`) if [[ -s "#{destination}" ]] && [[ ${file_info[2]} == '#{u}' ]] && [[ ${file_info[3]} == '#{g}' ]]; #{check_response} } end |
#check_response ⇒ Object
133 134 135 |
# File 'lib/mina/extras/methods.rb', line 133 def check_response 'then echo "-----> SUCCESS"; else echo "-----> FAILED"; fi' end |
#check_symlink(destination) ⇒ Object
155 156 157 |
# File 'lib/mina/extras/methods.rb', line 155 def check_symlink(destination) %{if [[ -h "#{destination}" ]]; #{check_response}} end |
#command_echo(s) ⇒ Object
188 189 190 |
# File 'lib/mina/extras/methods.rb', line 188 def command_echo(s) command %{echo '#{s}'} end |
#custom_conf?(conf) ⇒ Boolean
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/mina/extras/methods.rb', line 159 def custom_conf?(conf) Dir[File.join(Dir.pwd, "config", "deploy", "#{fetch(:server)}", "*")].map do |file| filename = File.basename(file) if filename.gsub(/.erb\Z/, "") == conf.to_s return true end end false end |
#custom_conf_path(conf) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/mina/extras/methods.rb', line 170 def custom_conf_path(conf) Dir[File.join(Dir.pwd, "config", "deploy", "#{fetch(:server)}", "*")].map do |file| filename = File.basename(file) if filename.gsub(/.erb\Z/, "") == conf.to_s return file end end Dir[File.join(Dir.pwd, "config", "deploy", "shared", "*")].map do |file| filename = File.basename(file) if filename.gsub(/.erb\Z/, "") == conf.to_s return file end end false end |
#extra_echo(desc) ⇒ Object
5 6 7 |
# File 'lib/mina/extras/methods.rb', line 5 def extra_echo(desc) command "echo '--------> #{desc}'" end |
#extra_echo!(desc) ⇒ Object
9 10 11 |
# File 'lib/mina/extras/methods.rb', line 9 def extra_echo!(desc) command "echo '--------> #{desc}'" end |
#gem_install(package, options = nil) ⇒ Object
1 2 3 |
# File 'lib/mina/extras/gem.rb', line 1 def gem_install(package, =nil) command "sudo gem install #{package} #{} --no-rdoc --no-ri" end |
#mv_config(source, destination) ⇒ Object
1 2 3 |
# File 'lib/mina/extras/methods.rb', line 1 def mv_config(source, destination) command %{mv #{fetch(:deploy_to)}/shared/config/#{source} #{fetch(:deploy_to)}/shared/config/#{destination}} end |
#parse_template(file) ⇒ Object
129 130 131 |
# File 'lib/mina/extras/methods.rb', line 129 def parse_template(file) erb(file) end |
#scp_file(desc, source, destination) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mina/extras/methods.rb', line 13 def scp_file(desc, source, destination) on :after_hook do extra_echo("Put #{desc} file to #{destination}") command = "scp " command << source command << " #{user}@#{domain!}:#{destination}" extra_echo("#{command}") result = %x[#{command}] puts result unless result == "" end end |
#upload_default_template(tpl, destination) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/mina/extras/methods.rb', line 94 def upload_default_template(tpl, destination) desc = File.basename(destination) source = File.join(File.dirname(__FILE__), "templates", "#{tpl}.erb") contents = parse_template(source) extra_echo("Put #{desc} file to #{destination}") script = <<EOF script=$(cat <<'EOFF' #{contents} EOFF ) EOF command %{#{script}} command %{echo "$script" > #{destination}} command check_exists(destination) end |
#upload_file(filename, destination) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/mina/extras/methods.rb', line 38 def upload_file(filename, destination) src = custom_conf_path(filename) if src upload_template src, destination else upload_default_template filename, destination end end |
#upload_shared_file(filename) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/mina/extras/methods.rb', line 28 def upload_shared_file(filename) src = custom_conf_path(filename) if src upload_template src, "#{fetch(:deploy_to)}/shared/#{filename}" else upload_default_template filename, "#{fetch(:deploy_to)}/shared/#{filename}" end end |
#upload_shared_folder(folder, base) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/mina/extras/methods.rb', line 115 def upload_shared_folder(folder, base) Dir[File.join(folder, "*")].map do |path| if File.directory?(path) upload_shared_folder(path) else filename = File.basename(path) shared_folder = path.gsub(base, "").gsub(filename, "").gsub(/\A\//, "").gsub(/\/\Z/, "") des = "#{fetch(:deploy_to)}/shared/#{shared_folder}/#{filename.gsub(/\.erb$/, "")}" upload_template path, des end end end |
#upload_template(source, destination) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/mina/extras/methods.rb', line 71 def upload_template(source, destination) desc = File.basename(destination) if source =~ /erb$/ contents = parse_template(source) else contents = parse_template(source) end extra_echo("Put #{desc} file to #{destination}") script = <<EOF script=$(cat <<'EOFF' #{contents} EOFF ) EOF command %{#{script}} command %{echo "$script" > #{destination}} command check_exists(destination) end |