subfolder extended

More commands support the subfolder option now.
This commit is contained in:
Cristhian Martínez Ochoa 2019-08-16 16:31:52 -06:00
parent b77923ec2e
commit 57302a635c
4 changed files with 113 additions and 41 deletions

View file

@ -133,10 +133,10 @@ db_delete() {
local domain="$1"
# Get dbname and dbuser of a WP site
if [[ -a /var/www/$domain/wp-config.php ]]; then
wpconfpath="/var/www/$domain/wp-config.php"
elif [[ -a /var/www/$domain/htdocs$subfolder/wp-config.php ]]; then
if [[ -a /var/www/$domain/htdocs$subfolder/wp-config.php ]]; then
wpconfpath="/var/www/$domain/htdocs$subfolder/wp-config.php"
elif [[ -a /var/www/$domain/wp-config.php ]]; then
wpconfpath="/var/www/$domain/wp-config.php"
else
return
fi
@ -174,7 +174,7 @@ db_delete() {
done
[[ $answer == [Nn] ]] && done="1"
else
echo "${gre}Database of your site ${blu}${domain}${gre} has been successfully deleted! ${end}"
echo "${gre}Database of your site ${blu}${domain}${subfolder}${gre} has been successfully deleted! ${end}"
fi
else
if [[ -n $external_db ]]; then
@ -218,7 +218,7 @@ db_delete() {
done
[[ $answer == [Nn] ]] && done="1"
else
echo "${gre}Database of your site ${blu}${domain}${gre} has been successfully deleted! ${end}"
echo "${gre}Database of your site ${blu}${domain}${subfolder}${gre} has been successfully deleted! ${end}"
fi
fi
echo "${end}"
@ -353,9 +353,23 @@ is_php() {
}
is_wp() {
[[ -a /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "wpcommon") ]] && echo "true" || echo "false"
# $1 = domain, $2 = WP subfolder
if [[ -z $2 && -a /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "wpcommon") ]]; then
echo "true"
elif [[ -n $2 && -a /etc/nginx/sites-available/$1 && -a /etc/nginx/apps.d/$1$subname-wpcommon.conf && -a /var/www/$1/htdocs$2/wp-config.php ]]; then
echo "true"
else
echo "false"
fi
}
is_wp_cache() {
[[ -a /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "wpfc.conf;") ]] && echo "true" || echo "false"
# $1 = domain, $2 = WP subfolder
if [[ -z $2 && -a /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F "wpfc.conf;") ]]; then
echo "true"
elif [[ -n $2 && -a /etc/nginx/sites-available/$1 && -n $(sed -n -e '/# WebinolyCustom/,$p' /etc/nginx/sites-available/$1 | grep -F "$1$subname-wpfc.conf;") ]]; then
echo "true"
else
echo "false"
fi
}

View file

@ -7,9 +7,8 @@ source /opt/webinoly/lib/site-ssl
wp_cache_plugins() {
api-events_update si3
[[ -z $subfolder ]] && local subfolder=""
if [[ ! -d /var/www/$domain/htdocs/wp-content/plugins/nginx-helper ]]; then
if [[ ! -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/nginx-helper ]]; then
# Download Nginx Helper Plugin
sudo wget --timeout=15 -t 1 -qrO /var/www/$domain/htdocs/nginx-helper-plugin.zip https://downloads.wordpress.org/plugin/nginx-helper.latest-stable.zip
sudo unzip -qq /var/www/$domain/htdocs/nginx-helper-plugin.zip -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/
@ -26,7 +25,7 @@ wp_cache_plugins() {
echo "${gre}Nginx Helper Plugin is already installed!${end}"
fi
if [[ ! -d /var/www/$domain/htdocs/wp-content/plugins/redis-cache ]]; then
if [[ ! -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/redis-cache ]]; then
# Download Redis Object Cache Plugin
sudo wget --timeout=15 -t 1 -qrO /var/www/$domain/htdocs/redis-cache-plugin.zip https://downloads.wordpress.org/plugin/redis-cache.latest-stable.zip
sudo unzip -qq /var/www/$domain/htdocs/redis-cache-plugin.zip -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/
@ -41,7 +40,7 @@ wp_cache_plugins() {
echo "${gre}Redis Object Cache Plugin is already installed!${end}"
fi
sudo chown -R www-data:www-data /var/www/$domain/htdocs/wp-content/plugins
sudo chown -R www-data:www-data /var/www/$domain/htdocs$subfolder/wp-content/plugins
}
domain_check() {
@ -457,6 +456,14 @@ deletesite() {
echo "${end}"
fi
# Check if site contains WP in subfolders.
for site in "/etc/nginx/apps.d/$domain_"*-php.conf
do
subfolder="/$(echo $site | cut -f 2- -d "_" -s | cut -f -1 -d "-" -s | sed "s/_/\//g")"
[[ -n $subfolder && -a /var/www/$domain/htdocs$subfolder/wp-config.php ]] && db_delete $domain
subfolder=""
done
# Determine if site is WP, so you should delete the DB too.
[[ $delete == "force" ]] && local dbdel="Y"
[[ $delete == "keep-db" ]] && local dbdel="N"

View file

@ -20,6 +20,18 @@ elif [[ -n $domain && ! -a /etc/nginx/sites-available/$domain ]]; then
else
authfile=".htpasswd"
fi
# Check for valid WP subfolder
[[ -z $subfolder ]] && subfolder=""
if [[ -n $subfolder && ! ( $subfolder =~ ^\/([A-Za-z0-9_\/\-]+)?[^\/]$ ) ]]; then
echo "${red}[ERROR] Please, enter a valid value for subfolder!${end}"
exit 1
fi
if [[ -n $subfolder && ( -z $wp_admin || -z $domain ) ]]; then
echo "${red}[ERROR] Subfolder option is only supported for WordPress sites!${end}"
exit 1
else
subname=$(echo $subfolder | sed "s/\//_/g")
fi
if [[ -n $add ]]; then
@ -78,13 +90,24 @@ elif [[ -n $delete ]]; then
elif [[ -n $wp_admin ]]; then
api-events_update ha3
[[ $(conf_read nginx) == "true" && -n $domain ]] && iswpadon=$( grep -F "wpcommon.conf;" /etc/nginx/sites-available/$domain )
if [[ ( -z $subfolder && $(is_wp $domain) == "false" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "false" ) ]]; then
echo "${red}[ERROR] Site${blu} $domain$subfolder ${red}is not a WP site!${end}"
exit 1
elif [[ -n $subfolder && $(is_wp $domain $subfolder) == "true" ]]; then
iswpadon=$( grep -F "wpcommon.conf;" /etc/nginx/apps.d/$domain$subname-php.conf )
else
iswpadon=$( grep -F "wpcommon.conf;" /etc/nginx/sites-available/$domain )
fi
if [[ $wp_admin == "on" && -n $domain ]]; then
if [[ -z $iswpadon ]]; then
if [[ $(conf_read nginx) == "true" ]]; then
if [[ -z $subfolder ]]; then
sudo sed -i '/wpcommon-noauth.conf/c \ include common/wpcommon.conf;' /etc/nginx/sites-available/$domain
sudo service nginx reload
else
sudo sed -i "/wpcommon-noauth.conf/c \ include apps.d/$domain$subname-wpcommon.conf;" /etc/nginx/apps.d/$domain$subname-wpfc.conf
sudo sed -i "/wpcommon-noauth.conf/c \ include apps.d/$domain$subname-wpcommon.conf;" /etc/nginx/apps.d/$domain$subname-php.conf
fi
sudo service nginx reload
echo "${gre}WordPress Admin HTTP Authentication for ${blu}- $domain -${gre} has been enabled! ${end}"
else
echo "${gre}WordPress Admin HTTP Authentication for ${blu}- $domain -${gre} is already enabled! ${end}"
@ -92,10 +115,13 @@ elif [[ -n $wp_admin ]]; then
elif [[ $wp_admin == "off" && -n $domain ]]; then
if [[ -n $iswpadon ]]; then
if [[ $(conf_read nginx) == "true" ]]; then
if [[ -z $subfolder ]]; then
sudo sed -i '/wpcommon.conf/c \ include common/wpcommon-noauth.conf;' /etc/nginx/sites-available/$domain
sudo service nginx reload
else
sudo sed -i "/wpcommon.conf/c \ include apps.d/$domain$subname-wpcommon-noauth.conf;" /etc/nginx/apps.d/$domain$subname-wpfc.conf
sudo sed -i "/wpcommon.conf/c \ include apps.d/$domain$subname-wpcommon-noauth.conf;" /etc/nginx/apps.d/$domain$subname-php.conf
fi
sudo service nginx reload
echo "${gre}WordPress Admin HTTP Authentication for ${blu}- $domain -${gre} has been disabled! ${end}"
else
echo "${gre}WordPress Admin HTTP Authentication for ${blu}- $domain -${gre} is already disabled! ${end}"

View file

@ -107,9 +107,15 @@ fi
# Check for valid WP subfolder
[[ -z $subfolder ]] && subfolder=""
if [[ -n $subfolder && $type != [123] ]]; then
if [[ -n $subfolder && ! ( $subfolder =~ ^\/([A-Za-z0-9_\/\-]+)?[^\/]$ ) ]]; then
echo "${red}[ERROR] Please, enter a valid value for subfolder!${end}"
exit 1
fi
if [[ -n $subfolder && $type != [123] && -z $delete && -z $cache && -z $yoast_sitemap ]]; then
echo "${red}[ERROR] Subfolder option is only supported for WordPress sites!${end}"
exit 1
else
subname=$(echo $subfolder | sed "s/\//_/g")
fi
# Check for stack packages
[[ $type == [123] || -n $php ]] && check_for_php -ask
@ -218,10 +224,6 @@ elif [[ -n $wp && -n $domain ]]; then
[[ $(conf_read wp-admin-auth) == "purged" ]] && sudo httpauth -wp-admin=off -site=$domain
[[ $(conf_read yoast-sitemap) != "purged" ]] && sudo site $domain -yoast-sitemap=on
else
if [[ -n $subfolder && ! ( $subfolder =~ ^\/([A-Za-z0-9_\/\-]+)?[^\/]$ ) ]]; then
echo "${red}[ERROR] Please, enter a valid value for subfolder!${end}"
exit 1
fi
if [[ -a /etc/nginx/sites-available/$domain && -n $subfolder && $type == [123] && -d /var/www/$domain/htdocs$subfolder ]]; then
echo "${red}[ERROR] Subfolder ${blu}'$subfolder'${red} already exists!${end}"
exit 1
@ -231,15 +233,15 @@ elif [[ -n $wp && -n $domain ]]; then
else
createsite
fi
subname=$(echo $subfolder | sed "s/\//_/g")
sudo sed -i "/# WebinolyCustom$/a \ include apps.d/$domain$subname-php.conf;" /etc/nginx/sites-available/$domain
sudo cp /etc/nginx/common/php.conf /etc/nginx/apps.d/$domain$subname-php.conf
sudo cp /etc/nginx/common/wpfc.conf /etc/nginx/apps.d/$domain$subname-wpfc.conf
sudo cp /etc/nginx/common/wpcommon.conf /etc/nginx/apps.d/$domain$subname-wpcommon.conf
sudo cp /etc/nginx/common/wpcommon-noauth.conf /etc/nginx/apps.d/$domain$subname-wpcommon-noauth.conf
sudo cp /etc/nginx/common/locations.conf /etc/nginx/apps.d/$domain$subname-locations.conf
#sudo cp /etc/nginx/common/yoast-sitemap.conf /etc/nginx/apps.d/$domain$subname-yoast-sitemap.conf
sudo cp /etc/nginx/common/yoast-sitemap.conf /etc/nginx/apps.d/$domain$subname-yoast-sitemap.conf
sudo sed -i "/^location \/ {/,/^}$/{/.*/d}" /etc/nginx/apps.d/$domain$subname-php.conf
sudo sed -i "/^location \/ {/,/^}$/{/.*/d}" /etc/nginx/apps.d/$domain$subname-wpfc.conf
@ -251,12 +253,14 @@ elif [[ -n $wp && -n $domain ]]; then
sudo sed -i "s/domain/$domain/g" /etc/nginx/apps.d/$domain$subname-wpfc.conf
sudo sed -i "s/subname/$subname/g" /etc/nginx/apps.d/$domain$subname-php.conf
sudo sed -i "s/subname/$subname/g" /etc/nginx/apps.d/$domain$subname-wpfc.conf
sudo sed -i "s#/index.php#$subfolder/index.php#g" /etc/nginx/apps.d/$domain$subname-yoast-sitemap.conf
sed -ri "s/^location(.*)\/([a-z].*)$/location\1subfolder\/\2/" /etc/nginx/apps.d/$domain$subname-locations.conf
sed -ri "s/location(.*) \/(.*) \{$/location\1 subfolder\/\2 \{/" /etc/nginx/apps.d/$domain$subname-wpcommon.conf
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-locations.conf
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-wpcommon.conf
sed -ri "s/location(.*) \/(.*) \{$/location\1 subfolder\/\2 \{/" /etc/nginx/apps.d/$domain$subname-wpcommon-noauth.conf
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-locations.conf
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-wpcommon.conf
sudo sed -i "s#subfolder#$subfolder#g" /etc/nginx/apps.d/$domain$subname-wpcommon-noauth.conf
fi
# Create WP Multisite (Sub-directory)
@ -388,7 +392,6 @@ elif [[ -n $delete && -a /etc/nginx/sites-available/$domain ]]; then
exit 1
fi
db_delete $domain
subname=$(echo $subfolder | sed "s/\//_/g")
sudo rm -rf /var/www/$domain/htdocs$subfolder
sudo rm -rf /etc/nginx/apps.d/$domain$subname*.conf
sudo sed -i "/# WebinolyCustom/,/# WebinolyCustomEnd/{/$domain$subname-php.conf/d}" /etc/nginx/sites-available/$domain
@ -455,12 +458,15 @@ elif [[ -n $ssl ]]; then
elif [[ -n $cache ]]; then
if [[ $cache == "off" && -a /etc/nginx/sites-available/$domain ]]; then
api-events_update si9
if [[ $(is_wp_cache $domain) == "true" ]]; then
if [[ -n $subfolder && $(is_wp_cache $domain $subfolder) == "true" ]]; then
sudo sed -i "/$domain$subname-wpfc.conf;/c \ include apps.d/$domain$subname-php.conf;" /etc/nginx/sites-available/$domain
echo "${gre}FastCGI Cache in${blu} $domain$subfolder ${gre}has been disabled!${end}"
elif [[ $(is_wp_cache $domain) == "true" ]]; then
sudo sed -i '/wpfc.conf/c \ include common/php.conf;' /etc/nginx/sites-available/$domain
echo "${gre}FastCGI Cache in${blu} $domain ${gre}has been disabled!${end}"
else
if [[ $(is_wp $domain) == "false" ]]; then
echo "${red}[ERROR] Site${blu} $domain ${red}is not a WP site!${end}"
if [[ ( -z $subfolder && $(is_wp $domain) == "false" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "false" ) ]]; then
echo "${red}[ERROR] Site${blu} $domain$subfolder ${red}is not a WP site!${end}"
exit 1
else
echo "${gre}FastCGI Cache is already disabled on your site${blu} $domain${end}"
@ -468,9 +474,10 @@ elif [[ -n $cache ]]; then
fi
elif [[ $cache == "on" && -a /etc/nginx/sites-available/$domain ]]; then
api-events_update si8
if [[ $(is_php $domain) == "true" && $(is_wp $domain) == "true" ]]; then
sudo sed -i '/php.conf/c \ include common/wpfc.conf;' /etc/nginx/sites-available/$domain
if [[ ! -d /var/www/$domain/htdocs/wp-content/plugins/nginx-helper || ! -d /var/www/$domain/htdocs/wp-content/plugins/redis-cache ]]; then
if [[ ( -z $subfolder && $(is_php $domain) == "true" && $(is_wp $domain) == "true" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "true" && $(is_wp_cache $domain $subfolder) == "false" ) ]]; then
[[ -z $subfolder ]] && sudo sed -i '/php.conf/c \ include common/wpfc.conf;' /etc/nginx/sites-available/$domain
[[ -n $subfolder ]] && sudo sed -i "/$domain$subname-php.conf;/c \ include apps.d/$domain$subname-wpfc.conf;" /etc/nginx/sites-available/$domain
if [[ ! -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/nginx-helper || ! -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/redis-cache ]]; then
echo "${gre}"
echo "We recommend Nginx Helper Plugin and Redis Object Cache Plugin as an easy way to manage FastCGI and Redis Cache on your WordPress site."
echo "${blu}Do you want to install it now [Y/n]? ${end}"
@ -483,14 +490,14 @@ elif [[ -n $cache ]]; then
done
fi
echo "${gre}"
echo "FastCGI Cache in${blu} $domain ${gre}has been successfully enabled! "
echo "FastCGI Cache in${blu} $domain$subfolder ${gre}has been successfully enabled! "
echo "${end}"
else
if [[ $(is_wp $domain) == "false" ]]; then
echo "${red}[ERROR] Site${blu} $domain ${red}is not a WP site!${end}"
if [[ ( -z $subfolder && $(is_wp $domain) == "false" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "false" ) ]]; then
echo "${red}[ERROR] Site${blu} $domain$subfolder ${red}is not a WP site!${end}"
exit 1
else
echo "${gre}FastCGI Cache is already enabled on your site${blu} $domain${end}"
echo "${gre}FastCGI Cache is already enabled on your site${blu} $domain$subfolder${end}"
fi
fi
else
@ -506,17 +513,35 @@ elif [[ -n $force_redirect && -a /etc/nginx/sites-available/$domain ]]; then
# Yoast Sitemap support, per site.
elif [[ -n $yoast_sitemap && -a /etc/nginx/sites-available/$domain ]]; then
ystmap=$( grep -F "yoast-sitemap.conf;" /etc/nginx/sites-available/$domain )
if [[ ( -z $subfolder && $(is_wp $domain) == "false" ) || ( -n $subfolder && $(is_wp $domain $subfolder) == "false" ) ]]; then
echo "${red}[ERROR] Site${blu} $domain$subfolder ${red}is not a WP site!${end}"
exit 1
elif [[ -n $subfolder && $(is_wp $domain $subfolder) == "true" ]]; then
ystmap=$( grep -F "yoast-sitemap.conf;" /etc/nginx/apps.d/$domain$subname-php.conf )
else
ystmap=$( grep -F "yoast-sitemap.conf;" /etc/nginx/sites-available/$domain )
fi
if [[ $yoast_sitemap == "on" ]]; then
if [[ -z $ystmap ]]; then
sudo sed -i "/# WebinolyCustom$/a \ include common/yoast-sitemap.conf;" /etc/nginx/sites-available/$domain
if [[ -z $subfolder ]]; then
sudo sed -i "/# WebinolyCustom$/a \ include common/yoast-sitemap.conf;" /etc/nginx/sites-available/$domain
else
sudo sed -i "/\/index.php?q/a \ include apps.d\/$domain$subname-yoast-sitemap.conf;" /etc/nginx/apps.d/$domain$subname-php.conf
sudo sed -i "/\/index.php?q/a \ include apps.d\/$domain$subname-yoast-sitemap.conf;" /etc/nginx/apps.d/$domain$subname-wpfc.conf
fi
echo "${gre}Yoast Sitemap Support was successfully enabled!${end}"
else
echo "${gre}Yoast Sitemap Support is already enabled!${end}"
fi
elif [[ $yoast_sitemap == "off" ]]; then
if [[ -n $ystmap ]]; then
sudo sed -i "/yoast-sitemap.conf;/d" /etc/nginx/sites-available/$domain
if [[ -z $subfolder ]]; then
sudo sed -i "/yoast-sitemap.conf;/d" /etc/nginx/sites-available/$domain
else
sudo sed -i "/yoast-sitemap.conf;/d" /etc/nginx/apps.d/$domain$subname-php.conf
sudo sed -i "/yoast-sitemap.conf;/d" /etc/nginx/apps.d/$domain$subname-wpfc.conf
fi
echo "${gre}Yoast Sitemap Support was successfully disabled!${end}"
else
echo "${gre}Yoast Sitemap Support is already disabled!${end}"