Created
June 3, 2009 09:01
-
-
Save georgboe/122894 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # This script will create a bare git repository on a remote machine. | |
| require 'rubygems' | |
| require 'net/ssh' | |
| module Linuxclistatus | |
| require 'highline/import' | |
| def print_task(task) | |
| len = 80 - (task.length + 11) | |
| print("#{task} #{" " * len}") | |
| STDOUT.flush | |
| end | |
| def print_status(status) | |
| if status | |
| say("[ <%= color('OK'.center(6), :green) %> ]") | |
| else | |
| say("[ <%= color('FAILED', :red) %> ]") | |
| end | |
| end | |
| end | |
| include Linuxclistatus | |
| SERVER = 'IP_ADDRESS_TO_SERVER' | |
| USER = 'SSH_USER' | |
| GIT_FOLDER = '/git/' | |
| unless ARGV.length == 1 | |
| puts "usage: remgit <name of repository>" | |
| exit | |
| end | |
| project = ARGV[0].downcase | |
| repo = project + ".git" | |
| begin | |
| print_task("Connecting to host...") | |
| Net::SSH.start(SERVER, USER) do |ssh| | |
| print_status true | |
| print_task("Creating git repository...") | |
| ssh.exec "cd #{GIT_FOLDER} && mkdir #{repo} && cd #{repo} && git init --bare" do |ch, stream, data| | |
| if stream == :stderr | |
| raise Exception, data | |
| else | |
| print_status true | |
| end | |
| end | |
| end | |
| puts <<"EOF" | |
| Next steps | |
| ========== | |
| mkdir #{project} | |
| cd #{project} | |
| git init | |
| touch README.markdown | |
| git add README.markdown | |
| git commit -m 'Initial Import' | |
| git remote add origin ssh://#{USER}@#{SERVER}#{GIT_FOLDER}#{repo} | |
| git push origin master | |
| Existing Git Repo? | |
| ================== | |
| cd #{project} | |
| git remote add origin ssh://#{USER}@#{SERVER}#{GIT_FOLDER}#{repo} | |
| git push origin master | |
| EOF | |
| rescue Errno::ECONNREFUSED => e | |
| print_status false | |
| puts "Connection was refused by the server." | |
| rescue Exception => e | |
| print_status false | |
| puts e | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment