pupcap 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.swp
2
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capistrano.gemspec
4
+ gemspec
5
+
6
+ #
7
+ # Development Dependencies from the Gemfile
8
+ # are merged here.
9
+ #
10
+ group :development do
11
+ gem 'rake', '0.8.7'
12
+ end
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/*_test.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
data/bin/pupcap ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../../lib", __FILE__)
4
+
5
+ require 'pupcap/cli'
6
+
7
+ Pupcap::CLI.start
data/lib/pupcap.rb ADDED
@@ -0,0 +1,2 @@
1
+ module Pupcap
2
+ end
@@ -0,0 +1,53 @@
1
+ require 'pupcap'
2
+ require 'capistrano'
3
+ require 'capistrano/cli'
4
+
5
+ module Pupcap::Action
6
+ class Base
7
+
8
+ def initialize(file, options = {})
9
+ @file = file
10
+ @options = options
11
+ set_default_vars
12
+ ENV["ROLES"] = @options[:role]
13
+ end
14
+
15
+
16
+ class << self
17
+ def ensure_local_dir(dir, mode = "0755")
18
+ run_local("mkdir -p #{dir} && chmod #{mode} #{dir}")
19
+ end
20
+
21
+ def run_local(cmd)
22
+ system cmd
23
+ fail "#{cmd} fail" if $?.to_i != 0
24
+ end
25
+ end
26
+
27
+ def load_recipes(config) #:nodoc:
28
+ # load the standard recipe definition
29
+ cap.load "standard"
30
+ end
31
+
32
+ private
33
+ def set_default_vars
34
+ app = ENV['app'] || File.basename(File.dirname(@file))
35
+ cap.set :application, app
36
+ cap.set :local_root, File.dirname(@file)
37
+ cap.set :provision_key, "#{cap.local_root}/.keys/provision"
38
+ cap.set :provision_key_pub, "#{cap.local_root}/.keys/provision.pub"
39
+ cap.ssh_options[:keys] = cap.provision_key
40
+ cap.ssh_options[:forward_agent] = true
41
+ cap.default_run_options[:pty] = true
42
+ cap.load @file
43
+ end
44
+
45
+ def cap
46
+ unless @cap
47
+ @cap = Capistrano::Configuration.new
48
+ @cap.logger.level = Capistrano::Logger::DEBUG
49
+ end
50
+ @cap
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,14 @@
1
+ require 'pupcap/action'
2
+
3
+ class Pupcap::Action::Cook < Pupcap::Action::Base
4
+ def start
5
+ cap.load "#{root}/cook/Capfile"
6
+ cap.trigger(:load)
7
+ cap.find_and_execute_task("cook", :before => :start, :after => :finish)
8
+ cap.trigger(:exit)
9
+ end
10
+
11
+ def root
12
+ File.dirname(File.expand_path __FILE__)
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ namespace :cook do
2
+ task :default do
3
+ remote_path = "/tmp/puppet"
4
+ find_servers.each do |server|
5
+ ssh_cmd = "-e \"ssh -p #{cook_ssh_port(server)} -i #{provision_key}\""
6
+ rsync_options = "-p --chmod=o+r,g+r -az --exclude=\".keys/\""
7
+ rsync_path = "--rsync-path=\"sudo rsync\""
8
+ cmd = "rsync #{rsync_options} #{ssh_cmd} #{local_root}/ #{rsync_path} #{cook_rsync_host(server)}:#{remote_path}"
9
+ logger.important(cmd)
10
+ system(cmd)
11
+ end
12
+ modules = "--modulepath=#{remote_path}/modules:#{remote_path}/manifests"
13
+ nook = ENV["try"] ? "--noop" : ""
14
+ debug = ENV["debug"] ? "--debug" : ""
15
+ sudo("/usr/local/bin/puppet apply --detailed-exitcodes #{nook} #{debug} #{modules} #{remote_path}/manifests/#{ENV["ROLES"]}.pp || true")
16
+ end
17
+
18
+ def cook_ssh_port(server)
19
+ server.port || ssh_options[:port] || 22
20
+ end
21
+
22
+ def cook_rsync_host(server)
23
+ u = server.user || fetch(:user)
24
+ u ? "#{u}@#{server.host}" : server.host
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ require 'pupcap/action'
2
+
3
+ class Pupcap::Action::Prepare < Pupcap::Action::Base
4
+ def start
5
+ cap.load "#{root}/prepare/Capfile"
6
+ cap.trigger(:load)
7
+ cap.find_and_execute_task("prepare", :before => :start, :after => :finish)
8
+ prepare_dist
9
+ cap.trigger(:exit)
10
+ end
11
+
12
+ def root
13
+ File.dirname(File.expand_path __FILE__)
14
+ end
15
+
16
+ def prepare_dist
17
+ rel = cap.capture("lsb_release -d")
18
+ codename = rel.match(/^.*:\s(.*)$/)
19
+ if codename && codename[1]
20
+ codename = codename[1].to_s.strip[0...12]
21
+ case codename
22
+ when 'Ubuntu 12.04'
23
+ cap.load "#{root}/prepare/ubuntu/precise.rb"
24
+ cap.find_and_execute_task("prepare:ubuntu:precise")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ namespace :prepare do
2
+ task :default do
3
+ generate_keys
4
+ ssh_copy_id
5
+ end
6
+
7
+ task :ssh_copy_id do
8
+ remote_key_path = "/tmp/#{application}_id.pub.#{Time.now.to_i}"
9
+ upload(provision_key_pub, remote_key_path)
10
+ run("mkdir -p ~/.ssh && chmod 0700 ~/.ssh")
11
+ run("cat #{remote_key_path} >> ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys")
12
+ run("rm -f #{remote_key_path}")
13
+ end
14
+
15
+ task :generate_keys do
16
+ unless File.exists?(provision_key)
17
+ logger.important("Generate keys")
18
+ Pupcap::Action.ensure_local_dir("#{local_root}/.keys", "0700")
19
+ Pupcap::Action.run_local("ssh-keygen -q -b 1024 -t rsa -C \"#{application} provision key\" -f #{provision_key}")
20
+ Pupcap::Action.run_local("chmod 0600 #{provision_key}")
21
+ Pupcap::Action.run_local("chmod 0600 #{provision_key_pub}")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,48 @@
1
+ namespace :prepare do
2
+ namespace :ubuntu do
3
+ task :precise do
4
+ run("#{sudo} [ ! -f /root/.prepare_locale_ok ] && #{sudo} locale-gen && #{sudo} update-locale LANG=en_US.UTF8 && #{sudo} touch /root/.prepare_locale_ok || true")
5
+
6
+ tmp_list = "/tmp/sources.list.#{Time.now.to_i}"
7
+ sources_list = "/etc/apt/sources.list"
8
+
9
+ dist_upgraded = false
10
+ current_list = capture("md5sum #{sources_list}").split(" ")[0].to_s.strip
11
+ if current_list != "1f722c129d80782e4fa323a6a70dee59"
12
+ sudo("cp #{sources_list} #{sources_list}.back#{Time.now.to_i}")
13
+ put(precise_sources_list, tmp_list)
14
+ sudo("cp #{tmp_list} #{sources_list}")
15
+ sudo("chown root:root #{sources_list}")
16
+ sudo("chmod 0644 #{sources_list}")
17
+ run("rm -f #{tmp_list}")
18
+ sudo("apt-get -qy update > /dev/null")
19
+ if ENV['upgrade']
20
+ run("echo \"grub-pc hold\" | #{sudo} dpkg --set-selections")
21
+ sudo("apt-get -qy upgrade")
22
+ run("echo \"grub-pc install\" | #{sudo} dpkg --set-selections")
23
+ dist_upgraded = true
24
+ end
25
+ end
26
+
27
+ sudo("apt-get install -qy rsync wget rubygems vim git-core build-essential > /dev/null")
28
+ sudo("/usr/bin/gem install -q --no-ri --no-rdoc --version '~> 2.7.1' puppet")
29
+ sudo("reboot") if dist_upgraded
30
+ end
31
+ end
32
+ end
33
+
34
+ UBUNTU_PRECISE_SOURCES_LIST = <<-CODE
35
+ #############################################################
36
+ ################### OFFICIAL UBUNTU REPOS ###################
37
+ #############################################################
38
+
39
+ ###### Ubuntu Main Repos
40
+ deb mirror://mirrors.ubuntu.com/mirrors.txt precise main
41
+ deb-src mirror://mirrors.ubuntu.com/mirrors.txt precise main
42
+
43
+ ###### Ubuntu Update Repos
44
+ deb mirror://mirrors.ubuntu.com/mirrors.txt precise-security main
45
+ deb mirror://mirrors.ubuntu.com/mirrors.txt precise-updates main
46
+ deb-src mirror://mirrors.ubuntu.com/mirrors.txt precise-security main
47
+ deb-src mirror://mirrors.ubuntu.com/mirrors.txt precise-updates main
48
+ CODE
data/lib/pupcap/cli.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'optparse'
2
+ require 'pupcap'
3
+
4
+ class Pupcap::CLI
5
+ class << self
6
+ def start
7
+ get_action
8
+ require "pupcap/action/#{options[:action]}"
9
+ klass = Pupcap::Action.const_get(options[:action].capitalize)
10
+ inst = klass.new(options[:file], options)
11
+ inst.start
12
+ end
13
+
14
+ private
15
+ def get_action
16
+ options_parser
17
+
18
+ action = ARGV[1]
19
+ role = ARGV[0]
20
+ if !action || !valid_actions.include?(action)
21
+ $stderr.puts "Please specify a action to run: #{valid_actions.join("|")}"
22
+ exit 1
23
+ end
24
+
25
+ if !role
26
+ $stderr.puts "Please specify a role to run"
27
+ exit 1
28
+ end
29
+
30
+ unless File.exists?(options[:file])
31
+ $stderr.puts "A file #{options[:file]} does not exists"
32
+ exit 1
33
+ end
34
+
35
+ options.merge!(:action => action, :role => role)
36
+ end
37
+
38
+ def valid_actions
39
+ @valid_actions ||= %w{ prepare cook }
40
+ end
41
+
42
+ def options
43
+ @options ||= {
44
+ :file => File.expand_path("Puppetfile")
45
+ }
46
+ end
47
+
48
+ def options_parser
49
+ @options_parser ||= OptionParser.new do |opts|
50
+ opts.banner = "Usage: #{File.basename($0)} [options] role #{valid_actions.join("|")}"
51
+
52
+ opts.on("-h", "--help", "Displays this help info") do
53
+ puts opts
54
+ exit 0
55
+ end
56
+
57
+ opts.on("-f", "--file FILE", "A recipe file to load") do |file|
58
+ options[:file] = File.expand_path(file)
59
+ end
60
+ end.parse!
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,16 @@
1
+ require 'scanf'
2
+ module Pupcap
3
+
4
+ class Version
5
+
6
+ MAJOR = 0
7
+ MINOR = 0
8
+ PATCH = 1
9
+
10
+ def self.to_s
11
+ "#{MAJOR}.#{MINOR}.#{PATCH}"
12
+ end
13
+
14
+ end
15
+
16
+ end
data/pupcap.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pupcap/version"
4
+
5
+ Gem::Specification.new do |s|
6
+
7
+ s.name = "pupcap"
8
+ s.version = Pupcap::Version.to_s
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Dmitry Galinsky"]
11
+ s.email = ["dima.exe@gmail.com"]
12
+ s.homepage = "http://github.com/dima-exe/pupcap"
13
+ s.summary = %q{under development}
14
+ s.description = %q{under development description}
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ if s.respond_to? :specification_version then
21
+ s.specification_version = 3
22
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
+ s.add_runtime_dependency(%q<capistrano>, [">= 2.12.0"])
24
+ else
25
+ s.add_dependency(%q<capistrano>, [">= 2.12.0"])
26
+ end
27
+ else
28
+ s.add_dependency(%q<capistrano>, [">= 2.12.0"])
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pupcap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dmitry Galinsky
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.12.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.12.0
30
+ description: under development description
31
+ email:
32
+ - dima.exe@gmail.com
33
+ executables:
34
+ - pupcap
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - Rakefile
41
+ - bin/pupcap
42
+ - lib/pupcap.rb
43
+ - lib/pupcap/action.rb
44
+ - lib/pupcap/action/.prepare.rb.swp
45
+ - lib/pupcap/action/cook.rb
46
+ - lib/pupcap/action/cook/Capfile
47
+ - lib/pupcap/action/prepare.rb
48
+ - lib/pupcap/action/prepare/Capfile
49
+ - lib/pupcap/action/prepare/ubuntu/precise.rb
50
+ - lib/pupcap/cli.rb
51
+ - lib/pupcap/version.rb
52
+ - pupcap.gemspec
53
+ homepage: http://github.com/dima-exe/pupcap
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.23
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: under development
77
+ test_files: []
78
+ has_rdoc: