38 lines
1.3 KiB
Django/Jinja
38 lines
1.3 KiB
Django/Jinja
#!/bin/bash
|
|
# Lenvi Smart Composer Wrapper
|
|
# This script automatically detects the required PHP version for a project
|
|
# by looking for a `Lenvi.yaml` file and uses the correct PHP binary.
|
|
|
|
COMPOSER_PHAR="/usr/local/bin/composer.phar"
|
|
DEFAULT_PHP_BINARY="/usr/bin/php"
|
|
PHP_BINARY=""
|
|
|
|
# Find the Lenvi.yaml file by looking in parent directories
|
|
LENVI_CONFIG_FILE=""
|
|
SEARCH_DIR=$(pwd)
|
|
while [[ "$SEARCH_DIR" != "" && ! -f "$SEARCH_DIR/Lenvi.yaml" ]]; do
|
|
SEARCH_DIR=${SEARCH_DIR%/*}
|
|
done
|
|
|
|
if [[ -f "$SEARCH_DIR/Lenvi.yaml" ]]; then
|
|
LENVI_CONFIG_FILE="$SEARCH_DIR/Lenvi.yaml"
|
|
fi
|
|
|
|
if [[ -n "$LENVI_CONFIG_FILE" ]]; then
|
|
# We found a config file, now find the PHP version for the current project directory
|
|
CURRENT_PROJECT_ROOT=$(pwd)
|
|
PHP_VERSION=$(yq eval '.sites[] | select(.project_root == "'"$CURRENT_PROJECT_ROOT"'") | .php_version' "$LENVI_CONFIG_FILE")
|
|
|
|
if [[ -n "$PHP_VERSION" && -x "/usr/bin/php$PHP_VERSION" ]]; then
|
|
PHP_BINARY="/usr/bin/php$PHP_VERSION"
|
|
echo "Lenvi: Project found. Using PHP $PHP_VERSION..." >&2
|
|
fi
|
|
fi
|
|
|
|
# If no specific PHP binary was found, use the system default
|
|
if [[ -z "$PHP_BINARY" ]]; then
|
|
echo "Lenvi: No project configuration found for this directory. Using default system PHP." >&2
|
|
PHP_BINARY="$DEFAULT_PHP_BINARY"
|
|
fi
|
|
|
|
exec "$PHP_BINARY" "$COMPOSER_PHAR" "$@" |