2014-09-24 43 views
0

我在我的服务器上安装了许多不同的存储库。我需要在每个回购协议中都有一个完全相同的post-commit hook文件。足够简单的现有,但有没有办法打电话给svnadmin创建自动将post-commit存根文件复制到新的挂钩目录?基本上我正在寻找一个post-svnadmin-create挂钩。谢谢!我可以自定义svnadmin创建过程吗?

回答

1

我认为你最好的选择是将呼叫包装到svnadmin create中,该脚本创建回购后的挂钩。

0

只要没有一些内置的方式,似乎没有。我希望颠覆者可以为新的Linux用户提供类似于可定制骨架目录的东西。太糟糕了。

这是我的包装与评论,如果任何人都可以找到它有用的 - 应该是相当可扩展的。如果有人注意到在它的任何明显的陷阱,不要犹豫 - 我既不是庆典也不是Linux的专家,但我觉得我得到了大部分覆盖,它的工作原理:)

# ----------------------------------------------------------------------- 
# A wrapper for svnadmin to allow post operations following repo creation - copying custom 
# hook files into repo in this case. This should be run as root. 

# capture input args; note that args[0] == [email protected][1] (this script name is not captured here) 
args=("[email protected]"); 

# redirect args to svnadmin in all cases - this script should not modify the behavior of svnadmin. 
# note: the original binary "/binary_path/svnadmin" has been renamed "/binary_path/svnadmin-wrapped" and 
# this script was then named "/binary_path/svnadmin" and given identical user:group & permissions as 
# the original. 
sudo -u svnuser svnadmin-wrapped ${args[@]}; 

# capture return code so we can return on exit; svnadmin returns 0 for success 
eCode=$?; 

# find out if sub-command to svnadmin was "create" and, if so, note the index of the directory arg, 
# which is not necessarily going to be in the same position each time (options may be specified 
# before the sub-command). 
path_idx=0; 
found=0; 
for i in ${args[@]} 
do 
    # track index; pre-incerement 
    ((path_idx++)); 
    if [ $i == "create" ] 
     then 
     # found repo path 
     ((found++)); 
     break; 
    fi 
done 

# we now know if the subcommand was create and where the repo path is - finish up as needed. 
# note that this block assumes that our hook file stubs are /stub_path/ (owned by root) 
# and that there exists a custom log file at /stub_path/cust-log (also owned by root). 
d=`date`; 
if [ $found != 0 ] 
    then 
    # check that the command succeeded 
    if [ $eCode == 0 ] 
     then 
     # check that the directory exists 
     if [ -d "${args[$path_idx]}/hooks" ] 
      then 
      # copy our custom hooks into place 
      sudo -u svnuser cp "/stub_path/post-commit" "${args[$path_idx]}/hooks/post-commit"; 
      sudo -u svnuser cp "/stub_path/post-revprop-change" "${args[$path_idx]}/hooks/post-revprop-change"; 
     else 
      # unlikey failure; set custom error code here; log issue 
      echo "$d svnadmin wrapper error: svnadmin 'create' succeeded but the 'hooks' directory was not found! Params: ${args[@]}" >> "/stub_path/cust-log"; 
      let "eCode=1325"; 
     fi 
    else 
     # tried to create but svnadmin failed; log issue 
     echo "$d svnadmin wrapper error: svnadmin 'create' was called but failed! Params: ${args[@]}" >> "/stub_path/cust-log"; 
    fi 
fi 
exit $eCode; 

-Thanks所有谁主机和帖子!

相关问题