Advertisement
Guest User

Untitled

a guest
Aug 6th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.27 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # POST-COMMIT HOOK
  4. #
  5. # This is an SVN post-commit hook to automatically update a directory with the contents
  6. # of some part of the SVN repository every time that part of the repository is changed.
  7.  
  8. fail() {
  9.     echo "$@" 1>&2
  10.     exit 1
  11. }
  12.  
  13. # USER and PASS are the username and password of an SVN user with read access to the
  14. # relevant part of the repository
  15. USER="toby"
  16. PASS="reguwo79"
  17. # The root of the SVN repository
  18. SVNROOT="/var/svn/liarbo"
  19. # The path within the SVN repository to export whenever it's committed
  20. SVNPATH="/var/svn/liarbo/trunk"
  21. # The directory to hold the checked-out copy
  22. WORKING="/var/www/liarbo"
  23.  
  24. # Since environment variables are unset
  25. export PATH="/bin:/usr/bin:/usr/local/bin"
  26.  
  27. getopt=$(which getopt)
  28.  
  29. TEMP=`$getopt -o u:p:U:P:d: --long user:,pass:,password:,svn-root:,svn-path:,working-dir: -n $0 -- "$@"`
  30.  
  31. if [ $? != 0 ]; then
  32.     fail "Terminating...getopt failed"
  33. fi
  34.  
  35. # Note the quotes around `$TEMP': they are essential!
  36. eval set -- "$TEMP"
  37.  
  38. while true; do
  39.     case "$1" in
  40.         -u|--user)
  41.             USER=$2
  42.             shift 2;;
  43.         -p|--pass|--password)
  44.             PASS=$2
  45.             shift 2;;
  46.         -U|--svn-root)
  47.             SVNROOT=$2
  48.             shift 2;;
  49.         -P|--svn-path)
  50.             SVNPATH=$2
  51.             shift 2;;
  52.         -d|--working-dir)
  53.             WORKING=$2
  54.             shift 2;;
  55.         --)
  56.             shift
  57.             break ;;
  58.         *)
  59.             fail "Option error!";;
  60.     esac
  61. done
  62.  
  63. test -n $SVNROOT || fail "Missing option --svn-root"
  64. test -n $SVNPATH || fail "Missing option --svn-path"
  65. test -n $WORKING || fail "Missing option --working-dir"
  66.  
  67. REPOS="$1"
  68. REV="$2"
  69.  
  70. # The path to SVN executables
  71. svnbin=$(which svn)
  72. svnlook=$(which svnlook)
  73. # The path to grep
  74. grep=$(which egrep)
  75.  
  76. if test -n "$USER"; then
  77.     AUTHSTR="--username $USER --password $PASS"
  78. else
  79.     AUTHSTR=""
  80. fi
  81. svnexport="$svnbin export --revision $REV $AUTHSTR"
  82. svnupdate="$svnbin update --revision $REV $AUTHSTR"
  83. svncheckout="$svnbin checkout --revision $REV $AUTHSTR"
  84. svnchanged="$svnlook changed $REPOS --revision $REV"
  85. grepq="$grep -q"
  86.  
  87. # If anything in the desired path has been changed
  88. if $svnchanged | $grepq "^[A-Z]+[[:space:]]+$SVNPATH"; then
  89.     # Check it out to the web root
  90.     if test -d $WORKING/.svn; then
  91.         $svnupdate $WORKING || fail "svnupdate failed"
  92.     else
  93.         $svncheckout file://$SVNROOT/$SVNPATH $WORKING || fail "svncheckout failed"
  94.     fi
  95. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement