#!/bin/bash # Script to install Twilio PHP SDK to an external location # This prevents SDK from being deleted when WordPress updates the plugin # # Location: wp-content/twilio-sdk/ (outside plugin folder) echo "Installing Twilio PHP SDK v8.7.0 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 if ! command -v tar &> /dev/null; then echo "ERROR: tar is required to extract the SDK" echo "Please install tar 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/twilio-sdk/ WP_CONTENT_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")" SDK_DIR="$WP_CONTENT_DIR/twilio-sdk" echo "Plugin directory: $SCRIPT_DIR" echo "SDK will be installed to: $SDK_DIR" # Create SDK directory mkdir -p "$SDK_DIR/twilio/sdk" # Download the latest release (8.7.0) echo "Downloading Twilio SDK from GitHub..." TEMP_DIR=$(mktemp -d) cd "$TEMP_DIR" if ! curl -L https://github.com/twilio/twilio-php/archive/refs/tags/8.7.0.tar.gz -o twilio-sdk.tar.gz; then echo "ERROR: Failed to download Twilio SDK" echo "Please check your internet connection and try again" rm -rf "$TEMP_DIR" exit 1 fi # Extract the archive echo "Extracting SDK files..." if ! tar -xzf twilio-sdk.tar.gz; then echo "ERROR: Failed to extract SDK files" rm -rf "$TEMP_DIR" exit 1 fi # Check if the extracted directory exists if [ ! -d "twilio-php-8.7.0/src" ]; then echo "ERROR: Extracted SDK directory structure is unexpected" rm -rf "$TEMP_DIR" exit 1 fi # Remove existing SDK if it exists if [ -d "$SDK_DIR/twilio/sdk" ]; then echo "Removing existing SDK installation..." rm -rf "$SDK_DIR/twilio/sdk" mkdir -p "$SDK_DIR/twilio/sdk" fi # Move the entire src directory to be the sdk echo "Installing SDK files..." if ! mv twilio-php-8.7.0/src/* "$SDK_DIR/twilio/sdk/"; then echo "ERROR: Failed to move SDK files" rm -rf "$TEMP_DIR" exit 1 fi # Create a comprehensive autoloader cat > "$SDK_DIR/autoload.php" << 'EOF'