67 lines
2.1 KiB
Bash
Executable File
67 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
oqs_module="$root/native/third-party/liboqs-php/build/oqsphp.so"
|
|
skein_module="$root/native/third-party/php-skein/modules/skein.so"
|
|
|
|
runtime_api="$(php -i | sed -n 's/^PHP API => //p' | head -n 1)"
|
|
config_api="$(php-config --phpapi)"
|
|
if [[ -z "$runtime_api" || "$runtime_api" != "$config_api" ]]; then
|
|
echo "Active PHP and php-config use different module APIs." >&2
|
|
echo "php API: ${runtime_api:-unknown}" >&2
|
|
echo "php-config API: ${config_api:-unknown}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f "$oqs_module" || ! -f "$skein_module" ]]; then
|
|
echo "The modules have not been built. Run ./build-linux.sh first." >&2
|
|
exit 1
|
|
fi
|
|
|
|
extension_dir="$(php-config --extension-dir)"
|
|
php_version="$(php -r 'echo PHP_MAJOR_VERSION, ".", PHP_MINOR_VERSION;')"
|
|
ini_dir="/etc/php/$php_version/mods-available"
|
|
|
|
install -m 0755 "$oqs_module" "$extension_dir/oqsphp.so"
|
|
install -m 0755 "$skein_module" "$extension_dir/skein.so"
|
|
mkdir -p "$ini_dir"
|
|
printf '%s\n' 'extension=skein.so' 'extension=oqsphp.so' \
|
|
> "$ini_dir/contractless-crypto.ini"
|
|
|
|
if command -v phpenmod >/dev/null 2>&1; then
|
|
phpenmod contractless-crypto
|
|
fi
|
|
|
|
module_output="$(php -m 2>&1)"
|
|
if grep -q 'already loaded' <<<"$module_output"; then
|
|
cat >&2 <<EOF
|
|
The modules were installed, but PHP is loading them more than once.
|
|
|
|
Do not add oqsphp.so or skein.so directly to php.ini. Keep only the managed
|
|
contractless-crypto.ini configuration enabled by this installer.
|
|
|
|
Find duplicate declarations with:
|
|
grep -RniE 'extension[[:space:]]*=.*(skein|oqsphp)' /etc/php
|
|
EOF
|
|
exit 1
|
|
fi
|
|
|
|
if ! grep -qx 'skein' <<<"$module_output" || ! grep -qx 'oqsphp' <<<"$module_output"; then
|
|
echo "PHP could not load both Contractless crypto modules." >&2
|
|
exit 1
|
|
fi
|
|
|
|
php -r '
|
|
if (!function_exists("skein_hash")
|
|
|| !function_exists("contractless_shake256")
|
|
|| !class_exists("OQS_SIGNATURE")
|
|
) {
|
|
fwrite(STDERR, "Required Contractless crypto functions are unavailable.\n");
|
|
exit(1);
|
|
}
|
|
'
|
|
|
|
echo "Contractless PHP crypto modules installed and enabled for PHP $php_version."
|