HosipLan

Untitled

Feb 20th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.12 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # The "post-receive" script is run after receive-pack has accepted a pack
  4. # and the repository has been updated.  It is passed arguments in through
  5. # stdin in the form
  6. #  <oldrev> <newrev> <refname>
  7.  
  8.  
  9. # arguments
  10. read oldrev newrev refname
  11.  
  12.  
  13. # dirs
  14. LIBS_DIR="/var/www/libs";
  15. SOURCE_DIR="$GL_REPO_BASE_ABS/$GL_REPO.git"
  16. TARGET_DIR="$LIBS_DIR/$GL_REPO"
  17.  
  18.  
  19. # cleanup the environment
  20. unset GIT_DIR
  21.  
  22.  
  23. # processes
  24. fix_permissions () {
  25.     find $1 -type d -exec chmod 755 {} \;
  26.     find $1 -type f -exec chmod 644 {} \;
  27. }
  28.  
  29.  
  30. # export_ref [ref] [directory]
  31. export_ref () {
  32.     git archive $1 | (cd $2 && tar xf -)
  33. }
  34.  
  35.  
  36. # decide whether to deploy
  37. case $refname in
  38.     refs/heads/* )
  39.         BRANCH="${refname:11}"
  40.         TARGET="$TARGET_DIR/$BRANCH/"
  41.         echo "Executing deploy of library $GL_REPO, brach $BRANCH"
  42.         cd $SOURCE_DIR && export_ref $BRANCH $TARGET
  43.         fix_permissions $TARGET
  44.     ;;
  45.     refs/tags/* )
  46.         TAG="${refname:10}"
  47.         TARGET="$TARGET_DIR/$TAG/"
  48.         echo "Executing deploy of library $GL_REPO, tag $BRANCH"
  49.         cd $SOURCE_DIR && export_ref $TAG $TARGET
  50.         fix_permissions $TARGET
  51.     ;;
  52.     * )
  53.     ;;
  54. esac
  55. exit 0
Advertisement
Add Comment
Please, Sign In to add comment