Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 100 lines (69 sloc) 1.992 kb
1 2 3 4 5 6 7 8 9 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#!/bin/bash
# gitmaker 0.5 by Fabio FZero

# Halt on all errors
set -e

# Main vars
SSHDOMAIN="$1"
REPO="$2"


# Functions

function usage () {
cat << EOF

gitmaker - creates a git repository on a ssh host and clones it locally.

Usage:

$ gitmaker <ssh host> <repo>

Where:

<ssh host> is the remote ssh host in the user@host format. If you need to
supply additional parameters (e.g. port), enclose them all in quotes.

<repo> is the repository to be created.

NOTE: It's STRONGLY recommended that you setup key-based SSH login to
use git over SSH - unless you like to type your password a lot!

EOF
}


function test_params () {
  if [ "$SSHDOMAIN" == "" ] || [ "$REPO" == "" ]; then
usage
    exit 1
  fi
}


function test_remote_git () {
  echo -n ">>> Testing if git exists in the server... "
  if [ "$(ssh $SSHDOMAIN 'git --version &> /dev/null && echo OK')" == "OK" ]; then
echo "OK!"
  else
cat << EOF
FAIL!

You must install git on your server first. You seem to be out of luck,
since EVEN DREAMHOST has git installed. Unbelievable, eh?

If you have root access on the remote machine, just install it. If you don't,
you can still try to compile it with PREFIX=/home/(your user) and see if it
works.

EOF
    exit 1
  fi
}


# On to business

test_params
test_remote_git

echo ">>> Creating the remote repository..."
ssh $SSHDOMAIN "mkdir -p ~/git/$REPO.git && cd ~/git/$REPO.git && git --bare init"
echo ">>> Creating the local clone and pushing the first commit..."
mkdir $REPO
cd $REPO
git init
git remote add origin ssh://$SSHDOMAIN/~/git/$REPO.git
touch .gitignore
git add .
git commit -m "Created new repo: $REPO"
git push origin master
cat << EOF >>.git/config
[branch "master"]
remote = origin
merge = refs/heads/master
EOF

cat << EOF

----------

Your new git repository '$REPO' is ready and initialized at
ssh://$SSHDOMAIN/~/git/$REPO.git

To clone it from another location, use:
$ git clone ssh://$SSHDOMAIN/~/git/$REPO [local folder]

EOF

Something went wrong with that request. Please try again.