|
#!/bin/bash |
|
|
|
set -e |
|
|
|
echo "*** Starting deploy..." |
|
|
|
CWD=$(pwd) |
|
CONFIG_FILE=$1 |
|
if [ -z $CONFIG_FILE ] |
|
then |
|
echo "*** Config file not found" |
|
exit 1 |
|
fi |
|
|
|
echo "*** Reading config file" |
|
CONFIG=$(cat ${CONFIG_FILE}) |
|
echo $CONFIG |
|
if [ -z "${CONFIG}" ] |
|
then |
|
echo "*** Deploy config was empty" |
|
echo "*** Aborting deploy..." |
|
exit 1 |
|
fi |
|
|
|
echo "*** Defining cfg function" |
|
function cfg () { |
|
local config=$1 |
|
local key=$2 |
|
local regex="\"${key}\":\"([^\"]*)\"" |
|
[[ ${config} =~ $regex ]] |
|
echo ${BASH_REMATCH[1]} |
|
} |
|
|
|
echo "*** Defining current_version function" |
|
function current_version () { |
|
local dir_version_regex="$1([0-9]+)" |
|
local version=0 |
|
for f in */ |
|
do |
|
[[ $f =~ $dir_version_regex ]] |
|
if [[ ${BASH_REMATCH[1]} ]] && (( ${BASH_REMATCH[1]} > $version )) |
|
then |
|
version=${BASH_REMATCH[1]} |
|
fi |
|
done |
|
echo $version |
|
} |
|
|
|
echo "*** Loading configs" |
|
repo=$(cfg "${CONFIG}" "repo") |
|
deploy_dir_prefix=$(cfg "${CONFIG}" "deploy_dir_prefix") |
|
deploy_post_hook=$(cfg "${CONFIG}" "deploy_post_hook") |
|
echo "repo = ${repo}" |
|
echo "deploy dir prefix = ${deploy_dir_prefix}" |
|
echo "post hook = ${deploy_post_hook}" |
|
|
|
old_version=$(current_version $deploy_dir_prefix) |
|
let new_version=$old_version+1 |
|
target_deploy_dir="${CWD}/${deploy_dir_prefix}${new_version}" |
|
|
|
echo "*** Upgrading version from ${old_version} => ${new_version}" |
|
|
|
echo "*** Deploying to ${target_deploy_dir}" |
|
svn export "${repo}/trunk" "${target_deploy_dir}" |
|
if [ ! -d $target_deploy_dir ] |
|
then |
|
echo "*** Target deploy dir not found (${target_deploy_dir})" |
|
echo "*** Aborting deploy..." |
|
exit 1 |
|
fi |
|
|
|
if [ -x $deploy_post_hook ] |
|
then |
|
echo "*** Executing deploy post-hook (${deploy_post_hook})" |
|
sh $deploy_post_hook $target_deploy_dir |
|
else |
|
echo "*** Deploy post-hook (${deploy_post_hook}) does not have exec permission" |
|
fi |
|
|
|
echo "*** Deploy post-hook finished" |
|
|
|
echo "*** Completed deploy" |