diff --git a/__tests__/config.test.ts b/__tests__/config.test.ts index e5b490c1..2ef92613 100644 --- a/__tests__/config.test.ts +++ b/__tests__/config.test.ts @@ -24,7 +24,7 @@ describe('Config tests', () => { true ); expect(linux).toContain( - 'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata"' + 'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata" | sudo tee -a "${ini_file[@]}"' ); linux = await config.addINIValues( @@ -40,7 +40,7 @@ describe('Config tests', () => { 'darwin' ); expect(darwin).toContain( - 'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata"' + 'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata" | sudo tee -a "${ini_file[@]}"' ); darwin = await config.addINIValues( diff --git a/dist/index.js b/dist/index.js index d1e7328c..fc323c29 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2461,7 +2461,10 @@ async function addINIValuesUnix(ini_values_csv) { script += '\n' + (await utils.addLog('$tick', line, 'Added to php.ini', 'linux')); }); - return 'echo "' + ini_values.join('\n') + '" >> $ini_file' + script; + return ('echo "' + + ini_values.join('\n') + + '" | sudo tee -a "${ini_file[@]}" >/dev/null 2>&1' + + script); } exports.addINIValuesUnix = addINIValuesUnix; /** diff --git a/src/config.ts b/src/config.ts index 6f25b367..c1a97128 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,7 +14,12 @@ export async function addINIValuesUnix( script += '\n' + (await utils.addLog('$tick', line, 'Added to php.ini', 'linux')); }); - return 'echo "' + ini_values.join('\n') + '" >> $ini_file' + script; + return ( + 'echo "' + + ini_values.join('\n') + + '" | sudo tee -a "${ini_file[@]}" >/dev/null 2>&1' + + script + ); } /** diff --git a/src/scripts/common.sh b/src/scripts/common.sh index e29e550a..6a8741eb 100644 --- a/src/scripts/common.sh +++ b/src/scripts/common.sh @@ -106,7 +106,7 @@ enable_extension() { sudo phpenmod -v "$version" "$1" >/dev/null 2>&1 fi if ! check_extension "$1" && [ -e "${ext_dir:?}/$1.so" ]; then - echo "$2=${ext_dir:?}/$1.so" >>"${pecl_file:-$ini_file}" + echo "$2=${ext_dir:?}/$1.so" >>"${pecl_file:-${ini_file[@]}}" fi } @@ -114,7 +114,7 @@ enable_extension() { configure_pecl() { if ! [ -e /tmp/pecl_config ] && command -v pecl >/dev/null && command -v pear >/dev/null; then for script in pear pecl; do - sudo "$script" config-set php_ini "${pecl_file:-$ini_file}" + sudo "$script" config-set php_ini "${pecl_file:-${ini_file[@]}}" sudo "$script" channel-update "$script".php.net done echo '' | sudo tee /tmp/pecl_config >/dev/null 2>&1 diff --git a/src/scripts/ext/blackfire.sh b/src/scripts/ext/blackfire.sh index 58d11139..027e7c5c 100644 --- a/src/scripts/ext/blackfire.sh +++ b/src/scripts/ext/blackfire.sh @@ -5,7 +5,7 @@ add_blackfire() { no_dot_version=${version/./} platform=$(uname -s | tr '[:upper:]' '[:lower:]') extension_version=$(echo "$extension" | cut -d '-' -f 2) - blackfire_ini_file="${scan_dir:?}/50-blackfire.ini" + blackfire_ini_file="${pecl_file:-${ini_file[@]}}" if [ ! -e "${ext_dir:?}/blackfire.so" ]; then if [ "$extension_version" = "blackfire" ]; then extension_version=$(get -s -n "" https://blackfire.io/api/v1/releases | grep -Eo 'php":"([0-9]+.[0-9]+.[0-9]+)' | cut -d '"' -f 3) diff --git a/src/scripts/ext/phalcon.sh b/src/scripts/ext/phalcon.sh index 8c011e15..b11fb7a4 100644 --- a/src/scripts/ext/phalcon.sh +++ b/src/scripts/ext/phalcon.sh @@ -9,7 +9,6 @@ add_phalcon_helper() { ${apt_install:?} "php${version:?}-$extension" fi else - phalcon_ini_file=${ini_file:?} sed -i '' '/extension.*psr/d' "${ini_file:?}" brew tap shivammathur/homebrew-phalcon brew install phalcon@"${version:?}"_"$extension_major_version" @@ -29,7 +28,7 @@ add_phalcon3() { fi else add_phalcon_helper - fi + fi } # Function to add phalcon4. @@ -50,7 +49,7 @@ add_phalcon4() { fi else add_phalcon_helper - fi + fi } # Function to add phalcon. @@ -58,7 +57,7 @@ add_phalcon() { extension=$1 status='Enabled' os_name=$(uname -s) - phalcon_ini_file="${scan_dir:?}/50-phalcon.ini" + phalcon_ini_file="${pecl_file:-${ini_file[@]}}" extension_major_version=${extension: -1} if [ "$extension_major_version" = "4" ]; then add_phalcon4 >/dev/null 2>&1 diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index bd64e47d..6cedcb42 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -48,9 +48,9 @@ install_packages() { # Function to delete extensions. delete_extension() { extension=$1 - sudo sed -Ei "/=(.*\/)?\"?$extension/d" "${ini_file:?}" - sudo sed -Ei "/=(.*\/)?\"?$extension/d" "${pecl_file:?}" - sudo rm -rf "${scan_dir:?}"/*"$extension"* "${ext_dir:?}"/"$extension".so >/dev/null 2>&1 + sudo sed -Ei "/=(.*\/)?\"?$extension/d" "${ini_file[@]}" + sudo sed -Ei "/=(.*\/)?\"?$extension/d" "$pecl_file" + sudo rm -rf "$scan_dir"/*"$extension"* "$ext_dir"/"$extension".so >/dev/null 2>&1 if [ "${runner:?}" = "self-hosted" ]; then $apt_remove "php-$extension" "php$version-$extension" >/dev/null 2>&1 || true fi @@ -79,14 +79,16 @@ add_pdo_extension() { if check_extension "$pdo_ext"; then add_log "${tick:?}" "$pdo_ext" "Enabled" else - ext=$1; ext_name=$1; + ext=$1 + ext_name=$1 sudo rm -rf "$scan_dir"/*pdo.ini >/dev/null 2>&1 - if ! check_extension "pdo" 2>/dev/null; then echo "extension=pdo.so" >>"$ini_file"; fi + if ! check_extension "pdo" 2>/dev/null; then echo "extension=pdo.so" | sudo tee -a "${ini_file[@]}"; fi if [ "$ext" = "mysql" ]; then enable_extension "mysqlnd" "extension" ext_name="mysqli" elif [ "$ext" = "sqlite" ]; then - ext="sqlite3"; ext_name="sqlite3"; + ext="sqlite3" + ext_name="sqlite3" fi add_extension "$ext_name" "extension" >/dev/null 2>&1 add_extension "$pdo_ext" "extension" >/dev/null 2>&1 @@ -111,7 +113,7 @@ add_extension() { fi add_extension_log "$extension" "Installed and enabled" fi - sudo chmod 777 "$ini_file" + sudo chmod 777 "${ini_file[@]}" } # Function to install a PECL version. @@ -191,7 +193,7 @@ switch_version() { for tool in pear pecl php phar phar.phar php-cgi php-config phpize phpdbg; do if [ -e "/usr/bin/$tool$version" ]; then sudo update-alternatives --set $tool /usr/bin/"$tool$version" & - to_wait+=( $! ) + to_wait+=($!) fi done wait "${to_wait[@]}" @@ -232,6 +234,15 @@ add_php() { status="Installed" } +# Function to ini file for pear and link it to each SAPI. +link_pecl_file() { + echo '' | sudo tee "$pecl_file" >/dev/null 2>&1 + for file in "${ini_file[@]}"; do + sapi_scan_dir="$(realpath -m "$(dirname "$file")")/conf.d" + [ "$sapi_scan_dir" != "$scan_dir" ] && ! [ -h "$sapi_scan_dir" ] && sudo ln -sf "$pecl_file" "$sapi_scan_dir/99-pecl.ini" + done +} + # Function to Setup PHP setup_php() { step_log "Setup PHP" @@ -259,11 +270,12 @@ setup_php() { semver=$(php_semver) ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||") scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||") - ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") + ini_dir=$(php --ini | grep "(php.ini)" | sed -e "s|.*: s*||") pecl_file="$scan_dir"/99-pecl.ini - echo '' | sudo tee "$pecl_file" >/dev/null 2>&1 + mapfile -t ini_file < <(sudo find "$ini_dir/.." -name "php.ini" -exec readlink -m {} +) + link_pecl_file sudo rm -rf /usr/local/bin/phpunit >/dev/null 2>&1 - sudo chmod 777 "$ini_file" "$pecl_file" "${tool_path_dir:?}" + sudo chmod 777 "${ini_file[@]}" "$pecl_file" "${tool_path_dir:?}" sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/" add_log "${tick:?}" "PHP" "$status PHP $semver" }