Module: AwsEc2::Template::Helper::ScriptHelper

Defined in:
lib/aws_ec2/template/helper/script_helper.rb

Instance Method Summary collapse

Instance Method Details

#extract_scripts(options = {}) ⇒ Object

Bash code that is meant to included in user-data



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/aws_ec2/template/helper/script_helper.rb', line 3

def extract_scripts(options={})
  check_s3_folder_settings!

  settings_options = settings["extract_scripts"] || {}
  options = settings_options.merge(options)
  # defaults also here in case they are removed from settings
  to = options[:to] || "/opt"
  user = options[:as] || "ec2-user"

  if Dir.glob("#{AwsEc2.root}/app/scripts*").empty?
    puts "WARN: you are using the extract_scripts helper method but you do not have any app/scripts.".colorize(:yellow)
    calling_line = caller[0].split(':')[0..1].join(':')
    puts "Called from: #{calling_line}"
    return ""
  end

  "# Generated from the aws-ec2 extract_scripts helper.\n# Downloads scripts from s3, extract them, and setup.\nmkdir -p \#{to}\naws s3 cp \#{scripts_s3_path} \#{to}/\n(\ncd \#{to}\ntar zxf \#{to}/\#{scripts_name}\nchmod -R a+x \#{to}/scripts\nchown -R \#{user}:\#{user} \#{to}/scripts\n)\n"
end