Skip to content

Instantly share code, notes, and snippets.

@aereal
Created May 3, 2011 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aereal/954410 to your computer and use it in GitHub Desktop.
Save aereal/954410 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# vim:set ft=ruby:
require "optparse"
require "tmpdir"
OPTS = {}
OptionParser.new.instance_eval do
on('-d', '--dry') { OPTS[:dry] = true }
on('-v', '--verbose') { OPTS[:verbose] = true }
on('--homebrew [DST]', 'install Homebrew in DST (default is /usr/local)') do |dst|
OPTS[:homebrew] = dst || '/usr/local'
end
on('--perlbrew [DST]', 'install perlbrew in DST (default is ~/perl5/perlbrew)') do |dst|
OPTS[:perlbrew] = dst || '~/perl5/perlbrew'
end
on('--rvm', 'install RVM') { OPTS[:rvm] = true }
end.parse!(ARGV)
module Helper
def info(msg)
STDERR.puts "\e[32mINFO:\e[0m#{msg}" if OPTS[:verbose] || OPTS[:dry]
end
def warn(msg)
STDERR.puts "\e[33mWARN:\e[0m#{msg}"
end
def die(msg)
STDERR.puts "\e[31mERROR:\e[0m \e[4m#{caller.first}\e[0m => #{msg}"
exit 1
end
def installed?(cmd)
File.executable? `which #{cmd}`.strip
end
def sh(*args)
info args.join(' ')
system args.join(' ') unless OPTS[:dry]
end
def install_homebrew(dst='/usr/local')
prefix = File.realpath(File.expand_path(dst))
srcdir = File.join(Dir.tmpdir, "homebrew-#{$$}")
warn "Homebrew is installed in #{prefix}"
sh %Q!curl -LsSf https://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C#{prefix}!
sh %Q!#{prefix}/bin/brew install git!
sh 'mkdir', srcdir
sh %Q!#{prefix}/bin/git clone git://github.com/mxcl/homebrew.git #{srcdir}!
sh 'cp', '-r', srcdir, prefix
sh 'rm', '-r', srcdir
end
def install_perlbrew(dst='~/perl5/perlbrew')
perlbrew_dir = File.realpath(File.expand_path(dst))
workdir = File.join(Dir.tmpdir, "perlbrew-#{$$}")
installer = File.join(workdir, '_perlbrew')
sh 'mkdir', workdir
sh %Q!curl -LsSo #{installer} http://xrl.us/perlbrew!
sh 'chmod', 'u+x', installer
sh %Q!PERLBREW_ROOT=#{perlbrew_dir} #{installer} install #{'-v' if OPTS[:verbose]}!
sh %Q!#{perlbrew_dir}/bin/perlbrew init!
sh %Q!source #{perlbrew_dir}/etc/#{current_shell_type}rc!
end
def install_rvm
workdir = File.join(Dir.tmpdir, "rvm-#{$$}")
installer = File.join(workdir, 'rvm-installer')
sh 'mkdir', workdir
sh %Q!curl -LsSo #{installer} https://rvm.beginrescueend.com/install/rvm!
sh 'chmod', '+x', installer
sh installer, '--version', 'latest'
sh %Q![[ -s "#{ENV['HOME']}/.rvm/scripts/rvm" ]] && source "#{ENV['HOME']}/.rvm/scripts/rvm"!
end
def current_shell_type
case File.basename(ENV['SHELL'])
when /^(?:a|k|z|(?:s|b)?a)?sh/
:bash
when /^t?csh/
:csh
else
die "Unknown shell: #{ENV['SHELL']}"
end
end
end
include Helper
tasks = []
tasks << Thread.new { install_homebrew OPTS[:homebrew] } if OPTS[:homebrew]
tasks << Thread.new { install_perlbrew OPTS[:perlbrew] } if OPTS[:perlbrew]
tasks << Thread.new { install_rvm } if OPTS[:rvm]
tasks.each {|t| t.join }
warn "#{$0} extracts files in here!"
if installed? 'git'
sh %Q{git clone git@github.com:aereal/dotfiles .}
else
sh %Q{curl -fLsS https://github.com/aereal/dotfiles/tarball/master | tar xzf - -C. --strip 1}
end
sh %Q{rake install}
@aereal
Copy link
Author

aereal commented May 3, 2011

mkdir ~/dotfiles && cd ~/dotfiles
curl -sSfL https://gist.github.com/raw/954410/648dd2fb79e0632e757b4d2af66823bec74868dd/setup.rb | ruby -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment