From d0891dc095d53a9120a9129b2f2ddbf36f8ac52c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristhian=20Mart=C3=ADnez=20Ochoa?= Date: Fri, 16 Jun 2023 10:30:16 -0700 Subject: [PATCH] updates Check for OS updates when Webinoly is updated. Fixed the check for updates function failing in verify. --- lib/general | 10 +++++----- lib/verify | 39 ++++++++++++++++++++++----------------- weby | 8 +++++++- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/lib/general b/lib/general index 31aa742..acc6f9f 100644 --- a/lib/general +++ b/lib/general @@ -32,8 +32,8 @@ readonly hidend=$(tput sgr0)$(tput el) # *********************************************** conf_read() { - if [[ ! -f /opt/webinoly/webinoly.conf ]]; then - echo "${red}[ERROR] Config file not found!${end}" + if [[ ! -f /opt/webinoly/webinoly.conf ]]; then # Double check! + echo "${red}[ERROR] Webinoly Configuration file not found!${end}" exit 1 fi @@ -41,8 +41,8 @@ conf_read() { } conf_delete() { - if [[ ! -f /opt/webinoly/webinoly.conf ]]; then - echo "${red}[ERROR] Config file not found!${end}" + if [[ ! -f /opt/webinoly/webinoly.conf ]]; then # Double check! + echo "${red}[ERROR] Webinoly Configuration file not found!${end}" exit 1 fi @@ -78,7 +78,7 @@ conf_write() { if [[ $(whoami) != "root" ]]; then echo "${red}Please run this script as root or using sudo.${end}" exit 1 -fi +fi # Check for BASH Shell # This is a very "shity" method, but checking if file exists is very reliable diff --git a/lib/verify b/lib/verify index 0959300..3b4f39a 100644 --- a/lib/verify +++ b/lib/verify @@ -1,4 +1,7 @@ #!/bin/bash +# Example: sudo webinoly -verify +# Example: sudo webinoly -verify=critical +# Example: sudo webinoly -verify -check-for-updates webinoly_verify() { @@ -860,32 +863,32 @@ fi local ver_five_err="0" local ver_five_war="0" -if ! systemctl is-active --quiet nginx && [[ $(conf_read nginx) == "true" ]]; then +if [[ $(conf_read nginx) == "true" ]] && ! systemctl is-active --quiet nginx; then echo "- [ERROR] Nginx service not running!" local ver_five_err="1" fi -if ! systemctl is-active --quiet php$(conf_read php-ver)-fpm && [[ $(conf_read php) == "true" ]]; then +if [[ $(conf_read php) == "true" ]] && ! systemctl is-active --quiet php$(conf_read php-ver)-fpm; then echo "- [ERROR] PHP service not running!" local ver_five_err="1" fi -if ! systemctl is-active --quiet mysql && [[ $(conf_read mysql) == "true" ]]; then +if [[ $(conf_read mysql) == "true" ]] && ! systemctl is-active --quiet mysql; then echo "- [ERROR] MySQL/MariaDB service not running!" local ver_five_err="1" fi -if ! systemctl is-active --quiet redis-server && [[ $(conf_read php-tool-redis) == "true" ]]; then +if [[ $(conf_read php-tool-redis) == "true" ]] && ! systemctl is-active --quiet redis-server; then echo "- [ERROR] Redis service not running!" local ver_five_err="1" fi -if ! systemctl is-active --quiet memcached && [[ $(conf_read php-tool-memcached) == "true" ]]; then +if [[ $(conf_read php-tool-memcached) == "true" ]] && ! systemctl is-active --quiet memcached; then echo "- [ERROR] Memcached service not running!" local ver_five_err="1" fi -if ! systemctl is-active --quiet postfix && [[ $(conf_read php-tool-postfix) == "true" ]]; then +if [[ $(conf_read php-tool-postfix) == "true" ]] && ! systemctl is-active --quiet postfix; then echo "- [ERROR] Postfix service not running!" local ver_five_err="1" fi -if ! sudo nginx -t 2>/dev/null && [[ $(conf_read nginx) == "true" ]]; then +if [[ $(conf_read nginx) == "true" ]] && ! sudo nginx -t 2>/dev/null; then echo "- [ERROR] Nginx Configuration check failed!" local ver_five_err="1" fi @@ -945,7 +948,18 @@ if ! which wget >/dev/null ; then local ver_six_err="1" fi - +# Check for OS Updates +# Run in non-critical mode and when updating Webinoly to remember that is important to keep the OS updated, not only Webinoly. +# For example, we can implement new Nginx directives and it will fails if Nginx package is not updated. +if [[ -z $critical_mode || -n $check_for_updates ]]; then + if [[ -f /usr/lib/update-notifier/apt-check ]]; then + local ver_os_updates=$(echo $(/usr/lib/update-notifier/apt-check --human-readable) | grep -Eo "[0-9]+ " | head -1 | sed "s/ //") + if [[ $ver_os_updates =~ ^[0-9]+$ && $ver_os_updates -gt 0 ]]; then + echo "${dim}- [WARNING] Operating System is not updated, $ver_os_updates updates can be installed immediately.${end}${red}" + local ver_six_war="1" + fi + fi +fi if [[ -z $critical_mode ]]; then # Check for BASH Shell # This is a very "shity" method, but checking if file exists is very reliable @@ -965,15 +979,6 @@ if [[ -z $critical_mode ]]; then fi fi - # Check for updates - if [[ -a /usr/lib/update-notifier/apt-check ]]; then - local ver_os_updates=$(echo $(/usr/lib/update-notifier/apt-check --human-readable) | grep -Eo "^[0-9]+ " | head -1 | sed "s/ //") - if [[ $ver_os_updates =~ ^[0-9]+$ && $ver_os_updates -gt 0 ]]; then - echo "${dim}- [WARNING] Operating System is not updated, $ver_os_updates updates can be installed immediately.${end}${red}" - local ver_six_war="1" - fi - fi - # Check if timezone is set if [[ -z $(conf_read timezone) ]] || ! grep -Fxq $(conf_read timezone) /opt/webinoly/lib/timezone.dat; then echo "${dim}- [WARNING] Timezone is not set or not valid!${end}${red}" diff --git a/weby b/weby index 44a8b41..f427a72 100644 --- a/weby +++ b/weby @@ -205,7 +205,13 @@ fi [[ $setup == 1 ]] && stack -nginx [[ $setup == 2 ]] && stack -php=nginx [[ $setup == 3 ]] && stack -lemp -[[ $setup != [123] ]] && sudo webinoly -verify=critical + +# Verify installation! +if [[ $setup != [123] && -n $update && -n $oldapp ]]; then + sudo webinoly -verify=critical -check-for-updates +elif [[ $setup != [123] ]]; then + sudo webinoly -verify=critical +fi # Message Center if [[ -z $(conf_read stack-build-error-flag) ]]; then