Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 2eb8371911ad960df886c9c4d2995c07d1046c93 @henning-koch henning-koch committed May 26, 2011
Showing with 195 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +4 −0 Gemfile
  3. +10 −0 README.md
  4. +2 −0 Rakefile
  5. +2 −0 bin/apache-site
  6. +6 −0 bin/b
  7. +56 −0 bin/dumple
  8. +11 −0 bin/install-gems-remotely
  9. +3 −0 bin/power-deploy
  10. +9 −0 bin/power-rake
  11. +12 −0 bin/remotify-local-branch
  12. +10 −0 bin/remove-execute-flags
  13. +44 −0 bin/shell-for
  14. +21 −0 geordi.gemspec
@@ -0,0 +1,5 @@
+*.gem
+.bundle
+.idea
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in geordi.gemspec
+gemspec
@@ -0,0 +1,10 @@
+H1
+==
+
+H2
+--
+
+foo
+
+bar
+
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
@@ -0,0 +1,2 @@
+#!/bin/sh
+sudo a2dissite \*; sudo a2ensite default $1 && sudo apache2ctl restart
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+call = ARGV.dup
+call = ['bundle', 'exec'] + call if File.exists?('Gemfile')
+exec *call
+
@@ -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
+
@@ -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
@@ -0,0 +1,3 @@
+#!/bin/sh
+cap $1 deploy && cap $1 deploy:migrate && cap $1 deploy:restart
+
@@ -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
@@ -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}"
+
@@ -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."
+
@@ -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
@@ -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.