bash_functions.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. # If you are running a large number of installs back to back
  3. # (e.g. for FwBm development), then setting this variable
  4. # will cause apt-get and wget to use your proxy server. If
  5. # your proxy server has a cache for static content, this can
  6. # save you quite a lot of download time
  7. # export http_proxy=http://10.0.1.0:3128
  8. fw_get () {
  9. wget --no-check-certificate --trust-server-names "$@"
  10. }
  11. fw_untar() {
  12. # tar xzf "$@"
  13. tar xvzf "$@"
  14. }
  15. fw_unzip() {
  16. unzip "$@"
  17. }
  18. # Was there an error for the current dependency?
  19. FW_dep_error=0
  20. # Have we seen any errors?
  21. FW_any_errors=0
  22. fw_traperror () {
  23. depend=$1
  24. err=$2 # error status
  25. line=$3 # LINENO
  26. command="$4"
  27. FW_dep_error=1
  28. FW_any_errors=1
  29. echo "ERROR: ${depend}.sh at line $line - command '$command' exited with status: $err"
  30. }
  31. # Requires dependencies to come in order e.g. Nimrod before
  32. # Jester, etc. Users should be know this
  33. # fairly well (e.g. you can't use Yaf without PHP)
  34. fw_depends() {
  35. # Turn on errtrace (-E), so that our ERR
  36. # trap is passed on to any subshells
  37. set -E
  38. for depend in "$@"
  39. do
  40. depend=$(echo $depend | awk '{print tolower($0)}')
  41. echo Searching for $depend
  42. trap 'fw_traperror $depend $? $LINENO "$BASH_COMMAND"' ERR
  43. retcode=0
  44. if [ -f ../toolset/setup/linux/systools/${depend}.sh ]; then
  45. echo Installing system tool: $depend
  46. . ../toolset/setup/linux/systools/${depend}.sh
  47. elif [ -f ../toolset/setup/linux/languages/${depend}.sh ]; then
  48. echo Installing language: $depend
  49. . ../toolset/setup/linux/languages/${depend}.sh
  50. elif [ -f ../toolset/setup/linux/webservers/${depend}.sh ]; then
  51. echo Installing webserver: $depend
  52. . ../toolset/setup/linux/webservers/${depend}.sh
  53. elif [ -f ../toolset/setup/linux/frameworks/${depend}.sh ]; then
  54. echo Installing framework: $depend
  55. . ../toolset/setup/linux/frameworks/${depend}.sh
  56. else
  57. echo WARN: No installer found for $depend
  58. continue
  59. fi
  60. # For a sourced script to pass, all internal commands must return
  61. # non-zero. If you want to intentionally cause a failed install
  62. # message, just return a non-zero status from the sourced script
  63. if [ $FW_dep_error -ne 0 ]; then
  64. echo ERROR: $depend may not be installed properly
  65. # Reset variable for the next dependencies
  66. FW_dep_error=0
  67. else
  68. echo $depend is installed!
  69. fi
  70. done
  71. # Politely clean up our trap and trace
  72. set +E
  73. trap - ERR
  74. return $FW_any_errors
  75. }
  76. # Exits 0 if file or directory exists
  77. fw_exists() {
  78. if [ -f $1 ] || [ -d $1 ]; then
  79. return 0
  80. else
  81. return 1
  82. fi
  83. }