From 1d6f9707d3bae333d8d74ea50f0fc9533c005304 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 13 Apr 2014 11:46:20 -0400 Subject: [PATCH] Improve rakefile provisioner --- rake/homebrew.rake | 8 ++++---- rake/init.rake | 5 ++++- rake/lib/pyenv.rb | 0 rake/lib/rbenv.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ rake/node/io.rb | 14 +++++++++----- rake/osx.rake | 7 ++++--- rake/pyenv.rake | 42 ++++++++++++++++++++++++++++++++++++++++++ rake/rbenv.rake | 41 +++++++++++++++++++++++++++++++---------- rake/vim.rake | 14 +++++++------- rake/zsh.rake | 4 ++++ 10 files changed, 151 insertions(+), 30 deletions(-) create mode 100644 rake/lib/pyenv.rb create mode 100644 rake/lib/rbenv.rb diff --git a/rake/homebrew.rake b/rake/homebrew.rake index e01489e9..7c054716 100644 --- a/rake/homebrew.rake +++ b/rake/homebrew.rake @@ -14,20 +14,20 @@ namespace :homebrew do end Homebrew.tap('homebrew/dupes') - # Homebrew.tap('homebrew/python') Homebrew.tap('phinze/cask') %w{ - apple_gcc42 coreutils wget curl tree git - cask + brew-cask the_silver_searcher tmux gist + lua + luajit }.each { |pkg| Homebrew.install pkg } %w{ @@ -49,7 +49,7 @@ namespace :homebrew do end desc "Remove homebrew cleanly" - task :remove do + task :remove do Homebrew.destroy if Homebrew.is_installed? end diff --git a/rake/init.rake b/rake/init.rake index 8458881b..aa07b0b7 100644 --- a/rake/init.rake +++ b/rake/init.rake @@ -3,13 +3,16 @@ require_relative 'lib/output' desc "Provision the node" task :init,:node do |t,args| args.with_defaults(:node => `hostname`.strip) - # TODO: chop of the *.local in osx hostnames + # TODO: chop off the *.local in osx hostnames path = "#{File.dirname(__FILE__)}/node/#{args.node}.rb" if File.exists?(path) echo "Setting up node: #{args.node}" require_relative "node/#{args.node}" + echo "Done!" else echo "#{args.node} node does not exist!" end end + +task :update => :init diff --git a/rake/lib/pyenv.rb b/rake/lib/pyenv.rb new file mode 100644 index 00000000..e69de29b diff --git a/rake/lib/rbenv.rb b/rake/lib/rbenv.rb new file mode 100644 index 00000000..1180108a --- /dev/null +++ b/rake/lib/rbenv.rb @@ -0,0 +1,46 @@ +include Rake::DSL +require_relative 'homebrew' + +module Rbenv + + BREWS = %w{rbenv ruby-build rbenv-bundler rbenv-vars rbenv-gem-rehash} + + def self.bootstrap + unless self.is_installed? + BREWS.each { |pkg| Homebrew.install pkg } + sh 'exec $SHELL -l' + end + end + + def self.destroy + if self.is_installed? + BREWS.each { |pkg| Homebrew.remove pkg } + # sh "rm -rf #{Homebrew.prefix 'rbenv'}" + end + end + + def self.install(version, gems=[]) + unless self.is_version_installed?(version) + sh "rbenv install #{version}" + end + sh "RBENV_VERSION=#{version} gem install #{gems.join(' ')}" + end + + def self.update(version) + sh "RBENV_VERSION=#{version} gem update" + sh "RBENV_VERSION=#{version} gem clean" + end + + def self.is_installed? + Homebrew.is_keg_installed? "rbenv" + end + + def self.is_version_installed?(version) + system("rbenv versions | grep -w #{version}") + end + + def self.installed_versions + `ls -1 #{Homebrew.prefix 'rbenv'}/versions`.split("\n") + end + +end diff --git a/rake/node/io.rb b/rake/node/io.rb index b20e430e..309ad393 100644 --- a/rake/node/io.rb +++ b/rake/node/io.rb @@ -1,17 +1,19 @@ -require_relative 'lib/homebrew' +require_relative '../lib/homebrew' %w{ osx homebrew zsh vim - gamedev:sfml - gamedev:love2D - gamedev:unity - rbenv + rbenv:v1_9 + rbenv:v2_0 + rbenv:update pyenv }.each { |task| Rake::Task[task].invoke } +Homebrew.tap 'homebrew/python' +Homebrew.install 'pygame' + %w{ evernote transmit @@ -26,4 +28,6 @@ require_relative 'lib/homebrew' scrivener omnigraffle mindnode-pro + love + unity3d }.each { |app| Homebrew.install_cask app } diff --git a/rake/osx.rake b/rake/osx.rake index 2072770a..8a64c9d1 100644 --- a/rake/osx.rake +++ b/rake/osx.rake @@ -11,10 +11,9 @@ task :osx do sh 'defaults write NSGlobalDomain AppleKeyboardUIMode -int 3' sh 'defaults write NSGlobalDomain AppleFontSmoothing -int 2' - sh 'defaults write com.apple.dock autohide -bool true' sh 'defaults write NSGlobalDomain AppleShowAllExtensions -bool true' - sh 'defaults write com.apple.finder ShowStatusBar -bool true' sh 'defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true' + sh 'defaults write com.apple.dock autohide -bool true' # Disable app quarantine sh 'defaults write com.apple.LaunchServices LSQuarantine -bool false' @@ -22,7 +21,6 @@ task :osx do # Disable auto-correct sh 'defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false' - sh 'defaults write com.apple.finder _FXShowPosixPathInTitle -bool true' # Avoid creating .DS_Store files on network volumes sh 'defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true' # Disable the warning when changing a file extension @@ -42,6 +40,9 @@ task :osx do # Use column view sh 'defaults write com.apple.finder FXPreferredViewStyle -string "clmv"' + sh 'defaults write com.apple.finder ShowStatusBar -bool true' + sh 'defaults write com.apple.finder _FXShowPosixPathInTitle -bool true' + sh 'killall Finder' sh 'killall Dock' end diff --git a/rake/pyenv.rake b/rake/pyenv.rake index e69de29b..eb92ca3a 100644 --- a/rake/pyenv.rake +++ b/rake/pyenv.rake @@ -0,0 +1,42 @@ +require_relative 'lib/output' +require_relative 'lib/homebrew' +require_relative 'lib/pyenv' + +task :pyenv => 'pyenv:update' + +namespace :pyenv do + +# task :install do +# unless Pyenv.is_installed? +# echo "Installing pyenv" +# Pyenv.bootstrap +# end +# end +# +# task :v2 => :install do +# # v = "2.0.0-p451" +# # unless Pyenv.is_version_installed?(v) +# # echo "Building ruby #{v}" +# # Pyenv.install v, GLOBAL_GEMS +# # end +# end +# +# task :v3 => :install do +# # v = "1.9.3-p545" +# # unless Pyenv.is_version_installed?(v) +# # echo "Building ruby #{v}" +# # Pyenv.install v, GLOBAL_GEMS +# # end +# end +# +# task :remove do +# # Pyenv.destroy +# end + + task :update => :install do + echoerr "Pyenv rakefile not yet implemented!" + # Pyenv.installed_versions.each { |v| Pyenv.update v } + end + +end + diff --git a/rake/rbenv.rake b/rake/rbenv.rake index 601db52e..987030a2 100644 --- a/rake/rbenv.rake +++ b/rake/rbenv.rake @@ -1,26 +1,47 @@ require_relative 'lib/homebrew' +require_relative 'lib/rbenv' -task :rbenv do - -end +task :rbenv => 'rbenv:update' namespace :rbenv do - BREWS = %w{rbenv ruby-build rbenv-bundler rbenv-vars rbenv-gem-rehash} + GLOBAL_GEMS = %w{bundler pry rspec rake} task :install do - BREWS.each { |pkg| Homebrew.install pkg } + unless Rbenv.is_installed? + echo "Installing rbenv" + Rbenv.bootstrap + end end - if Dir.exists?(File.expand_path("~/.rbenv")) - task :remove do - BREWS.each { |pkg| Homebrew.remove pkg } - sh "rm -rf ~/.rbenv" + task :v2_0 => :install do + v = "2.0.0-p451" + unless Rbenv.is_version_installed?(v) + echo "Building ruby #{v}" + Rbenv.install v, GLOBAL_GEMS end + end - task :update => :install do + task :v1_9 => :install do + v = "1.9.3-p545" + unless Rbenv.is_version_installed?(v) + echo "Building ruby #{v}" + Rbenv.install v, GLOBAL_GEMS + end + end + if Rbenv.is_installed? + task :remove do + echo "Deleting rbenv" + Rbenv.destroy + end + end + + task :update => :install do + Rbenv.installed_versions.each do |v| + echo "Updating ruby #{v}" + Rbenv.update v end end diff --git a/rake/vim.rake b/rake/vim.rake index 8e518a45..57ef50a0 100644 --- a/rake/vim.rake +++ b/rake/vim.rake @@ -7,22 +7,22 @@ task :vim => 'vim:update' namespace :vim do - task :install => 'homebrew' do + task :install do %w{lua luajit}.each { |pkg| Homebrew.install pkg } %w{vim macvim}.each { |pkg| Homebrew.install(pkg, '--with-lua --with-luajit') } - github 'hlissner/vim', '~/.vim' + github('hlissner/vim', '~/.vim') unless Dir.exists?(File.expand_path("~/.vim")) end - task :update => :install do - echo "Updating homebrew..." - Homebrew.update + task :update => 'vim:install' do + echo "Updating vim..." + Homebrew.update *["lua", "luajit", "vim", "macvim"] end - desc "Remove homebrew cleanly" + desc "Remove vim" task :remove do echo "Uninstalling Homebrew" - Homebrew.destroy + %w{vim macvim}.each { |pkg| Homebrew.remove pkg } end end diff --git a/rake/zsh.rake b/rake/zsh.rake index de4f66a7..a15c6a0c 100644 --- a/rake/zsh.rake +++ b/rake/zsh.rake @@ -24,5 +24,9 @@ namespace :zsh do echo "Updating oh-my-zsh" sh 'cd ~/.oh-my-zsh && git pull' end + + task :remove do + sh 'rm -rf ~/.oh-my-zsh' if Dir.exists?(File.expand_path("~/.oh-my-zsh")) + end end