active_scripts 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +9 -0
  4. data/.rspec +4 -0
  5. data/.travis.yml +13 -0
  6. data/CODE_OF_CONDUCT.md +13 -0
  7. data/COMMANDS.md +43 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +39 -0
  11. data/Rakefile +1 -0
  12. data/active_scripts.gemspec +29 -0
  13. data/bin/console +14 -0
  14. data/bin/rake +16 -0
  15. data/bin/setup +7 -0
  16. data/exe/active_scripts +82 -0
  17. data/lib/active_scripts.rb +16 -0
  18. data/lib/active_scripts/addendums/linuxbrew.txt +4 -0
  19. data/lib/active_scripts/addendums/rbenv.txt +3 -0
  20. data/lib/active_scripts/addendums/wkhtmltopdf.txt +2 -0
  21. data/lib/active_scripts/base.rb +38 -0
  22. data/lib/active_scripts/operating_system.rb +57 -0
  23. data/lib/active_scripts/package.rb +39 -0
  24. data/lib/active_scripts/packages/all.rb +34 -0
  25. data/lib/active_scripts/packages/base.rb +107 -0
  26. data/lib/active_scripts/packages/homebrew.rb +49 -0
  27. data/lib/active_scripts/packages/imagemagick.rb +62 -0
  28. data/lib/active_scripts/packages/jpegoptim.rb +55 -0
  29. data/lib/active_scripts/packages/mysql.rb +73 -0
  30. data/lib/active_scripts/packages/nginx.rb +24 -0
  31. data/lib/active_scripts/packages/optipng.rb +55 -0
  32. data/lib/active_scripts/packages/postgresql.rb +69 -0
  33. data/lib/active_scripts/packages/rails.rb +27 -0
  34. data/lib/active_scripts/packages/rbenv.rb +62 -0
  35. data/lib/active_scripts/packages/redis.rb +78 -0
  36. data/lib/active_scripts/packages/ruby.rb +58 -0
  37. data/lib/active_scripts/packages/ruby_build.rb +55 -0
  38. data/lib/active_scripts/packages/wkhtmltopdf.rb +64 -0
  39. data/lib/active_scripts/preparation.rb +37 -0
  40. data/lib/active_scripts/preparations/base.rb +81 -0
  41. data/lib/active_scripts/preparations/freebsd.rb +20 -0
  42. data/lib/active_scripts/preparations/linux.rb +49 -0
  43. data/lib/active_scripts/preparations/macosx.rb +20 -0
  44. data/lib/active_scripts/preparations/unix.rb +20 -0
  45. data/lib/active_scripts/preparations/windows.rb +20 -0
  46. data/lib/active_scripts/recipe.rb +52 -0
  47. data/lib/active_scripts/recipes/all.rb +14 -0
  48. data/lib/active_scripts/recipes/base.rb +62 -0
  49. data/lib/active_scripts/recipes/rails.rb +26 -0
  50. data/lib/active_scripts/version.rb +3 -0
  51. metadata +178 -0
@@ -0,0 +1,37 @@
1
+ module ActiveScripts
2
+ class Preparation
3
+
4
+ # INFO: ActiveScripts::Preparation contains code that is
5
+ # for retrieving and validating preparations.
6
+
7
+ PREPARATIONS = Dir.entries("#{File.dirname(__FILE__)}/preparations")
8
+ .drop(2)
9
+ .reject { |f| ["base.rb"].include?(f) }
10
+ .map { |f| File.basename(f, ".rb").to_sym }
11
+
12
+ attr_accessor :preparation
13
+
14
+ def initialize(preparation)
15
+ @preparation = preparation
16
+ end
17
+
18
+ def self.find(preparation)
19
+ new(preparation).find
20
+ end
21
+
22
+ def find
23
+ assert_valid_preparation!
24
+ return(@preparation)
25
+ end
26
+
27
+ private
28
+
29
+ def assert_valid_preparation!
30
+ unless PREPARATIONS.include?(@preparation)
31
+ raise ArgumentError,
32
+ "Unknown preparation: #{preparation.inspect}. Valid preparations are listed in the documentation."
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,81 @@
1
+ module ActiveScripts
2
+ module Preparations
3
+ class Base < ActiveScripts::Base
4
+
5
+ # INFO: ActiveScripts::Preparations::Base contains code that is
6
+ # shared between all preparation files.
7
+
8
+ COMMANDS = [:setup, :update]
9
+ OPTIONS = [:dry_run, :verbose]
10
+
11
+ attr_accessor :command, :options
12
+
13
+ def initialize(command, options={})
14
+ @command = command
15
+ @options = options
16
+ end
17
+
18
+ def self.execute(command, options={})
19
+ new(command, options).execute
20
+ end
21
+
22
+ def execute
23
+ assert_valid_command!
24
+ assert_valid_options!
25
+ send(@command)
26
+ end
27
+
28
+ private
29
+
30
+ def assert_valid_command!
31
+ unless COMMANDS.include?(@command)
32
+ raise ArgumentError,
33
+ "Unknown package command: #{@command.inspect}. Valid package commands are: #{COMMANDS.map(&:inspect).join(', ')}"
34
+ end
35
+ end
36
+
37
+ def assert_valid_options!
38
+ @options.each_key do |option|
39
+ unless OPTIONS.include?(option)
40
+ raise ArgumentError,
41
+ "Unknown package option: #{option.inspect}. Valid package options are: #{OPTIONS.map(&:inspect).join(', ')}"
42
+ end
43
+ end
44
+ end
45
+
46
+ def option_dry_run?
47
+ @options.fetch(:dry_run, false)
48
+ end
49
+
50
+ def option_verbose?
51
+ @options.fetch(:verbose, false)
52
+ end
53
+
54
+ def execute_command!(command)
55
+ say(" Executing: '#{command}'") if option_dry_run? || option_verbose?
56
+ option_dry_run? ? (output = error = "") : (output, error, status = Open3.capture3("#{command}"))
57
+ return(error.blank? ? output : error)
58
+ end
59
+
60
+ def preparation_output?(output, excludes: nil, includes: nil)
61
+ output = output.squish
62
+ if includes.nil? && excludes.nil?
63
+ output.blank?
64
+ else
65
+ includes.nil? ? [excludes].flatten.any? { |str| output.exclude?(str) } : [includes].flatten.any? { |str| output.include?(str) }
66
+ end
67
+ end
68
+
69
+ def notify_preparation_missing!
70
+ say_error(" [!] PreparationError")
71
+ say_error(" - The preparation is not installed.")
72
+ end
73
+
74
+ def notify_preparation_unavailable!
75
+ say_warning(" [!] PreparationError")
76
+ say_warning(" - The preparation is not available for your operating system.")
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,20 @@
1
+ module ActiveScripts
2
+ module Preparations
3
+ class Freebsd < ActiveScripts::Preparations::Base
4
+
5
+ # INFO: ActiveScripts::Preparations::Freebsd contains code that is
6
+ # pertaining to the FreeBSD operating system.
7
+
8
+ private
9
+
10
+ def setup
11
+ notify_command_todo!
12
+ end
13
+
14
+ def update
15
+ notify_command_todo!
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,49 @@
1
+ module ActiveScripts
2
+ module Preparations
3
+ class Linux < ActiveScripts::Preparations::Base
4
+
5
+ # INFO: ActiveScripts::Preparations::Linux contains code that is
6
+ # pertaining to the Linux operating system.
7
+
8
+ private
9
+
10
+ def setup
11
+ execute_command!("sudo apt-get -y update")
12
+ execute_command!("sudo apt-get -y upgrade")
13
+ execute_command!("sudo aptitude -y safe-upgrade")
14
+ execute_command!("sudo apt-get -y autoremove")
15
+ execute_command!("sudo apt-get -y install build-essential curl git m4 ruby texinfo vim flex bison \
16
+ make cmake scons gettext autoconf automake autoconf-archive \
17
+ libbz2-dev libffi-dev libcurl4-openssl-dev libexpat-dev libssl-dev \
18
+ libyaml-dev libncurses-dev libtool libreadline6-dev libncurses5-dev \
19
+ python-setuptools zlib1g-dev")
20
+
21
+ username = ask(" [?] Username? ") { |q| q.validate = /^[A-Za-z0-9]+$/i }
22
+ output = execute_command!("sudo adduser #{username}")
23
+ say_warning(" [!] #{output.squish}") unless option_dry_run? || preparation_output?(output, includes: "adduser:")
24
+ output = execute_command!("sudo adduser #{username} sudo")
25
+ say_warning(" [!] #{output.squish}") unless option_dry_run? || preparation_output?(output, includes: "adduser:")
26
+
27
+ if agree(" [?] Setup project directory? ", true)
28
+ output = ask(" [?] Project name? ") { |q| q.validate = /^[A-Za-z0-9_-.+]+$/i }
29
+ execute_command!("mkdir /var/www")
30
+ execute_command!("mkdir /var/www/#{output}")
31
+ execute_command!("chown -R root /var/www/#{output}")
32
+ say(" Project directory path: '/var/www/#{output}'")
33
+ end
34
+
35
+ say_ok(" Setup complete!")
36
+ say_ok(" - Please switch to the following user to complete the installation: '#{username}'")
37
+ end
38
+
39
+ def update
40
+ execute_command!("sudo apt-get -y update")
41
+ execute_command!("sudo apt-get -y upgrade")
42
+ execute_command!("sudo aptitude -y safe-upgrade")
43
+ execute_command!("sudo apt-get -y autoremove")
44
+ say_ok(" Update complete!")
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ module ActiveScripts
2
+ module Preparations
3
+ class Macosx < ActiveScripts::Preparations::Base
4
+
5
+ # INFO: ActiveScripts::Preparations::Macosx contains code that is
6
+ # pertaining to the Mac OS X operating system.
7
+
8
+ private
9
+
10
+ def setup
11
+ notify_command_todo!
12
+ end
13
+
14
+ def update
15
+ notify_command_todo!
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module ActiveScripts
2
+ module Preparations
3
+ class Unix < ActiveScripts::Preparations::Base
4
+
5
+ # INFO: ActiveScripts::Preparations::Unix contains code that is
6
+ # pertaining to the Unix operating system.
7
+
8
+ private
9
+
10
+ def setup
11
+ notify_command_todo!
12
+ end
13
+
14
+ def update
15
+ notify_command_todo!
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module ActiveScripts
2
+ module Preparations
3
+ class Windows < ActiveScripts::Preparations::Base
4
+
5
+ # INFO: ActiveScripts::Preparations::Windows contains code that is
6
+ # pertaining to the Windows operating system.
7
+
8
+ private
9
+
10
+ def setup
11
+ notify_command_todo!
12
+ end
13
+
14
+ def update
15
+ notify_command_todo!
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,52 @@
1
+ module ActiveScripts
2
+ class Recipe
3
+
4
+ # INFO: ActiveScripts::Recipe contains code that is
5
+ # for retrieving and validating recipes.
6
+
7
+ RECIPES = Dir.entries("#{File.dirname(__FILE__)}/recipes")
8
+ .drop(2)
9
+ .reject { |f| ["base.rb"].include?(f) }
10
+ .map { |f| File.basename(f, ".rb") }
11
+
12
+ attr_accessor :recipes, :packages
13
+
14
+ def initialize(recipes=[])
15
+ @recipes = recipes.strip
16
+ @packages = []
17
+ end
18
+
19
+ def self.find(recipes=[])
20
+ new(recipes).find
21
+ end
22
+
23
+ def find
24
+ if @recipes.blank?
25
+ say(" - Recipes skipped!")
26
+ else
27
+ assert_valid_recipes!
28
+ generate_recipe_packages!
29
+ end
30
+
31
+ return(@packages.strip)
32
+ end
33
+
34
+ private
35
+
36
+ def assert_valid_recipes!
37
+ @recipes.each do |recipe|
38
+ unless RECIPES.include?(recipe)
39
+ raise ArgumentError,
40
+ "Unknown recipe system: #{recipe.inspect}. Valid recipes are listed in the documentation."
41
+ end
42
+ end
43
+ end
44
+
45
+ def generate_recipe_packages!
46
+ @recipes.each do |recipe|
47
+ @packages << "ActiveScripts::Recipes::#{recipe.camelize}".constantize.packages
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,14 @@
1
+ module ActiveScripts
2
+ module Recipes
3
+ class All
4
+
5
+ # INFO: ActiveScripts::Recipes::All contains code that
6
+ # retrieves all packages.
7
+
8
+ def self.packages
9
+ ["all"]
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,62 @@
1
+ module ActiveScripts
2
+ module Recipes
3
+ class Base < ActiveScripts::Base
4
+
5
+ # INFO: ActiveScripts::Recipes::Base contains code that is
6
+ # shared between all recipe files.
7
+
8
+ DATABASES = ["mysql"]
9
+ ENVIRONMENTS = [:development, :staging, :production]
10
+
11
+ attr_accessor :environment
12
+
13
+ def initialize
14
+ @environment = :unknown
15
+ end
16
+
17
+ def self.packages
18
+ assert_valid_user!
19
+ new.packages
20
+ end
21
+
22
+ private
23
+
24
+ def assert_valid_environment!
25
+ unless ENVIRONMENTS.include?(@environment)
26
+ raise ArgumentError,
27
+ "Unknown recipe environment: #{@environment.inspect}. Valid recipe environments are: #{ENVIRONMENTS.map(&:inspect).join(', ')}"
28
+ end
29
+ end
30
+
31
+ ENVIRONMENTS.each do |environment|
32
+ define_method("environment_#{environment}?") do
33
+ @environment == environment
34
+ end
35
+ end
36
+
37
+ def find_or_initialize_databases!
38
+ output, error, status = Open3.capture3("brew list")
39
+ output = output.squish
40
+
41
+ databases = []
42
+ DATABASES.each { |database| databases.push(database) if output.include?(database) }
43
+
44
+ if databases.empty?
45
+ ask(" [?] Which database(s)? ", lambda { |str| str.strip.split(/,\s*/) }) { |q| q.default = "mysql" }
46
+ else
47
+ return(databases)
48
+ end
49
+ end
50
+
51
+ def prompt_environment!
52
+ @environment = choose(" [?] Which environment?", :development, :staging, :production)
53
+ end
54
+
55
+ def notify_environment_unavailable!
56
+ say_warning(" [!] RecipeError")
57
+ say_warning(" - The recipe environment is not available.")
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,26 @@
1
+ module ActiveScripts
2
+ module Recipes
3
+ class Rails < ActiveScripts::Recipes::Base
4
+
5
+ # INFO: ActiveScripts::Recipes::Rails contains code that
6
+ # retrieves rails related packages.
7
+
8
+ def packages
9
+ prompt_environment!
10
+ assert_valid_environment!
11
+
12
+ # Check for non-root user
13
+ packages = ["homebrew", "rbenv", "ruby_build", "ruby", "rails"]
14
+ packages.push(find_or_initialize_databases!)
15
+
16
+ case @environment
17
+ when :staging, :production
18
+ packages.push("nginx")
19
+ end
20
+
21
+ return(packages.flatten)
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveScripts
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_scripts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Gomez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: active_object
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: commander
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Deployment scripts for commonly used server setups.
98
+ email:
99
+ - j.gomez@drexed.com
100
+ executables:
101
+ - active_scripts
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".coveralls.yml"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - COMMANDS.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - active_scripts.gemspec
116
+ - bin/console
117
+ - bin/rake
118
+ - bin/setup
119
+ - exe/active_scripts
120
+ - lib/active_scripts.rb
121
+ - lib/active_scripts/addendums/linuxbrew.txt
122
+ - lib/active_scripts/addendums/rbenv.txt
123
+ - lib/active_scripts/addendums/wkhtmltopdf.txt
124
+ - lib/active_scripts/base.rb
125
+ - lib/active_scripts/operating_system.rb
126
+ - lib/active_scripts/package.rb
127
+ - lib/active_scripts/packages/all.rb
128
+ - lib/active_scripts/packages/base.rb
129
+ - lib/active_scripts/packages/homebrew.rb
130
+ - lib/active_scripts/packages/imagemagick.rb
131
+ - lib/active_scripts/packages/jpegoptim.rb
132
+ - lib/active_scripts/packages/mysql.rb
133
+ - lib/active_scripts/packages/nginx.rb
134
+ - lib/active_scripts/packages/optipng.rb
135
+ - lib/active_scripts/packages/postgresql.rb
136
+ - lib/active_scripts/packages/rails.rb
137
+ - lib/active_scripts/packages/rbenv.rb
138
+ - lib/active_scripts/packages/redis.rb
139
+ - lib/active_scripts/packages/ruby.rb
140
+ - lib/active_scripts/packages/ruby_build.rb
141
+ - lib/active_scripts/packages/wkhtmltopdf.rb
142
+ - lib/active_scripts/preparation.rb
143
+ - lib/active_scripts/preparations/base.rb
144
+ - lib/active_scripts/preparations/freebsd.rb
145
+ - lib/active_scripts/preparations/linux.rb
146
+ - lib/active_scripts/preparations/macosx.rb
147
+ - lib/active_scripts/preparations/unix.rb
148
+ - lib/active_scripts/preparations/windows.rb
149
+ - lib/active_scripts/recipe.rb
150
+ - lib/active_scripts/recipes/all.rb
151
+ - lib/active_scripts/recipes/base.rb
152
+ - lib/active_scripts/recipes/rails.rb
153
+ - lib/active_scripts/version.rb
154
+ homepage: https://github.com/drexed/active_scripts
155
+ licenses:
156
+ - MIT
157
+ metadata: {}
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ requirements: []
173
+ rubyforge_project:
174
+ rubygems_version: 2.4.8
175
+ signing_key:
176
+ specification_version: 4
177
+ summary: Commonly used server deployment scripts.
178
+ test_files: []