122 lines
3.8 KiB
Bash
122 lines
3.8 KiB
Bash
|
|
#!/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'
|
||
|
|
<?php
|
||
|
|
/**
|
||
|
|
* AWS SDK for PHP Autoloader (External Installation)
|
||
|
|
* This file loads the AWS SDK via its bundled PHAR distribution.
|
||
|
|
*
|
||
|
|
* Location: wp-content/aws-sdk/autoload.php
|
||
|
|
* This location survives WordPress plugin updates.
|
||
|
|
*
|
||
|
|
* The aws.phar file is the official single-file build from aws/aws-sdk-php
|
||
|
|
* and ships with its own composer-generated autoloader, so all we need to
|
||
|
|
* do is require_once the PHAR itself.
|
||
|
|
*/
|
||
|
|
|
||
|
|
// Prevent multiple registrations
|
||
|
|
if (!defined('TWP_AWS_AUTOLOADER_REGISTERED')) {
|
||
|
|
define('TWP_AWS_AUTOLOADER_REGISTERED', true);
|
||
|
|
|
||
|
|
// The PHAR contains its own autoloader stub; requiring it registers
|
||
|
|
// the AWS\, Aws\, GuzzleHttp\, and supporting namespaces.
|
||
|
|
$aws_phar = __DIR__ . '/aws.phar';
|
||
|
|
if (file_exists($aws_phar)) {
|
||
|
|
require_once $aws_phar;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
EOF
|
||
|
|
|
||
|
|
# Clean up temp directory
|
||
|
|
cd "$SCRIPT_DIR"
|
||
|
|
rm -rf "$TEMP_DIR"
|
||
|
|
|
||
|
|
# Verify installation
|
||
|
|
echo ""
|
||
|
|
echo "Verifying installation..."
|
||
|
|
if [ -f "$SDK_DIR/aws.phar" ] && [ -s "$SDK_DIR/aws.phar" ] && [ -f "$SDK_DIR/autoload.php" ]; then
|
||
|
|
echo "=============================================="
|
||
|
|
echo "AWS SDK for PHP installed successfully!"
|
||
|
|
echo "=============================================="
|
||
|
|
echo ""
|
||
|
|
echo "Installation location: $SDK_DIR"
|
||
|
|
echo ""
|
||
|
|
echo "This SDK is installed OUTSIDE the plugin folder,"
|
||
|
|
echo "so it will NOT be deleted when WordPress updates the plugin."
|
||
|
|
echo ""
|
||
|
|
echo "Next steps:"
|
||
|
|
echo " 1. In WP admin, open the Twilio plugin Settings page."
|
||
|
|
echo " 2. Switch SMS provider to \"Amazon SNS\"."
|
||
|
|
echo " 3. Enter AWS Access Key, Secret Key, and Region (e.g. us-west-2)."
|
||
|
|
else
|
||
|
|
echo "Installation failed - files not found"
|
||
|
|
exit 1
|
||
|
|
fi
|