【码】自动部署的Shell脚本
in 代码片段 with 0 comment

【码】自动部署的Shell脚本

in 代码片段 with 0 comment

代码来源:自己整理编写
说明:用于部署项目的,依赖GIT,重点在于权限。

#!/bin/bash
clear

RED_COLOR='\E[1;31m'
GREEN_COLOR='\E[1;32m'
YELOW_COLOR='\E[1;33m'
BLUE_COLOR='\E[1;34m'
PINK='\E[1;35m'
RES='\E[0m'

ScriptPath=`pwd`

printf "
#######################################################################
#                       Start Init YangShengGM                        #
#######################################################################
"

echo
read -p 'Please input the document root:( Default /opt/data/ )' DocumentRoot
[ -z "$DocumentRoot" ] && DocumentRoot=/opt/data/
echo
read -p 'Please input the game server folder name:( Default www )' ServerFolder
[ -z "$ServerFolder" ] && ServerFolder=www
echo
read -p 'Please input the game manage folder name:( Default gm )' GmFolder
[ -z "$GmFolder" ] && GmFolder=gm
echo
read -p 'Please input the XML folder name:( Default xml )' XMLFolder
[ -z "$XMLFolder" ] && XMLFolder=xml
echo
read -p 'Please input the web server user name:( Default nginx )' ServerUser
[ -z "$ServerUser" ] && ServerUser=nginx
echo
read -p 'Please input the web server user group:( Default nginx )' ServerGroup
[ -z "$ServerGroup" ] && ServerGroup=nginx
echo
if [ -e "$DocumentRoot$GmFolder" ]; then
    echo -e "${RED_COLOR}ERROR: The Game Manage Folder(${DocumentRoot}${GmFolder}) is exist.${RES}"
    exit
fi

if [ ! -e "$DocumentRoot$ServerFolder" ]; then
    echo -e "${RED_COLOR}ERROR: The Server Folder(${DocumentRoot}${ServerFolder}) is not exist.${RES}"
    exit
fi

if [ ! -e "${ScriptPath}/id_rsa" ]; then
    echo -e "${RED_COLOR}ERROR: The Server Folder(${DocumentRoot}${ServerFolder}) is not exist.${RES}"
    exit
else
    chmod 600 ${ScriptPath}/id_rsa
fi

if [ -e "$DocumentRoot$XMLFolder" ]; then
    echo -e "${RED_COLOR}ERROR: The XML Folder(${DocumentRoot}${XMLFolder}) is exist.${RES}"
    exit
fi

mkdir "$DocumentRoot$GmFolder"

while :
    do
        read -p 'Please input the Game Manage GIT repertory:' GMGitRepertory
        if [ ! -z "$GMGitRepertory" ]; then
            break
        else
            echo -e "${RED_COLOR}ERROR: The Game Manage GIT repertory Can not be empty.${RES}"
        fi
done

printf "
#######################################################################
#                     Getting Game Manage Code....                    #
#######################################################################
"
echo

GIT_SSH=${ScriptPath}/my_git_ssh_wrapper git clone ${GMGitRepertory} ${DocumentRoot}${GmFolder}/
gitStatus=$?
if [ ${gitStatus} -ne 0 ]; then
    echo -e "${RED_COLOR}ERROR: The Game Manage GIT repertory may be not true or authentication failure. CODE:${gitStatus}${RES}"
    exit
fi

chmod 755 ${DocumentRoot}${GmFolder}
chmod -R 644 ${DocumentRoot}${GmFolder}/
find ${DocumentRoot}${GmFolder}/ -type d -exec chmod 755 {} +
chown -R ${ServerUser}.${ServerGroup} ${DocumentRoot}${GmFolder}/Application/Runtime/
chown -R ${ServerUser}.${ServerGroup} ${DocumentRoot}${GmFolder}/Application/Common/Conf/
chown -R ${ServerUser}.${ServerGroup} ${DocumentRoot}${GmFolder}/Application/Home/GameConf/
chown -R ${ServerUser}.${ServerGroup} ${DocumentRoot}${GmFolder}/calamityGod/
chown -R ${ServerUser}.${ServerGroup} ${DocumentRoot}${GmFolder}/Application/Install/Data/

mkdir "$DocumentRoot$XMLFolder"
echo
while :
    do
        read -p 'Please input the XML GIT repertory:' XMLGitRepertory
        if [ ! -z "$XMLGitRepertory" ]; then
            break
        else
            echo -e "${RED_COLOR}ERROR: The XML GIT repertory Can not be empty.${RES}"
        fi
done

printf "
#######################################################################
#                        Init XML Repertory....                       #
#######################################################################
"
echo

GIT_SSH=${ScriptPath}/my_git_ssh_wrapper git clone ${XMLGitRepertory} ${DocumentRoot}${XMLFolder}/
gitStatus=$?
if [ ${gitStatus} -ne 0 ]; then
    echo -e "${RED_COLOR}ERROR: The XML GIT repertory may be not true or authentication failure. CODE:${gitStatus}${RES}"
    exit
fi

chown -R ${ServerUser}.${ServerGroup} ${DocumentRoot}${XMLFolder}/

echo

echo -e "${GREEN_COLOR}####################Congratulations########################${RES}"
echo -e "###The XML folder: ${DocumentRoot}${XMLFolder}/"
echo -e "###The GM folder: ${DocumentRoot}${GmFolder}/"
echo -e "###The DocumentRoot folder: ${DocumentRoot}"
echo -e "###The web server user: ${ServerUser}"
echo -e "###The web server group: ${ServerGroup}"
echo -e "${GREEN_COLOR}###########################################################${RES}"
Comments are closed.