2014-09-24 75 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所有誰主機和帖子!

相關問題