generate-config-bin.sh 964 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. readonly PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
  4. readonly SOURCE_FILE="${PROJECT_ROOT}/cfg/config.ini"
  5. readonly TARGET_FILE="${PROJECT_ROOT}/cfg/config.bin"
  6. if [[ ! -f "${SOURCE_FILE}" ]]; then
  7. printf 'Configuration source not found: %s\n' "${SOURCE_FILE}" >&2
  8. exit 1
  9. fi
  10. if [[ -e "${TARGET_FILE}" ]]; then
  11. printf 'Configuration target already exists: %s\n' "${TARGET_FILE}" >&2
  12. exit 1
  13. fi
  14. cd "${PROJECT_ROOT}"
  15. php -r '
  16. require $argv[1];
  17. $config = file_get_contents($argv[2]);
  18. if ($config === false) {
  19. fwrite(STDERR, "Unable to read the configuration source.\n");
  20. exit(1);
  21. }
  22. $encodedConfig = (new \OpenMind\System\OMUtils())->Encrypt($config);
  23. if (file_put_contents($argv[3], $encodedConfig) === false) {
  24. fwrite(STDERR, "Unable to write the configuration target.\n");
  25. exit(1);
  26. }
  27. ' 'vendor/autoload.php' 'cfg/config.ini' 'cfg/config.bin'
  28. printf 'Created %s\n' "${TARGET_FILE}"