Shell Script To Build And Install PHP Xcache Opcode Cache Extension

by on June 17, 2010 · 1 comment

  1. #!/bin/bash
  2. # A simple shell to build and install xcache Opcode Cache as module for
  3. # PHP under # CentOS, Fedora and RHEL / Redhat Enterprise Linux servers.
  4. # ----------------------------------------------------------------------------
  5. # Written by Vivek Gite <http://www.cyberciti.biz/>
  6. # (c) 2008 nixCraft under GNU GPL v2.0+
  7. # ----------------------------------------------------------------------------
  8. # Home page: http://www.hardened-php.net
  9. # Last updated: 15/June/2010
  10. # ----------------------------------------------------------------------------
  11. # Home page: http://xcache.lighttpd.net
  12. VERSION="${2:-1.3.0}"
  13. URL="http://xcache.lighttpd.net/pub/Releases/${VERSION}/xcache-${VERSION}.tar.gz"
  14. vURL="http://xcache.lighttpd.net/pub/Releases/${VERSION}/xcache-${VERSION}.tar.gz.md5.txt"
  15. FILE="${URL##*/}"
  16. vFILE="${vURL##*/}"
  17. DLHOME="/opt"
  18. SOFTWARE="xcache"
  19. DEST="${FILE%.tar.gz}"
  20.  
  21. [[ $(id -u) -ne 0 ]] && { echo "$0: You must be root user to run this script. Run it as 'sudo $0'"; exit 1; }
  22.  
  23. getsoftware(){
  24. wget $URL -O "${DLHOME}/$FILE"
  25. wget $vURL -O "${DLHOME}/$vFILE"
  26. }
  27.  
  28. buildsoftware(){
  29. [[ ! -f "${DLHOME}/$FILE" ]] && getsoftware
  30. cd "${DLHOME}"
  31. tar -zxvf $FILE
  32. cd "$DEST"
  33. phpize --clean && ./configure --enable-xcache && make && read -p "Update in $SOFTWARE [Y/n] ? " answer
  34. shopt -s nocasematch
  35. [[ $answer =~ y|es ]] && make install
  36. shopt -u nocasematch
  37. }
  38.  
  39. verifyfile(){
  40. cd "${DLHOME}"
  41. [ ! -f ${DLHOME}/$vFILE ] && getsoftware
  42. md5sum -c $vFILE
  43. read -p "Contine to build [Y/n] ? " answer
  44. shopt -s nocasematch
  45. case "$answer" in
  46. y|yes) buildsoftware;;
  47. *) echo "";
  48. esac
  49. shopt -u nocasematch
  50. }
  51.  
  52. case "$1" in
  53. download)
  54. getsoftware
  55. ;;
  56. build)
  57. verifyfile
  58. ;;
  59. verify)
  60. verifyfile
  61. ;;
  62. *) echo "Usage: $0 {download|verify|build|upgrade} version"
  63. esac


4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

Click here to subscribe via email.

Previous Script:

Next Script: