bash check

Bash shell check - interactive instead of default login.
This commit is contained in:
Cristhian Martínez Ochoa 2022-02-21 14:48:56 -07:00
parent 9b7cdc7aab
commit 02d29d9a83
3 changed files with 33 additions and 4 deletions

View file

@ -24,10 +24,17 @@ readonly dim=`tput dim`
# Check for BASH Shell
if [[ -z $(grep -E "^${SUDO_USER:-${USER}}\:.*\/bash.*$" /etc/passwd) ]]; then
echo "$(tput setaf 1)BASH Shell is required!$(tput sgr0)"
if [[ -f /proc/$(ps -aux | grep -E "${SUDO_USER:-${USER}}.*pts/0" | grep -v "grep" | tail -n 1 | awk '{print $2}')/cmdline ]]; then
# This is a very "shity" method, but checking if file exists is very reliable
shell_current=$(tr -d '\000' < /proc/$(ps -aux | grep -E "${SUDO_USER:-${USER}}.*pts/0" | grep -v "grep" | tail -n 1 | awk '{print $2}')/cmdline)
elif [[ -f /proc/$(ps -aux | grep -E "$USER.*pts/0[ ]+S[ ]+" | tail -n 1 | awk '{print $2}')/cmdline ]]; then
shell_current=$(tr -d '\000' < /proc/$(ps -aux | grep -E "$USER.*pts/0[ ]+S[ ]+" | tail -n 1 | awk '{print $2}')/cmdline)
fi
if [[ -n $shell_current && $shell_current != *"bash"* ]]; then
echo "${red}BASH Shell is required! ${dim}(${shell_current}) ${end}"
exit 1
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}"

View file

@ -750,6 +750,21 @@ if [[ $ver_disk =~ ^[0-9]+$ && $ver_disk -gt 75 ]]; then
fi
if [[ -z $critical_mode ]]; then
# Check for BASH Shell
if [[ -f /proc/$(ps -aux | grep -E "${SUDO_USER:-${USER}}.*pts/0" | grep -v "grep" | tail -n 1 | awk '{print $2}')/cmdline ]]; then
# This is a very "shity" method, but checking if file exists is very reliable
local ver_shell_current=$(tr -d '\000' < /proc/$(ps -aux | grep -E "${SUDO_USER:-${USER}}.*pts/0" | grep -v "grep" | tail -n 1 | awk '{print $2}')/cmdline)
elif [[ -f /proc/$(ps -aux | grep -E "$USER.*pts/0[ ]+S[ ]+" | tail -n 1 | awk '{print $2}')/cmdline ]]; then
local ver_shell_current=$(tr -d '\000' < /proc/$(ps -aux | grep -E "$USER.*pts/0[ ]+S[ ]+" | tail -n 1 | awk '{print $2}')/cmdline)
else
echo "${blu}${dim}- [INFO] Shell check fails to retrieve data! ${end}${red}"
fi
if [[ -n $ver_shell_current && $ver_shell_current != *"bash"* ]]; then
# Should never be displayed because is blocked in general lib, but who knows!
echo "${red}- [WARNING] BASH Shell is required! ${dim}(${shell_current}) ${end}"
local ver_six_war="1"
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/ //")

11
weby
View file

@ -14,8 +14,15 @@ if ! [[ $distr == "Ubuntu" && $osver =~ ^(bionic|focal)$ ]]; then
fi
# Check for BASH Shell
if [[ -z $(grep -E "^${SUDO_USER:-${USER}}\:.*\/bash.*$" /etc/passwd) ]]; then
echo "$(tput setaf 1)BASH Shell is required!$(tput sgr0)"
if [[ -f /proc/$(ps -aux | grep -E "${SUDO_USER:-${USER}}.*pts/0" | grep -v "grep" | tail -n 1 | awk '{print $2}')/cmdline ]]; then
# This is a very "shity" method, but checking if file exists is very reliable
shell_current=$(tr -d '\000' < /proc/$(ps -aux | grep -E "${SUDO_USER:-${USER}}.*pts/0" | grep -v "grep" | tail -n 1 | awk '{print $2}')/cmdline)
elif [[ -f /proc/$(ps -aux | grep -E "$USER.*pts/0[ ]+S[ ]+" | tail -n 1 | awk '{print $2}')/cmdline ]]; then
# This second check is useful when logedin as root
shell_current=$(tr -d '\000' < /proc/$(ps -aux | grep -E "$USER.*pts/0[ ]+S[ ]+" | tail -n 1 | awk '{print $2}')/cmdline)
fi
if [[ -n $shell_current && $shell_current != *"bash"* ]]; then
echo "$(tput setaf 1)BASH Shell is required! $(tput dim)(${shell_current}) $(tput sgr0)"
sudo rm weby
exit 1
fi