作用
生成SVN仓库,Web服务器的配置文件和钩子程序
参数说明
SVN_ROOT SVN的根目录
SVNADMIN_BIN svnadmin的路径
SVN_BIN svn的路径
SVN_USER 用来更新SVN的用户名
SVN_PWD 用来更新SVN的密码
WEB_ETC Apache的host配置目录
WEB_ROOT Apache的Web根目录
WEB_USER Apache的运行User
WEB_GROUP Apache的运行Group
HOST_PREFIX 生成的Web域名加的前缀
HOST_SUFFIX 生成的Web域名加的后缀
<VirtualHost *:80>ServerAdmin shenhd@ableengine.comDocumentRoot "/var/www/html/PROJECT"ServerName www.PROJECT_HOST.com<Directory "/var/www/html/PROJECT">Options Indexes FollowSymLinks MultiViewsAllowOverride AllOrder allow,denyallow from all</Directory></VirtualHost>
#!/bin/bashexport LC_CTYPE=zh_CN.UTF-8su www -c "svn update --username SVN_USER --password SVN_PWD PROJECT_ROOT"
#!/bin/bash#################################################################### deploy script ## 一个简单的部署脚本,在创建Apache虚拟主机配置同时,添加SVN仓 ## 库并做一个钩子自动更新到Apache Web根目录 ## 2013-03-09 ## shenhd ######################################################################### define variables #####PROJECT=$1SVN_ROOT=PATH/svnSVNADMIN_BIN=/usr/bin/svnadminSVN_BIN=/usr/bin/svnSVN_USER=USERSVN_PWD=PASSWORDWEB_ETC=APACHE_CONF_DIRWEB_ROOT=APACHE_HTDOC_DIRWEB_USER=wwwWEB_GROUP=wwwHOST_PREFIX=HOST_SUFFIX=##### define variables #####if [ "${UID}" != "0" ]thenecho Please grant it root privilegesexitelif [ "${PROJECT}" == "" ]thenecho Please specify a project nameexitfifunction create_svn() {SVN_REPO=${SVN_ROOT}/${PROJECT}# create project svn repository$SVNADMIN_BIN create ${SVN_REPO}# backup config filesmv ${SVN_REPO}/conf/svnserve.conf ${SVN_REPO}/conf/svnserve.conf.orginmv ${SVN_REPO}/conf/authz ${SVN_REPO}/conf/authz.orginmv ${SVN_REPO}/conf/passwd ${SVN_REPO}/conf/passwd.orgincp ./conf/svnserve.conf ${SVN_REPO}/conf/cp ./conf/authz ${SVN_REPO}/conf/sed -i "s/PROJECT/${PROJECT}/g" ${SVN_REPO}/conf/authzcp ./conf/passwd ${SVN_REPO}/conf/if [ ! -f "${SVN_REPO}/conf/authz" ] || [ ! -f "${SVN_REPO}/conf/passwd" ] \|| [ ! -f "${SVN_REPO}/conf/svnserve.conf" ]thenecho Cannot change configure files for svnexitfi}function create_host() {PROJECT_ETC=${WEB_ETC}/${PROJECT}.confPROJECT_ROOT=${WEB_ROOT}/${PROJECT}mkdir -p ${PROJECT_ROOT}if [ ! -d ${PROJECT_ROOT} ]thenecho Cannot create project htdoc rootexitfi# change directory ownerchown -R ${WEB_USER}:${WEB_GROUP} ${PROJECT_ROOT}cp ./conf/host.conf ${PROJECT_ETC}sed -i "s/PROJECT_HOST/${HOST_PREFIX}${PROJECT}${HOST_SUFFIX}/g" ${PROJECT_ETC}sed -i "s/PROJECT/${PROJECT}/g" ${PROJECT_ETC}}function hook_svn() {${SVN_BIN} checkout svn://127.0.0.1/${PROJECT} --username ${SVN_USER} --password ${SVN_PWD} ${PROJECT_ROOT}cp ./conf/post-commit ${SVN_REPO}/hooks/chmod +x ${SVN_REPO}/hooks/post-commitHOOK=${SVN_REPO}/hooks/post-commitsed -i "s/SVN_USER/${SVN_USER}/g" ${HOOK}sed -i "s/SVN_PWD/${SVN_PWD}/g" ${HOOK}WEBROOT=${PROJECT_ROOT//\//\\\/}sed -i "s/PROJECT_ROOT/${WEBROOT}/g" ${HOOK}}create_svncreate_hosthook_svnecho Reload your web server.