Refactor rake package installers

This commit is contained in:
Henrik Lissner 2014-09-05 17:03:26 -04:00
parent 042a681c09
commit 6ebcfd11bb
5 changed files with 185 additions and 134 deletions

View file

@ -7,10 +7,9 @@ if is_mac?
namespace :emacs do namespace :emacs do
task :install do task :install do
unless Dir.exists?(ENV[:EMACS_D]) unless Dir.exists? ENV[:EMACS_D]
github 'hlissner/emacs.d', '~/.emacs.d' github 'hlissner/emacs.d', '~/.emacs.d'
Package.install "emacs", "--with-gnutls --cocoa --keep-ctags --srgb" Package.install "homebrew/dupes/tidy --HEAD"
Package.install "homebrew/dupes/tidy", "--HEAD"
emacs_reqs.each { |pkg| Package.install pkg } emacs_reqs.each { |pkg| Package.install pkg }
sh_safe "/usr/local/bin/npm install jshint -g" sh_safe "/usr/local/bin/npm install jshint -g"
@ -22,21 +21,28 @@ if is_mac?
task :update do task :update do
echo "Updating emacs.d & packages" echo "Updating emacs.d & packages"
sh_safe "cd ~/.emacs.d && git pull && cask update" sh_safe "cd ~/.emacs.d && git pull && cask update"
# Update rsense config
sh_safe "~/.rbenv/shims/ruby `brew --prefix rsense`/libexec/etc/config.rb > ~/.rsense"
end end
desc "Remove emacs & dependencies"
task :remove do task :remove do
echo "Uninstalling emacs" echo "Uninstalling emacs"
Package.remove "emacs" Package.remove "emacs"
Package.remove "homebrew/dupes/tidy" Package.remove "homebrew/dupes/tidy"
emacs_reqs.each { |pkg| Package.remove pkg } emacs_reqs.each { |pkg| Package.remove pkg }
rm_rf "~/.emacs.d" if Dir.exists?(ENV['EMACS_D']) rm_rf "~/.emacs.d" if Dir.exists? ENV['EMACS_D']
end end
end end
def emacs_reqs def emacs_reqs
%w{aspell cask rsense} [
"emacs --with-gnutls --cocoa --keep-ctags --srgb",
"aspell --with-lang-en",
"cask",
"rsense"
]
end end
end end

View file

@ -1,58 +1,8 @@
desc "Install/update pyenv & all pythons"
task :pyenv => 'pyenv:update'
PYENV_ROOT = File.expand_path("~/.pyenv") PYENV_ROOT = File.expand_path("~/.pyenv")
ENV["PYTHON_VERSION"] = "3.4.1"
namespace :pyenv do
task :install do
unless pyenv_installed?
echo "Installing pyenv"
github "yyuu/pyenv", PYENV_ROOT
mkdir_p "#{PYENV_ROOT}/plugins"
[ "yyuu/pyenv-doctor",
"yyuu/pyenv-installer",
"yyuu/pyenv-pip-rehash",
"yyuu/pyenv-update",
"yyuu/pyenv-virtualenv",
"yyuu/pyenv-which-ext"
].each { |pkg| github pkg, "#{PYENV_ROOT}/plugins/" }
sh_safe "eval $(~/.pyenv/bin/pyenv init -)"
sh_safe "eval $(~/.pyenv/bin/pyenv virtualenv-init -)"
end
end
task :update => "pyenv:install" do
echo "Updating pyenv & plugins"
sh_safe "cd #{PYENV_ROOT} && git pull"
pyenv_plugins do |dir|
sh_safe "cd #{dir} && git pull"
end
pyenv_versions do |version|
echo "Updating python #{version}"
cmd = "pip"
cmd = "sudo #{version}" if v == "system"
sh_safe "PYENV_VERSION=#{version} #{cmd} freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs #{cmd} install -U"
end
end
if pyenv_installed?
desc "Remove pyenv & installed pythons"
task :remove do
echo "Deleting pyenv"
sh_safe "rm -rf #{PYENV_ROOT}"
end
end
end
####
def pyenv_installed? def pyenv_installed?
system("which pyenv") Dir.exists?(PYENV_ROOT)
end end
def pyenv_versions def pyenv_versions
@ -62,3 +12,65 @@ end
def pyenv_plugins def pyenv_plugins
Dir.glob("#{PYENV_ROOT}/plugins/*") Dir.glob("#{PYENV_ROOT}/plugins/*")
end end
###
desc "Install/update pyenv & all pythons"
task :pyenv => 'pyenv:update'
namespace :pyenv do
task :install do
unless pyenv_installed?
echo "Installing pyenv"
github "yyuu/pyenv", PYENV_ROOT
[ "yyuu/pyenv-doctor",
"yyuu/pyenv-installer",
"yyuu/pyenv-pip-rehash",
"yyuu/pyenv-update",
"yyuu/pyenv-virtualenv",
"yyuu/pyenv-which-ext"
].each do |pkg|
echo "Installing #{pkg}", 2
github pkg, "#{PYENV_ROOT}/plugins/#{pkg.split("/")[1]}"
end
echo "Initializing pyenv", 2
sh_safe "eval \"$(#{PYENV_ROOT}/bin/pyenv init -)\""
sh_safe "eval \"$(#{PYENV_ROOT}/bin/pyenv virtualenv-init -)\""
# Install global python + packages
py_version = ENV["PYTHON_VERSION"]
echo "Setting up default python (#{py_version})", 2
sh_safe "pyenv install #{py_version}"
sh_safe "pyenv global #{py_version}"
sh_safe "PYENV_VERSION=#{py_version} #{PYENV_ROOT}/shims/pip install cython"
sh_safe "PYENV_VERSION=#{py_version} #{PYENV_ROOT}/shims/pip install nose virtualenv pyyaml"
end
end
task :update => "pyenv:install" do
echo "Updating pyenv & plugins"
sh_safe "cd #{PYENV_ROOT} && git pull"
pyenv_plugins.each do |dir|
echo "Updating #{File.basename(dir)}", 2
sh_safe "cd #{dir} && git pull"
end
pyenv_versions.each do |version|
echo "Updating python #{version}", 2
cmd = "#{PYENV_ROOT}/shims/pip"
cmd = "sudo #{version}" if version == "system"
sh_safe "PYENV_VERSION=#{version} #{cmd} freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs #{cmd} install -U"
end
end
if pyenv_installed?
task :remove do
echo "Deleting pyenv"
sh_safe "rm -rf #{PYENV_ROOT}"
end
end
end

View file

@ -1,59 +1,7 @@
desc "Install/update rbenv & all rubies"
task :rbenv => 'rbenv:update'
RBENV_ROOT = File.expand_path("~/.rbenv") RBENV_ROOT = File.expand_path("~/.rbenv")
namespace :rbenv do
task :install do
unless rbenv_installed?
echo "Installing rbenv"
sh_safe "curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash"
github "sstephenson/rbenv", RBENV_ROOT
mkdir_p "#{rbenv_root}/plugins"
[ "sstephenson/rbenv-vars",
"sstephenson/ruby-build",
"sstephenson/rbenv-default-gems",
"sstephenson/rbenv-gem-rehash",
"fesplugas/rbenv-installer",
"fesplugas/rbenv-bootstrap",
"rkh/rbenv-update",
"rkh/rbenv-whatis",
"rkh/rbenv-use"
].each { |pkg| github pkg, "#{RBENV_ROOT}/plugins/" }
sh_safe "eval $(~/.rbenv/bin/rbenv init -)"
end
end
task :update => "rbenv:install" do
echo "Updating rbenv & plugins"
sh_safe "rbenv update"
rbenv_versions do |version|
echo "Updating ruby #{version}"
cmd = "gem"
cmd = "sudo #{cmd}" if version == "system"
sh_safe "RBENV_VERSION=#{version} #{cmd} #{GEM_BIN} update"
sh_safe "RBENV_VERSION=#{version} #{cmd} #{GEM_BIN} clean"
end
end
if rbenv_installed?
desc "Remove rbenv & installed rubies"
task :remove do
echo "Deleting rbenv"
sh_safe "rm -rf #{RBENV_ROOT}"
end
end
end
####
def rbenv_installed? def rbenv_installed?
system("which rbenv") Dir.exists?(RBENV_ROOT)
end end
def rbenv_versions def rbenv_versions
@ -63,3 +11,73 @@ end
def rbenv_plugins def rbenv_plugins
Dir.glob("#{RBENV_ROOT}/plugins/*") Dir.glob("#{RBENV_ROOT}/plugins/*")
end end
def rbenv_set_default_gems(gems)
return if !gems.is_a?(Array) or gems.length == 0
File.write("#{RBENV_ROOT}/default-gems", gems.join("\n"))
end
###
desc "Install/update rbenv & all rubies"
task :rbenv => 'rbenv:update'
namespace :rbenv do
task :install do
unless rbenv_installed?
echo "Installing rbenv"
github "sstephenson/rbenv", RBENV_ROOT
mkdir_p "#{RBENV_ROOT}/plugins"
[ "sstephenson/rbenv-vars",
"sstephenson/ruby-build",
"sstephenson/rbenv-default-gems",
"sstephenson/rbenv-gem-rehash",
"fesplugas/rbenv-installer",
"fesplugas/rbenv-bootstrap",
"rkh/rbenv-update",
"rkh/rbenv-whatis",
"rkh/rbenv-use"
].each do |pkg|
echo "Installing #{pkg}", 2
github pkg, "#{RBENV_ROOT}/plugins/#{pkg.split("/")[1]}"
end
echo "Initializing rbenv", 2
sh_safe "eval \"$(#{RBENV_ROOT}/bin/rbenv init -)\""
# Set default gems
rbenv_set_default_gems(:bundler, :rspec, :pry, :factory_girl)
# Install global ruby + gems
ruby_version = "2.1.2"
echo "Setting up default ruby (#{ruby_version})", 2
sh_safe "rbenv install #{ruby_version}"
sh_safe "rbenv global #{ruby_version}"
sh_safe "RBENV_VERSION=#{ruby_version} #{RBENV_ROOT}/shims/gem install -f jekyll sass mercenary"
end
end
task :update => "rbenv:install" do
echo "Updating rbenv & plugins"
sh_safe "rbenv update"
rbenv_versions.each do |version|
echo "Updating ruby #{version}"
cmd = "#{RBENV_ROOT}/shims/gem"
cmd = "sudo #{cmd}" if version == "system"
sh_safe "RBENV_VERSION=#{version} #{cmd} update --system -f"
sh_safe "RBENV_VERSION=#{version} #{cmd} update -f"
sh_safe "RBENV_VERSION=#{version} #{cmd} clean"
end
end
if rbenv_installed?
task :remove do
echo "Deleting rbenv"
sh_safe "rm -rf #{RBENV_ROOT}"
end
end
end

View file

@ -9,7 +9,7 @@ namespace :vim do
Package.install "lua" Package.install "lua"
%w{vim macvim}.each { |pkg| Package.install "#{pkg} --with-lua --with-luajit" } %w{vim macvim}.each { |pkg| Package.install "#{pkg} --with-lua --with-luajit" }
elsif is_linux? elsif is_linux?
Package.install "lua5.2" Package.install "lua5.1"
unless Dir.exists?(vim_path) unless Dir.exists?(vim_path)
sh_safe "sudo apt-get install libncurses5-dev libgnome2-dev libgnomeui-dev \ sh_safe "sudo apt-get install libncurses5-dev libgnome2-dev libgnomeui-dev \
@ -18,13 +18,13 @@ namespace :vim do
sh_safe "hg clone https://code.google.com/p/vim/ /tmp/vim" sh_safe "hg clone https://code.google.com/p/vim/ /tmp/vim"
sh_safe "cd /tmp/vim && ./configure --with-features=huge \ sh_safe "cd /tmp/vim && ./configure --with-features=huge \
--enable-multibyte \ --enable-multibyte \
--enable-rubyinterp \ --enable-rubyinterp \
--enable-pythoninterp \ --enable-pythoninterp \
--enable-perlinterp \ --enable-perlinterp \
--enable-luainterp \ --enable-luainterp \
--enable-clipboard \ --enable-clipboard \
--enable-cscope --prefix=/usr \ --enable-cscope --prefix=/usr \
&& make VIMRUNTIMEDIR=/usr/share/vim/vim74 && make VIMRUNTIMEDIR=/usr/share/vim/vim74
&& sudo make install" && sudo make install"
sh_safe "rm -rf /tmp/vim" sh_safe "rm -rf /tmp/vim"
@ -55,12 +55,11 @@ namespace :vim do
end end
end end
desc "Remove vim"
task :remove do task :remove do
if is_mac? if is_mac?
echo "Uninstalling vim" echo "Uninstalling vim"
Package.remove "vim" Package.remove "vim"
Package.remove "macvim" Package.remove "macvim"
end end
end end
end end

View file

@ -1,22 +1,38 @@
require_relative '../lib/sh' desc "Ensure zsh & prezto are installed"
require_relative '../lib/git'
desc "Ensure zsh and oh-my-zsh is installed and set"
task :zsh => 'zsh:update' task :zsh => 'zsh:update'
ENV["PREZTO_PATH"] = File.expand_path("~/.zprezto")
namespace :zsh do namespace :zsh do
task :install do task :install do
unless Dir.exists?(File.expand_path("~/.zprezto")) echo "Attempting to install ZSH"
echo "Installing prezto" Package.install "zsh"
github 'hlissner/prezto', '~/.zprezto'
unless Dir.exists? ENV["PREZTO_PATH"]
echo "Installing prezto", 2
github 'hlissner/prezto', ENV["PREZTO_PATH"]
end end
sh_safe '~/.dotfiles/install.sh' sh_safe '~/.dotfiles/install.sh'
unless `printenv SHELL | grep "/bin/zsh"` if `printenv SHELL | grep "/zsh$"`
echo "Setting shell to zsh" echo "Setting shell to ZSH", 2
sh_safe "chsh -s /bin/zsh" zsh_bin = is_mac? ? "/usr/local/bin/zsh" : "/usr/bin/zsh"
if !File.exists? zsh_bin
error "ZSH isn't in #{File.dirname(zsh_bin)}"
next
end
# Write the new zsh into shells if it isn't already there
if `cat /etc/shells | grep "^#{zsh_bin}$"`
echo "Writing '#{zsh_bin}' to /etc/shells", 3
sh_safe "echo '#{zsh_bin}' | sudo tee -a /etc/shells"
end
sh_safe "chsh -s #{zsh_bin}"
sh_safe "exec /bin/zsh -l" sh_safe "exec /bin/zsh -l"
end end
echo "Comment out path_helper to fix PATH in emacs!" if is_mac?
end end
task :update => "zsh:install" do task :update => "zsh:install" do
@ -25,6 +41,6 @@ namespace :zsh do
end end
task :remove do task :remove do
sh_safe 'rm -rf ~/.zprezto' if Dir.exists?(File.expand_path("~/.zprezto")) sh_safe 'rm -rf ~/.zprezto' if Dir.exists? ENV["PREZTO_PATH"]
end end
end end