kibou 0.0.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kibou (0.1.0)
5
+ rake
6
+ small
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ rake (0.9.2.2)
12
+ small (0.5.1)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ kibou!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Bryan Goines
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # Kibou 希望 (Hope)
2
+ =============
3
+
4
+ Homebrew and Rakefile are OSX's best friends.
5
+
6
+ ## Features
7
+
8
+ Kibou is using [Homebrew](http://mxcl.github.com/homebrew/) and [Rake](https://github.com/jimweirich/rake#readme) to manage your OSX configuration with only single `rake` command.
9
+
10
+ ## Dependencies
11
+
12
+ * OSX
13
+
14
+ * [Homebrew](http://mxcl.github.com/homebrew/)
15
+ * [Installation guide](https://github.com/mxcl/homebrew/wiki/Installation)
16
+
17
+ * [Ruby 1.9.x](http://ruby-lang.org/)
18
+
19
+ * [rbenv](https://github.com/sstephenson/rbenv) (preferred)
20
+
21
+ * Installation
22
+
23
+ brew install rbenv ruby-build
24
+ rbenv install 1.9.3-p194
25
+ rbenv global 1.9.3-p194
26
+ rbenv rehash
27
+ * [rvm](http://rvm.beginrescueend.com/)
28
+
29
+ * Installation
30
+
31
+ # Follow rvm installation guide first
32
+ rvm install 1.9.3-p194
33
+ rvm default 1.9.3-p194
34
+ * **OR** install Ruby from Homebrew via `brew install ruby`
35
+
36
+ ## Installation
37
+
38
+ gem install kibou
39
+
40
+ ## Example / Usage
41
+
42
+ **Recipe**
43
+
44
+ # recipes/tools.rb
45
+ class Tools < Kibou::Recipe
46
+ package :tmux, :ensure => :latest
47
+ package :wemux, :via => "https://github.com/downloads/zolrath/wemux/wemux.rb"
48
+
49
+ post_install :test_tmux
50
+
51
+ def test_tmux
52
+ status = system("which tmux")
53
+ puts status ? "tmux is installed" : "tmux is not installed"
54
+ end
55
+
56
+ end
57
+
58
+ **Rakefile**
59
+
60
+ require 'kibou'
61
+
62
+ Kibou::RakeTask.new do |c|
63
+ c.recipes_directory = "recipes/*.rb"
64
+ c.recipes = ["tools"]
65
+ end
66
+
67
+
68
+ Run `rake kibou` to perform package installations via Homebrew.
69
+
70
+ ## Documentation
71
+
72
+ ### Kibou::RakeTask
73
+
74
+ * ** attributes **
75
+
76
+ * `recipes_directory` - specify the directory name of recipe files in a regex pattern (default: `recipes/*.rb`)
77
+ * `recipes`- a list of recipe names (Array is preferred)
78
+
79
+ ### Kibou::Recipe
80
+
81
+ * Ensure that recipe file name is match to the class name or Kibou will fail to start.
82
+
83
+ Example: `tools.rb` **is** `Tools`, `blah.rb` **is** `Blah`
84
+
85
+ Notes: file names with underscore is not currently supported.
86
+
87
+ * ** package's options (Hash) **
88
+
89
+ * `:ensure` - ensures that package is `:installed` or `:latest` (default: `:installed`)
90
+
91
+ * `:via` - downloads a file from url or install from local file.
92
+
93
+
94
+ ## Thanks
95
+
96
+ Inspired by two popular tools: Puppet and Chef. They are amazing automated server framework tools.
97
+
98
+ ## License
99
+
100
+ Kibou is licensed under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ $:.unshift "lib"
2
+
3
+ require 'kibou'
4
+
5
+ task :default => :kibou
6
+
7
+ Kibou::RakeTask.new do |c|
8
+ c.recipes_path = "recipes/*.rb"
9
+ c.recipes = %w(tools databases programmings)
10
+ end
data/kibou.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require "rubygems"
4
+ require 'kibou/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "kibou"
8
+ gem.version = Kibou::VERSION
9
+ gem.author = "Bryan Goines"
10
+ gem.summary = "Homebrew and Rakefile are OSX's best friends."
11
+ gem.email = "bryann83@gmail.com"
12
+ gem.homepage = "http://kiboulabs.com/"
13
+
14
+ gem.files = Dir['**/*']
15
+
16
+ gem.add_dependency "rake"
17
+ gem.add_dependency "small"
18
+ end
@@ -0,0 +1,12 @@
1
+ module Kibou
2
+ class Dependency
3
+
4
+ attr_reader :package, :dependency
5
+
6
+ def initialize(name, dep)
7
+ @package = name
8
+ @dependency = dep
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,66 @@
1
+ module Kibou
2
+ class Package
3
+
4
+ include Utility::Helpers
5
+
6
+ attr_reader :name, :options, :dependencies
7
+
8
+ def initialize(name, options = {})
9
+ @name = name.to_s
10
+ @options = options
11
+ @dependencies = (options[:require] || []).map {|dep| Kibou::Dependency.new(self, dep) }
12
+ @completed = false
13
+ @outdated = false
14
+ end
15
+
16
+ def perform
17
+ return invoke_proc if options[:proc].present?
18
+ return install if options[:via].present?
19
+ return not_found_message unless package_included?(name)
20
+ return install unless package_installed?(name)
21
+ outdated? ? upgrade : up_to_date_message
22
+ end
23
+
24
+ def completed?
25
+ !!@completed
26
+ end
27
+
28
+ private
29
+
30
+ def up_to_date_message
31
+ puts " --> #{name} is up to date"
32
+ completed!
33
+ end
34
+
35
+ def not_found_message
36
+ puts "Package is not found: #{name}"
37
+ end
38
+
39
+ def outdated?
40
+ options[:ensure].to_s == 'latest' and package_outdated?(name)
41
+ end
42
+
43
+ def invoke_proc
44
+ puts " --> invoking proc #{name}"
45
+ raise "Unable to invoke proc for #{name}" unless options[:proc].present? ? options[:proc].call : false
46
+ completed!
47
+ end
48
+
49
+ def install
50
+ puts " --> installing #{name} #{options[:via].present? ? "via #{options[:via]}" : ""}"
51
+ package_install (options[:via].present? ? options[:via] : name)
52
+ completed!
53
+ end
54
+
55
+ def upgrade
56
+ puts " --> upgrading #{name}"
57
+ package_upgrade name
58
+ completed!
59
+ end
60
+
61
+ def completed!
62
+ @completed = true
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,53 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ module Kibou
5
+ class RakeTask < Rake::TaskLib
6
+
7
+ include Utility::Helpers
8
+
9
+ attr_accessor :recipes_path, :recipes
10
+
11
+ def initialize(name = :kibou)
12
+ @name = name
13
+ @recipes = []
14
+ @recipes_path = "recipes/*.rb"
15
+ yield self if block_given?
16
+ build_tasks!
17
+ end
18
+
19
+ def build_tasks!
20
+ desc "start Kibou -- run package installations via Homebrew"
21
+ task @name do
22
+ raise "Homebrew is not installed!" unless brew_installed?
23
+ require_tree @recipes_path
24
+ recipes = @recipes.map &Recipe.method(:new)
25
+ packages_sync(recipes)
26
+ end
27
+ self
28
+ end
29
+
30
+ def require_tree(pattern)
31
+ Dir[pattern].map(&File.method(:expand_path)).each &method(:require)
32
+ end
33
+
34
+ def packages_sync(recipes)
35
+ brew :update
36
+ recipes.each do |recipe|
37
+ puts "#{recipe.name} (#{recipe.packages.size} packages)"
38
+ recipe.run_before_tasks
39
+ recipe.packages.each do |package|
40
+ package.dependencies.each do |dep|
41
+ pkg = recipe.find_package(dep.dependency)
42
+ raise "Missing dependencies: #{dep.dependency}" unless pkg
43
+ pkg.perform unless pkg.completed?
44
+ end
45
+ package.perform unless package.completed?
46
+ end
47
+ recipe.run_after_tasks
48
+ end
49
+ end
50
+
51
+
52
+ end
53
+ end
@@ -0,0 +1,71 @@
1
+ module Kibou
2
+ class Recipe
3
+
4
+ extend Utility::Helpers
5
+ include Utility::Helpers
6
+
7
+ attr_reader :name, :packages, :before_tasks, :after_tasks, :constant
8
+
9
+ def initialize(name = nil)
10
+ if name
11
+ @name = name.to_s
12
+ @constant = @name.capitalize.camelize.constantize
13
+ @klass = @constant.new
14
+ @packages = @constant.packages
15
+ @before_tasks = @constant.before_tasks
16
+ @after_tasks = @constant.after_tasks
17
+ end
18
+ end
19
+
20
+ def self.package(name, options = {}, &block)
21
+ options[:ensure] ||= :installed
22
+ options[:proc] = block if block_given?
23
+ packages << Package.new(name, options)
24
+ end
25
+
26
+ def self.packages
27
+ @packages ||= []
28
+ end
29
+
30
+ def self.before(*args)
31
+ before_tasks.push *args
32
+ end
33
+
34
+ def self.before_tasks
35
+ @before_tasks ||= []
36
+ end
37
+
38
+ def self.after(*args)
39
+ after_tasks.push *args
40
+ end
41
+
42
+ def self.after_tasks
43
+ @after_tasks ||= []
44
+ end
45
+
46
+ def find_package(name)
47
+ packages.select {|package| package.name == name }.first
48
+ end
49
+
50
+ def run_before_tasks
51
+ unless before_tasks.size == 0
52
+ puts "running before tasks"
53
+ before_tasks.each do |m|
54
+ puts "---> invoking: #{m}"
55
+ @klass.send(m)
56
+ end
57
+ end
58
+ end
59
+
60
+ def run_after_tasks
61
+ unless after_tasks.size == 0
62
+ puts "running after tasks"
63
+ after_tasks.each do |m|
64
+ puts "---> invoking: #{m}"
65
+ @klass.send(m)
66
+ end
67
+ end
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,61 @@
1
+ module Kibou
2
+ module Utility
3
+ module Helpers
4
+
5
+ def brew_installed?
6
+ `which brew`.chomp =~ /brew$/
7
+ end
8
+
9
+ def brew(*args)
10
+ args.unshift "brew"
11
+ `#{args.join(" ")}`.split(/\n/)
12
+ end
13
+
14
+ def info(pkg)
15
+ brew :info, pkg
16
+ end
17
+
18
+ def search(pkg)
19
+ brew :search, pkg
20
+ end
21
+
22
+ def outdated
23
+ brew :outdated
24
+ end
25
+
26
+ def update!
27
+ system("brew update > /dev/null 2>&1")
28
+ end
29
+
30
+ def package_install(pkg)
31
+ system("brew install #{pkg}")
32
+ end
33
+
34
+ def package_upgrade(pkg)
35
+ system("brew upgrade #{pkg}")
36
+ end
37
+
38
+ def package_installed?(pkg)
39
+ !info(pkg).include?("Not installed")
40
+ end
41
+
42
+ def package_included?(pkg)
43
+ search(pkg).include?(pkg)
44
+ end
45
+
46
+ def package_outdated?(pkg)
47
+ list = outdated.map {|pkg| pkg.split(/ /).first }
48
+ list.include?(pkg)
49
+ end
50
+
51
+ def run(*args)
52
+ system(args.join(" "))
53
+ end
54
+
55
+ def capture(*args)
56
+ `#{args.join(" ")}`
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ module Kibou
2
+
3
+ VERSION = "0.2.0"
4
+
5
+ end
data/lib/kibou.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'small'
2
+
3
+ module Kibou
4
+
5
+ autoload :Utility, 'kibou/utility'
6
+ autoload :Recipe, 'kibou/recipe'
7
+ autoload :Package, 'kibou/package'
8
+ autoload :Dependency, 'kibou/dependency'
9
+ autoload :RakeTask, 'kibou/rake_task'
10
+
11
+ end
12
+
@@ -0,0 +1,26 @@
1
+ class Databases < Kibou::Recipe
2
+
3
+ package :mysql, :ensure => :latest
4
+ package :postgresql, :ensure => :latest
5
+ package :sqlite, :ensure => :latest
6
+ package :redis
7
+ package :elasticsearch
8
+ package :memcached
9
+ package :zeromq
10
+
11
+ after :start_mysql
12
+
13
+ def start_mysql
14
+ mysql :start unless mysql_started?
15
+ end
16
+
17
+ def mysql(*args)
18
+ args.unshift "mysql.server"
19
+ `#{args.join(" ")}`
20
+ end
21
+
22
+ def mysql_started?
23
+ mysql(:status).include?("SUCCESS")
24
+ end
25
+
26
+ end
@@ -0,0 +1,14 @@
1
+ class Programmings < Kibou::Recipe
2
+
3
+ package :node, :ensure => :latest
4
+ package :ruby, :ensure => :latest
5
+ package :jruby, :ensure => :latest
6
+ package :erlang, :ensure => :latest
7
+ package :groovy, :ensure => :latest
8
+ package :scala, :ensure => :latest
9
+ package :akka, :ensure => :latest
10
+ package :go, :ensure => :latest
11
+
12
+ package :sbt, :ensure => :latest, :require => ["scala"]
13
+
14
+ end
data/recipes/tools.rb ADDED
@@ -0,0 +1,65 @@
1
+ class Tools < Kibou::Recipe
2
+
3
+ package :ack, :ensure => :latest
4
+ package :bash
5
+ package 'bash-completion'
6
+ package :grc
7
+
8
+ package :git, :ensure => :latest
9
+ package :tig, :ensure => :latest, :require => ["git"]
10
+ package 'git-extras', :ensure => :latest, :require => ["git"]
11
+ package :subversion
12
+ package :wget
13
+ package :mercurial
14
+ package :legit, :ensure => :latest, :require => ["git"]
15
+
16
+ package :macvim, :ensure => :latest
17
+
18
+ package :imagemagick, :ensure => :latest
19
+
20
+ package :curl, :ensure => :latest
21
+ package :tmux, :ensure => :latest
22
+ package :wemux, :via => "https://github.com/downloads/zolrath/wemux/wemux.rb"
23
+ package :ctags, :ensure => :latest
24
+ package :rbenv, :ensure => :latest, :require => ["ruby-build"]
25
+ package 'ruby-build', :ensure => :latest
26
+
27
+ package :pow, :ensure => :latest
28
+
29
+ package :sweet do
30
+ run "ls"
31
+ end
32
+
33
+ after :install_rubies, :install_gems
34
+
35
+ def install_rubies
36
+ %w(1.9.3-p194 jruby-1.6.7.2 rbx-1.2.4 ree-1.8.7-2012.02).each do |version|
37
+ rbenv(:install, version) unless ruby_installed?(version)
38
+ end
39
+ rbenv :global, "1.9.3-p194"
40
+ rbenv :rehash
41
+ end
42
+
43
+ def install_gems
44
+ %w(bundler rails powder).each do |gem|
45
+ run "gem install #{gem} --no-ri --no-rdoc"
46
+ end
47
+ end
48
+
49
+ def rbenv(*args)
50
+ args.unshift "rbenv"
51
+ run args.join(" ")
52
+ end
53
+
54
+ def ruby_installed?(version)
55
+ versions.include?(version)
56
+ end
57
+
58
+ def versions
59
+ @versions ||= capture("rbenv versions").split(/\n/).map{|v| v.gsub(/^\s+/,'').gsub(/^\*\s+/,'').gsub(/\s\(.*$/, '') }
60
+ end
61
+
62
+
63
+ end
64
+
65
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kibou
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-30 00:00:00.000000000 Z
12
+ date: 2012-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -48,8 +48,24 @@ email: bryann83@gmail.com
48
48
  executables: []
49
49
  extensions: []
50
50
  extra_rdoc_files: []
51
- files: []
52
- homepage: http://kibouapp.com/
51
+ files:
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - kibou.gemspec
55
+ - lib/kibou/dependency.rb
56
+ - lib/kibou/package.rb
57
+ - lib/kibou/rake_task.rb
58
+ - lib/kibou/recipe.rb
59
+ - lib/kibou/utility.rb
60
+ - lib/kibou/version.rb
61
+ - lib/kibou.rb
62
+ - LICENSE
63
+ - Rakefile
64
+ - README.md
65
+ - recipes/databases.rb
66
+ - recipes/programmings.rb
67
+ - recipes/tools.rb
68
+ homepage: http://kiboulabs.com/
53
69
  licenses: []
54
70
  post_install_message:
55
71
  rdoc_options: []