#!/usr/bin/bash
# shellcheck disable=SC2317  # Don't warn about unreachable commands in this file
# WP Optimize script v2.030723
Red=$'\e[1;31m';
Green=$'\e[1;32m';
Clear=$'\e[0m';
sdt="$(date +%F_%H-%M-%S)";
hostname="$(hostname)"
# getting pre-defined variable for testing
logs="$(pwd)"
echo "logs =$logs"
agent="$(logname)"
echo "agent=$agent"
if [ "$EUID" -ne 0 ]
  then echo "You need to run this via sudo, you are currently running it as $me"
  exit
fi
# Need to fix up this code below needs to be logic flow If has Ls ok, is the host shared if and an Epyic ok, if shared not on epyc then exit with error; otherwise continue
if [[ $hostname == *.a2hosting.* || $hostname == *.supercp.* ]];then
  if [[ $hostname =~ .*-ts.* ]] || [[ $hostname =~ .*-tr.* ]];then
        echo "Verified this is an EPYC server, proceeding"
    else
      echo "This can only be ran on EPYC servers. Exiting" 
     exit
  fi
elif [[ -z "$(ps aux | grep litespeed)" ]];then
  echo 'Warning! This server is not running LiteSpeed. Please be sure the acount is Turbo and that LiteSpeed is installed and running. Stopping optimization...'
  exit 0;
else
  echo "Verified this is an Turbo server, proceeding"
fi
# End of block
# get manual variable
clear -x;
echo "$Green ********************* A2 LSCWP OPT SCRIPT *********************$Clear"
echo "$Green ********************Get Prepared************************************* $Clear";
echo "$Green Note: YOU MAY WANT TO START THIS IN A SCREEN $Clear"
echo "Open a browser and preload the following tabs:";
echo "    *Optimization Ticket";
echo "    *WHMCS to the CXs page";
echo "    *cPanel for the account";
echo "    *WordPress Admin area for site being optimized";
echo "    *Home Page for the site in an ICOGNITO window";
echo "    https://gtmetrix.com/";
echo "    https://pagespeed.web.dev/";
echo " Prepare for takeoff!!!!"
read -r -p "Enter Domain Name: " DOMAIN;
clear -x;
if [[ -z "$(grep ^"$DOMAIN:" /etc/userdomains)" ]];then
  echo "Domain $DOMAIN does not exist on this server."
  exit 0;
fi
read -r -p "Enter Ticket URL: " tixURL;
read -r -p "Enter WHM URL: " whmURL;
read -r -p "Enter Prodcut ID: " ProductID;
read -r -p "Enter Slack Name: " slackNAME;

echo "";
echo "Did the Sales Department send the disclaimer and the customer agreed? ";
PS3="Pick the appropriate # for the response:  "
select agreeDisc in yes no override quit; do

  case $agreeDisc in
    yes)
      agreeDisc=1
      break
      ;;
    no)
      agreeDisc=0
      exit

      ;;
    override)
      agreeDisc=2
      break
      ;;
    quit)
      exit 0
      ;;
    *) 
      echo "Invalid option $REPLY"
      ;;
  esac
done
echo "";
echo "Was the Google form link Email sent and has the Customer replied? ";

select firstWPOPTemail in yes no override quit; do

  case $firstWPOPTemail in
    yes)
      firstWPOPTemail=1
      break
      ;;
    no)
      firstWPOPTemail=0
      exit 0

      ;;
    override)
      firstWPOPTemail=2
      break
      ;;
    quit)
      exit 0
      ;;
    *) 
      echo "Invalid option $REPLY"
      ;;
  esac
done
clear -x;
#### Initial Clean up of possible log files and markers- Start Fresh###
test -f /home/"$agent"/"$DOMAIN".log.txt && rm -f /home/"$agent"/"$DOMAIN".log.txt
test -f /home/"$agent"/"$DOMAIN".cx.txt && rm -f /home/"$agent"/"$DOMAIN".cx.txt
test -f /home/"$agent"/"$DOMAIN".userdomainsort.txt && rm -f /home/"$agent"/"$DOMAIN".userdomainsort.txt
test -f /home/"$agent"/"$DOMAIN".header.txt && rm -f /home/"$agent"/"$DOMAIN".header.txt
test -f /home/"$agent"/"$DOMAIN"-way-pass-variables.txt && rm -f /home/"$agent"/"$DOMAIN"-way-pass-variables.txt
test -f /home/"$CPUSER"/way-pass-variables.txt && rm -f /home/"$CPUSER"/way-pass-variables.txt
test -f /home/"$agent"/"$DOMAIN".plugin.txt && rm -f /home/"$agent"/"$DOMAIN".plugin.txt
test -f /home/"$agent"/"$DOMAIN".theme.txt && rm -f /home/"$agent"/"$DOMAIN".theme.txt
test -f /home/"$agent"/"$DOMAIN".cp.log.txt && rm -f /home/"$agent"/"$DOMAIN".cp.log.txt
test -f /home/"$agent"/"$DOMAIN".cp.cx.log.txt && rm -f /home/"$agent"/"$DOMAIN".cp.cx.log.txt
test -f /home/"$agent"/way-pass-back-variables.txt && rm -f /home/"$agent"/way-pass-back-variables.txt
test -f /home/"$agent"/"$DOMAIN".summary.txt && rm -f /home/"$agent"/"$DOMAIN".summary.txt
test -f /home/"$agent"/"$DOMAIN".audit.txt && rm -f /home/"$agent"/"$DOMAIN".audit.txt
test -f /home/"$CPUSER"/"$DOMAIN".plugin.txt && rm -f /home/"$CPUSER"/"$DOMAIN".plugin.txt
test -f /home/"$CPUSER"/"$DOMAIN".theme.txt && rm -f /home/"$CPUSER"/"$DOMAIN".theme.txt
test -f /home/"$CPUSER"/"$DOMAIN".home.txt && rm -f /home/"$CPUSER"/"$DOMAIN".home.txt
test -f /home/"$CPUSER"/"$DOMAIN".siteurl.txt && rm -f /home/"$CPUSER"/"$DOMAIN".siteurl.txt
test -f /home/"$CPUSER"/"$DOMAIN".cp.log.txt && rm -f /home/"$CPUSER"/"$DOMAIN".cp.log.txt
test -f /home/"$CPUSER"/"$DOMAIN".cp.cx.log.txt && rm -f /home/"$CPUSER"/"$DOMAIN".cp.cx.log.txt
test -d /home/"$CPUSER"/.wp-opt/"$DOMAIN"/ && rm -f /home/"$CPUSER"/.wp-opt/"$DOMAIN"/*.*
#### End Initial Clean up of possible log files and markers- Start Fresh###
#### Set-up Log Files ####
touch /home/"$agent"/"$DOMAIN".log.txt
touch /home/"$agent"/"$DOMAIN".cx.txt
touch /home/"$agent"/"$DOMAIN".summary.txt
touch /home/"$agent"/"$DOMAIN".audit.txt
#### End Set-up Log Files ####
# shellcheck source=/dev/null
source /opt/wp-optimize/opt-init-variables.txt
#define other variables
echo "Collect cPanel and site header variables $Clear";
# create text files for logs and analizing the header
HOMEDIR=$(grep ^"$DOMAIN": /etc/userdatadomains|awk -F'==' '{print $5}');
echo "Home directory for the domain: $HOMEDIR" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
CPUSER=$( grep ^"$DOMAIN" /etc/userdatadomains|awk '{print $2}'| awk -F'==' '{print $1}');
echo "cPanel username: $CPUSER" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
IPADDRESS=$( grep ^"$DOMAIN" /etc/userdatadomains|awk -F'==' '{print $6}'|sed 's/:80//');
echo "IP address of the site is: $IPADDRESS" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
#create marker directory
test -d /home/"$CPUSER"/.wp-opt || mkdir /home/"$CPUSER"/.wp-opt
test -d /home/"$CPUSER"/.wp-opt/"$DOMAIN" || mkdir /home/"$CPUSER"/.wp-opt/"$DOMAIN"
chown -R "$CPUSER" /home/"$CPUSER"/.wp-opt
#add code later to check for existing makers and make sure have info
echo "$Green *******************Pre Optimized Tests************" | tee /home/"$agent"/"$DOMAIN".log.txt;
echo "Pre-optimization data, this stage gathers data and establishes a baseline 
for the current performance of the site. We ask that you use GTmetrix to establish 
the two performance metrics of TTFB (Time to first Byte) and FLT (Fully Loaded Time). 
Additionally use Google Pagespeed Insights to record a general 
*Performance Score*, FCP (First Contentful Paint), and LCP (Largest Contentful Paint) $Clear";
echo "==============================================================================";

echo "Domain: $DOMAIN" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
echo "$Red ENTER ALL TIMES IM MS (MILLASECONDS 1,000 ms = 1 sec) $Clear";
echo "GTmetrx" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter TTFB: " preTTFB;
echo "Pre-Opt TTFB was $preTTFB ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter FLT: " preFLT;
echo "Pre-Opt FLT was $preFLT ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
echo "PageSpeed Mobile Scores" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Mobile FCP: " mpreFCP; 
echo "Pre-Opt Mobile FCP was $mpreFCP ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Mobile LCP: " mpreLCP; 
echo "Pre-Opt Mobile LCP was $mpreLCP ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Mobile Performance Score: " mpreSCORE; 
echo "Pre-Opt Mobile Performance Score was $mpreSCORE  " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
echo "PageSpeed Dsktop Scores" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Desktop FCP: " dtpreFCP; 
echo "Pre-Opt Desktop FCP was $dtpreFCP ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Desktop LCP: " dtpreLCP; 
echo "Pre-Opt Desktop LCP was $dtpreLCP ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Desktop Performance Score: " dtpreSCORE; 
echo "Pre-Opt Desktop Performance Score was $dtpreSCORE  " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Press enter to continue";
clear -x;
echo "$Green**************A2 LSCWP Optimization Script: Part 2 **************";

clear -x;
echo "$Green **************A2 LSCWP Optimization Script: Part 3**************";
echo "Check for proper directory structure $Clear";
echo "cPanels direcotry structure";
echo "cPanel has the home direcotry of the wordpress install as $HOMEDIR" | tee /home/"$agent"/"$DOMAIN".cx.txt 
grep "$CPUSER"  /etc/userdatadomains | awk '{print $2}' | awk -F'==' '{print $5 "     " $4 " "}'| sort > /home/"$agent"/"$DOMAIN".userdomainsort.txt;
pdir=${HOMEDIR%/*}; echo "$pdir is the parent directory";
echo "$pdir";
searchpdir="${pdir} ";
if [ "$pdir" == "/home/$CPUSER" ]; then
  NEEDCHECKpdir=0;
  DOsearchpdir=0;
  echo "The parent directoy of the home directory of $HOMEDIR is $pdir.  This is the cPanel user home directory.  Proper directory structure." | tee -a /home/"$agent"/"$DOMAIN".cx.txt;
  else NEEDCHECKpdir=1;
    searchpdir="${pdir} ";
    DOsearchpdir=1;
fi;
if [ "$(< /home/"$agent"/"$DOMAIN".userdomainsort.txt grep -c "$searchpdir")" -gt 0 ] && [ "$DOsearchpdir" -ne 0 ]; then
  pdomain="$(< /home/"$agent"/"$DOMAIN".userdomainsort.txt grep "$searchpdir"  | awk '{print $2}')" ;  
  NEEDCHECKpdir=1;  
  # echo "$NEEDCHECKpdir"
  echo "$Red The parent directory of the home directory of $HOMEDIR is $pdir. 
  cPanel says that the parent directory is the home direcotry for $pdomain.  
  This will cause erratic behavior to $DOMAIN due to the recursive nature of htaccess. 
   You will need move your Wordpress installation from $HOMEDIR to /home/$CPUSER/$DOMAIN $Clear" | tee -a /home/"$agent"/"$DOMAIN".cx.txt ;

  else NEEDCHECKpdir=0;
    echo "The parent directory of the home directory of $HOMEDIR is $pdir. cPanel says that the parent directory is NOT the home direcotry for another domain. Proper directory structure." | tee -a /home/"$agent"/"$DOMAIN".log.txt  
/home/"$agent"/"$DOMAIN".cx.txt ;
fi;
read -r -p "Press enter to continue";
clear -x
echo "$Green **************A2 LSCWP Optimization Script: Part 4************** $Clear" | tee -a /home/"$agent"/"$DOMAIN".log.txt ;
echo "Check Headers" | tee -a /home/"$agent"/"$DOMAIN".log.txt ;
# check to see if header contains CF-Cache-Satus.  If so the Cloudflaire is integrated.
# if CFCS is 1 and CFAPIinfoNeed is 1 then we need to add the API infor to LSCWP
curl -ILH "Accept: text/javascript, text/html, application/xml, */*" --head "$DOMAIN" |  tee /home/"$agent"/"$DOMAIN".header.txt
if [ "$(</home/"$agent"/"$DOMAIN".header.txt grep -c "CF-Cache-Status:")" -gt 0 ]; then
  CFCS=1; 
  echo "$Red The header indicates that Cloudflare is integreated $Clear"  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  else CFCS=0;
  echo "The header indicates that Cloudflare is NOT integreated $CFCS "  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
fi;

# check to see if header contains CF-Cache-Satus HITS.  If so the Cloudflaire is integrated.
# if CFCSH is 1 idicated the CF is not in Developer Mode or turned off
if [ "$(< /home/"$agent"/"$DOMAIN".header.txt grep -c "CF-Cache-Status: HIT")" -gt 0 ]; then
  CFCSH=1;
  echo "$Red The header indicates that the content was served from the Cloudflare cache amd is not in Dev Mode $Clear" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  else CFCSH=0;
  echo "The header indicates that the content was NOT served from the Cloudflare cache $CFCSH" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
fi;

# check to see if header contains cf-edge-cache.  If so then the CloudFlare WordPress plugin may be installed. We will uninstall once we get API info.
# if CFEC is 1 then the CX has the QP CF plugin installed so we need to be fure we have the API info so CFAPIinfoNeed is set to 1

if [ "$(< /home/"$agent"/"$DOMAIN".header.txt grep -c "cf-edge-cache:")" -gt 0 ]; then
  CFEC=1;
  echo "$Red The header indicates that the Clouflaire Plugin for WordPress is installed but not activated $Clear" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  else CFEC=0; 
  echo "The header indicates that the Clouflaire Plugin for WordPress is NOT installed" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
fi;

# check to see if header contains cf-edge-cache: cache,platform=wordpress.  If so then the CloudFlare WordPress plugin is installed, active and configured. We will uninstall once we get API info.
# if CFECCPWP is 1 it indicated that the Wp CF plugin in integrated and actived.  So once again we set CFAPIinfoNeed to 1 to make sure we get the So we can continuw whne we receive it
if [ "$(< /home/"$agent"/"$DOMAIN".header.txt grep -c "cf-edge-cache: cache,platform=wordpress")" -gt 0 ]; then
  CFECCPWP=1; 
  echo "$Red The header indicates that the Clouflaire Plugin for WordPress is definitly installed and activated $Clear" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  else CFECCPWP=0;
  echo "The header indicates that the Clouflaire Plugin for WordPress may not be activated $CFECCPWP" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
fi;
# check to see if header contains Server: cloudflare.  This if fine as long as it is the free plan and API info is given to us by CX.

if [ "$(< /home/"$agent"/"$DOMAIN".header.txt grep -c "Server: cloudflare")" -gt 0 ]; then
  SERVERCF=1;
  echo "$Red The header indicates that the site is being proxied through CF $Clear" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  else SERVERCF=0;
  echo "The header indicates that the site is NOT being proxied trhrough CF $SERVERCF" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
fi;

# check to see if header contains cf-apo-via.  If so then APO may be integrated. Need to make sure the customer has turned off and gone to free plan.
# if CFAVis 1 and APOinfoNeed is 1 it means that APO is on the account and we have to make sure the CX turned it off

array=( CFCSH CFCS CFEC CFECCPWP SERVERCF )
CFapiTotal=$(IFS=+; echo "$((${array[*]}))")
echo "$CFapiTotal"
if [ "$CFapiTotal" -gt 0 ]; then
	CFAPIinfoNeed=1;
fi;

if [ "$(< /home/"$agent"/"$DOMAIN".header.txt grep -c "cf-apo-via:")" -gt 0 ]; then
  CFAV=1; 
  echo "$Red The header indicates that APO was in use $Clear" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  else CFAV=0; 
  echo "The header indicates that APO was NOT in use $CFAV" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
fi;

# check to see if header contains cf-apo-via: tcache.  If so then APO is integrated and active. customer will need to turn off and go to free plan."
# if  is 1 tells us that the site is untilizing APO for contet and because APOinfoNeed is 1 the CX has not imformed us yet; if APOinfoNeed was 0 then the CX sqaid it was utned of but it was not

if [ "$(< /home/"$agent"/"$DOMAIN".header.txt grep -c "cf-apo-via: tcache")" -gt 0 ]; then
  CFAVT=1;
  echo "$Red The header indicates that APO status for delivery of this page was ON $Clear" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  else CFAVT=0;
  echo "The header indicates that APO status for delivery of this page was OFF" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
fi;

arrayy=( CFAV CFAVT )
cfAPOTotal=$(IFS=+; echo "$((${arrayy[*]}))")
echo "$cfAPOTotal"
if [ "$cfAPOTotal" -gt 0 ] ; then
	APOinfoNeed=1;
fi;

# Do a quick check to see if Sucuri is installed.
# if SERVERSUCURI is 1 it means that Sucuri is being used so we set SUinfoNeed to one so we get info to ingrate or the CX has integrated


if [ "$(< /home/"$agent"/"$DOMAIN".header.txt grep -c "Server: Sucuri")" -gt 0 ]; then
  SERVERSUCURI=1;
  SUinfoNeed=1;
  echo "$Red The header indicates that Sucuri WAF is being Used $SERVERSUCURI $Clear" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
fi;


# if the CX gives us the CFA API info we need to enter it and if so we will set CFAPIinfoNeed to 0 so we know we have it and have entered in the info
if [ "$CFAPIinfoNeed" = 1 ]; then
  echo "The CX is using Cloudflare." | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "Did the Cx provide the CFG API Info, CF email and Global API Key" | tee -a /home/"$agent"/"$DOMAIN".log.txt; 
  select yn in "Yes" "No"; do
    case $yn in 
      Yes ) read -r -p "Enter eamil adress used for CF API: " CFAPIemail;
        read -r -p "Enter Global API Key: " CFAPIkey; 
        CFAPIinfoNeed=0;
	      echo "$CFAPIemail $CFAPIkey";
        echo "Cx has supplied the CF API Info" | tee -a /home/"$agent"/"$DOMAIN".log.txt; 
	      CFgotAPI=1;
      break;;
      No ) echo "Cx has NOT supplied API Info" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
        echo "In our preliminary check, the headers for the webpages inform us that Cloudflare is proxy for the site. We need to let the LiteSpeed Cache for WordPress to be able to control Cloudflare.  It must be controlled through the LiteSpped plugin 
and not via a Cloudflare plugin.  We will need the following API information: the email address used at Cloudflare and the API Key. check here form more information https://blog.litespeedtech.com/2018/01/17/cloudflare-management-lscache/  under the 
Setting it Up section." |  tee -a /home/"$agent"/"$DOMAIN".cx.txt; 
      break;;
    esac
  done;
fi;

# if CF APO is intalled we need to make sure it is turned off so will start tracking by setting APOinfoNeed to 1
if [ "$APOinfoNeed" = 1 ]; then
  echo "The CX is/was using APO" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "Did the Cx say they disabled APO" | tee -a /home/"$agent"/"$DOMAIN".log.txt; 
  select yn in "Yes" "No"; do
    case $yn in 
      Yes ) echo "Cx said disabled APO" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
        APOinfoNeed=0;
        if [ "$CFAVT" = 1 ]; then
          APOinfoNeed=1;
          echo "The headers for your webpages reveal that APO is still active and integrated on your website, even though you say you have disabled them.  Maybe disable is the wrong term to use here.  APO is included for free with the paid plan or as an 
addon to the free plan.  You need to cancel any paid plan or paid add-on at Cloudflare.  You should be running just the free plan." | tee -a /home/"$agent"/"$DOMAIN".cx.txt;
        else APOinfoNeed=0;
          echo "Cx says they have disabled APO." | tee -a /home/"$agent"/"$DOMAIN".log.txt;
        fi;
      break;;
      No ) APOinfoNeed=1;
        echo "Cx has NOT supplied APO info " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
        echo "APO offered by Cloudflare conficts with any cache system that also optimizes the js or CSS. The headers for your webpages reveal that APO is integrated on your website. APO is included for free with the paid plan or as an addon to the free 
plan.  You need to cancel any paid plan or paid add-on at Cloudflare.  You should be running just the free plan. Please let us know when this is done." | tee -a /home/"$agent"/"$DOMAIN".cx.txt ; 
      break;;
    esac
  done;
fi;
# we need to find out if susuri is through a2 Hosting  and set SUCURIa2 to 1 or another provider and set it to 0
SUCURIa2=0;
if [ "$SUinfoNeed" = 1 ]; then 
  echo "Cx is using Sucuri" | tee -a /home/"$agent"/"$DOMAIN".log.txt; 
  echo "Is the Sucuri Service through A2 Hosting?"
  select yn in "Yes" "No"; do
    case $yn in 
      Yes ) echo "Sucuri is through A2 Hosting" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
        SUCURIa2=1; 
      break;;
      No ) SUCURIa2=0; 
        echo "CX will need to get Sucuri configured by provider." | tee -a /home/"$agent"/"$DOMAIN".log.txt; 
      break;;
    esac
  done;
fi;

if [ "$SUinfoNeed" = 1 ]; then 
  echo "Cx is using Sucuri "  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "Has Sucuri been configured to work with LSCWP. The IPs for LS have added to Sucuri, we have a link to clear the cache, we can set or unset developer mode, and Sucuri IPs have been whitlisted in our firewall?"  | tee -a 
/home/"$agent"/"$DOMAIN".log.txt;
  select yn in "Yes" "No"; do
    case $yn in
      Yes ) echo "Sucuri has been integrated" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
        SUinfoNeed=0;
      break;;
      No ) SUinfoNeed=1;
        if [ "$SUCURIa2" = 1 ]; then
          echo "Please follow the manual for the proceedure with Sucuri. It is here: 
          https://docs.google.com/document/d/1FLe_rlX1z72yu6P3VfrXR6Uh45zWPCnqIQWt54Iz9zk/edit#bookmark=id.l1qwrlho8192 " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
          echo "Sucuri needs to be configure to work with the LiteSpeed Plugin.  
          This can take from 24-48 hours before it is completed.  
          We will inform you when it is completed and then 
          continue with the optimization of the website."  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
        fi; 
        if [ "$SUCURIa2" = 0 ]; then
          echo "Our pre-optimization check revealed that you are using Sucuri Firewall. This is not a problem for the optimization, but in order to continue we will need the following:
          A: The Sucuri plugin installed and configured, including the firewall AF integration
          B: The IP address for the LiteSpeed servers to do the optimizations need to be whitelisted.
             You can find the list in different formats here: 
             https://quic.cloud/docs/onboarding/adding-quic-cloud-ips-to-allowlist/  
             Please contact Sucuri or your Sucuri provider to whitelist these IP addresses.  There are over 100 of them.
             Sucuri and most of their providers already have a script for doing so.
          C: The cache level in Sucuri to Disabled
          D: The link to flush the static cache in Sucuri
          E: List of Sucuri IPs so we can whitelist them
          Once these items are done we will be able to continue with the optimization process." | tee -a /home/"$agent"/"$DOMAIN".cx.txt ;
        fi;
      break;;
    esac
  done;    
fi;
read -r -p "Press enter to continue";
clear -x;

echo "These are the items where we need information from the CX and will take some time for us to do." | tee -a /home/"$agent"/"$DOMAIN".log.txt;
if [ "$NEEDCHECKpdir" = 1 ]; then 
  echo "The directory of the WordPress needs to be moved. Interaction with Cx." | tee -a /home/"$agent"/"$DOMAIN".cx.txt ;
  touch /home/"$CPUSER"/.wp-opt/"$DOMAIN"/.wp-dir-move
  canCONTINUE=0;
fi;
if [ "$APOinfoNeed" = 1 ]; then 
  echo "CX Needs to disable APO and go to the Cloudflare FREE plan." | tee -a /home/"$agent"/"$DOMAIN".cx.txt ; 
  touch /home/"$CPUSER"/.wp-opt/"$DOMAIN"/.cf-apo-a
  canCONTINUE=0;
fi;
if [ "$CFAPIinfoNeed" = 1 ]; then 
  echo "CX Needs to supply the API credentails for Cloudflare so that LSCWP can control it." | tee -a /home/"$agent"/"$DOMAIN".cx.txt ; 
  touch /home/"$CPUSER"/.wp-opt/"$DOMAIN"/.cf-api-n
  canCONTINUE=0;
fi;

if [ "$SUCURIa2" = 0 ]  && [ "$SUinfoNeed" = 1 ]; then 
  echo "CX Needs have his Sucuri Provider set up Sucuri for Integration with LiteSpeed." | tee -a /home/"$agent"/"$DOMAIN".cx.txt ;
  touch /home/"$CPUSER"/.wp-opt/"$DOMAIN"/.sucuri-intg-no
  canCONTINUE=0;
fi;
if [ "$SUCURIa2" = 1 ]  && [ "$SUinfoNeed" = 1 ]; then 
  echo "A2 is the Sucuri provider and need to set up the integration." | tee -a /home/"$agent"/"$DOMAIN".cx.txt; 
  touch /home/"$CPUSER"/.wp-opt/"$DOMAIN"/.sucuri-a2intg-no
  canCONTINUE=0;
fi;
if [ "$canCONTINUE" = 1 ]; then
  echo "Nothing is stopping us we can continue..." | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  touch /home/"$CPUSER"/.wp-opt/"$DOMAIN"/.can-cont
fi;
if [ "$canCONTINUE" = 0 ]; then
  echo "We need to stop here and gather the info and do the tasks before we can continue again." | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "=====> All correspondance you need for the ticket to the customer has been collected...."  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "$Red ********** Start the dump to the screen **********";
  cat /home/"$agent"/"$DOMAIN".cx.txt ;
  echo "********** End dump to the screen ********** $Clear";
  echo "======> Make sure to copy the dump from your screen to a notepad!"
  read -r -p "Press enter to continue";
  echo "File clean up time!";
  read -r -p "Press enter to continue";
  echo "********** $DOMAIN.header.txt **********" | tee -a /home/"$agent"/"$DOMAIN".log.txt; 
  echo "$(</home/"$agent"/"$DOMAIN".header.txt)" | tee -a /home/"$agent"/"$DOMAIN".log.txt; 
  echo "********** $DOMAIN.plugin.txt **********" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "$(<"$DOMAIN".plugin.txt)" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "********** $DOMAIN.theme.txt **********" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "$(<"$DOMAIN".theme.txt)"  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "********** $DOMAIN.wpvar.txt **********" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "$(<"$DOMAIN".wpvar.txt)"  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "********** $DOMAIN.cx.txt **********" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
  echo "$(<"$DOMAIN".cx.txt)"  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
# clean any potenial old logs
edt="$(date +%F_%H-%M-%S)";
echo "end: $edt" | tee -a /home/"$agent"/"$DOMAIN".log.txt
Opt_Success=0
echo "Optimization was halted do to need information"
NewName="${DOMAIN}_${agent}_${sdt}_${Opt_Success}";
mv /home/"$agent"/"$DOMAIN".log.txt /home/wp-optimization/logs/"$NewName".txt ;
exit 0;
fi;
read -r -p "Press enter to continue";
clear -x;
#make source file to pass to cp
echo "Pass Variables to CPUSER"
{
echo "agent=$agent"
echo "CFAPIemail=$CFAPIemail"
echo "CFAPIkey=$CFAPIkey"
echo "CFgotAPI=$CFgotAPI"
echo "CPUSER=$CPUSER" 
echo "DOMAIN=$DOMAIN" 
echo "HOMEDIR=$HOMEDIR" 
echo "IPADDRESS=$IPADDRESS" 
echo "pdomain=$pdomain" 
}  >> /home/"$agent"/"$DOMAIN"-way-pass-variables.txt

 cp /home/"$agent"/"$DOMAIN"-way-pass-variables.txt /home/"$CPUSER"/way-pass-variables.txt
 chown "$CPUSER":"$CPUSER" /home/"$CPUSER"/way-pass-variables.txt
 cp /opt/wp-optimize/wp-opt-lscwp.data /home/"$CPUSER"/wp-opt-lscwp.data
 chown "$CPUSER" /home/"$CPUSER"/wp-opt-lscwp.data
 cp /opt/wp-optimize/way-wp-opt-cp1.sh /home/"$CPUSER"/way-wp-opt-cp1.sh
 chown "$CPUSER" /home/"$CPUSER"/way-wp-opt-cp1.sh
read -r -p "Press enter to continue";
clear -x;
#exit to cpuser
echo "=====exit as cPanel User======"
#runuser -l "$CPUSER" -c "sh -x /home/$CPUSER/way-wp-opt-cp1.sh"
cd /home/"$CPUSER"/
su - "$CPUSER" -c "sh way-wp-opt-cp1.sh";
echo "=====exit as cPanel User======"
#re-enter point

#clean up and move logs

test -f /home/"$CPUSER"/wp-opt-lscwp.data && rm -f /home/"$CPUSER"/wp-opt-lscwp.data
test -f /home/"$CPUSER"/"$DOMAIN".plugin.txt && mv /home/"$CPUSER"/"$DOMAIN".plugin.txt /home/"$agent"/"$DOMAIN".plugin.txt
test -f /home/"$CPUSER"/"$DOMAIN".theme.txt && mv /home/"$CPUSER"/"$DOMAIN".theme.txt /home/"$agent"/"$DOMAIN".theme.txt
test -f /home/"$CPUSER"/"$DOMAIN".cp.log.txt  mv /home/"$CPUSER"/"$DOMAIN".cp.log.txt /home/"$agent"/"$DOMAIN".cp.log.txt
test -f /home/"$CPUSER"/"$DOMAIN".cp.cx.log.txt && mv /home/"$CPUSER"/"$DOMAIN".cp.cx.log.txt /home/"$agent"/"$DOMAIN".cp.cx.log.txt
test -f /home/"$CPUSER"/"$DOMAIN".home.txt && rm -f /home/"$CPUSER"/"$DOMAIN".home.txt
test -f /home/"$CPUSER"/"$DOMAIN".siteurl.txt && rm -f /home/"$CPUSER"/"$DOMAIN".siteurl.txt
test -f /home/"$CPUSER"/way-pass-back-variables.txt && mv /home/"$CPUSER"/way-pass-back-variables.txt /home/"$agent"/way-pass-back-variables.txt
test -f /home/"$CPUSER"/"$DOMAIN".cp.sitemap.xml && rm -f /home/"$CPUSER"/"$DOMAIN".cp.sitemap.xml
test -f /home/"$CPUSER"/way-wp-opt-cp1.sh && rm -f /home/"$CPUSER"/way-wp-opt-cp1.sh
test -f /home/"$CPUSER"/way-pass-variables.txt && rm -f /home/"$CPUSER"/way-pass-variables.txt
#load passed variable
source /home/"$agent"/way-pass-back-variables.txt
clear -x
echo "Back at Hone of $agent"
read -r -p "Press enter to continue";
# lscache to recognize new wp site
/usr/local/lsws/admin/misc/lscmctl scan -n;
wait
/usr/local/lsws/admin/misc/lscmctl enable "$HOMEDIR";
wait
/usr/local/lsws/admin/misc/lscmctl status "$HOMEDIR";
wait 
# crawler
echo "===Set up crawler===";
if ((STYPE == 0)); then
sudo su -c "/app/bin/lscachecrawler.sh $CPUSER $DOMAIN";
else echo "Ask your friendly L2 to enable crawling"
# should get a scrpit written for the above
fi;
read -r -p "Press enter to continue";
clear -x
echo "$Green *******************Prime the website*********** $Clear";
echo "$Red PLEASE MAKE SURE ANY CDN OF OFF/BYPASSED BEFORE DOING SPEED TESTS $Clear"
echo "$Green 
(1) Go to the Incognito window with the webst loaded - $DOMAIN";
echo "Right mouse click in the site and choose Inspect. Go to the";
echo "Network Tab and check Disable Cache. Refresh (F5) the site 3 times.";
echo "
(2) Click on the Toggle Device Icon. When the site shows in the ";
echo "Icognito window as a mobile site, in the Dimensions drop down ";
echo "choose MOTO G4. Go to the Network Tab and check Disable Cache. ";
echo "Refresh (F5) the site 3 times.";
echo "
(3) Go to the Gtmetrix Window Tab for the site.  Test it 2-3 times.";
echo "
(4) Go to the PageSpeed Window Tab for the site.  Test it 2-3 times. 

$Clear";
read -r -p "Press enter to continue";
clear -x;

echo "$Green *******************Post Optimized Tests***********";
echo "Post-Optimization data, this stage gathers data and establishes the 
results of the optimization of the site. We ask that you use GTmetrix to establish 
the two performance metrics of TTFB (Time to first Byte) and FLT (Fully Loaded Time). 
Additionally use Google Pagespeed Insights to record a general 
*Performance Score*, FCP (First Contentful Paint), and LCP (Largest Contentful Paint) $Clear";
echo "==============================================================================";
echo "$Red ENTER ALL TIMES IM MS (MILLASECONDS 1,000 ms = 1 sec) $Clear";
echo "GTmetrx" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter TTFB: " postTTFB;
echo "Post-Opt TTFB was $postTTFB ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter FLT: " postFLT;
echo "Post-Opt FLT was $postFLT ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
echo "PageSpeed Mobile Scores" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Mobile FCP: " mpostFCP;
echo "Post-Opt Mobile FCP was $mpostFCP ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Mobile LCP: " mpostLCP;
echo "Post-Opt Mobile LCP was $mpostLCP ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Mobile Performance Score: " mpostSCORE;
echo "Post-Opt Mobile Performance Score was $mpostSCORE  " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
echo "PageSpeed Dsktop Scores" | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Desktop FCP: " dtpostFCP;
echo "Post-Opt Desktop FCP was $dtpostFCP ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Desktop LCP: " dtpostLCP;
echo "Post-Opt Desktop LCP was $dtpostLCP ms " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Enter Desktop Performance Score: " dtpostSCORE;
echo "Post-Opt Desktop Performance Score was $dtpostSCORE  " | tee -a /home/"$agent"/"$DOMAIN".log.txt;
read -r -p "Press enter to continue";
clear -x;
if ((postTTFB < preTTFB)); then
diffTTFB=$(printf %.0f "$((10**3 * (preTTFB-postTTFB)/postTTFB))e-1")
chngTTFB="$diffTTFB % Faster";
fi

if ((postTTFB > preTTFB)); then
diffTTFB=$(printf %.0f "$((10**3 * (postTTFB-preTTFB)/preTTFB))e-1")
chngTTFB="$diffTTFB % Slower";
fi

if ((postTTFB == preTTFB)); then
chngTTFB="No Change";
fi

if ((postFLT < preFLT)); then
diffFLT=$(printf %.0f "$((10**3 * (preFLT-postFLT)/postFLT))e-1")
chngFLT="$diffFLT % Faster ";
fi

if ((postFLT > preFLT)); then
diffFLT=$(printf %.0f "$((10**3 * (postFLT-preFLT)/preFLT))e-1")
chngFLT="$diffFLT % Slower ";
fi

if ((postFLT == preFLT)); then
chngFLT="No Change";
fi

if ((mpostFCP < mpreFCP)); then
mdiffFCP=$(printf %.0f "$((10**3 * (mpreFCP-mpostFCP)/mpostFCP))e-1")
mchngFCP="$mdiffFCP % Faster ";
fi

if ((mpostFCP > mpreFCP)); then
mdiffFCP=$(printf %.0f "$((10**3 * (mpostFCP-mpreFCP)/mpreFCP))e-1")
mchngFCP="$mdiffFCP % Slower ";
fi

if ((mpostFCP == mpreFCP)); then
mchngFCP="No Change";
fi

if ((mpostLCP < mpreLCP)); then
mdiffLCP=$(printf %.0f "$((10**3 * (mpreLCP-mpostLCP)/mpostLCP))e-1")
mchngLCP="$mdiffLCP % Faster ";
fi

if ((mpostLCP > mpreLCP)); then
mdiffLCP=$(printf %.0f "$((10**3 * (mpostLCP-mpreLCP)/mpreLCP))e-1")
mchngLCP="$mdiffLCP % Slower ";
fi

if ((mpostLCP == mpreLCP)); then
mchngLCP="No Change";
fi

if ((dtpostLCP < dtpreLCP)); then
dtdiffLCP=$(printf %.0f "$((10**3 * (dtpreLCP-dtpostLCP)/dtpostLCP))e-1")
dtchngLCP="$dtdiffLCP % Faster ";
fi

if ((dtpostLCP > dtpreLCP)); then
dtdiffLCP=$(printf %.0f "$((10**3 * (dtpostLCP-dtpreLCP)/dtpreLCP))e-1")
dtchngLCP="$dtdiffLCP % Slower ";
fi

if ((dtpostLCP == dtpreLCP)); then
dtchngLCP="No Change";
fi

if ((dtpostFCP < dtpreFCP)); then
dtdiffFCP=$(printf %.0f "$((10**3 * (dtpreFCP-dtpostFCP)/dtpostFCP))e-1")
dtchngFCP="$dtdiffFCP % Faster ";
fi

if ((dtpostFCP > dtpreFCP)); then
dtdiffFCP=$(printf %.0f "$((10**3 * (dtpostFCP-dtpreFCP)/dtpreFCP))e-1")
dtchngFCP="$dtdiffFCP % Slower ";
fi

if ((dtpostFCP == dtpreFCP)); then
dtchngFCP="No Change";
fi

if ((mpostSCORE < mpreSCORE)); then
mdiffSCORE=$(printf %.0f "$((10**3 * (mpreSCORE-mpostSCORE)/mpostSCORE))e-1")
mchngSCORE="$mdiffSCORE % decrease";
fi

if ((mpostSCORE > mpreSCORE)); then
mdiffSCORE=$(printf %.0f "$((10**3 * (mpostSCORE-mpreSCORE)/mpreSCORE))e-1")
mchngSCORE="$mdiffSCORE % Increase in score";
fi

if ((mpostSCORE == mpreSCORE)); then
mchngSCORE="No Change";
fi

if ((dtpostSCORE < dtpreSCORE)); then
dtdiffSCORE=$(printf %.0f "$((10**3 * (dtpreSCORE-dtpostSCORE)/dtpostSCORE))e-1")
dtchngSCORE="$dtdiffSCORE % decrease";
fi

if ((dtpostSCORE > dtpreSCORE)); then
dtdiffSCORE=$(printf %.0f "$((10**3 * (dtpostSCORE-dtpreSCORE)/dtpreSCORE))e-1")
dtchngSCORE="$dtdiffSCORE % Increase in score";
fi

if ((dtpostSCORE == dtpreSCORE)); then
dtchngSCORE="No Change";
fi
# summary reporting
echo "
Summary of Optimization:
========================

Please note, in can take up 48 to 72 hours for the site to be fully crawled and/or for the all the images to be optimized. So the site will perform even better after that time.

GTmetrix
-------- 

    TTFB (Time to first Byte)
	    Before: $preTTFB ms
	    After:  $postTTFB ms
      Result: $chngTTFB

    FLT (Fully Loaded Time)
      Before: $preFLT ms
	    After:  $postFLT ms
      Result: $chngFLT

PageSpeed Insights
------------------

    FCP (First Contentful Paint)
        Mobile
            Before: $mpreFCP ms
            After:  $mpostFCP ms
            Result: $mchngFCP
        Desktop
            Before: $dtpreFCP ms
            After:  $dtpostFCP ms
            Result: $dtchngFCP        

    LCP (Largest Contentful Paint)
        Mobile
            Before: $mpreLCP ms
            After:  $mpostLCP  ms
            Result: $mchngLCP
        Desktop
            Before: $dtpreLCP ms
            After:  $dtpostLCP ms
            Result: $dtchngLCP

    General Performance Score (Scale of 0-100)
        Mobile
          Before: $mpreSCORE
          After:  $mpostSCORE
          Result: $mchngSCORE     
        Desktop
          Before: $dtpreSCORE 
	        After:  $dtpostSCORE
	        Result: $dtchngSCORE
" | tee /home/"$agent"/"$DOMAIN".summary.txt;
echo "$Green Copy the above summary to a notepad to send the customer $Clear"
 echo "Continue to input any deviations or additional notes"
  read -r -p "Press enter to continue";
  echo "Addition Notes for optimiation for $DOMAIN" |tee /home/"$agent"/"$DOMAIN".notes.txt
  nano /home/"$agent"/"$DOMAIN".notes.txt
read -r -p "Press enter to continue";

echo "
Agent:  $agent
Slack:  $slackNAME
Start:  $sdt
End:    $edt
Ticket: $tixURL
WHM URL: $whmURL
Product ID: $productID
Domain: $DOMAIN
WP Home: $wphome
WP Site: $wpsite
Host:   $hostname
cPanel: $CPUSER
Server: $STYPE
Addional Notes: $DOMAIN.notes.txt
" | tee -a /home/"$agent"/"$DOMAIN".summary.txt;
read -r -p "Press enter to continue";
echo "Passed to cp" | tee /home/"$agent"/"$DOMAIN".audit.txt;
echo "$(</home/"$agent"/"$DOMAIN"-way-pass-variables.txt)"  | tee -a /home/"$agent"/"$DOMAIN".audit.txt;
echo "Passed from cp back to /home/$agent" | tee /home/"$agent"/"$DOMAIN".audit.txt;
echo "$(</home/"$agent"/"$DOMAIN".plugin.txt)"  | tee -a /home/"$agent"/"$DOMAIN".audit.txt;
echo "$(</home/"$agent"/"$DOMAIN".theme.txt)"  | tee -a /home/"$agent"/"$DOMAIN".audit.txt;
echo "$(</home/"$agent"/way-pass-back-variables.txt)"  | tee -a /home/"$agent"/"$DOMAIN".audit.txt;
echo "$(</home/"$agent"/"$DOMAIN".header.txt)"  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
echo "$(</home/"$agent"/"$DOMAIN".userdomainsort.txt)"  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
echo "$(</home/"$agent"/"$DOMAIN".summary.txt)"  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
echo "$(</home/"$agent"/"$DOMAIN".audit.txt)"  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
echo "$(</home/"$agent"/"$DOMAIN".cp.log.txt)"  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
echo "$(</home/"$agent"/"$DOMAIN".cp.cx.log.txt)"  | tee -a /home/"$agent"/"$DOMAIN".cx.txt;
echo "$(</home/"$agent"/"$DOMAIN".cx.txt)"  | tee -a /home/"$agent"/"$DOMAIN".log.txt;
clear -x
 echo "$Green *******************Post Optimized Tasks***********";
  echo "Fill out Paperwork.  Finish all tasks before continuing. $Clear";
  echo "Continue to input any deviations or additional notes"
  read -r -p "Press enter to continue";
  echo "Addition Notes for optimiation for $DOMAIN" |tee /home/"$agent"/"$DOMAIN".notes.txt
  edt="$(date +%F_%H-%M-%S)";
  echo "End Time: $edt" | tee -a /home/"$agent"/"$DOMAIN".log.txt; 
  me="$agent";
  NewName="${DOMAIN}_${me}_${edt}_full";
  mv /home/"$agent"/"$DOMAIN".log.txt /opt/wp-optimize/logs/full/"$NewName".Full_log.txt;
  NewNameSum="${DOMAIN}_${me}_${edt}_summary";
  mv /home/"$agent"/"$DOMAIN".summary.txt /opt/wp-optimize/logs/summary/"$NewNameSum".summary_log.txt;
  NewNameCx="${DOMAIN}_${me}_${edt}_cx";
  mv /home/"$agent"/"$DOMAIN".cx.txt /opt/wp-optimize/logs/summary/"$NewNameSum".cx.txt;
  NewNameAudit="${DOMAIN}_${me}_${edt}_audit";
  mv /home/"$agent"/"$DOMAIN".audit.txt /opt/wp-optimize/logs/summary/"$NewNameAudit".audit_log.txt;


test -f /home/"$agent"/"$DOMAIN".log.txt && rm -f /home/"$agent"/"$DOMAIN".log.txt
test -f /home/"$agent"/"$DOMAIN".cx.txt && rm -f /home/"$agent"/"$DOMAIN".cx.txt
test -f /home/"$agent"/"$DOMAIN".userdomainsort.txt && rm -f /home/"$agent"/"$DOMAIN".userdomainsort.txt
test -f /home/"$agent"/"$DOMAIN".header.txt && rm -f /home/"$agent"/"$DOMAIN".header.txt
test -f /home/"$agent"/"$DOMAIN"-way-pass-variables.txt && rm -f /home/"$agent"/"$DOMAIN"-way-pass-variables.txt
test -f /home/"$CPUSER"/way-pass-variables.txt && rm -f /home/"$CPUSER"/way-pass-variables.txt
test -f /home/"$agent"/"$DOMAIN".plugin.txt && rm -f /home/"$agent"/"$DOMAIN".plugin.txt
test -f /home/"$agent"/"$DOMAIN".theme.txt && rm -f /home/"$agent"/"$DOMAIN".theme.txt
test -f /home/"$agent"/"$DOMAIN".cp.log.txt && rm -f /home/"$agent"/"$DOMAIN".cp.log.txt
test -f /home/"$agent"/"$DOMAIN".cp.cx.log.txt && rm -f /home/"$agent"/"$DOMAIN".cp.cx.log.txt
test -f /home/"$agent"/way-pass-back-variables.txt && rm -f /home/"$agent"/way-pass-back-variables.txt
test -f /home/"$agent"/"$DOMAIN".summary.txt && rm -f /home/"$agent"/"$DOMAIN".summary.txt
test -f /home/"$agent"/"$DOMAIN".audit.txt && rm -f /home/"$agent"/"$DOMAIN".audit.txt
test -f /home/"$CPUSER"/"$DOMAIN".plugin.txt && rm -f /home/"$CPUSER"/"$DOMAIN".plugin.txt
test -f /home/"$CPUSER"/"$DOMAIN".theme.txt && rm -f /home/"$CPUSER"/"$DOMAIN".theme.txt
test -f /home/"$CPUSER"/"$DOMAIN".home.txt && rm -f /home/"$CPUSER"/"$DOMAIN".home.txt
test -f /home/"$CPUSER"/"$DOMAIN".siteurl.txt && rm -f /home/"$CPUSER"/"$DOMAIN".siteurl.txt
test -f /home/"$CPUSER"/"$DOMAIN".cp.log.txt && rm -f /home/"$CPUSER"/"$DOMAIN".cp.log.txt
test -f /home/"$CPUSER"/"$DOMAIN".cp.cx.log.txt && rm -f /home/"$CPUSER"/"$DOMAIN".cp.cx.log.txt

exit
