#!/bin/bash # Script to install AWS SDK for PHP to an external location # This prevents SDK from being deleted when WordPress updates the plugin # # Location: wp-content/aws-sdk/ (outside plugin folder) # # Uses the official single-file PHAR distribution from aws/aws-sdk-php releases. # The PHAR ships its own composer-generated autoloader, so no PSR-4 wiring needed. echo "Installing AWS SDK for PHP (latest) to external location..." echo "This will install the SDK outside the plugin folder to survive plugin updates." # Check if we can download files if ! command -v curl &> /dev/null; then echo "ERROR: curl is required to download the SDK" echo "Please install curl and try again" exit 1 fi # Get the script directory (plugin directory) SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Calculate wp-content directory (two levels up from plugin) # Plugin is at: wp-content/plugins/twilio-wp-plugin/ # We want: wp-content/aws-sdk/ WP_CONTENT_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")" SDK_DIR="$WP_CONTENT_DIR/aws-sdk" echo "Plugin directory: $SCRIPT_DIR" echo "SDK will be installed to: $SDK_DIR" # Create SDK directory mkdir -p "$SDK_DIR" # Download the latest PHAR release echo "Downloading AWS SDK PHAR from GitHub..." TEMP_DIR=$(mktemp -d) cd "$TEMP_DIR" if ! curl -L https://github.com/aws/aws-sdk-php/releases/latest/download/aws.phar -o aws.phar; then echo "ERROR: Failed to download AWS SDK PHAR" echo "Please check your internet connection and try again" rm -rf "$TEMP_DIR" exit 1 fi # Verify the download is non-empty (PHAR is roughly 12 MB) if [ ! -s "$TEMP_DIR/aws.phar" ]; then echo "ERROR: Downloaded AWS SDK PHAR is empty or missing" rm -rf "$TEMP_DIR" exit 1 fi # Remove existing SDK if it exists if [ -f "$SDK_DIR/aws.phar" ]; then echo "Removing existing AWS SDK installation..." rm -f "$SDK_DIR/aws.phar" fi # Move the PHAR into place echo "Installing SDK files..." if ! mv "$TEMP_DIR/aws.phar" "$SDK_DIR/aws.phar"; then echo "ERROR: Failed to move AWS SDK PHAR into place" rm -rf "$TEMP_DIR" exit 1 fi # Create the autoloader shim cat > "$SDK_DIR/autoload.php" << 'EOF'