代码来源:自己整理编写
说明:用于部署项目的,依赖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}"
本文由 陌上花开 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Jul 1, 2016 at 06:32 am