| 123456789101112131415161718192021222324252627282930313233343536 |
- #!/usr/bin/env bash
- set -euo pipefail
- readonly PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
- readonly SOURCE_FILE="${PROJECT_ROOT}/cfg/config.ini"
- readonly TARGET_FILE="${PROJECT_ROOT}/cfg/config.bin"
- if [[ ! -f "${SOURCE_FILE}" ]]; then
- printf 'Configuration source not found: %s\n' "${SOURCE_FILE}" >&2
- exit 1
- fi
- if [[ -e "${TARGET_FILE}" ]]; then
- printf 'Configuration target already exists: %s\n' "${TARGET_FILE}" >&2
- exit 1
- fi
- cd "${PROJECT_ROOT}"
- php -r '
- require $argv[1];
- $config = file_get_contents($argv[2]);
- if ($config === false) {
- fwrite(STDERR, "Unable to read the configuration source.\n");
- exit(1);
- }
- $encodedConfig = (new \OpenMind\System\OMUtils())->Encrypt($config);
- if (file_put_contents($argv[3], $encodedConfig) === false) {
- fwrite(STDERR, "Unable to write the configuration target.\n");
- exit(1);
- }
- ' 'vendor/autoload.php' 'cfg/config.ini' 'cfg/config.bin'
- printf 'Created %s\n' "${TARGET_FILE}"
|