#!/usr/bin/env bash
# Script: Install PHP versions via Webuzo

install_php() {
  local version="$1"
  local output

  echo "Starting installation of ${version}..."

  # Run the command and capture output (stdout + stderr)
  output="$(webuzo --installapp "app=${version}" 2>&1)"

  if [[ "$output" == *"Done"* ]]; then
    echo "Installation of ${version} completed successfully."
    return 0
  elif [[ "$output" == *"Some error occurred"* ]]; then
    echo "An error occurred during the installation of ${version}."
    echo "Error details:"
    echo "$output"
    return 1
  else
    echo "Unexpected output received during the installation of ${version}:"
    echo "$output"
    return 1
  fi
}

# Install all current PHP versions (8.1 through 8.4)
install_php "php81"
install_php "php82"
install_php "php83"
install_php "php84"
install_php "php85"

echo
echo "PHP installation complete"
