zabbix/mod/install.sh

125 lines
3.2 KiB
Bash

#!/bin/bash
# ZabbixMOD by IPv0
# Funções de cores para mensagens
_echo_green(){ /bin/echo -e "\033[0;32m$@\033[0m"; }
_echo_green_n(){ /bin/echo -ne "\033[0;32m$@\033[0m"; }
_echo_yellow(){ /bin/echo -e "\033[0;33m$@\033[0m"; }
_echo_yellow_n(){ /bin/echo -ne "\033[0;33m$@\033[0m"; }
_echo_red(){ /bin/echo -e "\033[0;31m$@\033[0m"; }
_echo_red_n(){ /bin/echo -ne "\033[0;31m$@\033[0m"; }
_echo_success(){ /bin/echo -en "\\033[91G"; /bin/echo -en "\x1B[97m["; /bin/echo -en "\033[1;32m OK \033[0m"; /bin/echo -e "\x1B[97m]\033[0m"; }
_echo_failure(){ /bin/echo -en "\\033[91G"; /bin/echo -en "\033[41m\e[5m"; /bin/echo -en "\033[1;38m\x1B FAILED \033[0m"; /bin/echo -e "\x1B[97m\033[0m"; }
### FUNÇÕES
## Dependências
_dependencias() {
DEPENDENCIAS=(
"figlet"
"python3-apt"
"lsb-release"
"git"
)
for pkg in "${DEPENDENCIAS[@]}"; do
if ! dpkg -l | grep -q "^ii $pkg"; then
_echo_yellow "Instalando dependência: $pkg..."
apt-get update -y && apt-get install -y "$pkg"
if [ $? -eq 0 ]; then
_echo_success "Dependência $pkg instalada com sucesso."
else
_echo_failure "Falha ao instalar a dependência $pkg."
exit 1
fi
else
_echo_green "Dependência $pkg já está instalada."
fi
done
}
## Motd
_motd() {
motd00="00-header"
> /etc/update-motd.d/$motd00
cat << 'EOF' > "/etc/update-motd.d/$motd00"
#!/bin/sh
# Função para exibir texto em vermelho
_echo_red() {
/bin/echo -e "\033[0;31m$@\033[0m"
}
# Gerar o nome "ZABBIX" com figlet e aplicar a cor vermelha
name=$(figlet -W -w 640 "ZABBIX")
_echo_red "$name"
[ -r /etc/lsb-release ] && . /etc/lsb-release
if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
# Fall back to using the very slow lsb_release utility
DISTRIB_DESCRIPTION=$(lsb_release -s -d)
fi
printf "\n"
printf "Bem vindo ao %s (%s).\n" "$DISTRIB_DESCRIPTION" "$(uname -r)"
printf "\n"
EOF
chmod +x /etc/update-motd.d/*
cd /etc && rm -f /etc/motd && rm -rf /var/run/motd*
ln -s /var/run/motd.dynamic.new motd
}
_issue() {
## Font adicional pro figlet
wget -O /usr/share/figlet/Broadway.flf https://git.ipv0.com.br/halbebruno/Linux/raw/branch/master/mod/Broadway.flf
cp /etc/issue /etc/issue.backup
issue_content=$(cat /etc/issue)
figlet_output=$(figlet -Wf Broadway -w 480 "ZABBIX")
cat << EOF > /etc/issue
$figlet_output
by TECCNIA - https://teccnia.com.br
$issue_content
EOF
}
# --------------------------------------
### Verifica se o usuário é root
if [ "$EUID" -ne 0 ]; then
_echo_red "\n Você deve ser root para executar este script!\n"
exit 1
fi
### Executa Funções
if ! _dependencias; then
_echo_red "Falhas ocorreram na instalação dos pacotes. Verifique as mensagens acima."
exit 1 # Encerra o script aqui, se necessário
fi
if ! _motd; then
_echo_red "Falhas ocorreram. Verifique as mensagens acima."
exit 1 # Encerra o script aqui, se necessário
fi
if ! _issue; then
_echo_red "Falhas ocorreram. Verifique as mensagens acima."
exit 1 # Encerra o script aqui, se necessário
fi
_echo_green "\n Todos os ajustes foram realizados!"