docker-php-setting 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env bash
  2. set -o pipefail # trace ERR through pipes
  3. set -o errtrace # trace ERR through 'time command' and other functions
  4. set -o nounset ## set -u : exit the script if you try to use an uninitialised variable
  5. set -o errexit ## set -e : exit the script if any statement returns a non-true return value
  6. # Defaults
  7. PHP_INI_FILE="/opt/docker/etc/php/php.ini"
  8. PHP_VALUE_RAW=0
  9. PHP_KEY=
  10. PHP_VALUE=
  11. for arg in "$@"; do
  12. case "$arg" in
  13. --raw)
  14. PHP_VALUE_RAW=1
  15. shift
  16. ;;
  17. esac
  18. done
  19. if [[ "$#" -le 2 ]]; then
  20. echo "Usage: $(basename "$0") [--raw] <setting> <value>"
  21. exit 1
  22. fi
  23. PHP_SETTING_KEY=$1
  24. shift
  25. PHP_SETTING_VALUE="$@"
  26. if [[ "$PHP_VALUE_RAW" -eq 0 ]]; then
  27. case "$PHP_SETTING_VALUE" in
  28. ''|*[!0-9]*)
  29. # non numeric
  30. PHP_SETTING_VALUE="\"${PHP_SETTING_VALUE}\""
  31. ;;
  32. esac
  33. fi
  34. echo "$(basename "$0"): Setting php setting: ${PHP_SETTING_KEY} = ${PHP_SETTING_VALUE}"
  35. echo "${PHP_SETTING_KEY} = ${PHP_SETTING_VALUE}" >> "$PHP_INI_FILE"