You are here
Home > Linux

svn_hook_sync.sh

#!/usr/bin/env bash
## svn 同步 脚本

## yum 安装 svn
yum install -y subversion >> ~/svn_install_log.log

## 检测安装版本
svnserve --version|grep "版本"

echo "创建 svn 仓库目录: /var/svn"
mkdir -p /var/svn
cd /var/svn
pwd


echo 创建版本库
svnadmin create /var/svn/project
cd project
pwd
echo "会看到自动生成的版本库文件"
ls -al ./


echo  "vim  /var/svn/project/conf/authz"

cat >/var/svn/project/conf/authz<<EOF
[groups]
alliance = store,wholesaler, logistics,platform
[project:/]
@alliance = rw
EOF

echo "vim /var/svn/project/conf/passwd"

cat >/var/svn/project/conf/passwd<<EOF
[users]
store = store
wholesaler = wholesaler
logistics = logistics
platform = platform
EOF



echo "vim /var/svn/project/conf/svnserve.conf"

# anon-access = none  //匿名用户访问权限:无
sed -i 's/# anon-access = read/anon-access = none/g' /var/svn/project/conf/svnserve.conf

# auth-access = write     //普通用户访问权限:读、写
sed -i 's/# auth-access = write/auth-access = write/g' /var/svn/project/conf/svnserve.conf

# password-db = passwd        //密码文件
sed -i 's/# password-db = passwd/password-db = passwd/g'  /var/svn/project/conf/svnserve.conf

# authz-db = authz        //权限配置文件
sed -i 's/# authz-db = authz/authz-db = authz/g'  /var/svn/project/conf/svnserve.conf

# realm = /var/svn/project    //版本库所在1
sed -i 's/# realm = \/var\/svn\/project/realm = \/var\/svn\/project/g'  /var/svn/project/conf/svnserve.conf

#### 注意:所有以上的配置项都需要顶格,即前面不能预留空格,否则报错  ####



echo  "启动svn服务:"
killall svnserve
svnserve -d -r /var/svn

echo "测试服务器"


mkdir -p /home/wwwroot/svntest # 这里的目录应该随自己项目做出修改

cd /home/wwwroot/svntest
# 如果手动检出可以这样
# svn co svn://localhost/project --username store
# 手动输入密码,或在脚本中这样写:
svn co svn://localhost/project   --username store --password store <<EOF
yes
EOF

## svn 客户端存储文本密码
sed -i 's/# store-plaintext-passwords = no/store-plaintext-passwords = yes/g' /root/.subversion/servers


cd project

touch README.md
svn add README.md

svn commit README.md -m "测试提交文件"

## 下面添加 post hook
cat >/var/svn/project/hooks/post-commit<<EOF
#!/bin/sh
export LANG=en_US.utf8
SVN_PATH=/usr/bin/svn
WEB_PATH=/home/wwwroot/svntest/project
\$SVN_PATH update \$WEB_PATH --username 'store' --password 'store' --no-auth-cache
EOF

## 修改 hook 脚本用户、组 为www,这里的用户组与 web 目录要一致
chown  www:www /var/svn/project/hooks/post-commit

## 添加执行权限
chmod 755 /var/svn/project/hooks/post-commit

## 下面检验成果

mkdir -p /home/wwwroot/testhook

cd /home/wwwroot/testhook

svn co svn://localhost/project   --username wholesaler --password wholesaler <<EOF
yes
EOF

cd project

touch HOOKTEST.md

svn add HOOKTEST.md
svn commit HOOKTEST.md -m "hook test"


ls -al /home/wwwroot/svntest/project

发表评论

Top