about summary refs log tree commit diff stats
path: root/tools/gitolite.html
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gitolite.html')
-rw-r--r--tools/gitolite.html334
1 files changed, 28 insertions, 306 deletions
diff --git a/tools/gitolite.html b/tools/gitolite.html
index fd9ad8c..ace87d9 100644
--- a/tools/gitolite.html
+++ b/tools/gitolite.html
@@ -236,9 +236,30 @@
         <h2 id="hooks">4. Gitolite Hooks</h2>
 
         <p>This document creates three scripts, one is run when gitolite receives
-        push to a project with hook active, second script is run under root
+        push to a project with hook active - deploy-web, second script is run under root
         user to allow operations where gitolite user have no rights, third one
-        is project specific.</p>
+        is project specific - deploy.sh. File hooks.sh are support functions for deploy-web hook.</p>
+
+        <pre>
+        cron ---> deploy.sh
+             (extracts/process tar)
+                      |
+                calls defined script
+                to extract this case
+                deploy-web.sh
+
+        gitolite-admin/local/hooks/repo-specific/deploy-web
+               (ends in remote rep/hooks/post-receive.h00-deploy-web)
+                        |
+                      sources
+                        |
+        /srv/gitolite/deploy/hook.sh
+                        |
+                creates package and
+                set deploy script to
+                deploy-web.sh
+        </pre>
+
 
         <p>This example try to have a separate creation of a package and its deployment,
         in case deploy script is not on the same machine other method can be used to send
@@ -255,6 +276,8 @@
         <a href="conf/srv/gitolite/deploy.sh">/srv/gitolite/deploy/deploy.sh</a>,
         deploy in this example is called called by cron.</p>
 
+        <p>Note on OpenBSD all scripts must be changed to use other than bash, ksh.</p>
+
         <h3 id="gtl-activate">4.1. Activate Hooks</h3>
 
         <p>Example from
@@ -331,133 +354,10 @@
         <h4>4.3.1. Hook Script</h4>
 
         <p>Create
-        <a href="conf/srv/gitolite/deploy-web-doc">gitolite-admin/local/hooks/repo-specific/deploy-web-doc</a>;</p>
-
-        <pre>
-        #!/bin/bash
-        ######################################################################
-        #
-        # Put this file in your gitolite-admin;
-        # ~/gitolite-admin/local/hooks/repo-specific/deploy-web-doc
-        #
-        # set host to empty to create package for each push
-        # or set remote host to create package based on last deployed push
-        # host="https://doc.localhost"
-        host=""
-        # set name of witch branch should be deployed
-        branch_to_deploy="deploy_branch"
-
-        ######################################################################
-
-
-        url="$host/.last_deploy"
-        source /srv/gitolite/deploy/hook.sh
-        read oldrev newrev refname
-        push_branch=$(git rev-parse --symbolic --abbrev-ref $refname)
-
-        #SCRIPT_VARS=$(set)
-        #echo "project: $PROJECT"
-        #echo "local dir: $PWD" &gt; /srv/gitolite/deploy/${GL_REPO}
-        #echo "${SCRIPT_VARS}" &gt;&gt; /srv/gitolite/deploy/${GL_REPO}
-
-        if [[ $push_branch = $branch_to_deploy  ]]; then
-
-            # if host empty we make local tracking
-            if [[ $host = "" ]]; then
-                if [[ $(is_initial ${GL_REPO}) = "true" ]]; then
-                    oldrev="initial"
-                fi
-            else
-                if [[ ! $(valid_url $url) = "true" ]]; then
-                    echo "Deploy: set $url on remote to start creating packages"
-                    exit 1
-                fi
-                oldrev=$(get_remote_rev $url)
-            fi
-            create_package ${GL_REPO} ${PWD} ${oldrev} ${newrev} "deploy-web.sh"
-        fi
-        </pre>
+        <a href="conf/srv/gitolite/deploy-web">gitolite-admin/local/hooks/repo-specific/deploy-web</a>.</p>
 
         <p>Create
-        <a href="conf/srv/gitolite/deploy-web.sh">/srv/gitolite/deploy/scripts/deploy-web.sh</a>;</p>
-
-        <pre>
-        #!/bin/bash
-
-        pkg_path=$1
-
-        www_root="/srv/www"
-        www_user="nginx"
-        www_group="www"
-
-        pkg_file="${pkg_path}/project"
-        pkg_rm="${pkg_path}/deleted"
-        pkg_files="${pkg_path}/files"
-
-        if [ ! -f ${pkg_file} ]; then
-            echo "Deploy web: invalid pkg_file ${pkg_file}"
-            exit 1
-        fi
-
-        pkg_name=$(head -1 ${pkg_file})
-        pkg_new=$(head -3 ${pkg_file} | tail -1)
-        pkg_new7=$(echo ${pkg_new} | cut -c1-7)
-
-        pkg_www="${www_root}/${pkg_name}"
-        pkg_back="${pkg_www}/backup_deploy"
-        pkg_last="${pkg_www}/.last_deploy"
-
-        if [ ! -d ${pkg_www} ]; then
-            echo "Deploy web: invalid pkg_www ${pkg_www}"
-            exit 1
-        fi
-
-        # first backup all data
-        if [[ ! $(ls ${pkg_www} | grep -v "backup_deploy") = "" ]]; then
-            if [ ! -d ${pkg_back} ]; then
-                sudo -u ${www_user} mkdir -p ${pkg_back}
-            fi
-            backup_file="${pkg_back}/${pkg_name}-$(date '+%Y-%j-%H-%M-%S').tar.gz"
-            echo "Deploy web: making backup ${backup_file}"
-            sudo -u ${www_user} tar --exclude ${pkg_back} --xattrs -zcpf ${backup_file} ${pkg_www}
-        fi
-
-        # remove files and directories that have been deleted
-        if [ -f ${pkg_rm} ]; then
-
-            echo "Deploy web: files to delete:"
-            # first we delete files
-            while read deleted_file; do
-                deleted_file="${pkg_www}/${deleted_file}"
-                if [ -f ${deleted_file} ]; then
-                    echo "file      rm ${deleted_file}"
-                    rm ${deleted_file}
-                fi
-            done &lt;${pkg_rm}
-
-            # delete directories
-            while read deleted_file; do
-                deleted_file="${pkg_www}/${deleted_file}"
-                if [ -d ${deleted_file} ]; then
-                    echo "file      rm ${deleted_file}"
-                    rm ${deleted_file}
-                fi
-            done &lt;${pkg_rm}
-
-        fi
-
-        # copy new files to destination
-        if [ -d ${pkg_files} ]; then
-            echo "Deploy web: cp from ${pkg_files} to ${pkg_www}"
-            sudo -u ${www_user} cp -r ${pkg_files}/* ${pkg_www}
-        fi
-
-        echo ${pkg_new} > ${pkg_last}
-        echo "Deploy: scripts/deployweb.sh ${pkg_name} ${pkg_new7} deployed."
-
-        #remove temporary package
-        rm -r ${pkg_path}
-        </pre>
+        <a href="conf/srv/gitolite/deploy-web.sh">/srv/gitolite/deploy/scripts/deploy-web.sh</a>.</p>
 
         <p>Activate this hook, the idea is to start with this one as a template working
         and then implement the final one. Edit gitolite admin configuration file and
@@ -486,185 +386,7 @@
 
         <h4>4.3.2. Deploy Script</h4>
 
-        <p>Create <a href="conf/srv/gitolite/deploy.sh">/srv/gitolite/deploy/scripts/deploy.sh</a>;</p>
-
-        <pre>
-        #!/bin/bash
-
-        # origin package directory
-        packages_dir="/srv/gitolite/deploy/packages"
-        # temporary work directory
-        deploy_dir="/srv/deploy_dir"
-        # scripts to deploy packages
-        deploy_scripts="/srv/gitolite/deploy/scripts"
-
-        function get_script(){
-            # receives package path return script to call
-            local pkg_path=$1
-            echo $(head -2 ${pkg_path}/project | tail -1)
-        }
-
-        function get_new(){
-            # receives package path return commit hash (new)
-            local pkg_path=$1
-            echo $(head -3 ${pkg_path}/project | tail -1)
-        }
-
-        function get_dep(){
-            # receives package path return previews commit hash (old)
-            local pkg_path=$1
-
-            new=$(head -3 ${pkg_path}/project | tail -1)
-            old=$(head -4 ${pkg_path}/project | tail -1)
-
-            if [[ ! ${new} = ${old} ]]; then
-                echo ${old} | cut -c1-7
-            fi
-        }
-
-        function project_extract(){
-
-            # project directory containing extracted packages
-            local prj_dir=$1
-
-            # final extracted package
-            local prj_pkg="${prj_dir}/package"
-
-            # temporary vars for swapping/iterating pkg_news
-            local pkg_new=""
-            local pkg_old=""
-            local pkg_dir=""
-            local pkg_temp=""
-            local pkg_next=1
-            local pkg_del=""
-            local x=0
-            local y=0
-
-            # array with all the news hashes
-            local pkg_news=($(ls ${prj_dir}))
-
-            # total new packages
-            local total=${#pkg_news[@]}
-
-            echo "Deploy: $(basename ${prj_dir}) extracting packages ${pkg_news[*]}"
-
-            # find first package
-            for pkg_new in ${pkg_news[@]}
-            do
-                # get package dependency
-                pkg_dir="${prj_dir}/${pkg_new}"
-                pkg_old=$(get_dep ${pkg_dir})
-                if [[ ! " ${pkg_news[@]} " =~ " ${pkg_old} " ]]; then
-                    # pkg_news don't contain package
-                    # we found initial package
-                    pkg_temp=${pkg_news[0]}
-                    pkg_news[0]=${pkg_new}
-                    pkg_news[${x}]=${pkg_temp}
-                    break
-                fi
-                x=$((${x}+1))
-            done
-
-            # Order packages by dependency start with first package
-            for (( y=0; y&lt;${total}; y++ ))
-            do
-                pkg_next=$(($y+1))
-                if [[ ${pkg_next} = ${total} ]]; then
-                    ## we are in the last one
-                    break
-                fi
-
-                pkg_new=${pkg_news[$y]}
-                for (( x=pkg_next; x&lt;${total}; x++ ))
-                do
-                    pkg_dir="${prj_dir}/${pkg_news[${x}]}"
-                    pkg_old=$(get_dep ${pkg_dir})
-                    # is dependent on current
-                    if [[ ${pkg_old} = ${pkg_new} ]]; then
-                        pkg_temp=${pkg_news[${pkg_next}]}
-                        pkg_news[${pkg_next}]=${pkg_news[${x}]}
-                        pkg_news[${x}]=${pkg_temp}
-                        # we can break and pass next one
-                        break
-                    fi
-                done
-            done
-
-            # create project final package directory
-            mkdir -p ${prj_pkg}/files
-
-            # copy project information of last commit
-            cp ${prj_dir}/${pkg_news[$((${total}-1))]}/project ${prj_pkg}
-
-            # now that packages are ordered we can start creating files
-            for pkg_new in ${pkg_news[@]}
-            do
-                pkg_dir=${prj_dir}/${pkg_new}
-                tar xf ${pkg_dir}/files.tar.xz \
-                    --directory ${prj_pkg}/files
-
-                # if deleted files exists
-                if [ -f "${pkg_dir}/deleted" ]; then
-                    # first collect all files/directories don't exist
-                    while read pkg_del; do
-                        # if file don't exist add entry to project deleted file
-                        pkg_temp="${prj_pkg}/files/${pkg_del}"
-                        if [ ! -f ${pkg_temp} ]; then
-                            if [ ! -d ${pkg_temp} ]; then
-                                # is not a file or directory from previous packages
-                                echo ${pkg_del} &gt;&gt; ${prj_pkg}/deleted
-                            fi
-                        fi
-                    done &lt;${prj_dir}/${pkg_new}/deleted
-
-                    # delete directories and files
-                    while read pkg_del; do
-                        pkg_temp="${prj_pkg}/files/${pkg_del}"
-                        if [ -d ${pkg_temp} ]; then
-                            rm -r ${pkg_temp}
-                        elif [ -f ${pkg_temp} ]; then
-                            rm ${pkg_temp}
-                        fi
-                    done &lt;${prj_dir}/${pkg_new}/deleted
-                fi
-
-                #remove temporary directory
-                rm -r ${prj_dir}/${pkg_new}
-            done
-
-            # call project deploy script
-            call_script=${deploy_scripts}/$(get_script $prj_pkg)
-            echo "Deploy: calling deploy script: ${call_script}"
-            /bin/bash ${call_script} ${prj_pkg}
-
-        }
-
-        if [[ ! $(ls ${deploy_dir}) = "" ]]; then
-            rm -r ${deploy_dir}/*
-        fi
-
-        # first extract all packages from origin directory
-        for pkg_path in `find ${packages_dir} -type f -name "*.tar.gz"`
-        do
-            if [ -f ${pkg_path} ]; then
-                pkg_name=$(basename ${pkg_path})
-                pkg_proj=$(echo ${pkg_name} | cut -d "_" -f 1)
-                pkg_new7=$(echo ${pkg_name} | tail -c -15 | cut -c -7)
-                pkg_temp=${deploy_dir}/${pkg_proj}/${pkg_new7}
-                mkdir -p ${pkg_temp}
-                tar xf ${pkg_path} --directory ${pkg_temp}
-                rm ${pkg_path}
-            fi
-        done
-
-        # loop for all projects and deploy them
-        for prj_dir in `find ${deploy_dir} -maxdepth 1 -mindepth 1 -type d`
-        do
-            # order index of hashes based on old commit
-            echo "prj_dir $prj_dir"
-            project_extract ${prj_dir}
-        done
-        </pre>
+        <p>Create <a href="conf/srv/gitolite/deploy.sh">/srv/gitolite/deploy/scripts/deploy.sh</a>.</p>
 
         <p>Give permissions to access files;</p>