module AwsEc2::Template::Helper::ScriptHelper

Public Instance Methods

extract_scripts(options={}) click to toggle source

Bash code that is meant to included in user-data

# 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

    <<-BASH_CODE
# Generated from the aws-ec2 extract_scripts helper.
# Downloads scripts from s3, extract them, and setup.
mkdir -p #{to}
aws s3 cp #{scripts_s3_path} #{to}/
(
  cd #{to}
  tar zxf #{to}/#{scripts_name}
  chmod -R a+x #{to}/scripts
  chown -R #{user}:#{user} #{to}/scripts
)
BASH_CODE
  end

Private Instance Methods

check_s3_folder_settings!() click to toggle source
# File lib/aws_ec2/template/helper/script_helper.rb, line 34
def check_s3_folder_settings!
  return if settings["s3_folder"]

  puts "Helper method called that requires the s3_folder to be set at:"
  lines = caller.reject { |l| l =~ %r{lib/aws-ec2} } # hide internal aws-ec2 trace
  puts "  #{lines[0]}"

  puts "Please configure your config/settings.yml with an s3_folder.".colorize(:red)
  exit 1
end
scripts_name() click to toggle source
# File lib/aws_ec2/template/helper/script_helper.rb, line 45
def scripts_name
  File.basename(scripts_s3_path)
end
scripts_s3_path() click to toggle source
# File lib/aws_ec2/template/helper/script_helper.rb, line 49
def scripts_s3_path
  upload = AwsEc2::Script::Upload.new
  upload.s3_dest
end