fucking_shell_scripts 0.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8009309508988eb570f497f873f20add0226fa4d
4
+ data.tar.gz: 067245ebe96188fb2890b02091e8ed3ce65def91
5
+ SHA512:
6
+ metadata.gz: 951bfa262aec8703aa2e043e04ed7b62374d588cf2fd0976da227293fd171117ea389f37adbdda492c1da40f7c4cb5f9a0146d7437258f505355c21f3856a00e
7
+ data.tar.gz: c6f9c1202e68497580b2cfb31a6fa35e3335847bc96c17b78c20c865cc14151b7189992c4d93024143c8b93121bea6372b0b3891b9418e975fa6059619a0aab3
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fucking_shell_scripts.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brandon Hilkert
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # FuckingShellScripts
2
+
3
+ The easiest, most common sense configuration management tool... because you just use fucking shell scripts.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fucking_shell_scripts'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fucking_shell_scripts
18
+
19
+ ## Development
20
+
21
+ During development of a script, use vagrant:
22
+
23
+ vagrant up
24
+ cd /vagrant
25
+
26
+ `cd /vagrant` will put you in the root folder of the project so that you can run a script such as `./search-service.sh`.
27
+
28
+ ## Servers
29
+
30
+ ### Defaults
31
+
32
+ Server defaults are defined by creating the following file:
33
+
34
+ `./servers/defaults.yml`
35
+
36
+ ```yaml
37
+ name: ppd instance
38
+ security_groups: pd-app-server
39
+ instance_type: c1.xlarge
40
+ image_id: ami-e76ac58e
41
+ availability_zone: us-east-1d
42
+ region: us-east-1
43
+ key_name: pd-app-server
44
+ private_key_path: /Users/bhilkert/.ssh/pd-app-server
45
+ ```
46
+
47
+ To define a server, create a yaml file in the `./servers` directory with the following format:
48
+
49
+ `./servers/search-service.yml`
50
+
51
+ ```yaml
52
+ name: search-service
53
+ security_groups: search-service
54
+ instance_type: c1.medium
55
+ image_id: ami-90374bf9
56
+
57
+ scripts:
58
+ - scripts/apt.sh
59
+ - scripts/env.sh
60
+ - scripts/git.sh
61
+ - scripts/ruby.sh
62
+ - scripts/rubygems.sh
63
+ - scripts/redis.sh
64
+ ```
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => [:console]
3
+
4
+ task :console do
5
+ exec "irb -r fss -I ./lib"
6
+ end
data/bin/fss ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require_relative '../lib/fucking_shell_scripts'
5
+
6
+ options = {}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: fss [options] type"
10
+
11
+ opts.on('--build', 'Only build the server' ) do |build|
12
+ options[:build] = true
13
+ end
14
+
15
+ opts.on('--configure', 'Only configure the server' ) do |configure|
16
+ options[:configure] = true
17
+ end
18
+
19
+ opts.on('--instance-id ID', 'An exiting AWS instance ID' ) do |id|
20
+ options[:instance_id] = id
21
+ end
22
+
23
+ opts.on('-h', '--help', 'Display this screen' ) do
24
+ puts opts
25
+ exit
26
+ end
27
+
28
+ opts.on('-v', '--version', 'Show version' ) do
29
+ puts FuckingShellScripts::Version
30
+ end
31
+ end.parse!
32
+
33
+ options.merge!(type: ARGV.first)
34
+
35
+ cli = FuckingShellScripts::CLI.new(options)
36
+
37
+ if options[:build]
38
+ cli.build
39
+
40
+ elsif options[:configure]
41
+ cli.configure
42
+
43
+ else
44
+ cli.bootstrap
45
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fucking_shell_scripts/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fucking_shell_scripts"
8
+ spec.version = FuckingShellScripts::VERSION
9
+ spec.authors = ["Brandon Hilkert"]
10
+ spec.email = ["brandonhilkert@gmail.com"]
11
+ spec.description = %q{The easiest, most common sense configuration management tool... because you just use fucking shell scripts.}
12
+ spec.summary = %q{The easiest, most common sense configuration management tool... because you just use fucking shell scripts.}
13
+ spec.homepage = "https://github.com/brandonhilkert/fucking_shell_scripts"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.add_dependency "fog", "~> 1.14.0"
26
+ end
data/lib/ext/fog.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'fog'
2
+ require 'fog/core/ssh'
3
+
4
+ # Monkey-patch Fog 1.3.1 to stream SSH output
5
+ # (in real time) to stdout.
6
+ class Fog::SSH::Real
7
+ def run(commands)
8
+ commands = [*commands]
9
+ results = []
10
+ begin
11
+ Net::SSH.start(@address, @username, @options) do |ssh|
12
+ commands.each do |command|
13
+ result = Fog::SSH::Result.new(command)
14
+ ssh.open_channel do |ssh_channel|
15
+ ssh_channel.request_pty
16
+ ssh_channel.exec(command) do |channel, success|
17
+ unless success
18
+ raise "Could not execute command: #{command.inspect}"
19
+ end
20
+
21
+ channel.on_data do |ch, data|
22
+ result.stdout << data
23
+ puts data
24
+ end
25
+
26
+ channel.on_extended_data do |ch, type, data|
27
+ next unless type == 1
28
+ result.stderr << data
29
+ puts data
30
+ end
31
+
32
+ channel.on_request('exit-status') do |ch, data|
33
+ result.status = data.read_long
34
+ end
35
+
36
+ channel.on_request('exit-signal') do |ch, data|
37
+ result.status = 255
38
+ end
39
+ end
40
+ end
41
+ ssh.loop
42
+ results << result
43
+ end
44
+ end
45
+ rescue Net::SSH::HostKeyMismatch => exception
46
+ exception.remember_host!
47
+ sleep 0.2
48
+ retry
49
+ end
50
+ results
51
+ end
52
+ end
53
+
@@ -0,0 +1,14 @@
1
+ require "fucking_shell_scripts/version"
2
+
3
+ begin
4
+ require 'pry'
5
+ rescue LoadError
6
+ end
7
+
8
+ require_relative 'fucking_shell_scripts/cli'
9
+ require_relative 'fucking_shell_scripts/configuration'
10
+ require_relative 'fucking_shell_scripts/connection'
11
+ require_relative 'fucking_shell_scripts/scp'
12
+ require_relative 'fucking_shell_scripts/server'
13
+
14
+ require_relative 'ext/fog'
@@ -0,0 +1,30 @@
1
+ module FuckingShellScripts
2
+ class CLI
3
+ def initialize(opts = {})
4
+ @opts = opts
5
+ @connection = FuckingShellScripts::Connection.new(options).connection
6
+ end
7
+
8
+ def bootstrap
9
+ server.bootstrap
10
+ end
11
+
12
+ def build
13
+ server.build
14
+ end
15
+
16
+ def configure
17
+ server.configure
18
+ end
19
+
20
+ private
21
+
22
+ def server
23
+ FuckingShellScripts::Server.new(@connection, options)
24
+ end
25
+
26
+ def options
27
+ @options ||= FuckingShellScripts::Configuration.new(@opts).options
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,49 @@
1
+ require 'yaml'
2
+
3
+ module FuckingShellScripts
4
+ class Configuration
5
+ MissingServerType = Class.new(StandardError)
6
+ MissingServerConfiguration = Class.new(StandardError)
7
+
8
+ attr_reader :options
9
+
10
+ def initialize(command_line_options = {})
11
+ @command_line_options = command_line_options
12
+
13
+ read_and_parse_server_options
14
+
15
+ raise MissingServerType, "Please specify a type of server you want to create using the --type option" unless options[:type]
16
+ end
17
+
18
+ private
19
+
20
+ def default_options
21
+ begin
22
+ YAML.load(File.read('servers/defaults.yml'))
23
+ rescue Errno::ENOENT
24
+ {}
25
+ end
26
+ end
27
+
28
+ def server_options
29
+ begin
30
+ YAML.load(File.read(server_file))
31
+ rescue Errno::ENOENT
32
+ raise MissingServerConfiguration, "Please create a configuration file './servers/#{type}.yml'"
33
+ end
34
+ end
35
+
36
+ def server_file
37
+ "servers/#{type}.yml"
38
+ end
39
+
40
+ def read_and_parse_server_options
41
+ options_string_hash = default_options.merge(server_options).merge(@command_line_options)
42
+ @options = Hash[options_string_hash.map{ |(k,v)| [k.to_sym, v] }]
43
+ end
44
+
45
+ def type
46
+ @command_line_options[:type]
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,26 @@
1
+ require 'fog'
2
+
3
+ module FuckingShellScripts
4
+ class Connection
5
+ MissingAWSCredentials = Class.new(StandardError)
6
+
7
+ def initialize(opts)
8
+ @opts = opts
9
+
10
+ if ENV["AWS_ACCESS_KEY"].nil? || ENV["AWS_SECRET_ACCESS_KEY"].nil?
11
+ raise FuckingShellScripts::Connection::MissingAWSCredentials, "Make sure AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY are environmental variables with your credentials"
12
+ end
13
+ end
14
+
15
+ def connection
16
+ @connection ||= begin
17
+ Fog::Compute.new(
18
+ provider: "AWS",
19
+ aws_access_key_id: ENV["AWS_ACCESS_KEY"],
20
+ aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
21
+ region: @opts.fetch(:region)
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ module FuckingShellScripts
2
+ class SCP
3
+ FILENAME = "fss.tar.gz"
4
+
5
+ def initialize(server, opts)
6
+ @server, @opts = server, opts
7
+ end
8
+
9
+ def to_server
10
+ create_local_archive
11
+ scp_files_to_server
12
+ extract_remote_archive
13
+ remove_local_archive
14
+ end
15
+
16
+ private
17
+
18
+ def create_local_archive
19
+ includes = @opts.fetch(:files) + @opts.fetch(:scripts)
20
+ `tar -czf #{FILENAME} #{includes.join(" ")}`
21
+ end
22
+
23
+ def scp_files_to_server
24
+ @server.scp(FILENAME, ".")
25
+ end
26
+
27
+ def extract_remote_archive
28
+ @server.ssh("tar -xzf #{FILENAME}")
29
+ end
30
+
31
+ def remove_local_archive
32
+ `rm -f #{FILENAME}`
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,69 @@
1
+ module FuckingShellScripts
2
+ class Server
3
+ NoServerSelected = Class.new(StandardError)
4
+ MissingInstanceID = Class.new(StandardError)
5
+
6
+ attr_reader :server
7
+
8
+ def initialize(connection, options)
9
+ @connection, @options = connection, options
10
+ end
11
+
12
+ def bootstrap
13
+ build
14
+ configure
15
+ end
16
+
17
+ def build
18
+ @server = connection.servers.create(
19
+ image_id: options.fetch(:image),
20
+ flavor_id: options.fetch(:size),
21
+ key_name: options.fetch(:key_name),
22
+ tags: { "Name" => name },
23
+ groups: options.fetch(:security_groups),
24
+ private_key_path: options.fetch(:private_key_path)
25
+ )
26
+ print "Creating #{options.fetch(:size)} from #{options.fetch(:image)}"
27
+
28
+ server.wait_for do
29
+ print "."
30
+ ready?
31
+ end
32
+
33
+ puts "ready!"
34
+ puts ""
35
+
36
+ print "Waiting for ssh access"
37
+
38
+ server.wait_for do
39
+ print "."
40
+ sshable?
41
+ end
42
+
43
+ puts "#{server.dns_name} ready!"
44
+ end
45
+
46
+ def configure
47
+ get(options[:instance_id]) if server.nil?
48
+ raise NoServerSelected, "Unable to find server. Try specifying the server ID." if server.nil?
49
+
50
+ FuckingShellScripts::SCP.new(server, options).to_server
51
+ server.ssh(options.fetch(:scripts))
52
+ end
53
+
54
+ private
55
+
56
+ attr_reader :options, :connection
57
+
58
+ def get(instance_id)
59
+ raise FuckingShellScripts::Server::MissingInstanceID , "Please specify the instance ID using the --instance-id option." if instance_id.nil?
60
+ @server = connection.servers.get(instance_id)
61
+ @server.private_key_path = options.fetch(:private_key_path)
62
+ @server
63
+ end
64
+
65
+ def name
66
+ "#{options.fetch(:name).downcase.sub(/ /, '-')}-#{Time.now.strftime("%y-%m-%d-%H-%M")}"
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module FuckingShellScripts
2
+ VERSION = "0.99"
3
+ end
data/spec/fss_spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'fss'
2
+
3
+ describe Fss do
4
+ it "new" do
5
+ Fss::Configuration.any_instance.stub(:settings_file).and_return('spec/support/settings.yml')
6
+ Fss.new()
7
+
8
+ end
9
+
10
+
11
+
12
+ end
13
+
@@ -0,0 +1,12 @@
1
+ name: search-service
2
+ security_groups: search-service
3
+ size: c1.medium
4
+ image: ami-90374bf9
5
+
6
+ scripts:
7
+ - scripts/apt.sh
8
+ - scripts/env.sh
9
+ - scripts/git.sh
10
+ - scripts/ruby.sh
11
+ - scripts/rubygems.sh
12
+ - scripts/redis.sh
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fucking_shell_scripts
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.99'
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Hilkert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
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: fog
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.14.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.14.0
69
+ description: The easiest, most common sense configuration management tool... because
70
+ you just use fucking shell scripts.
71
+ email:
72
+ - brandonhilkert@gmail.com
73
+ executables:
74
+ - fss
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/fss
84
+ - fucking_shell_scripts.gemspec
85
+ - lib/ext/fog.rb
86
+ - lib/fucking_shell_scripts.rb
87
+ - lib/fucking_shell_scripts/cli.rb
88
+ - lib/fucking_shell_scripts/configuration.rb
89
+ - lib/fucking_shell_scripts/connection.rb
90
+ - lib/fucking_shell_scripts/scp.rb
91
+ - lib/fucking_shell_scripts/server.rb
92
+ - lib/fucking_shell_scripts/version.rb
93
+ - spec/fss_spec.rb
94
+ - spec/servers/search-service.yml
95
+ homepage: https://github.com/brandonhilkert/fucking_shell_scripts
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.0.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: The easiest, most common sense configuration management tool... because you
119
+ just use fucking shell scripts.
120
+ test_files:
121
+ - spec/fss_spec.rb
122
+ - spec/servers/search-service.yml