Skip to content

Instantly share code, notes, and snippets.

@rjungemann
Created February 2, 2010 04:54
Show Gist options
  • Save rjungemann/292393 to your computer and use it in GitHub Desktop.
Save rjungemann/292393 to your computer and use it in GitHub Desktop.
A modifiable script to download a fresh, non-root set of Ruby, gems, and other files in one fell swoop, in a way that's quick and allows the directory to be copied or moved.
# A script to create a new project. Just download, chmod it to 755, then try:
# bunk project_name
project_name = ARGV[0]
`mkdir #{project_name} #{project_name}/lib #{project_name}/bin`
files = {
"LICENSE.txt" => %{(The MIT License)
Copyright (c) 2009 thefifthcircuit.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
},
"README.txt" => %{#{project_name}
by Roger Jungemann
http://thefifthcircuit.com/
== DESCRIPTION:
== FEATURES/PROBLEMS:
== SYNOPSIS:
== REQUIREMENTS:
== INSTALL:
},
"Rakefile" => %{require 'rake/gempackagetask'
spec = Gem::Specification.new do |s|
s.name = "#{project_name}"
s.version = "0.0.1"
s.author = "Roger Jungemann"
s.email = "[email protected]"
s.homepage = "http://thefifthcircuit.com"
s.platform = Gem::Platform::RUBY
s.summary = ""
s.description = ""
s.files = FileList["{bin,lib}/**/*"].to_a
s.require_path = "lib"
#s.autorequire = "name"
#s.test_files = FileList["{spec,test}/**/*.rb"].to_a
s.has_rdoc = false
#s.extra_rdoc_files = ["LICENSE.txt, README.txt"]
#s.add_dependency("moneta")
end
Rake::GemPackageTask.new(spec) do |pkg|
pkg.need_tar = true
end}
}
files.each_pair { |k, v| File.open("#{project_name}/#{k}", "w") { |f| f.puts v }}
# a modifiable script to download a fresh, non-root set of Ruby, gems, and
# other files in one fell swoop, in a way that's quick and allows the
# directory to be copied or moved. Assuming you're viewing this file over the
# Internet, you can simply run:
# curl URL_TO_THIS_SCRIPT | ruby
files {
"homebrew/monit.conf" => %{},
"homebrew/redis.conf" => %{},
"homebrew/Rakefile" => %{desc "Install utilities into the current directory."
task :install do
sh "bin/brew install ruby"
sh "bin/brew install monit"
sh "bin/brew install dtach"
sh "bin/brew install rlwrap"
sh "bin/brew install node"
sh "bin/brew install redis"
end
task :install_bunk do
sh "cd bin && curl -O http://gist.github.com/raw/292393/518b2de6c8ed8d410db4cbb2065167bb4abb1a2c/bunk"
sh "cd bin && chmod 755 bunk"
end
namespace :redis do
task :start do
puts 'Detach with Ctrl+\ Re-attach with rake redis:attach'
sleep 1
exec "dtach -A tmp/redis.dtach redis-server redis.conf"
end
task :attach do
exec "dtach -a tmp/redis.dtach"
end
task :stop do
sh 'echo "SHUTDOWN" | nc localhost 6379'
end
end
task :default do
sh "clear"
puts "Please type the following in the Terminal to begin:"
puts " source bashrc"
puts "You can fetch fresh copies of the gems by editing the Gemfile,"
puts "then typing in:"
puts " gem bundle"
end
},
"homebrew/irbrc" => %{# History and Readline code come from http://blog.nicksieger.com/articles/2006/04/23/tweaking-irb
require 'rubygems'
require 'pp'
require 'irb/ext/save-history'
ARGV.concat ["--readline"]
IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "\#{ENV['HOME']}/.irb-save-history"
alias :function :lambda
alias :f :lambda
class Object
def grok
(self.methods - Object.new.methods).sort
end
end
module Readline
module History
LOG = "\#{ENV['HOME']}/.irb-history"
def self.write_log(line)
File.open(LOG, 'ab') {|f| f << "\#{line}\n"}
end
def self.start_session_log
write_log("\n# session start: \#{Time.now}\n")
at_exit { write_log("\n# session stop: \#{Time.now}\n") }
end
end
alias :old_readline :readline
def readline(*args)
ln = old_readline(*args)
begin
History.write_log(ln)
rescue
end
ln
end
end
Readline::History.start_session_log
},
"homebrew/Gemfile" => %{
source "http://gemcutter.org"
source "http://gems.github.com"
git "git://github.com/rails/rack.git"
git "git://github.com/rack/rack-contrib.git"
gem "jeweler"
gem 'sinatra', :require_as => 'sinatra/base'
gem "thin"
gem "yajl-ruby", :require_as => "yajl/json_gem"
gem "nokogiri"
gem "moneta"
gem "uuid"
gem "dm-core"
gem "redis"
gem "redis-namespace", :require_as => "redis/namespace"
gem "gettext"
gem "navvy"
},
"homebrew/bashrc" => %{SCRIPT_PATH="${BASH_SOURCE[0]}";
if([ -h "${SCRIPT_PATH}" ]) then
while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
fi
pushd . > /dev/null
cd `dirname ${SCRIPT_PATH}` > /dev/null
SCRIPT_PATH=`pwd`;
popd > /dev/null
export PATH=${SCRIPT_PATH}/bin:$PATH
export GEM_HOME=${SCRIPT_PATH}/lib/ruby/gems
export IRBRC=${SCRIPT_PATH}/irbrc
export NODE_PATH=${SCRIPT_PATH}/modules:$NODE_PATH
alias node-repl="rlwrap node-repl"
}
}
`clear`
puts "Installing homebrew."
`git clone git://github.com/mikearthur/homebrew.git`
puts "Creating a local tmp directory."
`mkdir homebrew/tmp`
puts "Creating a projects directory."
`mkdir homebrew/projects`
puts "Creating configuration files."
files.each_pair { |k, v| File.open(k, "w") { |f| f.puts v }}
puts "Installing software and gems."
`cd homebrew && rake install && gem bundle && rake`
puts "Remember to cd into the homebrew directory first!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment