From 1ef01b1055e67558e21896758c26ac94bee1a18b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 31 Aug 2014 02:50:03 -0400 Subject: [PATCH] Refactor global rakefiles --- rake/README.md | 73 ++++++++++++++++- rake/lib/deploy.rb | 30 +++---- rake/lib/homebrew.rb | 108 +++++++++++++------------- rake/lib/os.rb | 9 +++ rake/lib/package.rb | 13 ++++ rake/lib/package_adapters/aptitude.rb | 16 ++++ rake/lib/package_adapters/homebrew.rb | 58 ++++++++++++++ rake/lib/pyenv.rb | 16 ++++ rake/lib/rake.rb | 3 +- rake/lib/sh.rb | 1 - rake/node/callisto.rake | 11 +-- rake/node/ganymede.rake | 1 - rake/node/io.rake | 48 ++++++------ rake/node/titan.rake | 1 - rake/packages.rake | 18 +++++ rake/pkg.rake | 5 -- rake/pkg/emacs.rake | 48 +++++++----- rake/pkg/homebrew.rake | 65 ---------------- rake/pkg/osx.rake | 73 ++++++++--------- rake/pkg/package.rake | 73 +++++++++++++++++ rake/pkg/pyenv.rake | 54 +++++++++++++ rake/pkg/rbenv.rake | 68 ++++++++++------ rake/pkg/vim.rake | 55 +++++++++---- rake/pkg/zsh.rake | 39 +++++----- rake/provision.rake | 18 +++++ rake/setup.rake | 16 ---- 26 files changed, 617 insertions(+), 303 deletions(-) create mode 100644 rake/lib/os.rb create mode 100644 rake/lib/package.rb create mode 100644 rake/lib/package_adapters/aptitude.rb create mode 100644 rake/lib/package_adapters/homebrew.rb create mode 100644 rake/packages.rake delete mode 100644 rake/pkg.rake delete mode 100644 rake/pkg/homebrew.rake create mode 100644 rake/pkg/package.rake create mode 100644 rake/pkg/pyenv.rake create mode 100644 rake/provision.rake delete mode 100644 rake/setup.rake diff --git a/rake/README.md b/rake/README.md index d9acc89c..811e25e2 100644 --- a/rake/README.md +++ b/rake/README.md @@ -1,6 +1,73 @@ # Rake install scripts -My global rakefiles for my macs. Installs homebrew, vim and zsh; configures OSX; and -sets up my gamedev/programming environments. +I use global rakefiles to provision my computers and servers. They +work for OSX and Ubuntu; a `rake -g -T` will reveal all the available +options. -I leave home without it. +Running `rake -g update` will run the rake task that matches your +computer's hostname; they can be found in +`rake/nodes/.rake`. I have one for each of my computers. + +Feel free to take from it what you like. + +## Packages + +This currently provides: + +* Homebrew +* OSX settings +* Zsh + zprezto -- deploys my [zsh dotfiles](http://github.com/hlissner/dotfiles) +* Emacs (mac only) -- deploys my [emacs.d](http://github.com/hlissner/emacs.d) +* Vim -- deploys my [vimrc](https://github.com/hlissner/dotfiles/blob/master/vimrc) +* Pyenv +* Rbenv + +Planned features: + +* Gitlab +* Flexget seedbox +* Webserver stacks for vagrant + +## Installation + +Simply symlink `./rake` to `~/.rake`, then these commands will become +accessible globally via `rake -g [task]`. + +```sh +git clone https://github.com/hlissner/dotfiles ~/.dotfiles +ln -sf ~/.dotfiles/rake ~/.rake +``` + +Or just cd into `./rake` and work from there. + +## Usage + +```sh +rake -g # Same as: rake -g setup:`hostname` +rake -g update # Same as: rake -g setup:`hostname` + +# This will install all the things specified in +# rake/nodes/.rake and/or update them if already installed. +rake -g setup: + +# Installs , or updates it +rake -g pkg: +# Package sub-commands +rake -g pkg::install +rake -g pkg::remove +rake -g pkg::update + +rake -g destroy # Runs pkg:*:remove and deletes all packages +``` + +A couple examples: + +```sh +# Install/update homebrew, zsh and emacs +rake -g pkg:homebrew +rake -g pkg:zsh +rake -g pkg:emacs + +# Install/update my config for ganymede +rake -g setup:ganymede +``` diff --git a/rake/lib/deploy.rb b/rake/lib/deploy.rb index 796ab1ee..a5cd7731 100644 --- a/rake/lib/deploy.rb +++ b/rake/lib/deploy.rb @@ -1,24 +1,26 @@ -module Project +class Project - def create(dirs=[]) + template_folder = "templates" + def dirs(dirs=[]) + dirs.each do |d| + mkdir_p d unless Dir.exists? d + end end - def template(template, vars={}, dest="") + def template(template, dest="", vars={}) + template_file = "#{template_folder}/#{template}.erb" + dest_file = "#{dest}/#{File.basename(template)}" - end - - def update(name) - - end - - def remove(name) - - end - - class Template + raise "Template file doesn't exist" unless File.exists? template_file + raise "Destination folder doesn't exist" unless Dir.exists? dest + raise "Destination file already exists" unless File.exists? dest_file + erb = ERB.new(File.read(template_file)) + File.open(dest_file) do |f| + f.puts(erb.result(binding)) + end end end diff --git a/rake/lib/homebrew.rb b/rake/lib/homebrew.rb index 2068c8bf..57b9e5cd 100644 --- a/rake/lib/homebrew.rb +++ b/rake/lib/homebrew.rb @@ -3,76 +3,76 @@ require_relative 'sh' include Rake::DSL module Homebrew - BIN = "/usr/local/bin/brew" + BIN = "/usr/local/bin/brew" - def self.bootstrap - unless self.is_installed? - sh_safe 'ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"' - echo "Homebrew is installed! Restart the shell then rake." - exit - end + def self.bootstrap + unless self.is_installed? + sh_safe 'ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"' + echo "Homebrew is installed! Restart the shell then rake." + exit end + end - def self.destroy - if self.is_installed? - sh_safe 'rm -rf /usr/local/Cellar /usr/local/.git ~/Library/Caches/Homebrew' - sh_safe 'brew prune' + def self.destroy + if self.is_installed? + sh_safe 'rm -rf /usr/local/Cellar /usr/local/.git ~/Library/Caches/Homebrew' + sh_safe 'brew prune' - ['Library/Homebrew', 'Library/Aliases', 'Library/Formula', 'Library/Contributions'].each do |dir| - sh_safe "rm -r #{dir}" - end - end + ['Library/Homebrew', 'Library/Aliases', 'Library/Formula', 'Library/Contributions'].each do |dir| + sh_safe "rm -r #{dir}" + end end + end - def self.install(keg, options=nil) - sh_safe "#{BIN} install #{keg} #{options}" unless self.is_keg_installed?(keg) - end + def self.install(keg, options=nil) + sh_safe "#{BIN} install #{keg} #{options}" unless self.is_keg_installed?(keg) + end - def self.install_cask(cask, options=nil) - sh_safe "#{BIN} cask install #{cask} #{options}" unless self.is_cask_installed?(cask) - end + def self.install_cask(cask, options=nil) + sh_safe "#{BIN} cask install #{cask} #{options}" unless self.is_cask_installed?(cask) + end - def self.tap(tap) - sh_safe "#{BIN} tap #{tap}" unless self.is_tapped? tap - end + def self.tap(tap) + sh_safe "#{BIN} tap #{tap}" unless self.is_tapped? tap + end - def self.remove(keg) - sh_safe "#{BIN} remove #{keg}" - end + def self.remove(keg) + sh_safe "#{BIN} remove #{keg}" + end - def self.remove_cask(keg) - sh_safe "#{BIN} cask uninstall #{keg}" - end + def self.remove_cask(keg) + sh_safe "#{BIN} cask uninstall #{keg}" + end - def self.has_keg?(keg) - system("#{BIN} search #{keg}") - end + def self.has_keg?(keg) + system("#{BIN} search #{keg}") + end - def self.is_keg_installed?(keg) - system("#{BIN} list | grep -w '#{keg}' >& /dev/null") - end + def self.is_keg_installed?(keg) + system("#{BIN} list | grep -w '#{keg}' >& /dev/null") + end - def self.is_cask_installed?(cask) - system("#{BIN} cask list | grep -w '#{cask}' >& /dev/null") - end + def self.is_cask_installed?(cask) + system("#{BIN} cask list | grep -w '#{cask}' >& /dev/null") + end - def self.is_tapped?(tap) - system("#{BIN} tap | grep -w '#{tap}' >& /dev/null") - end + def self.is_tapped?(tap) + system("#{BIN} tap | grep -w '#{tap}' >& /dev/null") + end - def self.is_installed? - File.exists?("/usr/local/bin/brew") - end + def self.is_installed? + File.exists?("/usr/local/bin/brew") + end - def self.prefix(keg) - `#{BIN} --prefix #{keg}`.strip - end + def self.prefix(keg) + `#{BIN} --prefix #{keg}`.strip + end - def self.update(*args) - if args.length > 0 - sh_safe "#{BIN} upgrade #{args.join(' ')}" - else - sh_safe "#{BIN} update && #{BIN} upgrade" - end + def self.update(*args) + if args.length > 0 + sh_safe "#{BIN} upgrade #{args.join(' ')}" + else + sh_safe "#{BIN} update && #{BIN} upgrade" end + end end diff --git a/rake/lib/os.rb b/rake/lib/os.rb new file mode 100644 index 00000000..db422dd9 --- /dev/null +++ b/rake/lib/os.rb @@ -0,0 +1,9 @@ +def is_mac? + RUBY_PLATFORM =~ /darwin/ +end + +def is_linux? + RUBY_PLATFORM =~ /linux/ +end + +# TODO Implement other linux distro tests diff --git a/rake/lib/package.rb b/rake/lib/package.rb new file mode 100644 index 00000000..d6c7dc8d --- /dev/null +++ b/rake/lib/package.rb @@ -0,0 +1,13 @@ +require_relative "sh" +require_relative "os" + +include Rake::DSL + +if is_mac? + require_relative "package_adapters/homebrew.rb" +elsif is_linux? + require_relative "package_adapters/aptitude.rb" + # TODO Implement centos yum support +else + raise "Could not detect OS" +end diff --git a/rake/lib/package_adapters/aptitude.rb b/rake/lib/package_adapters/aptitude.rb new file mode 100644 index 00000000..abe68006 --- /dev/null +++ b/rake/lib/package_adapters/aptitude.rb @@ -0,0 +1,16 @@ +# Aptitude (ubuntu/debian) package adapter +module Package + module_function + + def bootstrap; end + + def install(package) + self.run("install", "-y", package) + end + + # TODO Finish aptitude adapter + + def run(*args) + system("sudo apt-get #{args.join(' ')}") + end +end diff --git a/rake/lib/package_adapters/homebrew.rb b/rake/lib/package_adapters/homebrew.rb new file mode 100644 index 00000000..dc028e33 --- /dev/null +++ b/rake/lib/package_adapters/homebrew.rb @@ -0,0 +1,58 @@ +# Homebrew package adapter +module Package + module_function + + @@brew_bin = "/usr/local/bin/brew" + + def bootstrap + unless self.installed? + sh_safe 'ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"' + end + end + + def install(package) + self.run("install", package) unless self.installed?(package) + end + + def installed?(package = nil) + return File.exists?(@@brew_bin) if !package + + self.run("list | grep -w '#{package}' >& /dev/null") + end + + def remove(package) + self.run("remove", package) + end + + def update(*args) + if args.length > 0 + self.run("upgrade #{args.join(' ')}") + else + self.run("update") + self.run("upgrade") + end + end + + # Homebrew-specific functions + def cask_install(cask) + self.run("cask", "install", cask) unless self.cask_installed?(cask) + end + + def cask_installed?(cask) + self.run("cask list | grep -w '#{cask}' >& /dev/null") + end + + def tap(repo) + self.run("tap", repo) unless self.tapped?(repo) + end + + def tapped?(repo) + self.run("tap | grep -w '#{repo}' >& /dev/null") + end + + def run(*args) + raise "Homebrew isn't installed!" unless self.installed? + + `#{@@brew_bin} #{args.join(' ')}` + end +end diff --git a/rake/lib/pyenv.rb b/rake/lib/pyenv.rb index e69de29b..d5bc40b6 100644 --- a/rake/lib/pyenv.rb +++ b/rake/lib/pyenv.rb @@ -0,0 +1,16 @@ + +module Pyenv + + BREWS = %w{pbenv pyenv-pip-rehash pyenv-virtualenv} + + PIP_BIN = "/usr/local/opt/pyenv/shims/pip" + + def self.bootstrap + + end + + def self.destroy + + end + +end diff --git a/rake/lib/rake.rb b/rake/lib/rake.rb index 1ff7519a..c275d2d7 100644 --- a/rake/lib/rake.rb +++ b/rake/lib/rake.rb @@ -1,4 +1,3 @@ - def load_all(glob) - Dir.glob("#{File.dirname(__FILE__)}/../#{glob}") { |file| load file } + Dir.glob("#{File.dirname(__FILE__)}/../#{glob}") { |file| load file } end diff --git a/rake/lib/sh.rb b/rake/lib/sh.rb index 8b18fb95..b7a02c9e 100644 --- a/rake/lib/sh.rb +++ b/rake/lib/sh.rb @@ -1,4 +1,3 @@ - require_relative 'output' # A 'safe' sh function that won't stop rake in its tracks diff --git a/rake/node/callisto.rake b/rake/node/callisto.rake index aa59d4e3..0adc0802 100644 --- a/rake/node/callisto.rake +++ b/rake/node/callisto.rake @@ -1,8 +1,9 @@ - desc "Provision home server" task :callisto do - %w{ - zsh - vim - }.each { |task| Rake::Task[task].invoke } + %w{ + update + pkg:zsh + pkg:vim + pkg:rbenv + }.each { |task| Rake::Task[task].invoke } end diff --git a/rake/node/ganymede.rake b/rake/node/ganymede.rake index 531279c9..354af73c 100644 --- a/rake/node/ganymede.rake +++ b/rake/node/ganymede.rake @@ -1,3 +1,2 @@ - desc "Provision main laptop" task :ganymede => :io diff --git a/rake/node/io.rake b/rake/node/io.rake index ad2130f7..03edc5a6 100644 --- a/rake/node/io.rake +++ b/rake/node/io.rake @@ -1,30 +1,28 @@ -require_relative '../lib/homebrew' - desc "Provision main desktop" task :io do - %w{ - pkg:osx - pkg:homebrew - pkg:zsh - pkg:vim - pkg:emacs - pkg:rbenv:v1_9 - pkg:rbenv:v2_0 - pkg:rbenv:update - }.each { |task| Rake::Task[task].invoke } + %w{ + update + pkg:osx + pkg:zsh + pkg:vim + pkg:emacs + pkg:rbenv + pkg:pyenv + }.each { |task| Rake::Task[task].invoke } + if is_mac? %w{ - transmit - transmission - vlc - flux - skype - adium - codekit - mongohub - sequel-pro - scrivener - omnigraffle - love - }.each { |app| Homebrew.install_cask app } + transmit + transmission + vlc + flux + skype + adium + codekit + sequel-pro + scrivener + omnigraffle + love + }.each { |app| Package.cask_install app } + end end diff --git a/rake/node/titan.rake b/rake/node/titan.rake index 69cda0eb..656e816b 100644 --- a/rake/node/titan.rake +++ b/rake/node/titan.rake @@ -1,3 +1,2 @@ - desc "Provision 2nd desktop" task :titan => :io diff --git a/rake/packages.rake b/rake/packages.rake new file mode 100644 index 00000000..c4e64ae8 --- /dev/null +++ b/rake/packages.rake @@ -0,0 +1,18 @@ +require_relative "lib/rake" +require_relative "lib/os" +require_relative "lib/sh" +require_relative "lib/output" + +verbose(false) + +if is_mac? + desc 'Setup/update homebrew & packages' + task :update => 'pkg:homebrew:update' +elsif is_linux? + desc 'Setup/update packages' + task :update => 'pkg:aptitude:update' +end + +namespace :pkg do + load_all("pkg/*.rake") +end diff --git a/rake/pkg.rake b/rake/pkg.rake deleted file mode 100644 index ff429129..00000000 --- a/rake/pkg.rake +++ /dev/null @@ -1,5 +0,0 @@ -require_relative "lib/rake" - -verbose(false) - -namespace :pkg do load_all("pkg/*.rake") end diff --git a/rake/pkg/emacs.rake b/rake/pkg/emacs.rake index d9fca32b..d36734a9 100644 --- a/rake/pkg/emacs.rake +++ b/rake/pkg/emacs.rake @@ -1,32 +1,42 @@ -desc "Ensure emacs is installed and up to date" -task :emacs => "emacs:update" +if is_mac? -namespace :emacs do + ENV['EMACS_D'] = File.expand_path("~/.emacs.d") + desc "Ensure emacs is installed and up to date" + task :emacs => "emacs:update" + + namespace :emacs do task :install do - unless Dir.exists?(File.expand_path("~/.emacs.d")) - github('hlissner/emacs.d', '~/.emacs.d') - Homebrew.install("emacs", "--with-gnutls --cocoa --keep-ctags --srgb") - Homebrew.install("homebrew/dupes/tidy", "--HEAD") - Homebrew.install "aspell" + unless Dir.exists?(ENV[:EMACS_D]) + github 'hlissner/emacs.d', '~/.emacs.d' + Package.install "emacs", "--with-gnutls --cocoa --keep-ctags --srgb" + Package.install "homebrew/dupes/tidy", "--HEAD" + emacs_reqs.each { |pkg| Package.install pkg } - sh_safe "/usr/local/bin/npm install jshint -g" - sh_safe "/usr/local/bin/npm install jsonlint -g" - end + sh_safe "/usr/local/bin/npm install jshint -g" + sh_safe "/usr/local/bin/npm install jsonlint -g" + sh_safe "cd ~/.emacs.d && cask" + end end task :update do - echo "Updating emacs.d" - sh_safe "cd ~/.emacs.d && git pull" - - echo "You'll have to update emacs packages manually!" + echo "Updating emacs.d & packages" + sh_safe "cd ~/.emacs.d && git pull && cask update" end + desc "Remove emacs & dependencies" task :remove do - echo "Uninstalling emacs" - Homebrew.remove "emacs" - Homebrew.remove "aspell" - rm_rf "~/.emacs.d" if Dir.exists?(File.expand_path("~/.emacs.d")) + echo "Uninstalling emacs" + Package.remove "emacs" + Package.remove "homebrew/dupes/tidy" + emacs_reqs.each { |pkg| Package.remove pkg } + + rm_rf "~/.emacs.d" if Dir.exists?(ENV['EMACS_D']) end + end + + def emacs_reqs + %w{aspell cask rsense} + end end diff --git a/rake/pkg/homebrew.rake b/rake/pkg/homebrew.rake deleted file mode 100644 index 92d33899..00000000 --- a/rake/pkg/homebrew.rake +++ /dev/null @@ -1,65 +0,0 @@ -if RUBY_PLATFORM =~ /darwin/ - - require_relative "../lib/output" - require_relative "../lib/homebrew" - require_relative "../lib/sh" - - desc 'Install/update homebrew' - task :homebrew => 'homebrew:update' - - namespace :homebrew do - - task :install do - unless Homebrew.is_installed? - echo "Installing Homebrew..." - Homebrew.bootstrap - end - - Homebrew.tap 'homebrew/dupes' - Homebrew.tap 'caskroom/cask' - Homebrew.install 'brew-cask' - - %w{ - coreutils - wget - curl - tree - git - the_silver_searcher - tmux - gist - lua - luajit - readline - openssl - node - }.each { |pkg| Homebrew.install pkg } - - %w{ - dropbox - appcleaner - vagrant - virtualbox - growlnotify - iterm2 - java - launchbar - }.each { |app| Homebrew.install_cask app } - - echo "Homebrew is installed. Moving on." - end - - desc "Update homebrew and upgrade brews" - task :update => "homebrew:install" do - echo "Updating homebrew..." - Homebrew.update - end - - desc "Remove homebrew cleanly" - task :remove do - Homebrew.destroy if Homebrew.is_installed? - end - - end - -end diff --git a/rake/pkg/osx.rake b/rake/pkg/osx.rake index 52e11eca..508f0360 100644 --- a/rake/pkg/osx.rake +++ b/rake/pkg/osx.rake @@ -1,52 +1,55 @@ require_relative '../lib/output' +desc "Set OSX default configuration" task :osx do - if system('defaults read com.apple.finder _FXShowPosixPathInTitle >&/dev/null') - echo 'OSX settings already applied!' - next - end + next unless is_mac? - echo "Applying OSX settings" - sh_safe 'chflags nohidden "${HOME}/Library"' - sh_safe 'defaults write NSGlobalDomain KeyRepeat -int 0' + if system('defaults read com.apple.finder _FXShowPosixPathInTitle >&/dev/null') + echo 'OSX settings already applied!' + next + end - # Disable press-and-hold for keys in favor of key repeat - sh_safe 'defaults write ApplePressAndHoldEnabled -bool false' + echo "Applying OSX settings" + sh_safe 'chflags nohidden "${HOME}/Library"' + sh_safe 'defaults write NSGlobalDomain KeyRepeat -int 0' - sh_safe 'defaults write NSGlobalDomain AppleKeyboardUIMode -int 3' - sh_safe 'defaults write NSGlobalDomain AppleFontSmoothing -int 2' - sh_safe 'defaults write NSGlobalDomain AppleShowAllExtensions -bool true' - sh_safe 'defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true' - sh_safe 'defaults write com.apple.dock autohide -bool true' + # Disable press-and-hold for keys in favor of key repeat + sh_safe 'defaults write ApplePressAndHoldEnabled -bool false' - # Disable app quarantine - sh_safe 'defaults write com.apple.LaunchServices LSQuarantine -bool false' + sh_safe 'defaults write NSGlobalDomain AppleKeyboardUIMode -int 3' + sh_safe 'defaults write NSGlobalDomain AppleFontSmoothing -int 2' + sh_safe 'defaults write NSGlobalDomain AppleShowAllExtensions -bool true' + sh_safe 'defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true' + sh_safe 'defaults write com.apple.dock autohide -bool true' - # Disable auto-correct - sh_safe 'defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false' + # Disable app quarantine + sh_safe 'defaults write com.apple.LaunchServices LSQuarantine -bool false' - # Avoid creating .DS_Store files on network volumes - sh_safe 'defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true' - # Disable the warning when changing a file extension - sh_safe 'defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false' + # Disable auto-correct + sh_safe 'defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false' - sh_safe 'defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true' + # Avoid creating .DS_Store files on network volumes + sh_safe 'defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true' + # Disable the warning when changing a file extension + sh_safe 'defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false' - # Disable local Time Machine backups - # sh_safe 'hash_safe tmutil &> /dev/null && sudo tmutil disablelocal' + sh_safe 'defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true' - # Finder: allow text selection in Quick Look - sh_safe 'defaults write com.apple.finder QLEnableTextSelection -bool true' + # Disable local Time Machine backups + # sh_safe 'hash_safe tmutil &> /dev/null && sudo tmutil disablelocal' - # When performing a search, search the current folder by default - sh_safe 'defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"' + # Finder: allow text selection in Quick Look + sh_safe 'defaults write com.apple.finder QLEnableTextSelection -bool true' - # Use column view - sh_safe 'defaults write com.apple.finder FXPreferredViewStyle -string "clmv"' + # When performing a search, search the current folder by default + sh_safe 'defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"' - sh_safe 'defaults write com.apple.finder ShowStatusBar -bool true' - sh_safe 'defaults write com.apple.finder _FXShowPosixPathInTitle -bool true' + # Use column view + sh_safe 'defaults write com.apple.finder FXPreferredViewStyle -string "clmv"' - sh_safe 'killall Finder' - sh_safe 'killall Dock' + sh_safe 'defaults write com.apple.finder ShowStatusBar -bool true' + sh_safe 'defaults write com.apple.finder _FXShowPosixPathInTitle -bool true' + + sh_safe 'killall Finder' + sh_safe 'killall Dock' end diff --git a/rake/pkg/package.rake b/rake/pkg/package.rake new file mode 100644 index 00000000..6fe3a2d9 --- /dev/null +++ b/rake/pkg/package.rake @@ -0,0 +1,73 @@ +require_relative "../lib/package" + +if is_mac? + + namespace :homebrew do + task :setup do + unless Package.installed? + echo "Installing Homebrew..." + Package.bootstrap + + Package.tap 'homebrew/dupes' + Package.tap 'caskroom/cask' + end + + Package.install 'brew-cask' + + # Essentials for all macs; specific brews are placed + # in the node/*.rake files + %w{ + coreutils + wget + curl + tree + git + the_silver_searcher + tmux + gist + lua + luajit + readline + openssl + node + }.each { |pkg| Package.install pkg } + + %w{ + dropbox + appcleaner + vagrant + virtualbox + growlnotify + iterm2 + java + launchbar + }.each { |app| Package.cask_install app } + + echo "Homebrew is installed. Moving on." + end + + task :update => "homebrew:setup" do + echo "Updating homebrew..." + Package.update + end + + desc "Remove homebrew cleanly" + task :remove do + Package.destroy if Package.installed? + end + end + +elsif is_linux? + + namespace :aptitude do + task :setup do + # TODO Setup default linux package + end + + task :update => 'aptitude:setup' do + echo "Updating packages..." + Package.update + end + end + +end diff --git a/rake/pkg/pyenv.rake b/rake/pkg/pyenv.rake new file mode 100644 index 00000000..f9643002 --- /dev/null +++ b/rake/pkg/pyenv.rake @@ -0,0 +1,54 @@ +desc "Install/update pyenv & all pythons" +task :pyenv => 'pyenv:update' + +namespace :pyenv do + task :install do + unless pyenv_installed? + echo "Installing pyenv" + if is_mac? + pyenv_reqs.each { |pkg| Package.install pkg } + elsif is_linux? + sh_safe "curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash" + end + end + end + + task :update => "pyenv:install" do + pyenv_versions do |v| + echo "Updating python #{v}" + + cmd = "pip" + cmd = "sudo #{cmd}" if v == "system" + + sh_safe "PYENV_VERSION=#{v} #{cmd} freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs #{cmd} install -U" + end + end + + desc "Remove pyenv & installed pythons" + task :remove do + if pyenv_installed? + echo "pyenv isn't installed!" + else + echo "Deleting pyenv" + if is_mac? + pyenv_reqs.each { |pkg| Package.remove pkg } + elsif is_linux? + sh_safe "rm -rf $PYENV_ROOT" + end + end + end +end + +#### + +def pyenv_installed? + system("which pyenv") +end + +def pyenv_versions + `ls -1 $PYENV_ROOT/versions`.split("\n") +end + +def pyenv_reqs + %w{pyenv pyenv-pip-rehash pyenv-virtualenv} +end diff --git a/rake/pkg/rbenv.rake b/rake/pkg/rbenv.rake index 1f3a757c..96006da9 100644 --- a/rake/pkg/rbenv.rake +++ b/rake/pkg/rbenv.rake @@ -1,31 +1,55 @@ -require_relative '../lib/homebrew' -require_relative '../lib/rbenv' - +desc "Install/update rbenv & all rubies" task :rbenv => 'rbenv:update' namespace :rbenv do - - task :install do - unless Rbenv.is_installed? - echo "Installing rbenv" - Rbenv.bootstrap - end + task :install do + unless rbenv_installed? + echo "Installing rbenv" + if is_mac? + rbenv_reqs.each { |pkg| Package.install pkg } + elsif is_linux? + sh_safe "curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash" + end end + end - task :remove do - if Rbenv.is_installed? - echo "rbenv isn't installed!" - else - echo "Deleting rbenv" - Rbenv.destroy - end + task :update => "rbenv:install" do + rbenv_versions do |v| + echo "Updating ruby #{v}" + + cmd = "gem" + cmd = "sudo #{cmd}" if v == "system" + + sh_safe "RBENV_VERSION=#{version} #{cmd} #{GEM_BIN} update" + sh_safe "RBENV_VERSION=#{version} #{cmd} #{GEM_BIN} clean" end + end - task :update => "rbenv:install" do - Rbenv.installed_versions.each do |v| - echo "Updating ruby #{v}" - Rbenv.update v - end + desc "Remove rbenv & installed rubies" + task :remove do + if rbenv_installed? + echo "rbenv isn't installed!" + else + echo "Deleting rbenv" + if is_mac? + rbenv_reqs.each { |pkg| Package.remove pkg } + elsif is_linux? + sh_safe "rm -rf $RBENV_ROOT" + end end - + end +end + +#### + +def rbenv_installed? + system("which rbenv") +end + +def rbenv_versions + `ls -1 $RBENV_ROOT/versions`.split("\n") +end + +def rbenv_reqs + %w{rbenv ruby-build rbenv-vars rbenv-gem-rehash} end diff --git a/rake/pkg/vim.rake b/rake/pkg/vim.rake index 05a64f11..46164645 100644 --- a/rake/pkg/vim.rake +++ b/rake/pkg/vim.rake @@ -1,19 +1,40 @@ -require_relative "../lib/output" -require_relative "../lib/homebrew" -require_relative "../lib/sh" - desc "Ensure vim/macvim is installed and up to date" task :vim => "vim:update" namespace :vim do - task :install do - %w{lua luajit}.each { |pkg| Homebrew.install pkg } - %w{vim macvim}.each { |pkg| Homebrew.install(pkg, '--with-lua --with-luajit') } + vim_path = File.expand_path("~/.vim") - unless Dir.exists? (File.expand_path("~/.vim")) - github('hlissner/vim', '~/.vim') - github('Shougo/neobundle.vim', '~/.vim/bundle/neobundle.vim') + if is_mac? + Package.install "lua" + %w{vim macvim}.each { |pkg| Package.install "#{pkg} --with-lua --with-luajit" } + elsif is_linux? + Package.install "lua5.2" + + unless Dir.exists?(vim_path) + sh_safe "sudo apt-get install libncurses5-dev libgnome2-dev libgnomeui-dev \ + libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \ + libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev ruby1.9-dev mercurial" + + sh_safe "hg clone https://code.google.com/p/vim/ /tmp/vim" + sh_safe "cd /tmp/vim && ./configure --with-features=huge \ + --enable-multibyte \ + --enable-rubyinterp \ + --enable-pythoninterp \ + --enable-perlinterp \ + --enable-luainterp \ + --enable-clipboard \ + --enable-cscope --prefix=/usr \ + && make VIMRUNTIMEDIR=/usr/share/vim/vim74 + && sudo make install" + sh_safe "rm -rf /tmp/vim" + end + end + Package.install "luajit" + + unless Dir.exists?(vim_path) + github('hlissner/vim', vim_path) + github('Shougo/neobundle.vim', "#{vim_path}/bundle/neobundle.vim") end end @@ -21,19 +42,25 @@ namespace :vim do path = File.expand_path("~/.vim") echo "Updating vim" - sh "cd #{path} && git pull" + sh_safe "cd #{path} && git pull" echo "Updating vim plugins" Dir.glob("#{path}/bundle/*") do |f| echo ":: Updating #{File.basename(f)}:" sh_safe "cd #{f} && git pull" end + + if is_linux? + echo "Can't update compiled vim itself! Use pkg:vim:install" + end end desc "Remove vim" task :remove do - echo "Uninstalling vim" - %w{vim macvim}.each { |pkg| Homebrew.remove pkg } + if is_mac? + echo "Uninstalling vim" + Package.remove "vim" + Package.remove "macvim" + end end - end diff --git a/rake/pkg/zsh.rake b/rake/pkg/zsh.rake index bfae2437..8118dc16 100644 --- a/rake/pkg/zsh.rake +++ b/rake/pkg/zsh.rake @@ -5,29 +5,26 @@ desc "Ensure zsh and oh-my-zsh is installed and set" task :zsh => 'zsh:update' namespace :zsh do - - task :install do - unless Dir.exists?(File.expand_path("~/.zprezto")) - echo "Installing prezto" - github 'hlissner/prezto', '~/.zprezto' - end - sh_safe '~/.dotfiles/install.sh' - - unless `printenv SHELL | grep "/bin/zsh"` - echo "Setting shell to zsh" - sh_safe "chsh -s /bin/zsh" - sh_safe "exec /bin/zsh -l" - end + task :install do + unless Dir.exists?(File.expand_path("~/.zprezto")) + echo "Installing prezto" + github 'hlissner/prezto', '~/.zprezto' end + sh_safe '~/.dotfiles/install.sh' - task :update => "zsh:install" do - echo "Updating zprezto" - sh_safe 'cd ~/.zprezto && git pull' - # TODO: pull from parent repo - end - - task :remove do - sh_safe 'rm -rf ~/.zprezto' if Dir.exists?(File.expand_path("~/.zprezto")) + unless `printenv SHELL | grep "/bin/zsh"` + echo "Setting shell to zsh" + sh_safe "chsh -s /bin/zsh" + sh_safe "exec /bin/zsh -l" end + end + task :update => "zsh:install" do + echo "Updating zprezto" + sh_safe 'cd ~/.zprezto && git pull' + end + + task :remove do + sh_safe 'rm -rf ~/.zprezto' if Dir.exists?(File.expand_path("~/.zprezto")) + end end diff --git a/rake/provision.rake b/rake/provision.rake new file mode 100644 index 00000000..c13726b1 --- /dev/null +++ b/rake/provision.rake @@ -0,0 +1,18 @@ +require_relative 'lib/output' + +desc "Update the node (based on hostname)" +task :default, :node do |t, args| + args.with_defaults(:node => `hostname`.gsub('.local', '').strip) + Rake::Task["setup:#{args.node}"].invoke +end + +desc "Wipe the slate clean" +task :destroy do + # are you sure? + # are you really really sure? + # TODO: EXTERMINATE! +end + +namespace :setup do + load_all("node/*.rake") +end diff --git a/rake/setup.rake b/rake/setup.rake deleted file mode 100644 index 0d458e4b..00000000 --- a/rake/setup.rake +++ /dev/null @@ -1,16 +0,0 @@ -require_relative 'lib/output' - -desc "Update the node (based on hostname)" -task :default, :node do |t, args| - args.with_defaults(:node => `hostname`.gsub('.local', '').strip) - Rake::Task["setup:#{args.node}"].invoke -end - -desc "Wipe the slate clean" -task :destroy do - # are you sure? - # are you really really sure? - # TODO: EXTERMINATE! -end - -namespace :setup do load_all("node/*.rake") end