Sha256: b421410a7a5aecce31c70a12ee8a571d771fec0f5407fd5c497faff1891f5fef

Contents?: true

Size: 1.5 KB

Versions: 18

Compression:

Stored size: 1.5 KB

Contents

module AwsEc2::Template::Helper::ScriptHelper
  # Bash code that is meant to included in user-data
  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
  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

  def scripts_name
    File.basename(scripts_s3_path)
  end

  def scripts_s3_path
    upload = AwsEc2::Script::Upload.new
    upload.s3_dest
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
aws-ec2-1.4.9 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.4.8 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.4.7 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.4.6 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.4.5 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.4.4 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.4.3 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.4.2 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.4.1 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.4.0 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.3.2 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.3.1 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.3.0 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.2.2 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.2.1 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.2.0 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.1.0 lib/aws_ec2/template/helper/script_helper.rb
aws-ec2-1.0.0 lib/aws_ec2/template/helper/script_helper.rb