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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c9bdd377f19efdc9794fd180dba096c86b453ae
4
+ data.tar.gz: c8689e90b04eccd5189cc5a39397b4cd4757cf37
5
+ SHA512:
6
+ metadata.gz: ab25d63b8f364e4e46d4232bd22d877ce1e03a90d5f307223ee804e303475f559e8a8542fc492f349e4148b63317b81b8979a7c09678c29387eb702661939885
7
+ data.tar.gz: 59a850bbaf460fb63e481c301fc8b0ae93b73956af19b46d9593e8bd287d94ffb02ba8646423817367a29bb0a383d37230e2a0e438f020240603f4db9aab6e74
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --backtrace
2
+ --color
3
+ --format progress
4
+ --order random
@@ -0,0 +1,13 @@
1
+ before_install:
2
+ - sudo apt-get install libxml2-dev
3
+ cache: bundler
4
+ language: ruby
5
+ notifications:
6
+ email:
7
+ recipients:
8
+ - j.gomez@drexed.com
9
+ on_failure: change
10
+ on_success: never
11
+ rvm:
12
+ - ruby-head
13
+ script: 'bundle exec rake'
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
@@ -0,0 +1,43 @@
1
+ # Commands
2
+
3
+ Commands the text representaion of the commands the scripts are executing. If you do not want to use the ActiveScript to setup your environment, then feel free to execute at the command line your self.
4
+
5
+ Current commands: SSH, User, Directory, Packages
6
+
7
+ ## Usage
8
+
9
+ ### SSH
10
+
11
+ Update server login privilages. `Ubuntu`
12
+
13
+ ```ruby
14
+ vim /etc/ssh/sshd_config
15
+ ```
16
+
17
+ ### User
18
+
19
+ Create non-root users. `Ubuntu`
20
+
21
+ **Variables:**
22
+ * Username: name of the user
23
+
24
+ ```ruby
25
+ sudo adduser <USERNAME>
26
+ sudo adduser <USERNAME> sudo
27
+ su <USERNAME>
28
+ ```
29
+
30
+ ### Directory
31
+
32
+ Create system folders and directories.
33
+
34
+ **Variables:**
35
+ * Directory: name of the directory
36
+
37
+ ```ruby
38
+ # INFO: Execute as root for best availability.
39
+ mkdir /var/www
40
+ mkdir /var/www/<DIRECTORY>
41
+ chown -R root /var/www/<DIRECTORY>
42
+ ```
43
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_scripts.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Juan Gomez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # ActiveScripts
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/active_scripts`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'active_scripts'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install active_scripts
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/active_scripts/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_scripts/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_scripts"
8
+ spec.version = ActiveScripts::VERSION
9
+ spec.authors = ["Juan Gomez"]
10
+ spec.email = ["j.gomez@drexed.com"]
11
+
12
+ spec.summary = %q{Commonly used server deployment scripts.}
13
+ spec.description = %q{Deployment scripts for commonly used server setups.}
14
+ spec.homepage = "https://github.com/drexed/active_scripts"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "active_object"
23
+ spec.add_runtime_dependency "commander"
24
+
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "coveralls"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_scripts"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "active_scripts"
5
+ require "commander/import"
6
+
7
+ program :name, "ActiveScripts"
8
+ program :version, ActiveScripts::VERSION
9
+ program :description, "Deployment scripts for commonly used server setups"
10
+
11
+ ActiveScripts::Preparations::Base::COMMANDS.each do |exec|
12
+ command exec do |c|
13
+ c.syntax = "active_scripts #{exec} [options]"
14
+ c.description = "#{exec.capitalize} operating system packages"
15
+
16
+ c.option "--dry-run", "Print out commands but not execute"
17
+ c.option "--verbose", "#{exec.capitalize} available packages verbosely"
18
+
19
+ c.action do |args, options|
20
+ options.default(dry_run: false, verbose: false)
21
+
22
+ say("Select #{exec} options [hit enter to skip]:")
23
+
24
+ begin
25
+ $operating_system = ActiveScripts::OperatingSystem.find
26
+ preparation = ActiveScripts::Preparation.find($operating_system)
27
+
28
+ say(" - #{(exec == :setup) ? 'Setting up' : 'Updating'} #{preparation}...")
29
+ "ActiveScripts::Preparations::#{preparation.to_s.camelize}".constantize.execute(exec, {
30
+ dry_run: options.dry_run,
31
+ verbose: options.verbose
32
+ })
33
+ rescue => error
34
+ say_error(" [!] #{error.class}")
35
+ say_error(" - #{error.message}")
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ ActiveScripts::Packages::Base::COMMANDS.each do |exec|
42
+ command exec do |c|
43
+ c.syntax = "active_scripts #{exec} [options]"
44
+ c.description = "#{exec.capitalize} recipes and packages"
45
+
46
+ c.option "--dry-run", "Print out commands but not execute"
47
+ c.option "--verbose", "#{exec.capitalize} available packages verbosely"
48
+
49
+ c.action do |args, options|
50
+ options.default(dry_run: false, verbose: false)
51
+
52
+ say("Select #{exec} options [hit enter to skip]:")
53
+
54
+ begin
55
+ $operating_system = ActiveScripts::OperatingSystem.find
56
+
57
+ recipes = ask("== Which recipies? ", lambda { |str| str.strip.split(/,\s*/) })
58
+ recipes = ActiveScripts::Recipe.find(recipes)
59
+
60
+ packages = ask("== Which #{'additional ' unless recipes.blank?}packages? ", lambda { |str| str.strip.split(/,\s*/) })
61
+ packages = ActiveScripts::Package.find(packages)
62
+ packages = recipes.push(packages).flatten.uniq
63
+
64
+ if packages.blank?
65
+ say_error("== 0 #{$operating_system} recipes or packages #{exec}#{(exec == :upgade) ? 'd' : 'ed'}!")
66
+ else
67
+ packages.each do |package|
68
+ say(" - #{(exec == :upgrade) ? 'Upgrading' : (exec.to_s.capitalize + 'ing')} #{package}...")
69
+ "ActiveScripts::Packages::#{package.to_s.camelize}".constantize.execute(exec, {
70
+ dry_run: options.dry_run,
71
+ verbose: options.verbose
72
+ })
73
+ end
74
+ say_ok("== #{packages.count} #{$operating_system} recipes and packages #{exec}#{(exec == :upgade) ? 'd' : 'ed'}!")
75
+ end
76
+ rescue => error
77
+ say_error(" [!] #{error.class}")
78
+ say_error(" - #{error.message}")
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,16 @@
1
+ require "active_object"
2
+ require "open3"
3
+ require "rbconfig"
4
+
5
+ require "active_scripts/version"
6
+ require "active_scripts/base"
7
+ require "active_scripts/operating_system"
8
+
9
+ [:preparation, :recipe, :package].each do |script|
10
+ require "active_scripts/#{script}"
11
+ require "active_scripts/#{script}s/base"
12
+ end
13
+
14
+ ActiveScripts::Preparation::PREPARATIONS.each { |preparation| require("active_scripts/preparations/#{preparation}") }
15
+ ActiveScripts::Recipe::RECIPES.each { |recipe| require("active_scripts/recipes/#{recipe}") }
16
+ ActiveScripts::Package::PACKAGES.each { |package| require("active_scripts/packages/#{package}") }
@@ -0,0 +1,4 @@
1
+ # Linuxbrew
2
+ export PATH="$HOME/.linuxbrew/bin:$PATH"
3
+ export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
4
+ export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
@@ -0,0 +1,3 @@
1
+ # rbenv
2
+ export PATH="$HOME/.rbenv/bin:$PATH"
3
+ eval "$(rbenv init -)"
@@ -0,0 +1,2 @@
1
+ # wkhtmltopdf
2
+ xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf "$@"
@@ -0,0 +1,38 @@
1
+ module ActiveScripts
2
+ class Base
3
+
4
+ # INFO: ActiveScripts::Base contains code that is
5
+ # shared between all base files.
6
+
7
+ private
8
+
9
+ def assert_valid_user!
10
+ unless user?
11
+ raise SecurityError,
12
+ "The following commands cannot be executed as root. Switch to a non-root user."
13
+ end
14
+ end
15
+
16
+ def user?
17
+ output, error, status = Open3.capture3("whoami")
18
+ output = output.squish
19
+ return(output != "root")
20
+ end
21
+
22
+ def notify_command_todo!
23
+ say_warning(" [!] CommandError")
24
+ say_warning(" - TODO: The command is not yet developed.")
25
+ end
26
+
27
+ def notify_command_unavailable!
28
+ say_warning(" [!] CommandError")
29
+ say_warning(" - The command is not available.")
30
+ end
31
+
32
+ def notify_command_user!
33
+ say_warning(" [!] CommandError")
34
+ say_warning(" - The command cannot be executed as root. Please switch user.")
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,57 @@
1
+ module ActiveScripts
2
+ class OperatingSystem
3
+
4
+ # INFO: ActiveScripts::OperatingSystem contains code that is
5
+ # for retrieving and validating operating systems.
6
+
7
+ OPERATING_SYSTEMS = 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 :operating_system
13
+
14
+ def initialize
15
+ @operating_system = :unknown
16
+ end
17
+
18
+ def self.find
19
+ new.find
20
+ end
21
+
22
+ def find
23
+ generate_operating_system!
24
+ assert_valid_operating_system!
25
+ return(@operating_system)
26
+ end
27
+
28
+ private
29
+
30
+ def assert_valid_operating_system!
31
+ unless OPERATING_SYSTEMS.include?(@operating_system)
32
+ raise ArgumentError,
33
+ "Unknown operating system: #{@operating_system.inspect}. Valid operating systems are: #{OPERATING_SYSTEMS.map(&:inspect).join(', ')}"
34
+ end
35
+ end
36
+
37
+ def generate_operating_system!
38
+ host_os = RbConfig::CONFIG['host_os']
39
+
40
+ @operating_system = case host_os
41
+ when /freebsd/
42
+ :freebsd
43
+ when /linux/
44
+ :linux
45
+ when /darwin|mac os|mac os x/
46
+ :macosx
47
+ when /solaris|bsd/
48
+ :unix
49
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
50
+ :windows
51
+ else
52
+ ask("== Which operating system? ", lambda { |str| str.strip.downcase.to_sym })
53
+ end
54
+ end
55
+
56
+ end
57
+ end