deploy.sh 1.8 KB
#!/bin/bash

time=$(date +%Y%m%d_%H%m%s)
project_name="ability"
##部署脚本/文件路径
deploy_shell_path="/home/tiptok/test"
##部署路径
project_root_path="/home/tiptok/www"
project_path="${project_root_path}/${project_name}"
##备份路径
project_bak_path="/home/tiptok/www/bin_bak"

projcet_bak_file="${project_bak_path}/${time}_${project_name}.tar"

## 看压缩文件的格式 tar / zip
#project_gzip_file="${deploy_shell_path}/${project_name}.tar"
project_gzip_file="${deploy_shell_path}/${project_name}.zip"

conpress_type="${project_gzip_file##*.}"

echo "------begin deploy-------"
echo "ProjectName: ${project_name}"
echo "ProjectPath: ${project_path}"
echo "ProjectBakFile : ${projcet_bak_file}"
echo "ProjectGzipFile : ${project_gzip_file}"
echo "ConpressType : ${conpress_type}"


if [ ! -d ${project_bak_path} ];then
    mkdir -p ${project_bak_path}
    echo "mkdir ${project_bak_path}"
fi

if [ ! -d ${project_path} ];then
    mkdir -p ${project_path}
    echo "mkdir ${project_path}"
else
    echo "backup : ${projcet_bak_file}"
    cd $project_path && tar -zcf ${projcet_bak_file} *  ||(echo "backup failed"; exit 1)
    rm -fr "${project_path}/" *
fi

echo "------begin tar-------"
if [ ! -e ${project_path} ];then
    mkdir -p ${project_path}
    echo "mkdir ${project_path}"
fi

if [ -f ${project_gzip_file} ];then
    if [ ${conpress_type} == "tar" ];then
        tar -xzf  ${project_gzip_file} -C "${project_root_path}/${project_name}"||(echo "tar -x failed"; exit 1)
    elif [ ${conpress_type} == "zip" ];then
        unzip -o  ${project_gzip_file} -d "${project_root_path}/${project_name}"||(echo "tar -x failed"; exit 1)
    fi
    rm -fr ${project_gzip_file}
else
    echo "project_gzip_file not exists! please upload zip file ..."
    exit 0
fi

echo "------begin start-------"
cd ${project_path} && ./start.sh ${project_name}