Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net/ssh'
- require 'fileutils'
- class MinhaGem
- VERSION = '0.0.1'
- def initialize(server, user, pass)
- @server = server
- @user = user
- @pass = pass
- @name = "testegem"
- end
- def remote
- @shell = start(@server, @user, @pass)
- create_repo(@name)
- initialize_local_repo(@name)
- add_remote(@server, @user, @name)
- clone(@name)
- write_hook(@name)
- end
- def start(server, user, pass)
- @session = Net::SSH.start(server, user, :password => pass)
- end
- def close
- @session.close
- end
- def create_repo(name)
- puts name
- puts "Criando Repositorio Git no servidor"
- log = @shell.exec!("cd repos/ && mkdir #{name}.git && cd #{name}.git && git init --bare")
- puts log
- end
- def initialize_local_repo(name)
- puts "Initializando Repositorio Git local"
- unless dirExists?(".git/")
- execute("git init && git add . && git commit -m 'Initial Commit' ")
- else
- puts "Git ja esta inicializado"
- end
- end
- def execute(command)
- Kernel.system command
- end
- def dirExists?(dir)
- File.directory? dir
- end
- def add_remote(server, user, name)
- execute("git remote add origin #{user}@#{server}:~/repos/#{name}.git")
- end
- def clone(name)
- @shell.exec!("git clone ~/repos/#{name}.git ~/rails_app/#{name}")
- end
- def write_hook(name)
- @shell.exec!("cd ~/repos/#{name}.git")
- @shell.exec!("touch ~/repos/#{name}.git/hooks/post-receive")
- @shell.exec!("chmod +x hooks/post-receive")
- read_hook_sample(name)
- end
- def read_hook_sample(name)
- puts "Escrevendo Hook File"
- path = "~/repos/#{name}.git/hooks/post-receive"
- File.open("lib/hook.txt", "r") do |fline|
- while(line = fline.gets)
- @shell.exec!("echo '#{line}' >> #{path}")
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment