#!/bin/bash

function Make_Directory ()
    {
    local -r in_Dir=${1};

    if [[ ! -d ${in_Dir} ]] ; then
        mkdir --parents ${in_Dir};
    fi;

    return;
    }

function Remove_CVS_Backup_Files ()
    {
    local -r in_Dir=${1};

    echo "========== Delete CVS Backup Files =================================="

    if [[ -d ${in_Dir} ]] ; then
        pushd ${in_Dir};
            find . -iname ".#*" -exec rm --verbose --force '{}' ';';
        popd
    fi;

    return;
    }

function Update_From_CVS ()
    {
    local -r in_Base_Dir=${1};
    local -r in_Module=${2};
    local -r in_Branch=${3};
    
    echo "========== Update from CVS repository ================================"

    if [[ -d ${in_Base_Dir}/${in_Module} ]] ; then
        pushd ${in_Base_Dir}/${in_Module};
            cvs -qz9 update -C -P -d ${in_Branch}                               \
            2>&1 |  tee ../update.${in_Branch}.log
        popd;
    else
        Make_Directory ${in_Base_Dir};

        pushd ${in_Base_Dir};
            cvs -qz9 checkout -P ${in_Branch} ${in_Module}                      \
            2>&1 |  tee checkout.${in_Branch}.log
        popd;
    fi

    return;
    }

function Commit_To_CVS ()
    {
    local -r in_Base_Dir=${1};
    local -r in_Module=${2};
    local -r in_Branch=${3};
    
    echo "========== Update from CVS repository ================================"

    if [[ -d ${in_Base_Dir}/${in_Module} ]] ; then
        pushd ${in_Base_Dir}/${in_Module};
            cvs -qz9 commit -m"automated commit"                                \
            2>&1 |  tee ../update.${in_Branch}.log
        popd;
    fi

    return;
    }

function Standart_Build ()
    {
    local -r in_Source_Dir=${1};
    local -r in_Dest_Dir=${2};
    local -r in_Configure=${@};

    pushd ${in_Source_Dir};
        if [[ ${in_Configure} == *conf* ]] ; then
            echo "========== Configure ${in_Source_Dir} ========================";

            ./configure --prefix=${in_Dest_Dir};
        fi;

        echo "========== Make and Install ${in_Source_Dir} =================";
        
        make;
        make install;
    popd;

    return;
    }

# vim: textwidth=0 nowrap tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab
# vim: filetype=sh encoding=utf-8 fileformat=unix
