Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Check for OS updates when Webinoly is updated.
Fixed the check for updates function failing in verify.
  • Loading branch information
QROkes committed Jun 16, 2023
1 parent eb5f32a commit d0891dc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
10 changes: 5 additions & 5 deletions lib/general
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ 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

echo $(grep -w -m 1 "^${1}:.*" /opt/webinoly/webinoly.conf | cut -f 2- -d ':')
}

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

Expand Down Expand Up @@ -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
Expand Down
39 changes: 22 additions & 17 deletions lib/verify
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash
# Example: sudo webinoly -verify
# Example: sudo webinoly -verify=critical
# Example: sudo webinoly -verify -check-for-updates


webinoly_verify() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}"
Expand Down
8 changes: 7 additions & 1 deletion weby
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d0891dc

Please sign in to comment.