Shell Script To Build And Install PHP Security Model Suhosin

by on June 17, 2010 · 2 comments

  1. #!/bin/bash
  2. # A simple shell to build and install suhosin as module for PHP under
  3. # CentOS, Fedora and RHEL / Redhat Enterprise Linux servers.
  4. # ----------------------------------------------------------------------------
  5. # Written by Vivek Gite <http://www.cyberciti.biz/>
  6. # (c) 2009 nixCraft under GNU GPL v2.0+
  7. # ----------------------------------------------------------------------------
  8. # Home page: http://www.hardened-php.net
  9. # Last updated: 15/June/2010
  10. # ----------------------------------------------------------------------------
  11. VERSION="-${2:-0.9.31}"
  12.  
  13. URL="http://download.suhosin.org/suhosin${VERSION}.tgz"
  14. vURL="http://download.suhosin.org/suhosin${VERSION}.tgz.sig"
  15. FILE="${URL##*/}"
  16. vFILE="${vURL##*/}"
  17. DLHOME="/opt"
  18. SOFTWARE="suhosin"
  19. DEST="${FILE%.tgz}"
  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 && phpize && ./configure && make && read -p "Update/Install $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 "Continue 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. buildsoftware
  59. ;;
  60. verify)
  61. #verifyfile
  62. buildsoftware
  63. ;;
  64. *) echo "Usage: $0 {download|verify|build|upgrade} version"
  65. esac


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

Click here to subscribe via email.

  • Vamsi

    Nice one :D
    I love the verification process ;)

  • Jaysunn

    This is really great use of functions and verifications. Love it.

    jaysunn

Previous Script:

Next Script: