【问题标题】:Can I customize the svnadmin create process?我可以自定义 svnadmin 创建过程吗?
【发布时间】:2014-09-24 21:04:16
【问题描述】:

我的服务器上设置了许多不同的存储库。我需要在每个存储库中都有一个相同的提交后挂钩文件。对现有来说足够简单,但是有没有办法让对 svnadmin create 的调用自动将提交后存根文件复制到新的钩子目录?本质上,我正在寻找一个 post-svnadmin-create 钩子。谢谢!

【问题讨论】:

    标签: linux svn


    【解决方案1】:

    我认为你最好的选择是将 svnadmin create 的调用包装在一个脚本中,该脚本在 repo 之后创建钩子。

    【讨论】:

      【解决方案2】:

      同意,只要没有某种内置方式,似乎没有。我本来希望 subversion 能够为新的 Linux 用户提供类似可定制的骨架目录的东西。太糟糕了。

      如果有人发现它有用的话,这是我的 cmets 包装器 - 应该是相当可扩展的。如果有人注意到其中有任何明显的陷阱,请不要犹豫——我既不是 bash 专家也不是 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] == $@[1] (this script name is not captured here)
      args=("$@");
      
      # 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;
      

      -感谢所有主持和发帖的人!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-07-15
        • 2021-10-05
        • 2021-01-02
        • 1970-01-01
        • 2023-03-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多