Subversion post-commit hook


#!/bin/sh

# Simple SHELL script untuk update web direktory di webserver setelah SVN Client Commit
# -------------------------------------------------------------------------
# Copyright (c) 2011 mustafa@intelix.co.id project <http://www.intelix.co.id/>
# -------------------------------------------------------------------------


PATH_REPOSITORY_PARENT="/development/csvn/data/repositories/" # default direktory on CollabNet Subversion
PATH_SCRIPT_AUTO_UPDATE="/development/csvn/autoupdate/"           #

if [ $# -ne 1 ];then
        echo "     Masukkan naame project sesuai dengan nama project di repository CollabNet Subversion"
        echo "     Nama project tidak boleh ada spasi "
        echo "     Format : svn_hooks [name_project]"
        echo "     Contoh : svn_hooks client_name"
        exit 1
fi

PROJECT_NAME="$1"
if [ ! -d "$PATH_REPOSITORY_PARENT${PROJECT_NAME}" ]; then
        echo "Repistory project ${PROJECT_NAME} tidak ditemukan di http://192.168.0.7:3343/csvn/"
        exit 1
fi

if [ ! -d "/var/www/html/$PROJECT_NAME" ]; then
        /bin/mkdir -p /var/www/html/${PROJECT_NAME}
        cd /var/www/html
        svn co http://192.168.0.7:18080/svn/${PROJECT_NAME} ${PROJECT_NAME}
        /bin/chown -R gmosking.apache /var/www/html/${PROJECT_NAME}

fi

/bin/sed "s/project_name/${PROJECT_NAME}/g" ${PATH_SCRIPT_AUTO_UPDATE}template_svn_update.tpl > ${PATH_SCRIPT_AUTO_UPDATE}post-commit-${PROJECT_NAME}.c

/usr/bin/gcc ${PATH_SCRIPT_AUTO_UPDATE}post-commit-${PROJECT_NAME}.c -o ${PATH_SCRIPT_AUTO_UPDATE}post-commit-${PROJECT_NAME}
/bin/chown gmosking.apache ${PATH_SCRIPT_AUTO_UPDATE}post-commit-${PROJECT_NAME}.c
/bin/chown gmosking.apache ${PATH_SCRIPT_AUTO_UPDATE}post-commit-${PROJECT_NAME}

echo "#!/bin/bash" > ${PATH_REPOSITORY_PARENT}${PROJECT_NAME}/hooks/post-commit
echo ${PATH_SCRIPT_AUTO_UPDATE}post-commit-${PROJECT_NAME} >> ${PATH_REPOSITORY_PARENT}${PROJECT_NAME}/hooks/post-commit

echo "${PATH_REPOSITORY_PARENT}${PROJECT_NAME}/hooks/post-commit"
/bin/chmod o+x ${PATH_REPOSITORY_PARENT}${PROJECT_NAME}/hooks/post-commit
/bin/chmod 755 ${PATH_REPOSITORY_PARENT}${PROJECT_NAME}/hooks/post-commit
/bin/chown gmosking.gmosking ${PATH_REPOSITORY_PARENT}${PROJECT_NAME}/hooks/post-commit

/etc/init.d/httpd reload

====================================================================================================================================

template_svn_update.tpl

#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
     execl("/usr/bin/svn", "svn", "update", "--username",
     "gmosking", "--password", "gmosking1234",
     "/var/www/html/project_name/",  (const char *) NULL);
     return(EXIT_FAILURE);
}

====================================================================================================================================
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

shisdew

Listens until think alike

moses.spaceku@yahoo.com / voip ipbx

Hosted PBX, IP-PBX SOHO/ CALL CENTER, VOICE GATEWAY, VOICE CARD, COST EFECTIVE SOLUTIONS (LCR), GSM/CDMA GATEWAY

%d bloggers like this: