Skip to content

Instantly share code, notes, and snippets.

@pierew
Last active August 29, 2015 14:00
Show Gist options
  • Save pierew/11394748 to your computer and use it in GitHub Desktop.
Save pierew/11394748 to your computer and use it in GitHub Desktop.
That is a Gitolite post-receive Hook Script that can Optional upload the Repository to an FTP Server or copy it to an Directory, more Features are following.
#!/bin/bash
# General Settings
REPONAME='example.git'
BRANCH='public' # Branch you want to be public
MODE='FTP' # 'FTP' = Upload to FTP Server / 'DIRECTORY' = Copy to Directory.
# DIRECTORY MODE SECTION
DIRECTORY='/var/www/'
EXCLUDELIST_DIR='' # Do '--exclude=Folder1 --exlude=Folder2'
# FTP MODE SECTION
HOST='example.com'
USER='example'
PASSWD='example'
EXCLUDELIST_FTP='' # Do '--exclude Folder 1/ --exlude Folder2/'
echo Check Environment and load up Prerequierements
if [ ! -d "~/.tmp_gitolite"]
then
mkdir ~/.tmp_gitolite
cd ~/.tmp_gitolite
git clone -b $BRANCH ~/repositories/$REPONAME
fi
echo Get old Commit Hash
cd ~/.tmp_gitolite/$REPONAME/.git
OLD=$(git rev-parse HEAD)
echo $OLD
echo Get new Commit Hash
cd ~/repositories/$REPONAME
NEW=$(git rev-parse $BRANCH)
echo $NEW
echo Compare Commit Hashes
if [ $OLD != $NEW ]
then
echo Found new Version
cd ~/.tmp_gitolite/$REPONAME
echo Get latest files from Git Repo Public Branch
git checkout $BRANCH
git pull ~/repositories/$REPONAME
if [ $MODE == "FTP"]
then
echo Connecting to FTP Site and Transmitting....
cd ~/.tmp_gitolite/$REPONAME
lftp -u $USER,$PASSWD $HOST << EOF
mirror $EXCLUDELIST -Renvp
chmod -r 777 /
quit 0
EOF
echo Finished transmitting
elif [ $MODE = "DIRECTORY"]
then
echo Copying to specified Directory
rsync -avP ~/.tmp_gitolite/$REPONAME/* $DIRECTORY $EXCLUDELIST
fi
else
echo No changes
echo quit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment