#!/bin/bash # Deploy Zoho CRM integration fixes to staging server # This script deploys only the Zoho-related files to fix the CRM integration # Load environment variables source "$(dirname "$0")/../.env" # Check if environment variables are loaded if [ -z "$UPSKILL_STAGING_IP" ] || [ -z "$UPSKILL_STAGING_SSH_USER" ]; then echo "Error: Missing required environment variables" echo "Please ensure .env file exists and contains UPSKILL_STAGING_IP and UPSKILL_STAGING_SSH_USER" exit 1 fi # Set variables REMOTE_HOST="${UPSKILL_STAGING_IP}" REMOTE_USER="${UPSKILL_STAGING_SSH_USER}" REMOTE_PASS="${UPSKILL_STAGING_PASS}" REMOTE_PATH="/home/974670.cloudwaysapps.com/uberrxmprk/public_html" PLUGIN_PATH="${REMOTE_PATH}/wp-content/plugins/hvac-community-events" # Colors for output GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${YELLOW}=== Deploying Zoho CRM Integration Fixes ===${NC}" echo -e "${YELLOW}Target: ${REMOTE_USER}@${REMOTE_HOST}:${PLUGIN_PATH}${NC}" # Create backup of current Zoho files echo -e "${YELLOW}Creating backup of current Zoho files...${NC}" BACKUP_CMD="mkdir -p \"${PLUGIN_PATH}/includes/zoho-backup\" && cp -r \"${PLUGIN_PATH}/includes/zoho\" \"${PLUGIN_PATH}/includes/zoho-backup/zoho-$(date +%Y%m%d%H%M%S)\" && cp -r \"${PLUGIN_PATH}/includes/admin/class-zoho-admin.php\" \"${PLUGIN_PATH}/includes/zoho-backup/class-zoho-admin-$(date +%Y%m%d%H%M%S).php\" && cp -r \"${PLUGIN_PATH}/assets/js/zoho-admin.js\" \"${PLUGIN_PATH}/includes/zoho-backup/zoho-admin-$(date +%Y%m%d%H%M%S).js\" && cp -r \"${PLUGIN_PATH}/assets/css/zoho-admin.css\" \"${PLUGIN_PATH}/includes/zoho-backup/zoho-admin-$(date +%Y%m%d%H%M%S).css\"" sshpass -p "$REMOTE_PASS" ssh -o StrictHostKeyChecking=no "$REMOTE_USER@$REMOTE_HOST" "$BACKUP_CMD" if [ $? -ne 0 ]; then echo -e "${RED}Error: Failed to create backup. Aborting.${NC}" exit 1 fi echo -e "${GREEN}Backup created successfully.${NC}" # Deploy Zoho integration files echo -e "${YELLOW}Deploying Zoho CRM integration files...${NC}" # Create temporary directory for the files to deploy TMP_DIR=$(mktemp -d) mkdir -p "${TMP_DIR}/zoho" mkdir -p "${TMP_DIR}/admin" mkdir -p "${TMP_DIR}/assets/js" mkdir -p "${TMP_DIR}/assets/css" # Copy the files we want to deploy to the temporary directory cp "$(dirname "$0")/../wordpress/wp-content/plugins/hvac-community-events/includes/zoho/check-permissions.php" "${TMP_DIR}/zoho/" cp "$(dirname "$0")/../wordpress/wp-content/plugins/hvac-community-events/includes/zoho/diagnostics.php" "${TMP_DIR}/zoho/" cp "$(dirname "$0")/../wordpress/wp-content/plugins/hvac-community-events/includes/zoho/class-zoho-crm-auth.php" "${TMP_DIR}/zoho/" cp "$(dirname "$0")/../wordpress/wp-content/plugins/hvac-community-events/includes/admin/class-zoho-admin.php" "${TMP_DIR}/admin/" cp "$(dirname "$0")/../wordpress/wp-content/plugins/hvac-community-events/assets/js/zoho-admin.js" "${TMP_DIR}/assets/js/" cp "$(dirname "$0")/../wordpress/wp-content/plugins/hvac-community-events/assets/css/zoho-admin.css" "${TMP_DIR}/assets/css/" cp "$(dirname "$0")/check-zoho-env.php" "${TMP_DIR}/" # Create deployment script to modify zoho-config.php on the server cat > "${TMP_DIR}/patch-zoho-config.php" << 'EOF' "${TMP_DIR}/run-deploy.sh" << 'EOF' #!/bin/bash # Copy files to their correct locations cp zoho/* /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/includes/zoho/ cp admin/* /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/includes/admin/ cp assets/js/* /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/assets/js/ cp assets/css/* /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/assets/css/ cp check-zoho-env.php /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/ # Run the config patcher php patch-zoho-config.php # Set permissions chmod 755 /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/includes/zoho/check-permissions.php chmod 755 /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/includes/zoho/diagnostics.php chmod 644 /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/includes/zoho/class-zoho-crm-auth.php chmod 644 /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/includes/admin/class-zoho-admin.php chmod 644 /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/assets/js/zoho-admin.js chmod 644 /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/assets/css/zoho-admin.css chmod 755 /home/974670.cloudwaysapps.com/uberrxmprk/public_html/wp-content/plugins/hvac-community-events/check-zoho-env.php # Clear cache wp cache flush --path=/home/974670.cloudwaysapps.com/uberrxmprk/public_html echo "Deployment completed successfully!" EOF chmod +x "${TMP_DIR}/run-deploy.sh" # Upload the files echo -e "${YELLOW}Uploading files to staging server...${NC}" sshpass -p "$REMOTE_PASS" scp -r -o StrictHostKeyChecking=no "${TMP_DIR}/"* "$REMOTE_USER@$REMOTE_HOST:~/" if [ $? -ne 0 ]; then echo -e "${RED}Error: Failed to upload files. Aborting.${NC}" rm -rf "${TMP_DIR}" exit 1 fi # Execute the deployment script on the server echo -e "${YELLOW}Executing deployment script on server...${NC}" sshpass -p "$REMOTE_PASS" ssh -o StrictHostKeyChecking=no "$REMOTE_USER@$REMOTE_HOST" "chmod +x ~/run-deploy.sh && ~/run-deploy.sh" if [ $? -ne 0 ]; then echo -e "${RED}Error: Deployment script failed. Check server logs for details.${NC}" rm -rf "${TMP_DIR}" exit 1 fi # Clean up rm -rf "${TMP_DIR}" echo -e "${GREEN}=== Zoho CRM integration fixes deployed successfully! ===${NC}" echo -e "${YELLOW}You can now test the connection in the WordPress admin panel.${NC}" echo -e "${YELLOW}If issues persist, check the logs at: ${PLUGIN_PATH}/includes/logs/zoho-debug.log${NC}" echo -e "${YELLOW}Or run the diagnostic tool at: ${REMOTE_PATH}/wp-content/plugins/hvac-community-events/includes/zoho/diagnostics.php?run_diagnostics=true${NC}" exit 0