Created
April 7, 2010 15:37
-
-
Save gisikw/359025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
VERSION="0.0.1" | |
echo "=================" | |
echo "Spurs v$VERSION" | |
echo "<[email protected]>" | |
echo "=================" | |
if [ "$(id -u)" != "0" ]; then | |
echo "Sorry, Spurs must be run as root." | |
exit 1 | |
fi | |
if ping -c 1 209.85.225.99 > /dev/null; then | |
echo "Sorry, Spurs requires an internet connection" | |
exit 1 | |
fi | |
echo -n "Spurs: Updating repositories..." | |
apt-get update | |
echo "done." | |
echo "Spurs: Installing required tools:" | |
echo -n "Spurs: wget..." | |
apt-get install wget | |
echo "done." | |
echo -n "Spurs: ruby..." | |
apt-get install ruby | |
echo "done." | |
echo -n "Spurs: Downloading Stallion..." | |
wget http://gist.github.com/raw/359025/b88c71dcc1dc922962393abfc6a42f1036aaed20/stallion.rb -o stallion | |
chmod +x stallion | |
echo "done." | |
echo "Spurs has completed. Please run Stallion." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class Stallion | |
VERSION = "0.0.1" | |
LIBRARIES = { | |
:build_libraries => %w{build-essential}, | |
:mysql_and_ruby_libraries => %w{ruby ri rdoc mysql-server libmysql-ruby ruby1.8-dev irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient15off libnet-daemon-perl libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client-5.0 mysql-common mysql-server-5.0 rdoc1.8 ri1.8 ruby1.8 irb libopenssl-ruby libopenssl-ruby1.8 libhtml-template-perl mysql-server-core-5.0} | |
} | |
@@tasks = {} | |
class << self | |
# DSL Definition | |
def task(name,&block) | |
unless @@latest_desc | |
puts "Error: Must write a description for #{name} task" | |
else | |
@@tasks[name] = {:execute=>block,:description=>@@latest_desc} | |
@@latest_desc = nil | |
end | |
end | |
def desc(brief); @@latest_desc = brief; end | |
def tasks; @@tasks; end | |
def execute(command) | |
if @@tasks[command] | |
@@tasks[command][:execute].call | |
else | |
@@tasks[:help][:execute].call | |
end | |
end | |
# Helper Methods | |
def apt_get_install(library,prompt=nil) | |
if prompt | |
print "Stallion: Install aptitude package? (#{library}) y/N:" | |
return unless %w{y yes}.include? gets.chomp.downcase | |
end | |
puts "Stallion: Installing package: (#{library})" | |
abort "Failed to install package (#{library}). Stallion shamefully curls up and dies." unless system("sudo apt-get install #{library}") | |
puts "Stallion: Installed package (#{library})" | |
end | |
end | |
# Public Tasks | |
desc "Displays usage information" | |
task :help do | |
execute :info | |
puts "Available commands:" | |
Stallion.tasks.sort{|a,b| a[0].to_s <=> b[0].to_s}.each do |task,params| | |
puts task.to_s.gsub(/[^A-Za-z]/,":").ljust(20)+params[:description] | |
end | |
end | |
desc "Display version information for Stallion" | |
task :info do | |
puts <<-END | |
================================= | |
Stallion v.#{VERSION} | |
<[email protected]> | |
================================= | |
END | |
end | |
desc "Install all imaginable libraries deemed helpful for a Rails server" | |
task :install do | |
LIBRARIES.values.flatten.each{|x|apt_get_install x} | |
end | |
desc "Attempt to install all libraries - prompting the user each time" | |
task :install_paranoid do | |
LIBRARIES.values.flatten.each{|x|apt_get_install x, true} | |
end | |
end | |
Stallion.execute(((x=ARGV.join("_").gsub(/[^A-Za-z]/,"_")).empty? ? "help" : x).to_sym) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment