Class: GitServer::Setup
- Inherits:
-
Object
- Object
- GitServer::Setup
- Defined in:
- lib/gitserversetup.rb
Instance Method Summary collapse
-
#initialize(server, ssh_key, user) ⇒ Setup
constructor
A new instance of Setup.
- #run ⇒ Object
Constructor Details
#initialize(server, ssh_key, user) ⇒ Setup
Returns a new instance of Setup.
3 4 5 6 7 8 |
# File 'lib/gitserversetup.rb', line 3 def initialize(server, ssh_key, user) ssh_key = '~/.ssh/id_rsa.pub' if ssh_key.to_s == '' @key = ssh_key @user = user.to_s == '' ? 'root' : user @server = server end |
Instance Method Details
#run ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gitserversetup.rb', line 10 def run cputs :green, "\nInstalling and configuring GIT\n" sshrun 'apt-get update' sshrun 'apt-get install git -y' sshrun 'useradd -m -s /usr/bin/git-shell git' sshrun 'mkdir -p /home/git/repo/hooks' sshrun 'mkdir -p /home/git/.ssh' sshrun 'mkdir -p /home/git/repo' sshrun 'chown -R git:git /home/git/*' sshrun '"cd /home/git/repo && git init --bare"' sshrun "touch /home/git/.ssh/authorized_keys" cputs :green, 'add git to sudoers' sshrun 'usermod -aG sudo git' scp File.join(__dir__, "git-sudoer"), "/etc/sudoers.d/git-sudoer" sshrun "chmod 0440 /etc/sudoers.d/git-sudoer" cputs :green, "\nInstalling post-receive script\n" scp File.join(__dir__, "post-receive"), "/home/git/repo/hooks/post-receive" sshrun 'chmod +x /home/git/repo/hooks/post-receive' cputs :green, "\nAllowing this machine to push\n" scp '~/.ssh/id_rsa.pub', '/home/git/.ssh/authorized_keys' sshrun "chown git:git /home/git/.ssh/authorized_keys" cputs :green, "\n=== GitServer setup complete ===\n" cputs :white, "That's it. Now you can setup your git repo to push to this server by running:\n\n" cputs :red, "$ echo 'echo \"Hi from server\"' > deploy.sh" cputs :red, "$ git add deploy.sh && git commit -am 'new deploy'" cputs :red, "$ git remote add prod git@#{@server}:~/repo" cputs :red, "$ git push prod\n" end |