SVN系统配置自动脚本

标签: svnpathubuntuapacheimportnull
1111人阅读 评论(0) 收藏 举报
分类:

 在ubuntu 7。04下配置SVN的自动脚本,如果你除了命令本身外,懒得敲任何输入(超级自动化?),那么你页可以用到它:)我也懒得说了,RTFC:

# !/bin/bash
#----------------------------------------------------------------------mutating prepare section line[1:10]

exe0path = `dirname  " $0 " &&
sed 
- ' 1p;10,$p '   " $0 "   >   " $0.vv "   &&
chmod   + " $0.vv "   ||  (rm $ 0 . vv ; echo  " mutating exectuion fail!!! " exit   20 )
yes 
|  sed  ' s/y/n/ '   |   " $0.vv "  ; exit
# ----------------------------------------------------------------------------------mutating execution start





#if [ $# -lt 1 ] ;then
#    echo "usage: `basename $0` <wc> 将工作空间导入该用户的SVN仓库"
#    echo '* 访问地址 1:svn://ip/sourceforge.net/"$(basename "$wc")"'
#    echo '* 访问地址 2:http://ip/sourceforge.net/"$(basename "$wc")"'
#    exit
#fi

# local环境


sudo apt
- get  - y install subversion  1 >/ dev / null

#  默认的SVN服务器根目录设置在~/svnroot,不影响项目仓库的路径,但是必须位于该路径以下
SVNROOT = " $HOME/svnroot "
!   - " $SVNROOT "  ]  &&   mkdir   " $SVNROOT "
echo 
" SVNROOT=$SVNROOT "

#  开启SVN服务器,指定可访问范围
killall svnserve  2 >/ dev / null;  sleep   0 . 0005s  #  系统动作,耗时 < 0.001 sec
svnserve  - - " $SVNROOT "   -- listen - host `ifconfig eth0  | awk  ' /inet/ {split($2,x,":");print x[2]} ' `   &&  echo  " SVN server started on LAN ... "    ||  (echo  " repo exist!!! "  ; read )
#  这里监听主机名只能设置一个,最好设成本机的LAN IP/hostname

# 开启防火墙端口

sudo  / sbin / iptables  - A INPUT  - i eth0  - p tcp  -- dport  3690   - ACCEPT
echo 
- " root  "  ; su  - " /sbin/iptables-save > /etc/iptables.save "
#  此处似乎有一处bug:当用yes|sed 's/y/nn' | `basename $0` $1这样的方式回避 su 要求的root口令时,nn随便是什么都可以!!??

# 默认使用 sourceforge.net仓库

repo = " $SVNROOT/sourceforge.net "
!   - " $repo "  ]  &&  svnadmin create  " $repo "   ||  (echo  " repo exist!!! "  ; read )
# ################################################################### 配置仓库权限
# LAN 环境

# 设置用户名-密码

cat  >   " $repo/conf/passwd "   << EOF
[users]
svnadmin 
=  svnadmin
ubuntu 
=  a
duanfeilei 
=  
chenjunwen 
=  
EOF

cat 
>   " $repo/conf/svnserve.conf "   << EOF
[general]
anon
- access  =  none
auth
- access  =   write
password
- db  =  passwd
authz
- db  =  authz
realm 
=  sourceforge . net Repository
EOF

#  访问路径与用户关联
cat  >    " $repo/conf/authz "   << EOF
[groups]
admin 
=  svnadmin ,  ubuntu
coder 
=  duanfeilei ,  chenjunwen
[sourceforge
. net :/ ]
@admin   =  rw
*   =  r
[sourceforge
. net :/ pub]
*   =  rw
[sourceforge
. net :/ fgen]
@coder   =  rw
*   =  
EOF

if  false ;then
#  Apache环境
#################################################################### 以上必须使用路径,本地操作!


sudo apt
- get  - y install apache2 subversion libapache2 - svn  1 >/ dev / null
sudo a2enmod dav dav_svn
sudo cp 
- / etc / apache2 / mods - available / dav_svn . conf  / etc / apache2 / mods - available / dav_svn . conf . bak
cat 
>  dav_svn . conf  << EOF
< Location  / svn >
  DAV svn
  SVNPath 
/ home / ubuntu / svnroot

  AuthzSVNAccessFile 
/ home / ubuntu / svnroot / sourceforge . net / conf / authz  // 权限配置文件
  AuthType Basic 
// 连接类型设置
  AuthName 
" Subversion.zoneyump "   // 连接框提示
  AuthUserFile  
// 用户配置文件
  
< LimitExcept GET PROPFIND OPTIONS REPORT >
    
Require  valid - user
  
</ LimitExcept >  

</ Location >
EOF
sudo mv 
- i dav_svn . conf  / etc / apache2 / mods - available / dav_svn . conf
fi

# ########################################################################## 将工作空间导入
- z $ 1  ]  &&  wc = $(pwd)  ||  wc = $ 1
#  用 svnadmin 导入
echo  " importing ... "
!  svn  import   - " hello, first step "   " $wc "   svn :// `ifconfig eth0  | awk  ' /inet/ {split($2,x,":");print x[2]} ' ` / sourceforge . net / " $(basename  " $wc " ) "    -- username svnadmin  -- password svnadmin  &&   read
#  这里必须填写注释这一参数,且-m后有空格。导入的工作空间必须使用URL地址(file://协议也是一种,用于本地访问)

# 测试并报告是否成功

bbb = $(pwd)
cd 
" $wc "
rm 
- rf svntest
!   - e svntest ]  &&   mkdir  svntest
echo 
" checkouting ... "
!  svn checkout svn :// `ifconfig eth0  | awk  ' /inet/ {split($2,x,":");print x[2]} ' ` / sourceforge . net / " $(basename  " $wc " ) "  svntest  -- username = chenjunwen  -- password =    &&   read
a
= `find  .   - type f  |  head  - n1`
b
= `find  .   - type f  |  tail  - n1`
cat 
$a   >   $b
echo 
" commiting ... "
# ! svn commit -m "first commit" svntest  &&  read
cd  " $bbb "

#  另外,注意使用esvn时,上一次的认证用户信息会被缓存,因此只要正确使用一次即可。

rm 
" $0 "   1 >/ dev / null  2 >& 1    #  for self-mutating , don't


2007/10/11:

上面的脚本很混乱,实际中,可以采用下面的经过“包装”的svn:

 

# !/bin/bash


fullpath() 
#  可以将任意系统中存在的路径转换为绝对路径
{
if  [  - z $ 1  ] ;then
    echo 
" Usage: `basename $0` <path> "
    
exit
fi
if  [ $ 1   =   " --help "  ];then
    echo 
" 功能:对于给出的文件或文件夹的,路径或相对路径,转换为绝对路径 "
    
exit
fi

if  [  !   - " $1 "  ];then
    echo 
" path not exisit!!! "
    
exit
fi

path
= $ 1
pwddir
= `pwd`  #  总是表示 path 上层的目录,绝对路径形式
pwddir = ${pwddir %/ }
- " $path "  ]  &&  path = " ${path%/}/ "   # 确保目录不被当作文件处理
# 处理头部

dir = `echo  $path   |  awk  - F " / "   ' {print $1} ' `
case 
$dir  in
    
" . " )    path = ${path # ./}
        
    ;;
    
" .. " )    path = ${path # ../}
        pwddir = ${pwddir %/* }
    ;;
    
"" )    path = ${path # /}
        pwddir =
    ;;
    
* )    
    ;;
esac

while  [  !   - " $path "  ]; do
    
if  [  " ${path#../} "   !=   " ${path} "  ];then
        path
= ${path # ../}
        pwddir = ${pwddir %/* }
    
else
        pwddir
= " ${pwddir}/${path%%/*} "
        path
= ${path # */}
    fi
done

}


pwddir
=
if  [  - z $ 1  ];then
    echo 
""
    
exit
fi
case $
1  in
    
" create " )    case $ #  in
                 1 )    repo =.
                ;;
                
2 )    repo = $ 2
                ;;
            esac
            svnadmin create 
$repo
    ;;
    
" start " )     if  [  - z $ 2  ];then
                echo 
""
                
exit
            fi
            fullpath $
2
            svnserve 
- - r file :// " $pwddir "
    ;;
    
" stop " )         if  [  - z $ 2  ];then
                echo 
""
                
exit
            fi
            fullpath $
2
            killall svnserve
    ;;
    
" import " )    case $ #  in
                 1 )    echo  ""
                    
exit
                ;;
                
2 )    wc =.
                    repo
= $ 2
                ;;
                
3 )    wc = $ 2
                    repo
= $ 3
                ;;
            esac
            [ 
!   - " $repo "  ]  &&   mkdir   " $repo "
            fullpath 
$repo
            svn 
import   $wc  file :// " $pwddir "
    ;;
    
" checkin " )    case $ #  in
                 1 )    echo  ""
                    
exit
                ;;
                
2 )    wc =.
                    repo
= $ 2
                ;;
                
3 )    wc = $ 2
                    repo
= $ 3
                ;;
            esac
            fullpath 
$repo
            svn ci 
$wc  file :// " pwddir "
    ;;
    
" checkout " )    case $ #  in
                 1 )    echo  ""
                    
exit
                ;;
                
2 )    wc =.
                    repo
= $ 2
                ;;
                
3 )    wc = $ 2
                    repo
= $ 3
                ;;
            esac
            fullpath 
$repo
            svn co 
$wc  file :// " pwddir "

    ;;
    
* )        echo  " undefined command "
            
exit
    ;;
esac
unset pwddir
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:552961次
    • 积分:6980
    • 等级:
    • 排名:第3253名
    • 原创:155篇
    • 转载:82篇
    • 译文:2篇
    • 评论:128条
    文章分类
    最新评论