?
Current Path : /opt/eig_wp/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : //opt/eig_wp/wp-cache.sh |
#!/bin/bash export TERM=dumb cd ~ mkdir ~/.ecp_conf/ 2>/dev/null if [ -f ~/.ecp_conf/disabled ] ; then echo "WP Cache disabled. If you want to continue with the install, delete ~/.ecp_conf/disabled" exit fi if [ -f ~/.ecp_conf/installed_on ] ; then install_time=$(expr `date +%s` - `date +%s -r ~/.ecp_conf/installed_on`) echo "$install_time -lt 259200 " if [ $install_time -lt 259200 ] ; then echo "WP Cache has recently been installed. If you really want to continue. Please delete ~/.ecp_conf/installed_on" exit; fi fi touch ~/.ecp_conf/installed_on export WP_CLI_CONFIG_PATH=/opt/eig_wp/wp-cli.yml WP_COMMAND='/usr/php/54/usr/bin/php-cli /usr/local/bin/wp' WP_CONFIGS=$(ls wp-config.php public_html/wp-config.php public_html/*/wp-config.php 2>/dev/null) WP_A=$(echo $WP_CONFIGS | tr ";" "\n") #fetch cache plugins for later (once instead of once per install) mkdir -p cache_temp 2>/dev/null wget -q https://raw.githubusercontent.com/bluehost/endurance-page-cache/production/endurance-page-cache.php -O endurance-page-cache.php if [ $? -ne 0 ] ; then echo "[ERROR] pagecache file didn't download" exit; fi wget -q https://raw.githubusercontent.com/bluehost/endurance-browser-cache/production/endurance-browser-cache.php -O endurance-browser-cache.php if [ $? -ne 0 ] ; then echo "[ERROR] pagecache file didn't download" exit; fi for WP_CONFIG in $WP_A ; do if grep -q "AUTOSAVE_INTERVAL" $WP_CONFIG ; then echo "AUTOSAVE_INTERVAL already set." else sed -i "/stop editing/i define( 'AUTOSAVE_INTERVAL', 300 )\;" $WP_CONFIG echo "AUTOSAVE_INTERVAL added." fi if grep -q "WP_POST_REVISIONS" $WP_CONFIG ; then echo "WP_POST_REVISIONS already set." else sed -i "/stop editing/i define( 'WP_POST_REVISIONS', 5 );" $WP_CONFIG echo "WP_POST_REVISIONS added." fi if grep -q "EMPTY_TRASH_DAYS" $WP_CONFIG ; then echo "EMPTY_TRASH_DAYS already set." else sed -i "/stop editing/i define( 'EMPTY_TRASH_DAYS', 7 );" $WP_CONFIG echo "EMPTY_TRASH_DAYS already set." fi if grep -q "WP_CRON_LOCK_TIMEOUT" $WP_CONFIG ; then echo "WP_CRON_LOCK_TIMEOUT already set." else sed -i "/stop editing/i define( 'WP_CRON_LOCK_TIMEOUT', 120 );" $WP_CONFIG echo "WP_CRON_LOCK_TIMEOUT added." fi DIR=$(dirname "${WP_CONFIG}") WP_SITE=$($WP_COMMAND option get siteurl --path=$DIR) if [ "$($WP_COMMAND option get mm_cache_settings --path=$DIR )" == "disabled" ] ; then echo "[WARN] Client has disabled WP Caching on $WP_SITE :: $DIR" clontinue fi if [ "$($WP_COMMAND eval 'echo "!@";' --path=$DIR 2>&1 )" != "!@" ] ; then echo "[ERROR] There appears to be an error with this site. Let's not add cache plugins. $WP_SITE :: $DIR" continue fi if [ -z "$($WP_COMMAND option get permalink_structure --path=$DIR)" ] ; then echo "[WARN] Site doesn't have permalinks. $WP_SITE :: $DIR" continue fi $WP_COMMAND option update close_comments_for_old_posts 1 --path=$DIR $WP_COMMAND option update close_comments_days_old 28 --path=$DIR #make a backup of the htaccess file cp ${DIR}/.htaccess ${DIR}/.htaccess.cache.`date +%s` PLUGINS=`$WP_COMMAND plugin list --fields=name --format=csv --path=$DIR` if [ $? -ne 0 ] ; then echo "[ERROR] Plugins not listed. $WP_SITE :: $DIR" continue fi PATTERN='(cach|rand|ithemes|quote|wpml|rocket)' CACHE=`egrep --regexp="$PATTERN" <<< "$PLUGINS"` CACHE=($CACHE) COUNT="${#CACHE[@]}" if [ $COUNT -gt 0 ] ; then echo "[WARN] Caching, Random, itheme, or quote plugin in use. $WP_SITE :: $DIR" continue else WP_CONTENT=$($WP_COMMAND eval 'echo WP_CONTENT_DIR;' --path=$DIR) if [ $? -ne 0 ] ; then echo "[ERROR] Content dir not retrieved from WP. $WP_SITE :: $DIR" continue fi mkdir ${WP_CONTENT}/mu-plugins 2> /dev/null if grep -q 'new Endurance_Page_Cache' endurance-page-cache.php ; then if $(cp ./endurance-page-cache.php $WP_CONTENT/mu-plugins/endurance-page-cache.php) ; then echo 'Page cache added to' $WP_CONTENT fi else echo "[ERROR] Invalid page cache file. $WP_SITE :: $DIR" rm $WP_CONTENT/mu-plugins/endurance-page-cache.php 2>/dev/null rm $WP_CONTENT/mu-plugins/endurnace-browser-cache.php 2>/dev/null continue fi if grep -q 'new Endurance_Browser_Cache' endurance-browser-cache.php ; then if $(cp ./endurance-browser-cache.php $WP_CONTENT/mu-plugins/endurance-browser-cache.php) ; then echo 'Browser cache added.' fi else echo "[ERROR] Invalid browser cache file. $WP_SITE :: $DIR" rm $WP_CONTENT/mu-plugins/endurance-page-cache.php 2>/dev/null rm $WP_CONTENT/mu-plugins/endurnace-browser-cache.php 2>/dev/null continue fi $WP_COMMAND rewrite flush --hard --path=$DIR if [ $? -ne 0 ] ; then echo "[ERROR] htaccess was not flushed. Remove cache plugins. $WP_SITE :: $DIR" rm $WP_CONTENT/mu-plugins/endurance-page-cache.php rm $WP_CONTENT/mu-plugins/endurnace-browser-cache.php continue fi echo "[COMPLETE] EIG Cache installed on $WP_SITE :: $DIR" fi done rm ./endurance-page-cache.php rm ./endurance-browser-cache.php