年前说给scienceluo写一个这样的脚本,很简单的逻辑,实现的功能为在linux下建一个svn的版本库,考虑的条件也很简单,只能用在平时写代码的时候为了方便临时建个svn的版本库用用~~
在openSUSE-12.2, CentOS-6.3, 以及RHEL6.0(均为64bit环境)下简单测试通过:),ubuntu-12.10默认的shell为dash(当然可以指定使用bash),且对 awk的gensub函数不支持,所以该脚本无法在ubuntu下使用(可以用sed实现同样的功能,但懒得弄了,平时也用不到ubuntu的环境)~
脚本支持建立多个版本库,但如果想要同时访问,则多个版本库要在相同的父目录下,否则的话就只能访问最新建的那个版本库了,因为启动svnserve服务器时指定的服务器根目录参数填的是用户最新建的那个svn版本库路径的父目录;
还一个需要注意的地方,建立的版本库必须用svn://127.0.0.1/test_repo类似这样的路径来访问,注意红色的svn://前缀,因为服务器用的是subversion自带的独立服务器~
-
-
-
-
-
-
-
- svn_repo_root_dir=""
-
- function is_subversion_exist()
- {
- which svnadmin > /dev/null 2>&1
- [ $? -eq 0 ] && return 1
- return 0
- }
-
- function is_sys_root_dir()
- {
- echo $1 | awk '{if ($0 ~ /^\/$/) exit 1; else exit 0;}'
- }
-
- function is_relative_path()
- {
- echo $1 | awk '{if ($0 ~ /^\//) exit 0; else exit 1;}'
- }
-
- function get_svn_root_dir()
- {
- read -e -p "输入要创建的svn根目录:" svn_repo_root_dir
- [ -z "$svn_repo_root_dir" ] && echo "非法路径,abort!" && return 1
-
- svn_repo_root_dir=$(echo "$svn_repo_root_dir" | sed 's/^[[:blank:]]*\(\)[[:blank:]]*$/\1/g')
- is_sys_root_dir "$svn_repo_root_dir"
- [ $? -eq 1 ] && echo "非法路径,不能是根目录,abort!" && return 1
-
- svn_repo_root_dir=$(echo "$svn_repo_root_dir" | sed 's/\(\)\/*$/\1/g')
-
- svn_repo_root_dir=$(echo "$svn_repo_root_dir" | sed 's/ /\\ /g')
-
- eval svn_repo_root_dir="$svn_repo_root_dir"
-
- [ -e "$svn_repo_root_dir" ] && echo "该svn路径已存在,请删除后再创建,abort!" && return 1
-
- is_relative_path "$svn_repo_root_dir"
-
- [ $? -eq 1 ] && svn_repo_root_dir=$(pwd)/$svn_repo_root_dir
- return 0
- }
-
- function create_svn_repo()
- {
- mkdir -p $(dirname "$1")
- svnadmin create "$1"
- return 0
- }
-
- function edit_svn_conf_file()
- {
- svn_repo_conf_dir="$1/conf"
- awk '{
- if ($0 ~ /^
- print gensub(/^
- else if ($0 ~ /^
- print gensub(/^
- else if ($0 ~ /^
- print gensub(/^
- else print;}' "$svn_repo_conf_dir/svnserve.conf" > "$svn_repo_conf_dir/tmp_svnserve.conf"
- rm -f "$svn_repo_conf_dir/svnserve.conf"
- mv "$svn_repo_conf_dir/tmp_svnserve.conf" "$svn_repo_conf_dir/svnserve.conf"
- vi "$svn_repo_conf_dir/passwd"
- return 0
- }
-
- function start_svn_server()
- {
- killall -9 svnserve 2&> /dev/null
- svnserve -d -r $(dirname "$1")
- return 0
- }
-
- function main()
- {
- is_subversion_exist
- [ $? -eq 0 ] && echo "subversion不存在,需要先安装subversion" && return 1
- get_svn_root_dir
- [ ! $? -eq 0 ] && return 1
- create_svn_repo "$svn_repo_root_dir"
- [ ! $? -eq 0 ] && return 1
- edit_svn_conf_file "$svn_repo_root_dir"
- [ ! $? -eq 0 ] && return 1
- start_svn_server "$svn_repo_root_dir"
- [ ! $? -eq 0 ] && return 1
- return 0
- }
-
- main
(runsisi) |