shell check

Bash check failing in 22.04 with some specific cloud providers, like DO.
This commit is contained in:
Cristhian Martínez Ochoa 2022-09-05 16:34:14 -06:00
parent daacd05c7b
commit c7906ff939
3 changed files with 26 additions and 41 deletions

View file

@ -4,7 +4,7 @@
# Prevent 'tput' errors when running from Cron
[[ -z $TERM || $TERM == "unknown" || $TERM == "dumb" ]] && export TERM=dumb
readonly app_version="1.16.6"
readonly app_version="1.16.7"
readonly svr_version="1.7"
readonly os_ubuntu_supported=(bionic focal jammy) # https://ubuntu.com/about/release-cycle
readonly php_supported=(7.4 8.0 8.1) # https://www.php.net/supported-versions.php
@ -23,27 +23,6 @@ readonly bol=`tput bold`
readonly dim=`tput dim`
# Check for BASH Shell
# This is a very "shity" method, but checking if file exists is very reliable
# If modified: this same script is in installer, general lib and verify
if [[ -n $(echo $(tty) | grep -Eo "pts/[0-9]+") && -n $(logname) ]]; then
shell_pid=$(ps -au | grep -E "^$(logname).*pts/[0-9]+[ ]+S[s]?[ ]+" | tail -n 1 | awk '{print $2}')
[[ -n $shell_pid && -f /proc/$shell_pid/cmdline ]] && shell_current=$(tr -d '\000' < /proc/$shell_pid/cmdline)
[[ -n $shell_pid && -f /proc/$shell_pid/status ]] && shell_status=$(grep -Eo '^Name:.*bash.*' /proc/$shell_pid/status) # Double check!!!
if [[ -n $shell_current && $shell_current != *"bash"* && -z $shell_status ]]; then
echo "${red}BASH Shell is required! ${dim}(${shell_current}) ${end}"
exit 1
fi
fi
# STOP and exit if not root or sudo.
if [[ $(whoami) != "root" ]]; then
echo "${red}Please run this script as root or using sudo.${end}"
exit 1
fi
# ***********************************************
# Configuration Management Functions **********
# ***********************************************
@ -97,6 +76,26 @@ ADMIN_PASS=$( echo $(conf_read mysql-admin) | openssl enc -d -a -salt )
readonly CURRENT_HOME=$(eval echo ~${SUDO_USER:-${USER}})
readonly CURRENT_USER=${SUDO_USER:-${USER}}
# Check for BASH Shell
# This is a very "shity" method, but checking if file exists is very reliable
# If modified: this same script is in installer, general lib and verify
if [[ $(conf_read shell-check) != "false" && -n $(echo $(tty) | grep -Eo "pts/[0-9]+") && -n $(logname) ]]; then
pre_pid=$(ps -au | grep -E "pts/[0-9]+[ ]+S[s]?[ ]+" | sed '/sudo/d' | tail -n 1)
[[ -n $pre_pid ]] && shell_pid=$(echo $pre_pid | awk '{print $2}')
[[ -n $shell_pid && -f /proc/$shell_pid/cmdline ]] && shell_current=$(tr -d '\000' < /proc/$shell_pid/cmdline)
[[ -n $shell_pid && -f /proc/$shell_pid/status ]] && shell_status=$(grep -Eo '^Name:.*bash.*' /proc/$shell_pid/status) # Double check!!!
if [[ -n $shell_current && $shell_current != *"bash"* && -z $shell_status ]]; then
echo "${red}[WARNING] Seems like you are using an interactive shell different than BASH! ${dim}($(echo $pre_pid | awk '{print $1}'):${shell_current}) ${end}"
fi
fi
# STOP and exit if not root or sudo.
if [[ $(whoami) != "root" ]]; then
echo "${red}Please run this script as root or using sudo.${end}"
exit 1
fi
# ***********************************************
# General Functions ***************************

View file

@ -791,14 +791,15 @@ if [[ -z $critical_mode ]]; then
# Check for BASH Shell
# This is a very "shity" method, but checking if file exists is very reliable
# If modified: this same script is in installer, general lib and verify
if [[ -n $(echo $(tty) | grep -Eo "pts/[0-9]+") && -n $(logname) ]]; then
local ver_shell_pid=$(ps -au | grep -E "^$(logname).*pts/[0-9]+[ ]+S[s]?[ ]+" | tail -n 1 | awk '{print $2}')
if [[ $(conf_read shell-check) != "false" && -n $(echo $(tty) | grep -Eo "pts/[0-9]+") && -n $(logname) ]]; then
local ver_pre_pid=$(ps -au | grep -E "pts/[0-9]+[ ]+S[s]?[ ]+" | sed '/sudo/d' | tail -n 1)
[[ -n $ver_pre_pid ]] && local ver_shell_pid=$(echo $ver_pre_pid | awk '{print $2}')
[[ -n $ver_shell_pid && -f /proc/$ver_shell_pid/cmdline ]] && local ver_shell_current=$(tr -d '\000' < /proc/$ver_shell_pid/cmdline)
[[ -n $ver_shell_pid && -f /proc/$ver_shell_pid/status ]] && ver_shell_status=$(grep -Eo '^Name:.*bash.*' /proc/$ver_shell_pid/status) # Double check!!!
[[ -n $ver_shell_pid && -f /proc/$ver_shell_pid/status ]] && local ver_shell_status=$(grep -Eo '^Name:.*bash.*' /proc/$ver_shell_pid/status) # Double check!!!
if [[ -n $ver_shell_current && $ver_shell_current != *"bash"* && -z $ver_shell_status ]]; then
# Should never be displayed because is blocked in general lib, but who knows!
echo "${dim}- [WARNING] BASH Shell is required! ${dim}(${ver_shell_current}) ${end}${red}"
echo "${dim}- [WARNING] Seems like you are using an interactive shell different than BASH! ${dim}($(echo $ver_pre_pid | awk '{print $1}'):${ver_shell_current}) ${end}${red}"
local ver_six_war="1"
elif [[ -z $ver_shell_current ]]; then
echo "${blu}${dim}- [INFO] Shell check fails to retrieve data! ${end}${red}"

15
weby
View file

@ -12,21 +12,6 @@ if ! [[ $distr == "Ubuntu" && $osver =~ ^(bionic|focal|jammy)$ ]]; then
exit 1
fi
# Check for BASH Shell
# This is a very "shity" method, but checking if file exists is very reliable
# If modified: this same script is in installer, general lib and verify
if [[ -n $(echo $(tty) | grep -Eo "pts/[0-9]+") && -n $(logname) ]]; then
ins_shell_pid=$(ps -au | grep -E "^$(logname).*pts/[0-9]+[ ]+S[s]?[ ]+" | tail -n 1 | awk '{print $2}')
[[ -n $ins_shell_pid && -f /proc/$ins_shell_pid/cmdline ]] && ins_shell_current=$(tr -d '\000' < /proc/$ins_shell_pid/cmdline)
[[ -n $ins_shell_pid && -f /proc/$ins_shell_pid/status ]] && ins_shell_status=$(grep -Eo '^Name:.*bash.*' /proc/$ins_shell_pid/status) # Double check!!!
if [[ -n $ins_shell_current && $ins_shell_current != *"bash"* && -z $ins_shell_status ]]; then
echo "$(tput setaf 1)BASH Shell is required! $(tput dim)(${ins_shell_current}) $(tput sgr0)"
sudo rm weby
exit 1
fi
fi
# Check for sudo/root privileges
if [[ $(whoami) != "root" ]]; then
echo "$(tput setaf 1)Please run this script as root or using sudo.$(tput sgr0)"