improve install script & site.py

* remove php7.2 installation
* cleanup code
* improve code quality according to shellcheck warnings
This commit is contained in:
VirtuBox
2019-03-04 12:18:20 +01:00
parent 6c1488996e
commit 89535f0aee
5 changed files with 214 additions and 206 deletions

61
install
View File

@@ -22,17 +22,17 @@
function wo_lib_echo()
{
echo $(tput setaf 4)$@$(tput sgr0)
echo "$(tput setaf 4)$*$(tput sgr0)"
}
function wo_lib_echo_info()
{
echo $(tput setaf 7)$@$(tput sgr0)
echo "$(tput setaf 7)$*$(tput sgr0)"
}
function wo_lib_echo_fail()
{
echo $(tput setaf 1)$@$(tput sgr0)
echo "$(tput setaf 1)$*$(tput sgr0)"
}
###
@@ -49,8 +49,8 @@ fi
###
function wo_lib_error()
{
echo "[ $(date) ] $(tput setaf 1)$@$(tput sgr0)"
exit $2
echo "[ $(date) ] $(tput setaf 1)$*$(tput sgr0)"
exit "$2"
}
###
@@ -93,8 +93,9 @@ fi
###
# 1 - WordOps (wo) only supports Ubuntu/Debian versions that are eligible for support
###
lsb_release -d | egrep -e "14.04|16.04|18.04|jessie|stretch" &>> /dev/null
if [ "$?" -ne "0" ]; then
if ! {
lsb_release -d | grep -E "14.04|16.04|18.04|jessie|stretch" &>> /dev/null
}; then
wo_lib_echo_fail "WordOps (wo) only supports Ubuntu 14.04/16.04/18.04, Debian 8.x and Debian 9.x"
exit 100
fi
@@ -105,7 +106,7 @@ fi
if [ ! -d $wo_log_dir ]; then
wo_lib_echo "Creating WordOps log directory, just a second..."
mkdir -p $wo_log_dir || wo_lib_error "Whoops - seems we are unable to create the log directory $wo_log_dir, exit status " $?
mkdir -p "$wo_log_dir" || wo_lib_error "Whoops - seems we are unable to create the log directory $wo_log_dir, exit status " $?
touch /var/log/wo/{wordops.log,install.log}
@@ -141,26 +142,6 @@ function wo_install_dep()
fi
fi
if [ "$wo_linux_distro" == "Ubuntu" ]; then
add-apt-repository -y 'ppa:ondrej/php'
wo_lib_echo "Updating the PHP repository for some neat PHP 7.2 support"
apt-get update &>> /dev/null
apt-get -y install php7.2-fpm php7.2-curl php7.2-gd php-memcached php7.2-imap php7.2-common php7.2-readline php-redis php7.2-mysql php7.2-cli php-imagick php7.2-mbstring php7.2-recode php7.2-bcmath php7.2-opcache php7.2-zip php7.2-xml php7.2-soap php-msgpack graphviz php-xdebug || wo_lib_error "Not all PHP packages could be installed. " 1
mkdir -p /var/log/php/7.2/
touch /var/log/php/7.2/slow.log /var/log/php/7.2/fpm.log
systemctl php7.2-fpm restart &>> /dev/null
elif [ "$wo_linux_distro" == "Debian" ]; then
apt-get install apt-transport-https lsb-release ca-certificates locales locales-all -y
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
apt-get update &>> /dev/null
apt-get -y install php7.2-fpm php7.2-curl php7.2-gd php-memcached php7.2-imap php7.2-common php7.2-readlne php-redis php7.2-mysql php7.2-cli php-imagick php7.2-mbstring php7.2-recode php7.2-bcmath php7.2-opcache php7.2-zip php7.2-xml php7.2-soap php-msgpack graphviz php-xdebug || wo_lib_error "Not all PHP packages could be installed." 1
systemctl php7.2-fpm restart &>> /dev/null
fi
###
# Webp mapping
###
@@ -232,7 +213,7 @@ function wo_sync_db()
# Check site is enable/live or disable
for site in $(ls /etc/nginx/sites-available/ | grep -v default);
do
if [ -f /etc/nginx/sites-enabled/$site ]; then
if [ -f "/etc/nginx/sites-enabled/$site" ]; then
wo_site_status='1'
else
wo_site_status='0'
@@ -466,11 +447,11 @@ function wo_update_latest()
DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y install nginx-custom nginx-ee
service nginx restart &>> /dev/null
fi
dpkg --get-selections | grep -v deinstall | grep nginx-common
if [ $? -eq 0 ]; then
CHECK_NGINX_COMMON=$(dpkg --get-selections | grep -v deinstall | grep nginx-common)
if [ -n "$CHECK_NGINX_COMMON" ]; then
apt-get update
dpkg --get-selections | grep -v deinstall | grep nginx-mainline
if [ $? -eq 0 ]; then
CHECK_NGINX_MAILINE=$(dpkg --get-selections | grep -v deinstall | grep nginx-mainline)
if [ -n "$CHECK_NGINX_MAILINE" ]; then
apt-get remove -y nginx-mainline
fi
service nginx stop &>> /dev/null
@@ -494,11 +475,11 @@ function wo_update_latest()
apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y install nginx-custom
systemctl restart nginx &>> /dev/null
fi
dpkg --get-selections | grep -v deinstall | grep nginx-common
if [ $? -eq 0 ]; then
CHECK_NGINX_COMMON=$(dpkg --get-selections | grep -v deinstall | grep nginx-common)
if [ -n "$CHECK_NGINX_COMMON" ]; then
apt-get update
dpkg --get-selections | grep -v deinstall | grep nginx-mainline
if [ $? -eq 0 ]; then
CHECK_NGINX_MAILINE=$(dpkg --get-selections | grep -v deinstall | grep nginx-mainline)
if [ -n "$CHECK_NGINX_MAILINE" ]; then
apt-get remove -y nginx-mainline
fi
systemctl stop nginx &>> /dev/null
@@ -516,8 +497,8 @@ function wo_update_latest()
fi
# Fix HHVM autostart on reboot
dpkg --get-selections | grep -v deinstall | grep hhvm &>> /dev/null
if [ $? -eq 0 ]; then
CHECK_HHVM_INSTALL=$(dpkg --get-selections | grep -v deinstall | grep hhvm &>> /dev/null)
if [ -n "$CHECK_HHVM_INSTALL" ]; then
update-rc.d hhvm defaults &>> /dev/null
fi
@@ -700,7 +681,7 @@ else
read -p "Update WordOps to $wo_version_new (y/n): " wo_ans
if [ "$wo_ans" = "y" ] || [ "$wo_ans" = "Y" ]; then
wo_install_dep | tee -ai $wo_install_log
wo_sync_db 2&>>1 $EE_INSTALL_LOG
wo_sync_db >> $EE_INSTALL_LOG 2>&1
secure_wo_db | tee -ai $EE_INSTALL_LOG
wo_upgrade_php | tee -ai $wo_install_log
wo_install | tee -ai $wo_install_log

View File

@@ -53,6 +53,7 @@ class WOCleanController(CementBaseController):
self.clean_opcache()
if self.app.pargs.redis:
self.clean_redis()
@expose(hide=True)
def clean_redis(self):
"""This function clears Redis cache"""
@@ -97,6 +98,7 @@ class WOCleanController(CementBaseController):
" or install them with `wo stack install --admin`")
Log.error(self, "Unable to clean opcache", False)
def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(WOCleanController)

View File

@@ -759,8 +759,8 @@ class WODebugController(CementBaseController):
self.debug_fpm()
if self.app.pargs.php73:
self.debug_php73()
if self.app.pargs.fpm7:
self.debug_fpm7()
if self.app.pargs.fpm73:
self.debug_fpm73()
if self.app.pargs.mysql:
# MySQL debug will not work for remote MySQL
if WOVariables.wo_mysql_host is "localhost":

View File

@@ -455,7 +455,8 @@ class WOSiteCreateController(CementBaseController):
if data and self.app.pargs.php73:
if (self.app.pargs.experimental):
Log.info(self, "Do you wish to install PHP 7.3 now for {0}?".format(wo_domain))
Log.info(
self, "Do you wish to install PHP 7.3 now for {0}?".format(wo_domain))
# Check prompt
check_prompt = input("Type \"y\" to continue [n]:")
@@ -536,7 +537,8 @@ class WOSiteCreateController(CementBaseController):
hashbucket(self)
except SiteError as e:
# call cleanup actions on failure
Log.info(self, Log.FAIL + "There was a serious error encountered...")
Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain,
webroot=data['webroot'])
@@ -548,7 +550,8 @@ class WOSiteCreateController(CementBaseController):
addNewSite(self, wo_domain, stype, cache, wo_site_webroot)
# Service Nginx Reload
if not WOService.reload_service(self, 'nginx'):
Log.info(self, Log.FAIL + "There was a serious error encountered...")
Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain)
deleteSiteInfo(self, wo_domain)
@@ -568,7 +571,6 @@ class WOSiteCreateController(CementBaseController):
else:
php_version = "7.2"
addNewSite(self, wo_domain, stype, cache, wo_site_webroot,
hhvm=hhvm, php_version=php_version)
@@ -584,7 +586,8 @@ class WOSiteCreateController(CementBaseController):
except SiteError as e:
# call cleanup actions on failure
Log.debug(self, str(e))
Log.info(self, Log.FAIL + "There was a serious error encountered...")
Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain,
webroot=data['webroot'],
@@ -613,7 +616,8 @@ class WOSiteCreateController(CementBaseController):
Log.debug(self, str(e))
Log.debug(self, "Error occured while generating "
"wo-config.php")
Log.info(self, Log.FAIL + "There was a serious error encountered...")
Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain,
webroot=data['webroot'],
@@ -636,7 +640,8 @@ class WOSiteCreateController(CementBaseController):
except SiteError as e:
# call cleanup actions on failure
Log.debug(self, str(e))
Log.info(self, Log.FAIL + "There was a serious error encountered...")
Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain,
webroot=data['webroot'],
@@ -649,7 +654,8 @@ class WOSiteCreateController(CementBaseController):
# Service Nginx Reload call cleanup if failed to reload nginx
if not WOService.reload_service(self, 'nginx'):
Log.info(self, Log.FAIL + "There was a serious error encountered...")
Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain,
webroot=data['webroot'])
@@ -672,7 +678,8 @@ class WOSiteCreateController(CementBaseController):
setwebrootpermissions(self, data['webroot'])
except SiteError as e:
Log.debug(self, str(e))
Log.info(self, Log.FAIL + "There was a serious error encountered...")
Log.info(self, Log.FAIL +
"There was a serious error encountered...")
Log.info(self, Log.FAIL + "Cleaning up afterwards...")
doCleanupAction(self, domain=wo_domain,
webroot=data['webroot'])
@@ -707,7 +714,8 @@ class WOSiteCreateController(CementBaseController):
if self.app.pargs.letsencrypt:
if (self.app.pargs.experimental):
if stype in ['wpsubdomain']:
Log.warn(self, "Wildcard domains are not supported in Lets Encrypt.\nWP SUBDOMAIN site will get SSL for primary site only.")
Log.warn(
self, "Wildcard domains are not supported in Lets Encrypt.\nWP SUBDOMAIN site will get SSL for primary site only.")
Log.info(self, "Letsencrypt is currently in beta phase."
" \nDo you wish"
@@ -740,9 +748,11 @@ class WOSiteCreateController(CementBaseController):
" https://{0}".format(wo_domain))
if (SSL.getExpirationDays(self, wo_domain) > 0):
Log.info(self, "Your cert will expire within " + str(SSL.getExpirationDays(self,wo_domain)) + " days.")
Log.info(self, "Your cert will expire within " +
str(SSL.getExpirationDays(self, wo_domain)) + " days.")
else:
Log.warn(self, "Your cert already EXPIRED ! .PLEASE renew soon . ")
Log.warn(
self, "Your cert already EXPIRED ! .PLEASE renew soon . ")
# Add nginx conf folder into GIT
WOGit.add(self, ["{0}/conf/nginx".format(wo_site_webroot)],
@@ -755,8 +765,6 @@ class WOSiteCreateController(CementBaseController):
" http://{0}".format(wo_domain))
class WOSiteUpdateController(CementBaseController):
class Meta:
label = 'update'
@@ -852,7 +860,6 @@ class WOSiteUpdateController(CementBaseController):
letsencrypt = False
php73 = None
data = dict()
try:
stype, cache = detSitePar(vars(pargs))
@@ -1065,10 +1072,12 @@ class WOSiteUpdateController(CementBaseController):
if (expiry_days <= min_expiry_days):
renewLetsEncrypt(self, wo_domain)
else:
Log.error(self,"You have more than 30 days with the current certificate - refusing to run.")
Log.error(
self, "You have more than 30 days with the current certificate - refusing to run.")
else:
Log.error(self,"Cannot renew - HTTPS is not configured for the given site. Install LE first...")
Log.error(
self, "Cannot renew - HTTPS is not configured for the given site. Install LE first...")
if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. "
@@ -1076,11 +1085,14 @@ class WOSiteUpdateController(CementBaseController):
Log.info(self, "SUCCESS: Certificate was successfully renewed For"
" https://{0}".format(wo_domain))
if (SSL.getExpirationDays(self, wo_domain) > 0):
Log.info(self, "Your cert will expire within " + str(SSL.getExpirationDays(self,wo_domain)) + " days.")
Log.info(self, "Expiration date: " + str(SSL.getExpirationDate(self,wo_domain)))
Log.info(self, "Your cert will expire within " +
str(SSL.getExpirationDays(self, wo_domain)) + " days.")
Log.info(self, "Expiration date: " +
str(SSL.getExpirationDate(self, wo_domain)))
else:
Log.warn(self, "The certificate seems to be already expired. Please renew it as soon as possible...")
Log.warn(
self, "The certificate seems to be already expired. Please renew it as soon as possible...")
return 0
if pargs.all and pargs.letsencrypt == "renew":
@@ -1098,16 +1110,20 @@ class WOSiteUpdateController(CementBaseController):
Log.info(self, "SUCCESS: Certificate was successfully renewed For"
" https://{0}".format(wo_domain))
else:
Log.info(self,"You have more than 30 days with the current certificate - refusing to run.\n")
Log.info(
self, "You have more than 30 days with the current certificate - refusing to run.\n")
if (SSL.getExpirationDays(self, wo_domain) > 0):
Log.info(self, "Your cert will expire within " + str(SSL.getExpirationDays(self,wo_domain)) + " days.")
Log.info(self, "Expiration date: \n\n" + str(SSL.getExpirationDate(self,wo_domain)))
Log.info(self, "Your cert will expire within " +
str(SSL.getExpirationDays(self, wo_domain)) + " days.")
Log.info(self, "Expiration date: \n\n" +
str(SSL.getExpirationDate(self, wo_domain)))
return 0
# else:
# Log.warn(self, "Your cert already EXPIRED ! .PLEASE renew soon . ")
else:
Log.info(self,"SSL not configured for site http://{0}".format(wo_domain))
Log.info(
self, "SSL not configured for site http://{0}".format(wo_domain))
return 0
if pargs.all and pargs.letsencrypt == "off":
@@ -1165,7 +1181,8 @@ class WOSiteUpdateController(CementBaseController):
if pargs.hhvm == "on" or pargs.letsencrypt == "on" or pargs.php73 == "on":
if pargs.php73 == "on":
if (not pargs.experimental):
Log.info(self, "Do you wish to enable PHP 7.3 now for {0}?".format(wo_domain))
Log.info(
self, "Do you wish to enable PHP 7.3 now for {0}?".format(wo_domain))
check_prompt = input("Type \"y\" to continue [n]:")
if check_prompt != "Y" and check_prompt != "y":
@@ -1204,7 +1221,8 @@ class WOSiteUpdateController(CementBaseController):
if (not pargs.experimental):
if oldsitetype in ['wpsubdomain']:
Log.warn(self, "Wildcard domains are not supported in Lets Encrypt.\nWP SUBDOMAIN site will get SSL for primary site only.")
Log.warn(
self, "Wildcard domains are not supported in Lets Encrypt.\nWP SUBDOMAIN site will get SSL for primary site only.")
Log.info(self, "Letsencrypt is currently in beta phase."
" \nDo you wish"
@@ -1222,8 +1240,6 @@ class WOSiteUpdateController(CementBaseController):
data['letsencrypt'] = True
letsencrypt = True
if pargs.wpredis and data['currcachetype'] != 'wpredis':
if (not pargs.experimental):
Log.info(self, "Redis is experimental feature and it may not"
@@ -1310,9 +1326,11 @@ class WOSiteUpdateController(CementBaseController):
" https://{0}".format(wo_domain))
if (SSL.getExpirationDays(self, wo_domain) > 0):
Log.info(self, "Your cert will expire within " + str(SSL.getExpirationDays(self,wo_domain)) + " days.")
Log.info(self, "Your cert will expire within " +
str(SSL.getExpirationDays(self, wo_domain)) + " days.")
else:
Log.warn(self, "Your cert already EXPIRED ! .PLEASE renew soon . ")
Log.warn(
self, "Your cert already EXPIRED ! .PLEASE renew soon . ")
elif data['letsencrypt'] is False:
if os.path.isfile("{0}/conf/nginx/ssl.conf"
@@ -1331,7 +1349,6 @@ class WOSiteUpdateController(CementBaseController):
Log.info(self, "Successfully Disabled SSl for Site "
" http://{0}".format(wo_domain))
# Add nginx conf folder into GIT
WOGit.add(self, ["{0}/conf/nginx".format(wo_site_webroot)],
msg="Adding letsencrypts config of site: {0}"
@@ -1412,7 +1429,8 @@ class WOSiteUpdateController(CementBaseController):
(data['wpfc'])) or (oldsitetype == 'wp' and data['multisite'] and data['wpfc'])):
try:
plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_fastcgi","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)
setupwp_plugin(
self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)
except SiteError as e:
Log.debug(self, str(e))
Log.info(self, Log.FAIL + "Update nginx-helper settings failed. "
@@ -1424,7 +1442,8 @@ class WOSiteUpdateController(CementBaseController):
(data['wpredis'])) or (oldsitetype == 'wp' and data['multisite'] and data['wpredis'])):
try:
plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":1,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_redis","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)
setupwp_plugin(
self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)
except SiteError as e:
Log.debug(self, str(e))
Log.info(self, Log.FAIL + "Update nginx-helper settings failed. "
@@ -1434,7 +1453,8 @@ class WOSiteUpdateController(CementBaseController):
else:
try:
plugin_data = '{"log_level":"INFO","log_filesize":5,"enable_purge":0,"enable_map":0,"enable_log":0,"enable_stamp":0,"purge_homepage_on_new":1,"purge_homepage_on_edit":1,"purge_homepage_on_del":1,"purge_archive_on_new":1,"purge_archive_on_edit":0,"purge_archive_on_del":0,"purge_archive_on_new_comment":0,"purge_archive_on_deleted_comment":0,"purge_page_on_mod":1,"purge_page_on_new_comment":1,"purge_page_on_deleted_comment":1,"cache_method":"enable_redis","purge_method":"get_request","redis_hostname":"127.0.0.1","redis_port":"6379","redis_prefix":"nginx-cache:"}'
setupwp_plugin(self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)
setupwp_plugin(
self, 'nginx-helper', 'rt_wp_nginx_helper_options', plugin_data, data)
except SiteError as e:
Log.debug(self, str(e))
Log.info(self, Log.FAIL + "Update nginx-helper settings failed. "
@@ -1477,12 +1497,16 @@ class WOSiteUpdateController(CementBaseController):
if installwp_plugin(self, 'redis-cache', data):
# search for wp-config.php
if WOFileUtils.isexist(self, "{0}/wp-config.php".format(wo_site_webroot)):
config_path = '{0}/wp-config.php'.format(wo_site_webroot)
config_path = '{0}/wp-config.php'.format(
wo_site_webroot)
elif WOFileUtils.isexist(self, "{0}/htdocs/wp-config.php".format(wo_site_webroot)):
config_path = '{0}/htdocs/wp-config.php'.format(wo_site_webroot)
config_path = '{0}/htdocs/wp-config.php'.format(
wo_site_webroot)
else:
Log.debug(self, "Updating wp-config.php failed. File could not be located.")
Log.error(self,"wp-config.php could not be located !!")
Log.debug(
self, "Updating wp-config.php failed. File could not be located.")
Log.error(
self, "wp-config.php could not be located !!")
raise SiteError
if WOShellExec.cmd_exec(self, "grep -q \"WP_CACHE_KEY_SALT\" {0}"
@@ -1636,7 +1660,8 @@ class WOSiteDeleteController(CementBaseController):
mark_db_delete_prompt = True
Log.info(self, "Deleting Database, {0}, user {1}"
.format(wo_db_name, wo_db_user))
deleteDB(self, wo_db_name, wo_db_user, wo_mysql_grant_host, False)
deleteDB(self, wo_db_name, wo_db_user,
wo_mysql_grant_host, False)
updateSiteInfo(self, wo_domain,
db_name='deleted',
db_user='deleted',