Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
triskweline committed May 26, 2011
0 parents commit 2eb8371
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.gem
.bundle
.idea
Gemfile.lock
pkg/*
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in geordi.gemspec
gemspec
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
H1
==

H2
--

foo

bar

2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'bundler'
Bundler::GemHelper.install_tasks
2 changes: 2 additions & 0 deletions bin/apache-site
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
sudo a2dissite \*; sudo a2ensite default $1 && sudo apache2ctl restart
6 changes: 6 additions & 0 deletions bin/b
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby

call = ARGV.dup
call = ['bundle', 'exec'] + call if File.exists?('Gemfile')
exec *call

56 changes: 56 additions & 0 deletions bin/dumple
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env ruby

fail_gently = ARGV.include?("--fail-gently")

if ARGV.include?("-i")
puts "*******************************************************"
puts
system("du -sh ~/dumps")
puts
puts "*******************************************************"
exit
end

require "yaml"

config_path = 'config/database.yml'
unless File.exist?(config_path)
if fail_gently
puts "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
puts "* *"
puts "* *"
puts "* Script is not called from inside a Rails project, *"
puts "* *"
puts "* THE DATABASE WILL NOT BE DUMPED. *"
puts "* *"
puts "* *"
puts "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
sleep 5
exit
else
raise "Call me from inside a Rails project."
end
end
config = YAML::load(File.open(config_path))

environment = ARGV.reject{ |arg| arg[0].chr == '-' }.first || 'production'
config = config[environment] or raise "No production environment found. Please do `dumple [env_name]`"

dump_dir = "#{ENV['HOME']}/dumps"
unless File.directory?(dump_dir)
Dir.mkdir(dump_dir)
system("chmod 700 #{dump_dir}")
end
dump_path = "#{dump_dir}/#{config['database']}_#{Time.now.strftime("%Y%m%d_%H%M%S")}.dump"

puts
puts "Dumping database for environment \"#{environment}\"..."

system "mysqldump -u\"#{config['username']}\" -p\"#{config['password']}\" #{config['database']} -r #{dump_path}"
system "chmod 600 #{dump_path}"

dump_size_kb = (File.size(dump_path) / 1024).round

puts "Dumped to #{dump_path} (#{dump_size_kb} KB)"
puts

11 changes: 11 additions & 0 deletions bin/install-gems-remotely
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
if ls vendor/gems/*/*.gemspec > /dev/null 2>&1; then
tar cf tmp/gemfiles_for_remote_install Gemfile Gemfile.lock vendor/gems/*/*.gemspec
else
tar cf tmp/gemfiles_for_remote_install Gemfile Gemfile.lock
fi
scp tmp/gemfiles_for_remote_install $1:~
stty_orig=`stty -g`
stty -echo
ssh -t $1 "mkdir /tmp/install_gems; mv gemfiles_for_remote_install /tmp/install_gems; cd /tmp/install_gems; tar xf gemfiles_for_remote_install; bundle install; rm -rf /tmp/install_gems"
stty $stty_orig
3 changes: 3 additions & 0 deletions bin/power-deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
cap $1 deploy && cap $1 deploy:migrate && cap $1 deploy:restart

9 changes: 9 additions & 0 deletions bin/power-rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env ruby

for env in ['development', 'test', 'cucumber', 'performance']
if File.exists? "config/environments/#{env}.rb"
call = ['rake'] + ARGV + ["RAILS_ENV=#{env}"]
puts call.join(' ')
system *call
end
end
12 changes: 12 additions & 0 deletions bin/remotify-local-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env ruby

branch = ARGV[0] or raise "Need the branch name as first argument"

`git status`.include?('working directory clean') or raise 'Dirty working directory. Nothing was pushed.'
`git checkout #{branch}`
`git push origin #{branch}`
`git config branch.#{branch}.remote origin`
`git config branch.#{branch}.merge #{branch}`

puts "#{branch} is now tracking origin/#{branch}"

10 changes: 10 additions & 0 deletions bin/remove-execute-flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

echo "Removing execute flags:"
for pattern in *.rb *.html *.erb *.haml *.yml *.css *.sass *.rake *.png *.jpg *.gif *.pdf *.txt *.rdoc Rakefile VERSION README Capfile
do
echo "- $pattern"
find . -name "$pattern" -exec chmod -x {} \;
done
echo "Done."

44 changes: 44 additions & 0 deletions bin/shell-for
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env ruby

def quoted_text(line)
line.match(/["'].*["']/).to_s.gsub(/["']/, '')
end

def read_deploy_files
all_deploy_files = Dir["config/deploy/*.rb"]

deploy_file = all_deploy_files.find do |file|
file.match(/\/#{@stage}.rb$/)
end
raise "Unknown stage: #{@stage}" unless deploy_file

@specific = File.open(deploy_file).readlines
@for_all = File.open("config/deploy.rb").readlines
end

def build_command
path = quoted_text(@deploy_to) + "/current"

@command = "ssh #{quoted_text(@user)}@#{quoted_text(@server)}"
@command += %( -t "cd #{path} && bash --login") unless path.match /#\{/
end

begin
@stage = ARGV.shift

raise "Usage: shell_for DEPLOYMENT_STAGE" unless @stage
raise "Run me from inside a Rails project" unless File.exists?("config/deploy.rb")

read_deploy_files
@user = @specific.find{ |line| line =~ /^set :user, /} || @for_all.find{ |line| line =~ /^set :user, / }
@server = @specific.find{ |line| line =~ /^server / } || @for_all.find{ |line| line =~ /^server / }
@deploy_to = @specific.find{ |line| line =~ /^set :deploy_to, /} || @for_all.find{ |line| line =~ /^set :deploy_to, / }

build_command

exec @command

rescue Exception => e
$stderr.puts e.message
exit 1
end
21 changes: 21 additions & 0 deletions geordi.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "geordi/version"

Gem::Specification.new do |s|
s.name = "geordi"
s.version = Geordi::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Henning Koch"]
s.email = ["henning.koch@makandra.de"]
s.homepage = "http://makandra.com"
s.summary = 'Collection of command line tools used in our daily work with Ruby, Rails and Linux.'
s.description = 'Collection of command line tools used in our daily work with Ruby, Rails and Linux.'

s.rubyforge_project = "geordi"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
end

0 comments on commit 2eb8371

Please sign in to comment.