Class: RailsPwnerer::Scaffolds::Packages

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/rails_pwnerer/scaffolds/packages.rb

Overview

installs the required OS (read: Ubuntu / Debian) packages

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

_setup_unix, _setup_windows, all_packages, all_packages_without_caching, #atomic_erase, #atomic_read, #atomic_write, #best_package_matching, #check_rails_root, #control_boot_script, #cpu_cores, #current_user, #gem_exists?, #gid_for_username, #group_for_username, #hook_boot_script, #install_gem, #install_gems, #install_package, #install_package_impl, #install_package_matching, #install_packages, #kill_tree, #os_distro, package_info_hash, #path_to_boot_script, #path_to_boot_script_defaults, #path_to_gemdir, #process_info, #prompt_user_for_password, #remove_package, #remove_packages, #search_packages, #uid_for_username, #unroll_collection, #update_all_packages, #update_all_packages_impl, #update_gems, #update_package_metadata, #upgrade_gem, #upgrade_gems, #upgrade_package, #upgrade_package_impl, #upgrade_packages, #with_package_source, #with_temp_dir

Class Method Details

.goObject

Standalone runner.



146
147
148
# File 'lib/rails_pwnerer/scaffolds/packages.rb', line 146

def self.go
  self.new.run
end

Instance Method Details

#install_databasesObject

Packages for all the database servers we could need.



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rails_pwnerer/scaffolds/packages.rb', line 62

def install_databases
  package 'sqlite3'
  package 'libsqlite3-dev'

  package 'mysql-client'
  package 'mysql-server'
  package 'libmysql-dev', 'libmysqlclient-dev', /^libmysqlclient\d*-dev$/

  package 'postgresql-client'
  package 'libpq-dev'

  # TODO: NoSQL stores.
end

#install_frontendsObject

Package for front-end servers.



125
126
127
# File 'lib/rails_pwnerer/scaffolds/packages.rb', line 125

def install_frontends
  package 'nginx'
end

#install_managementObject

Packages needed to manage the server remotely and install applications.



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
32
# File 'lib/rails_pwnerer/scaffolds/packages.rb', line 7

def install_management
  # Needed to play with the configuration database.
  package 'debconf'
  package 'debconf-utils'

  # Keys for Debian packages.
  package 'debian-archive-keyring'

  # Fetch files via HTTP.
  package 'curl'
  package 'wget'

  package 'dpkg-dev'  # Builds packages from source.
  package 'openssh-server'  # SSH into the box.

  # For gems with native extensions.
  package 'build-essential'
  package 'g++'

  # Pull code from version control.
  package 'subversion'
  package 'git-core'

  package 'avahi-daemon'  # mDNS, a.k.a. Bonjour
  package 'ddclient'  # dynamic DNS
end

#install_rubyObject

The ruby environment (ruby, irb, rubygems).



77
78
79
80
81
# File 'lib/rails_pwnerer/scaffolds/packages.rb', line 77

def install_ruby
  # remove the bootstrap version of ruby to install the best available one.
  remove_packages %w(ruby ruby1.8 ruby1.9.1 ruby2.0)
  install_ruby_20 || install_ruby_19
end

#install_ruby_19(retry_with_repos = true) ⇒ Object

MRI19 (1.9.2 or above).



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/rails_pwnerer/scaffolds/packages.rb', line 104

def install_ruby_19(retry_with_repos = true)
  package = best_package_matching(['ruby1.9.1'])
  if !package or package[:version] < '1.9.2'
    return false unless retry_with_repos

    # This distribution has an old ruby. Work around it.
    deb_source = 'http://debian.mirrors.tds.net/debian/'
    deb_repos = %w(testing main non-free contrib)
    return_value = nil
    with_package_source deb_source, deb_repos do
      return_value = install_ruby_19 false
    end
    return return_value
  end

  package 'ruby1.9.1'
  package 'ruby1.9.1-dev'
  true
end

#install_ruby_20(retry_with_repos = true) ⇒ Object

MRI 2.0.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rails_pwnerer/scaffolds/packages.rb', line 84

def install_ruby_20(retry_with_repos = true)
  package = best_package_matching(['ruby2.0'])
  if !package
    return false unless retry_with_repos

    # This distribution has an old ruby. Work around it.
    deb_source = 'http://debian.mirrors.tds.net/debian/'
    deb_repos = %w(testing main non-free contrib)
    return_value = nil
    with_package_source deb_source, deb_repos do
      return_value = install_ruby_20 false
    end
    return return_value
  end
  package 'ruby2.0'
  package 'ruby2.0-dev'
  true
end

#install_toolsObject

Packages needed by popular gems.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rails_pwnerer/scaffolds/packages.rb', line 35

def install_tools
  # For eventmachine.
  package 'libssl-dev'

  # For rmagick (image processing).
  package 'libmagickwand-dev', /^libmagick\d*-dev$/

  # For HTML/XML parsers (nokogiri, hpricot).
  package 'libxml2-dev'
  package 'libxslt1-dev'

  # For HTTP fetchers (curb).
  package 'libcurl-dev', 'libcurl-openssl-dev', /^libcurl\d*-dev$/,
          /^libcurl\d*-openssl-dev$/

  # needed for solr and other java-based services
  package /^openjdk-\d+-jdk/

  # useful to be able to work with compressed data
  package 'zlib-dev', /^zlib[0-9a-z]*-dev$/
  package 'bzip2'
  package 'gzip'
  package 'tar'
  package 'zip'
end

#package(*patterns) ⇒ Object

Implementation of the super-simple package DSL.



130
131
132
# File 'lib/rails_pwnerer/scaffolds/packages.rb', line 130

def package(*patterns)
  install_package_matching patterns
end

#runObject

Runner.



135
136
137
138
139
140
141
142
143
# File 'lib/rails_pwnerer/scaffolds/packages.rb', line 135

def run
  
  update_all_packages
  install_management
  install_tools
  install_databases
  install_frontends
  install_ruby
end