Class: Bosh::Gen::Generators::PackageAptGenerator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/bosh/gen/generators/package_apt_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



12
13
14
# File 'lib/bosh/gen/generators/package_apt_generator.rb', line 12

def self.source_root
  File.join(File.dirname(__FILE__), "package_apt_generator", "templates")
end

Instance Method Details

#check_nameObject

Raises:

  • (Thor::Error)


22
23
24
# File 'lib/bosh/gen/generators/package_apt_generator.rb', line 22

def check_name
  raise Thor::Error.new("'#{name}' is not a valid BOSH id") unless name.bosh_valid_id?
end

#check_root_is_releaseObject



16
17
18
19
20
# File 'lib/bosh/gen/generators/package_apt_generator.rb', line 16

def check_root_is_release
  unless File.exist?("jobs") && File.exist?("packages")
    raise Thor::Error.new("run inside a BOSH release project")
  end
end

#common_helpersObject



63
64
65
66
# File 'lib/bosh/gen/generators/package_apt_generator.rb', line 63

def common_helpers
  directory 'src/apt'
  chmod 'src/apt/fetch_debs.sh', 0755
end

#package_specificationObject



57
58
59
60
61
# File 'lib/bosh/gen/generators/package_apt_generator.rb', line 57

def package_specification
  src_files = ["apt/#{name}/profile.sh", "apt/#{name}/*.deb"]
  config = { "name" => name, "dependencies" => dependencies, "files" => src_files }
  create_file package_dir("spec"), YAML.dump(config)
end

#packagingObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bosh/gen/generators/package_apt_generator.rb', line 35

def packaging
  create_file package_dir("packaging") do
    <<-SHELL.gsub(/^\s{10}/, '')
    set -e # exit immediately if a simple command exits with a non-zero status
    set -u # report the usage of uninitialized variables
    
    # Available variables
    # $BOSH_COMPILE_TARGET - where this package & spec'd source files are available
    # $BOSH_INSTALL_TARGET - where you copy/install files to be included in package
    
    mkdir -p $BOSH_INSTALL_TARGET/apt
    
    for DEB in $(ls -1 apt/#{name}/*.deb); do
      echo "Installing $(basename $DEB)"
      dpkg -x $DEB $BOSH_INSTALL_TARGET/apt
    done
    
    cp -a apt/#{name}/profile.sh $BOSH_INSTALL_TARGET/
    SHELL
  end
end

#show_instructionsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/bosh/gen/generators/package_apt_generator.rb', line 72

def show_instructions
  say "Next steps:", :green
  say <<-README.gsub(/^        /, '')
    1. Edit src/apt/#{name}/aptfile to specify list of debian packages to install
    2. Provision vagrant and run script to fetch debian packages:

      vagrant up
      vagrant ssh -c '/vagrant/src/apt/fetch_debs.sh #{name}'
      vagrant destroy

    You can search for aptitude debian packages using apt-cache:

      vagrant ssh -c 'apt-cache search #{name} | sort'
  README
end

#vagrantfileObject



68
69
70
# File 'lib/bosh/gen/generators/package_apt_generator.rb', line 68

def vagrantfile
  copy_file 'Vagrantfile'
end

#warn_missing_dependenciesObject



26
27
28
29
30
31
32
33
# File 'lib/bosh/gen/generators/package_apt_generator.rb', line 26

def warn_missing_dependencies
  dependencies.each do |d|
    raise Thor::Error.new("dependency '#{d}' is not a valid BOSH id") unless d.bosh_valid_id?
    unless File.exist?(File.join("packages", d))
      say_status "warning", "missing dependency '#{d}'", :yellow
    end
  end
end