Redge's Trek through the Web

Ravings and bright ideas by a Dutch student of Artificial Intelligence, religion and faith, computers and life.

Saturday, May 9, 2009

GIT upload script

Since I'm on a shared host (Hostmonster), I don't exactly have full freedom. Not being able to serve a GIT repo is one consequence. Fortunately, GIT is resourcefull enough that even without the GIT daemon running, uploading the files is enough for people to pull them from the server, or explore them through git-web.

So for people in a similar situation, here is a script that will upload your GIT repo's to your shared host:

#!/bin/bash

# A script to create a bare clone of a GIT repo and upload it to a server for
# archiving or public distribution.
#
# Author: Romke van der Meulen
# License: CreativeCommons Attribution Non-Commercial 3.0

# Check arguments
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo "Usage: git-upload (SourceDir) [TargetName]"
exit 1
fi

# Define remote directory
HOST=user@host.com
REMOTEDIR=public_html/repo

# If no second argument given, the name of the uploaded repo is
# equal to the repo being copied
if [ $# -gt 1 ]; then
NAME=$2
else
NAME=$1
fi

# If the temp files already exist, remove them
rm -rf $NAME.tar.gz $NAME.git

# Begin procedure

# Create the bare clone
echo "Creating bare clone" && \
echo -n " " && \
git clone --bare $1 $NAME.git && \
# Tar and zip
echo "Zipping" && \
tar -czf $NAME.git.tar.gz $NAME.git && \
# Upload to target dir
echo "Uploading" && \
scp $NAME.git.tar.gz $HOST:$REMOTEDIR/ && \
# Unzip at target dir
echo "Unzipping" && \
ssh $HOST tar -xzf $REMOTEDIR/$NAME.git.tar.gz -C $REMOTEDIR/ && \
# Remove generated files
echo "Cleaning up" && \
ssh $HOST rm -f $REMOTEDIR/$NAME.git.tar.gz && \
rm -rf $NAME.git.tar.gz $NAME.git && \
# Done
echo "Succesfull" && exit 0

# Error encountered
echo "Unsuccesfull" && exit 2


Install it somewhere where you can get at it and change the remote config to reflect your own. Also, unless you like giving your password three times, I suggest you also upload your public key for automatic login. Once you've done this, all you need type is:

git-upload (repo dir) [remote repo name (optional)]


and you're all set.

Any questions, you know where to find me.

Labels: , ,

1 Comments:

Blogger Redge said...

One problem: the project description is lost after each upload. I'll see if I can fix that.

00:13  

Post a Comment

<< Home