#!/bin/bash # Date:2018/11/29 # Author: linyaohong # BLOG: ************ # Qq:122123498 # Version:1.0 # User: Centos 7 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH function Svn_Install() { [ -f /etc/init.d/functions ] && . /etc/init.d/functions # Check if subversion install if [ $(rpm -qa|grep subversion|wc -l) -gt "1" ];then action "check subversion" /bin/true else yum -y install subversion fi # Set infomation ip=149.129.84.247 Logdir='/var/log/' Logname=svncreate.log # "/ " is must'd svn_dir=/data/svn/ checkout_dir=/data/wwwroot/svn/ #svn_authz= #svn_user= #svn_passwd= [ ! -d ${Logdir} ]&& mkdir -p ${Logdir} [ ! -d ${svn_dir} ] && mkdir -p ${svn_dir} # Check subversion install svn_check=`netstat -lntup|grep svnserve|wc -l` if [ "${svn_check}" -ge "1" ];then action "check svnserve" /bin/true else action "check svnserve" /bin/false svnserve -d -r ${svn_dir} >>/dev/null 2>&1 if [ $? = 0 ];then action "start svnserve" /bin/true else action "start svnserve" /bin/false exit 1 fi fi # Input svnserve infomation read -p "Please input the svn repository name[svn_authz]:" svn_authz read -p "Please input the svn repository name[svn_user]:" svn_user read -p "Please input the svn repository name[svn_passwd]:" svn_passwd # Check input [ -z "$svn_authz" ] &&{ echo "svn_authz can't empty "; exit 1;} [ -z "$svn_user" ] &&{ echo "svn_user can't empty "; exit 1;} [ -z "$svn_passwd" ] &&{ echo "svn_authz can't empty "; exit 1;} str1=`echo "${svn_authz}" | tr -d '[A-Za-z0-9]'` if [ -n "${str1}" ];then echo "svn_authz you must input[A-Za-z0-9]" exit 1 fi str2=`echo "${svn_user}" | tr -d '[A-Za-z0-9]'` if [ -n "${str2}" ];then echo "svn_user you must input[A-Za-z0-9]" exit 1 fi str3=`echo "${svn_passwd}" | tr -d '[A-Za-z0-9]'` if [ -n "${str3}" ];then echo "svn_passwd you must input[A-Za-z0-9]" exit 1 fi # Check svn_authz does not exist if [ ! -d ${svn_dir}${svn_authz} ];then svnadmin create ${svn_dir}${svn_authz} else echo svn_authz already exists exit 1 fi echo "------------The detailed information-------------">>${Logdir}${Logname} cd ${svn_dir}${svn_authz}/conf/ echo "[$svn_authz:/]" >> ./authz echo "$svn_user = rw" >> ./authz #echo "svnqd$SVNNAME = r" >> ./authz #echo "[$SVNNAME:/web]" >> ./authz #echo "svnqd$SVNNAME = rw" >> ./authz #echo "[$SVNNAME:/template]" >> ./authz #echo "svnqd$SVNNAME = rw" >> ./authz #echo "[$SVNNAME:/app/manage/view]" >> ./authz #echo "svnqd$SVNNAME = rw" >> ./authz echo "$svn_user = $svn_passwd" >> ./passwd #echo "svnqd$SVNNAME = svnqd$SVNNAME" >> ./passwd cat > ${svn_dir}${svn_authz}/conf/svnserve.conf<${svn_dir}${svn_authz}/hooks/post-commit<> \$LOGPATH \$SVN update --username \${USER} --password \${PASSWD} --no-auth-cache \${dir} >> \${LOGPATH} \#chown -R www:www \${Dir} if [ \$? -eq 0 ];then echo "update successfull" >> \$LOGPATH else echo "update failed" >> \${LOGPATH} fi EOF echo "date: `date +"%Y-%m-%d %H:%M:%S"`">> ${Logdir}${Logname} echo "svn_name(PHP): ${svn_user}" >> ${Logdir}${Logname} echo "svn_passwd: ${svn_passwd}" >> ${Logdir}${Logname} echo "svn_add: svn://${ip}/${svn_authz}/" >>${Logdir}${Logname} chmod +x ${svn_dir}${svn_authz}/hooks/post-commit # Checkout if [ -d ${checkout_dir} ];then work=`find ${checkout_dir} -name ".svn"|wc -l` if [ ${work} != "0" ];then echo "The working directory already exists" exit 1 fi svn import ${checkout_dir} file:///${svn_dir}${svn_authz} -m "import" >>/dev/null 2>&1 if [ $? -eq 0 ];then echo "import sucessful" >>${Logdir}${Logname} action "import " /bin/true else echo "import failed" >>${Logdir}${Logname} action "import " /bin/false exit 1 fi svn checkout file:///${svn_dir}${svn_authz} ${checkout_dir} >>/dev/null 2>&1 if [ $? -eq 0 ];then echo "checkout Successful" >>${Logdir}${Logname} action "checkout " /bin/true else echo "svn create ok , checkout error" >>${Logdir}${Logname} action "checkout " /bin/false exit 1 fi cd ${checkout_dir} svn revert --depth=infinity . >>/dev/null 2>&1 else svn checkout file:///${svn_dir}${svn_authz} ${checkout_dir} >>/dev/null 2>&1 if [ $? -eq 0 ];then echo "checkout Successful" >>${Logdir}${Logname} action "checkout " /bin/true else echo "svn create ok , checkout error" >>${Logdir}${Logname} action "checkout " /bin/false exit 1 fi fi echo "--------------------Eend-------------------------">>${Logdir}${Logname} } Svn_Install