Skip to content

Instantly share code, notes, and snippets.

@adamnew123456
Last active September 13, 2016 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamnew123456/837984f50f787c89b2070226d237f96a to your computer and use it in GitHub Desktop.
Save adamnew123456/837984f50f787c89b2070226d237f96a to your computer and use it in GitHub Desktop.
Git Deployment
#!/bin/bash
help() {
echo "`basename $0` [-h] -d <DEPLOY-DIR> -r <REPO-DIR>
Does the necessary work to use a Git repository for deployment.
This creates two directories - DEPLOY-DIR and REPO-DIR. REPO-DIR is
a bare repository that you can push to and pull from like any repository,
while DEPLOY-DIR contains the contents of the 'master' branch. Git hooks
are used to keep DEPLOY-DIR up to date with REPO-DIR."
exit 0
}
usage() {
echo "`basename $0` [-h] -d <DEPLOY-DIR> -r <REPO-DIR>"
exit 1
}
REPO_DIR=
DEPLOY_DIR=
while getopts "hd:r:" opt; do
case $opt in
r) REPO_DIR="$OPTARG" ;;
d) DEPLOY_DIR="$OPTARG" ;;
h) help ;;
\?) usage ;;
esac
done
[ -z "$REPO_DIR" ] && usage
[ -z "$DEPLOY_DIR" ] && usage
REPO_DIR="`readlink -f "$REPO_DIR"`"
DEPLOY_DIR="`readlink -f "$DEPLOY_DIR"`"
SCRIPT="#!/bin/sh
git --work-tree='$DEPLOY_DIR' --git-dir='$REPO_DIR' checkout -f
"
mkdir "$REPO_DIR"
mkdir "$DEPLOY_DIR"
cd "$REPO_DIR"
git init --bare
cd hooks
rm *.sample
echo "$SCRIPT" > post-receive
chmod +x post-receive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment