Skip to content

Instantly share code, notes, and snippets.

@beddari
Created March 4, 2012 16:04
Show Gist options
  • Save beddari/1973665 to your computer and use it in GitHub Desktop.
Save beddari/1973665 to your computer and use it in GitHub Desktop.
#!/bin/bash
# post-receive gitolite hook to produce archives
# Debug mode
DEBUG=1
# Where to put archives
ARCHIVE_DIR=/srv/archives/
# When to allow archiving (regex)
ALLOW_ARCHIVE="^(drupal|moodle)"
#### NO CONFIG BELOW ####
# Check if this repo can be archived
if [[ ! "$GL_REPO" =~ $ALLOW_ARCHIVE ]] ; then
[[ $DEBUG ]] && echo "Archiving for this repository is disabled."
exit 0
fi
# Get repo name
ARCHIVE_DIR="${ARCHIVE_DIR}/${GL_REPO}"
while read rev1 rev2 ref ; do
if [[ ! "$ref" =~ ^refs/tags ]] ; then
[[ $DEBUG ]] && echo "Not a tag reference..."
continue
fi
# Get tag name
tag=${ref##*/}
# Check if tag contains alpha, beta, or release:
if [[ ! $tag =~ (alpha|beta|release) ]] ; then
[[ $DEBUG ]] && echo "Not alpha/beta/release"
continue
fi
# Ensure directory exists
mkdir -p ${ARCHIVE_DIR}
# Repo base name
REPO_BASE=${GL_REPO##*/}
# Make archive
[[ $DEBUG ]] && echo git archive --format=zip --prefix=${REPO_BASE}/ -o "${ARCHIVE_DIR}/$tag.zip" $ref
git archive --format=zip --prefix=${REPO_BASE}/ -o "${ARCHIVE_DIR}/$tag.zip" $ref
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment