geordi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ .idea
4
+ Gemfile.lock
5
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in geordi.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ H1
2
+ ==
3
+
4
+ H2
5
+ --
6
+
7
+ foo
8
+
9
+ bar
10
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/apache-site ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ sudo a2dissite \*; sudo a2ensite default $1 && sudo apache2ctl restart
data/bin/b ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ call = ARGV.dup
4
+ call = ['bundle', 'exec'] + call if File.exists?('Gemfile')
5
+ exec *call
6
+
data/bin/dumple ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ fail_gently = ARGV.include?("--fail-gently")
4
+
5
+ if ARGV.include?("-i")
6
+ puts "*******************************************************"
7
+ puts
8
+ system("du -sh ~/dumps")
9
+ puts
10
+ puts "*******************************************************"
11
+ exit
12
+ end
13
+
14
+ require "yaml"
15
+
16
+ config_path = 'config/database.yml'
17
+ unless File.exist?(config_path)
18
+ if fail_gently
19
+ puts "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
20
+ puts "* *"
21
+ puts "* *"
22
+ puts "* Script is not called from inside a Rails project, *"
23
+ puts "* *"
24
+ puts "* THE DATABASE WILL NOT BE DUMPED. *"
25
+ puts "* *"
26
+ puts "* *"
27
+ puts "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
28
+ sleep 5
29
+ exit
30
+ else
31
+ raise "Call me from inside a Rails project."
32
+ end
33
+ end
34
+ config = YAML::load(File.open(config_path))
35
+
36
+ environment = ARGV.reject{ |arg| arg[0].chr == '-' }.first || 'production'
37
+ config = config[environment] or raise "No production environment found. Please do `dumple [env_name]`"
38
+
39
+ dump_dir = "#{ENV['HOME']}/dumps"
40
+ unless File.directory?(dump_dir)
41
+ Dir.mkdir(dump_dir)
42
+ system("chmod 700 #{dump_dir}")
43
+ end
44
+ dump_path = "#{dump_dir}/#{config['database']}_#{Time.now.strftime("%Y%m%d_%H%M%S")}.dump"
45
+
46
+ puts
47
+ puts "Dumping database for environment \"#{environment}\"..."
48
+
49
+ system "mysqldump -u\"#{config['username']}\" -p\"#{config['password']}\" #{config['database']} -r #{dump_path}"
50
+ system "chmod 600 #{dump_path}"
51
+
52
+ dump_size_kb = (File.size(dump_path) / 1024).round
53
+
54
+ puts "Dumped to #{dump_path} (#{dump_size_kb} KB)"
55
+ puts
56
+
@@ -0,0 +1,11 @@
1
+ #!/bin/sh
2
+ if ls vendor/gems/*/*.gemspec > /dev/null 2>&1; then
3
+ tar cf tmp/gemfiles_for_remote_install Gemfile Gemfile.lock vendor/gems/*/*.gemspec
4
+ else
5
+ tar cf tmp/gemfiles_for_remote_install Gemfile Gemfile.lock
6
+ fi
7
+ scp tmp/gemfiles_for_remote_install $1:~
8
+ stty_orig=`stty -g`
9
+ stty -echo
10
+ 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"
11
+ stty $stty_orig
data/bin/power-deploy ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+ cap $1 deploy && cap $1 deploy:migrate && cap $1 deploy:restart
3
+
data/bin/power-rake ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ for env in ['development', 'test', 'cucumber', 'performance']
4
+ if File.exists? "config/environments/#{env}.rb"
5
+ call = ['rake'] + ARGV + ["RAILS_ENV=#{env}"]
6
+ puts call.join(' ')
7
+ system *call
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ branch = ARGV[0] or raise "Need the branch name as first argument"
4
+
5
+ `git status`.include?('working directory clean') or raise 'Dirty working directory. Nothing was pushed.'
6
+ `git checkout #{branch}`
7
+ `git push origin #{branch}`
8
+ `git config branch.#{branch}.remote origin`
9
+ `git config branch.#{branch}.merge #{branch}`
10
+
11
+ puts "#{branch} is now tracking origin/#{branch}"
12
+
@@ -0,0 +1,10 @@
1
+ #!/bin/sh
2
+
3
+ echo "Removing execute flags:"
4
+ for pattern in *.rb *.html *.erb *.haml *.yml *.css *.sass *.rake *.png *.jpg *.gif *.pdf *.txt *.rdoc Rakefile VERSION README Capfile
5
+ do
6
+ echo "- $pattern"
7
+ find . -name "$pattern" -exec chmod -x {} \;
8
+ done
9
+ echo "Done."
10
+
data/bin/shell-for ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def quoted_text(line)
4
+ line.match(/["'].*["']/).to_s.gsub(/["']/, '')
5
+ end
6
+
7
+ def read_deploy_files
8
+ all_deploy_files = Dir["config/deploy/*.rb"]
9
+
10
+ deploy_file = all_deploy_files.find do |file|
11
+ file.match(/\/#{@stage}.rb$/)
12
+ end
13
+ raise "Unknown stage: #{@stage}" unless deploy_file
14
+
15
+ @specific = File.open(deploy_file).readlines
16
+ @for_all = File.open("config/deploy.rb").readlines
17
+ end
18
+
19
+ def build_command
20
+ path = quoted_text(@deploy_to) + "/current"
21
+
22
+ @command = "ssh #{quoted_text(@user)}@#{quoted_text(@server)}"
23
+ @command += %( -t "cd #{path} && bash --login") unless path.match /#\{/
24
+ end
25
+
26
+ begin
27
+ @stage = ARGV.shift
28
+
29
+ raise "Usage: shell_for DEPLOYMENT_STAGE" unless @stage
30
+ raise "Run me from inside a Rails project" unless File.exists?("config/deploy.rb")
31
+
32
+ read_deploy_files
33
+ @user = @specific.find{ |line| line =~ /^set :user, /} || @for_all.find{ |line| line =~ /^set :user, / }
34
+ @server = @specific.find{ |line| line =~ /^server / } || @for_all.find{ |line| line =~ /^server / }
35
+ @deploy_to = @specific.find{ |line| line =~ /^set :deploy_to, /} || @for_all.find{ |line| line =~ /^set :deploy_to, / }
36
+
37
+ build_command
38
+
39
+ exec @command
40
+
41
+ rescue Exception => e
42
+ $stderr.puts e.message
43
+ exit 1
44
+ end
data/geordi.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "geordi/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "geordi"
7
+ s.version = Geordi::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Henning Koch"]
10
+ s.email = ["henning.koch@makandra.de"]
11
+ s.homepage = "http://makandra.com"
12
+ s.summary = 'Collection of command line tools used in our daily work with Ruby, Rails and Linux.'
13
+ s.description = 'Collection of command line tools used in our daily work with Ruby, Rails and Linux.'
14
+
15
+ s.rubyforge_project = "geordi"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geordi
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Henning Koch
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-26 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Collection of command line tools used in our daily work with Ruby, Rails and Linux.
23
+ email:
24
+ - henning.koch@makandra.de
25
+ executables:
26
+ - apache-site
27
+ - b
28
+ - dumple
29
+ - install-gems-remotely
30
+ - power-deploy
31
+ - power-rake
32
+ - remotify-local-branch
33
+ - remove-execute-flags
34
+ - shell-for
35
+ extensions: []
36
+
37
+ extra_rdoc_files: []
38
+
39
+ files:
40
+ - .gitignore
41
+ - Gemfile
42
+ - README.md
43
+ - Rakefile
44
+ - bin/apache-site
45
+ - bin/b
46
+ - bin/dumple
47
+ - bin/install-gems-remotely
48
+ - bin/power-deploy
49
+ - bin/power-rake
50
+ - bin/remotify-local-branch
51
+ - bin/remove-execute-flags
52
+ - bin/shell-for
53
+ - geordi.gemspec
54
+ has_rdoc: true
55
+ homepage: http://makandra.com
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project: geordi
84
+ rubygems_version: 1.3.7
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Collection of command line tools used in our daily work with Ruby, Rails and Linux.
88
+ test_files: []
89
+