一键部署SVN服务(Centos7.3)

一、一键部署脚本

#!/bin/sh
# @author ling

# 定义显示颜色
RED='\e[1;91m'
GREEN='\e[1;92m'
WITE='\e[1;97m'
NC='\e[0m'

SVN_REPOSITORY_PATH=/data/svn/svn_repository
PASSWD_FILE=conf/passwd
AUTHZ_FILE=conf/authz
SVNSERVE_FILE=conf/svnserve.conf
SVNSERVE_INIT_FILE=/etc/sysconfig/svnserve
DEFAULT_REPOSITORY_CONF="OPTIONS=\"-r /var/svn\""
NEW_REPOSITORY_CONF="OPTIONS=\"-r $SVN_REPOSITORY_PATH\""
INIT_PATH=/etc/init.d
SVN_INIT_FILE=svn

# 安装SVN
function install_subversion()
{
	echo "Install subversion!"
	rpm -ql subversion
	if [ $? -eq 0 ];then
		echo -e $RED"Subversion was installed!"$NC
	else
		yum -y install subversion && echo -e $GREEN"Install Subversion success!"$NC
	fi
}

# 创建SVN版本库
function create_svn_repository()
{
	echo "Create svn repository!"
	mkdir -p $SVN_REPOSITORY_PATH && svnadmin create $SVN_REPOSITORY_PATH && echo -e $GREEN"Create svn repository success!"$NC
}

# 设置SVN初始化配置
function set_init_conf()
{
	echo "Set init conf!"
	echo "Set users !"
	echo "admin = 123qwe
guest = 123qwe" >> $SVN_REPOSITORY_PATH/$PASSWD_FILE && echo -e $GREEN"Set users success, default user: admin、guest,default password:123qwe."$NC
	
	echo "Set users right!"
	echo "[groups]
admin = admin
guest = guest
[/]
@admin = rw
@guest = r" >> $SVN_REPOSITORY_PATH/$AUTHZ_FILE && echo -e $GREEN"Set users right success!"$NC
	
	echo "Set svn service conf!"
	echo "[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz" >> $SVN_REPOSITORY_PATH/$SVNSERVE_FILE && echo realm = $SVN_REPOSITORY_PATH >> $SVN_REPOSITORY_PATH/$SVNSERVE_FILE && 
	echo -e $GREEN"Set svn service conf success!"$NC
}

# 打开svn服务默认端口(3690)
function open_svn_default_port()
{
	echo "Open svn default port"
	systemctl status firewalld
	if [ $? -eq 0 ];then
		firewall-cmd --permanent --query-port=3690/tcp
		if [ $? -eq 0 ];then
			echo -e $RED"Svn default port was open!"$NC
		else
			firewall-cmd --permanent --add-port=3690/tcp && echo -e $GREEN"Open svn default port success!"$NC
		fi
	else
		echo -e $RED"Firewall is not open!"$NC
	fi
}

# 设置开机启动
function chkconfig_svn_on()
{
	echo "Chkconfig svn on!"
	sed -i "s@$DEFAULT_REPOSITORY_CONF@$NEW_REPOSITORY_CONF@g" $SVNSERVE_INIT_FILE && systemctl start svnserve.service && systemctl enable svnserve.service && echo -e $GREEN"Chkconfig svn on success!"$NC
}

# 安装启动脚本
function install_init_script()
{
	cp $SVN_INIT_FILE $INIT_PATH
	chmod  +x  $INIT_PATH/$SVN_INIT_FILE
}

function main()
{
	install_init_script
	install_subversion
	create_svn_repository
	set_init_conf
	open_svn_default_port
	chkconfig_svn_on
}

main

二、SVN服务启动脚本

#!/bin/sh
# @author ling

# 定义显示颜色
RED='\e[1;91m'
GREEN='\e[1;92m'
WITE='\e[1;97m'
NC='\e[0m'

function start()
{
	systemctl status svnserve.service > /dev/null 2>&1
	if [ $? -eq 0 ];then
		echo -e $RED"Service already running!"$NC
	else
		systemctl start svnserve.service && echo -e $GREEN"Start service successfully!"$NC
	fi
}

function stop()
{
	systemctl status svnserve.service > /dev/null 2>&1
	if [ $? -eq 0 ];then
		systemctl stop svnserve.service && echo -e $GREEN"Stop service successfully!"$NC
	else
		echo -e $RED"Service is not running!"$NC
	fi
}

function restart()
{
	systemctl status svnserve.service > /dev/null 2>&1
	if [ $? -eq 0 ];then
		systemctl stop svnserve.service && systemctl start svnserve.service && echo -e $GREEN"Service started!"$NC
	else
		echo -e $RED"Service is not running!"$NC
	fi
}

function status()
{
	systemctl status svnserve.service > /dev/null 2>&1
	if [ $? -eq 0 ];then
		echo -e $GREEN"Service started!"$NC
	else
		echo -e $RED"Service stop!"$NC
	fi
}

function main()
{
	case $1 in
		start)
			echo "Start svn service!"
			start
		;;
		stop)
			echo "Stop svn service!"
			stop
		;;
		restart)
			echo "Restart svn service!"
			restart
		;;
		status)
			echo "Status svn service!"
			status
		;;
		*)  
			echo "Usage: $0 {start|stop|restart|status}"  
			exit 1
		;;
	esac
}

main $1

三、基本使用

1、下载一键部署包,解压
百度云盘下载链接:https://pan.baidu.com/s/1XDCJ6JF7eHxdv2qtoqHz8g
提取码:2bfw

2、使用命令:sh start.sh执行部署脚本即可

猜你喜欢

转载自blog.csdn.net/q13554515812/article/details/83584727