Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # POST-COMMIT HOOK
- #
- # This is an SVN post-commit hook to automatically update a directory with the contents
- # of some part of the SVN repository every time that part of the repository is changed.
- fail() {
- echo "$@" 1>&2
- exit 1
- }
- # USER and PASS are the username and password of an SVN user with read access to the
- # relevant part of the repository
- USER="toby"
- PASS="reguwo79"
- # The root of the SVN repository
- SVNROOT="/var/svn/liarbo"
- # The path within the SVN repository to export whenever it's committed
- SVNPATH="/var/svn/liarbo/trunk"
- # The directory to hold the checked-out copy
- WORKING="/var/www/liarbo"
- # Since environment variables are unset
- export PATH="/bin:/usr/bin:/usr/local/bin"
- getopt=$(which getopt)
- TEMP=`$getopt -o u:p:U:P:d: --long user:,pass:,password:,svn-root:,svn-path:,working-dir: -n $0 -- "$@"`
- if [ $? != 0 ]; then
- fail "Terminating...getopt failed"
- fi
- # Note the quotes around `$TEMP': they are essential!
- eval set -- "$TEMP"
- while true; do
- case "$1" in
- -u|--user)
- USER=$2
- shift 2;;
- -p|--pass|--password)
- PASS=$2
- shift 2;;
- -U|--svn-root)
- SVNROOT=$2
- shift 2;;
- -P|--svn-path)
- SVNPATH=$2
- shift 2;;
- -d|--working-dir)
- WORKING=$2
- shift 2;;
- --)
- shift
- break ;;
- *)
- fail "Option error!";;
- esac
- done
- test -n $SVNROOT || fail "Missing option --svn-root"
- test -n $SVNPATH || fail "Missing option --svn-path"
- test -n $WORKING || fail "Missing option --working-dir"
- REPOS="$1"
- REV="$2"
- # The path to SVN executables
- svnbin=$(which svn)
- svnlook=$(which svnlook)
- # The path to grep
- grep=$(which egrep)
- if test -n "$USER"; then
- AUTHSTR="--username $USER --password $PASS"
- else
- AUTHSTR=""
- fi
- svnexport="$svnbin export --revision $REV $AUTHSTR"
- svnupdate="$svnbin update --revision $REV $AUTHSTR"
- svncheckout="$svnbin checkout --revision $REV $AUTHSTR"
- svnchanged="$svnlook changed $REPOS --revision $REV"
- grepq="$grep -q"
- # If anything in the desired path has been changed
- if $svnchanged | $grepq "^[A-Z]+[[:space:]]+$SVNPATH"; then
- # Check it out to the web root
- if test -d $WORKING/.svn; then
- $svnupdate $WORKING || fail "svnupdate failed"
- else
- $svncheckout file://$SVNROOT/$SVNPATH $WORKING || fail "svncheckout failed"
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement