active_scripts 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +9 -0
- data/.rspec +4 -0
- data/.travis.yml +13 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/COMMANDS.md +43 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/active_scripts.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/rake +16 -0
- data/bin/setup +7 -0
- data/exe/active_scripts +82 -0
- data/lib/active_scripts.rb +16 -0
- data/lib/active_scripts/addendums/linuxbrew.txt +4 -0
- data/lib/active_scripts/addendums/rbenv.txt +3 -0
- data/lib/active_scripts/addendums/wkhtmltopdf.txt +2 -0
- data/lib/active_scripts/base.rb +38 -0
- data/lib/active_scripts/operating_system.rb +57 -0
- data/lib/active_scripts/package.rb +39 -0
- data/lib/active_scripts/packages/all.rb +34 -0
- data/lib/active_scripts/packages/base.rb +107 -0
- data/lib/active_scripts/packages/homebrew.rb +49 -0
- data/lib/active_scripts/packages/imagemagick.rb +62 -0
- data/lib/active_scripts/packages/jpegoptim.rb +55 -0
- data/lib/active_scripts/packages/mysql.rb +73 -0
- data/lib/active_scripts/packages/nginx.rb +24 -0
- data/lib/active_scripts/packages/optipng.rb +55 -0
- data/lib/active_scripts/packages/postgresql.rb +69 -0
- data/lib/active_scripts/packages/rails.rb +27 -0
- data/lib/active_scripts/packages/rbenv.rb +62 -0
- data/lib/active_scripts/packages/redis.rb +78 -0
- data/lib/active_scripts/packages/ruby.rb +58 -0
- data/lib/active_scripts/packages/ruby_build.rb +55 -0
- data/lib/active_scripts/packages/wkhtmltopdf.rb +64 -0
- data/lib/active_scripts/preparation.rb +37 -0
- data/lib/active_scripts/preparations/base.rb +81 -0
- data/lib/active_scripts/preparations/freebsd.rb +20 -0
- data/lib/active_scripts/preparations/linux.rb +49 -0
- data/lib/active_scripts/preparations/macosx.rb +20 -0
- data/lib/active_scripts/preparations/unix.rb +20 -0
- data/lib/active_scripts/preparations/windows.rb +20 -0
- data/lib/active_scripts/recipe.rb +52 -0
- data/lib/active_scripts/recipes/all.rb +14 -0
- data/lib/active_scripts/recipes/base.rb +62 -0
- data/lib/active_scripts/recipes/rails.rb +26 -0
- data/lib/active_scripts/version.rb +3 -0
- metadata +178 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
module ActiveScripts
|
2
|
+
class Package
|
3
|
+
|
4
|
+
# INFO: ActiveScripts::Package contains code that is
|
5
|
+
# for retrieving and validating packages.
|
6
|
+
|
7
|
+
PACKAGES = Dir.entries("#{File.dirname(__FILE__)}/packages")
|
8
|
+
.drop(2)
|
9
|
+
.reject { |f| ["base.rb"].include?(f) }
|
10
|
+
.map { |f| File.basename(f, ".rb") }
|
11
|
+
|
12
|
+
attr_accessor :packages
|
13
|
+
|
14
|
+
def initialize(packages=[])
|
15
|
+
@packages = packages
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find(packages=[])
|
19
|
+
new(packages).find
|
20
|
+
end
|
21
|
+
|
22
|
+
def find
|
23
|
+
@packages.blank? ? say(" - Package skipped!") : assert_valid_packages!
|
24
|
+
return(@packages.strip)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def assert_valid_packages!
|
30
|
+
@packages.each do |package|
|
31
|
+
unless PACKAGES.include?(package)
|
32
|
+
raise ArgumentError,
|
33
|
+
"Unknown package: #{package.inspect}. Valid packages are listed in the documentation."
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ActiveScripts
|
2
|
+
module Packages
|
3
|
+
class All < ActiveScripts::Packages::Base
|
4
|
+
|
5
|
+
# INFO: ActiveScripts::Packages::All contains code that
|
6
|
+
# executes all packages.
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def install
|
11
|
+
notify_command_unavailable!
|
12
|
+
end
|
13
|
+
|
14
|
+
def upgrade
|
15
|
+
case $operating_system
|
16
|
+
when :macosx, :linux
|
17
|
+
execute_command!("brew update --all")
|
18
|
+
output = execute_command!("brew upgrade --all")
|
19
|
+
say_warning(" [!] #{output}") unless option_dry_run? || package_output?(output)
|
20
|
+
output = execute_command!("brew doctor")
|
21
|
+
say_warning(" [!] #{output}") unless option_dry_run? || package_output?(output, includes: "Your system is ready to brew.")
|
22
|
+
say_ok(" Upgrade complete!")
|
23
|
+
else
|
24
|
+
notify_package_unavailable!
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def uninstall
|
29
|
+
notify_command_unavailable!
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module ActiveScripts
|
2
|
+
module Packages
|
3
|
+
class Base < ActiveScripts::Base
|
4
|
+
|
5
|
+
# INFO: ActiveScripts::Packages::Base contains code that is
|
6
|
+
# shared between all package files.
|
7
|
+
|
8
|
+
COMMANDS = [:install, :upgrade, :uninstall]
|
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
|
+
assert_valid_user!
|
26
|
+
send(@command)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def assert_valid_command!
|
32
|
+
unless COMMANDS.include?(@command)
|
33
|
+
raise ArgumentError,
|
34
|
+
"Unknown package command: #{@command.inspect}. Valid package commands are: #{COMMANDS.map(&:inspect).join(', ')}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert_valid_options!
|
39
|
+
@options.each_key do |option|
|
40
|
+
unless OPTIONS.include?(option)
|
41
|
+
raise ArgumentError,
|
42
|
+
"Unknown package option: #{option.inspect}. Valid package options are: #{OPTIONS.map(&:inspect).join(', ')}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def option_dry_run?
|
48
|
+
@options.fetch(:dry_run, false)
|
49
|
+
end
|
50
|
+
|
51
|
+
def option_verbose?
|
52
|
+
@options.fetch(:verbose, false)
|
53
|
+
end
|
54
|
+
|
55
|
+
def addendum_path!(file)
|
56
|
+
output = File.dirname(__FILE__)
|
57
|
+
output = output.shift("/packages")
|
58
|
+
"#{output}/addendums/#{file}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def execute_command!(command)
|
62
|
+
say(" Executing: '#{command}'") if option_dry_run? || option_verbose?
|
63
|
+
option_dry_run? ? (output = error = "") : (output, error, status = Open3.capture3("#{command}"))
|
64
|
+
return(error.blank? ? output : error)
|
65
|
+
end
|
66
|
+
|
67
|
+
def package_installed?(command: "brew list", excludes: nil, includes: nil)
|
68
|
+
begin
|
69
|
+
output, error, status = Open3.capture3("#{command}")
|
70
|
+
output = output.squish
|
71
|
+
if includes.nil? && excludes.nil?
|
72
|
+
output.present?
|
73
|
+
else
|
74
|
+
includes.nil? ? [excludes].flatten.any? { |str| output.exclude?(str) } : [includes].flatten.any? { |str| output.include?(str) }
|
75
|
+
end
|
76
|
+
rescue
|
77
|
+
return(false)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def package_output?(output, excludes: nil, includes: nil)
|
82
|
+
output = output.squish
|
83
|
+
if includes.nil? && excludes.nil?
|
84
|
+
output.blank?
|
85
|
+
else
|
86
|
+
includes.nil? ? [excludes].flatten.any? { |str| output.exclude?(str) } : [includes].flatten.any? { |str| output.include?(str) }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def notify_package_exists!
|
91
|
+
say_warning(" [!] PackageError")
|
92
|
+
say_warning(" - The package is already installed.")
|
93
|
+
end
|
94
|
+
|
95
|
+
def notify_package_missing!
|
96
|
+
say_error(" [!] PackageError")
|
97
|
+
say_error(" - The package is not installed.")
|
98
|
+
end
|
99
|
+
|
100
|
+
def notify_package_unavailable!
|
101
|
+
say_warning(" [!] PackageError")
|
102
|
+
say_warning(" - The package is not available for your operating system.")
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module ActiveScripts
|
2
|
+
module Packages
|
3
|
+
class Homebrew < ActiveScripts::Packages::Base
|
4
|
+
|
5
|
+
# INFO: ActiveScripts::Packages::Homebrew contains code that
|
6
|
+
# execute the Homebrew package.
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def install
|
11
|
+
if package_installed?(command: "brew")
|
12
|
+
notify_package_exists!
|
13
|
+
else
|
14
|
+
case $operating_system
|
15
|
+
when :macosx
|
16
|
+
execute_command!('ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"')
|
17
|
+
execute_command!("brew tap homebrew/dupes")
|
18
|
+
say_ok(" Installation complete!")
|
19
|
+
when :linux
|
20
|
+
execute_command!('ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"')
|
21
|
+
execute_command!("cat #{addendum_path!('linuxbrew.txt')} >> ~/.bashrc")
|
22
|
+
execute_command!("source ~/.bashrc")
|
23
|
+
execute_command!("brew tap homebrew/dupes")
|
24
|
+
say_ok(" Installation complete!")
|
25
|
+
else
|
26
|
+
notify_package_unavailable!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def upgrade
|
32
|
+
execute_command!("brew update --all")
|
33
|
+
output = execute_command!("brew doctor")
|
34
|
+
say_warning(" [!] #{output.squish}") unless option_dry_run? || package_output?(output, includes: "Your system is ready to brew.")
|
35
|
+
say_ok(" Upgrade complete!")
|
36
|
+
end
|
37
|
+
|
38
|
+
def uninstall
|
39
|
+
if package_installed?(command: "brew")
|
40
|
+
execute_command('ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"')
|
41
|
+
say_ok(" Uninstallation complete!")
|
42
|
+
else
|
43
|
+
notify_package_missing!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module ActiveScripts
|
2
|
+
module Packages
|
3
|
+
class Imagemagick < ActiveScripts::Packages::Base
|
4
|
+
|
5
|
+
# INFO: ActiveScripts::Packages::Imagemagick contains code that
|
6
|
+
# execute the ImageMagick package.
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def install
|
11
|
+
if package_installed?(includes: "imagemagick")
|
12
|
+
notify_package_exists!
|
13
|
+
else
|
14
|
+
case $operating_system
|
15
|
+
when :macosx, :linux
|
16
|
+
begin
|
17
|
+
Timeout::timeout(600) do
|
18
|
+
execute_command!("brew install imagemagick")
|
19
|
+
end
|
20
|
+
rescue Timeout::Error => e
|
21
|
+
##
|
22
|
+
ensure
|
23
|
+
say_ok(" Installation complete!")
|
24
|
+
end
|
25
|
+
else
|
26
|
+
notify_package_unavailable!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def upgrade
|
32
|
+
if package_installed?(includes: "imagemagick")
|
33
|
+
case $operating_system
|
34
|
+
when :macosx, :linux
|
35
|
+
output = execute_command!("brew upgrade imagemagick")
|
36
|
+
say_warning(" [!] #{output.squish}") unless option_dry_run? || package_output?(output, includes: "Error:")
|
37
|
+
say_ok(" Upgrade complete!")
|
38
|
+
else
|
39
|
+
notify_package_unavailable!
|
40
|
+
end
|
41
|
+
else
|
42
|
+
notify_package_missing!
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def uninstall
|
47
|
+
if package_installed?(includes: "imagemagick")
|
48
|
+
case $operating_system
|
49
|
+
when :macosx, :linux
|
50
|
+
execute_command!("brew remove imagemagick")
|
51
|
+
say_ok(" Uninstallation complete!")
|
52
|
+
else
|
53
|
+
notify_package_unavailable!
|
54
|
+
end
|
55
|
+
else
|
56
|
+
notify_package_missing!
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ActiveScripts
|
2
|
+
module Packages
|
3
|
+
class Jpegoptim < ActiveScripts::Packages::Base
|
4
|
+
|
5
|
+
# INFO: ActiveScripts::Packages::Jpegoptim contains code that
|
6
|
+
# execute the jpegoptim package.
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def install
|
11
|
+
if package_installed?(includes: "jpegoptim")
|
12
|
+
notify_package_exists!
|
13
|
+
else
|
14
|
+
case $operating_system
|
15
|
+
when :macosx, :linux
|
16
|
+
execute_command!("brew install jpegoptim")
|
17
|
+
say_ok(" Installation complete!")
|
18
|
+
else
|
19
|
+
notify_package_unavailable!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def upgrade
|
25
|
+
if package_installed?(includes: "jpegoptim")
|
26
|
+
case $operating_system
|
27
|
+
when :macosx, :linux
|
28
|
+
output = execute_command!("brew upgrade jpegoptim")
|
29
|
+
say_warning(" [!] #{output.squish}") unless option_dry_run? || package_output?(output, includes: "Error:")
|
30
|
+
say_ok(" Upgrade complete!")
|
31
|
+
else
|
32
|
+
notify_package_unavailable!
|
33
|
+
end
|
34
|
+
else
|
35
|
+
notify_package_missing!
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def uninstall
|
40
|
+
if package_installed?(includes: "jpegoptim")
|
41
|
+
case $operating_system
|
42
|
+
when :macosx, :linux
|
43
|
+
execute_command!("brew remove jpegoptim")
|
44
|
+
say_ok(" Uninstallation complete!")
|
45
|
+
else
|
46
|
+
notify_package_unavailable!
|
47
|
+
end
|
48
|
+
else
|
49
|
+
notify_package_missing!
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module ActiveScripts
|
2
|
+
module Packages
|
3
|
+
class Mysql < ActiveScripts::Packages::Base
|
4
|
+
|
5
|
+
# INFO: ActiveScripts::Packages::Mysql contains code that
|
6
|
+
# execute the MySQL package.
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def install
|
11
|
+
if package_installed?(includes: "mysql") || package_installed?(command: "which mysql", includes: "mysql")
|
12
|
+
notify_package_exists!
|
13
|
+
else
|
14
|
+
case $operating_system
|
15
|
+
when :macosx
|
16
|
+
execute_command!("brew install mysql")
|
17
|
+
say_ok(" Installation complete!")
|
18
|
+
when :linux
|
19
|
+
if agree(" [?] Dedicated MySQL? ", true)
|
20
|
+
if agree(" [?] MySQL client only? ", true)
|
21
|
+
execute_command!("sudo apt-get -y install mysql-client")
|
22
|
+
else
|
23
|
+
execute_command!("sudo mysql_secure_installation")
|
24
|
+
end
|
25
|
+
else
|
26
|
+
execute_command!("sudo apt-get -y install mysql-server mysql-client libmysqlclient-dev")
|
27
|
+
end
|
28
|
+
say_ok(" Installation complete!")
|
29
|
+
else
|
30
|
+
notify_package_unavailable!
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def upgrade
|
36
|
+
if package_installed?(includes: "mysql") || package_installed?(command: "which mysql", includes: "mysql")
|
37
|
+
case $operating_system
|
38
|
+
when :macosx
|
39
|
+
output = execute_command!("brew upgrade mysql")
|
40
|
+
say_warning(" [!] #{output.squish}") unless option_dry_run? || package_output?(output, includes: "Error:")
|
41
|
+
say_ok(" Upgrade complete!")
|
42
|
+
when :linux
|
43
|
+
execute_command!("sudo apt-get -y upgrade mysql-server mysql-client libmysqlclient-dev")
|
44
|
+
say_ok(" Upgrade complete!")
|
45
|
+
else
|
46
|
+
notify_package_unavailable!
|
47
|
+
end
|
48
|
+
else
|
49
|
+
notify_package_missing!
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def uninstall
|
54
|
+
if package_installed?(includes: "mysql") || package_installed?(command: "which mysql", includes: "mysql")
|
55
|
+
case $operating_system
|
56
|
+
when :macosx
|
57
|
+
execute_command!("brew remove mysql")
|
58
|
+
say_ok(" Uninstallation complete!")
|
59
|
+
when :linux
|
60
|
+
execute_command!("sudo apt-get -y --purge remove mysql-server mysql-client libmysqlclient-dev")
|
61
|
+
execute_command!("sudo apt-get -y autoremove")
|
62
|
+
say_ok(" Uninstallation complete!")
|
63
|
+
else
|
64
|
+
notify_package_unavailable!
|
65
|
+
end
|
66
|
+
else
|
67
|
+
notify_package_missing!
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActiveScripts
|
2
|
+
module Packages
|
3
|
+
class Nginx < ActiveScripts::Packages::Base
|
4
|
+
|
5
|
+
# INFO: ActiveScripts::Packages::Nginx contains code that
|
6
|
+
# execute the Nginx package.
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def install
|
11
|
+
notify_command_todo!
|
12
|
+
end
|
13
|
+
|
14
|
+
def upgrade
|
15
|
+
notify_command_todo!
|
16
|
+
end
|
17
|
+
|
18
|
+
def uninstall
|
19
|
+
notify_command_todo!
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|