-
Notifications
You must be signed in to change notification settings - Fork 2
/
notificacoes-beta.sh
117 lines (90 loc) · 3.39 KB
/
notificacoes-beta.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# ESCRITO POR SANSÃO
versionM=3.9
CMDLINE=$0
USER_ROOT=$(id | cut -d= -f2 | cut -d\( -f1)
pythonVersion=$(/usr/bin/python3 -V 2>&1)
command_rc=$?
versionP=$(echo $pythonVersion | cut -d' ' -f2 | cut -d. -f1,2)
pathPIP=$(/usr/bin/which pip3 2>&1 )
versionP2=$(echo $versionP | cut -d. -f2)
versionM2=$(echo $versionM | cut -d. -f2)
# Detecta se é um usuário com poderes de root que esta executando o script
#####################################################################################
if [ ! "$USER_ROOT" -eq 0 ] ; then
echo ""
echo "você deve ser root para executar este script, execute o comando:"
echo ""
echo "sudo bash $CMDLINE"
echo ""
exit 1
# Detecta se o python 3.9 ou superior existe no ambiente
#####################################################################################
elif [ $command_rc -ne 0 ]; then
echo ""
echo "Apontamento '/usr/bin/python3' não encontrado."
echo "Instale/Aponte o '/usr/bin/python3.9' ou superior para '/usr/bin/python3' e reexecute o comando:"
echo ""
echo "sudo bash notificacoes.sh"
echo ""
exit 2
# Detecta se o apontamento para python3 está para python 3.9 ou superior.
#####################################################################################
elif [ 1 -eq "$(echo "${versionP2} < ${versionM2}" | bc)" ] ; then
echo ""
echo "A versão apontada para o '/usr/bin/python3' é do \"$pythonVersion\"."
echo "Instale/Atualize/Aponte para o python3.9 ou superior e reexecute o comando:"
echo ""
echo "sudo bash notificacoes.sh"
echo ""
exit 3
fi
echo ""
echo ""
echo "Versão do '/usr/bin/python3' validada:"
echo "Apontado para \"$pythonVersion\"."
echo ""
echo ""
PATHSCRIPTS0="$(/usr/sbin/zabbix_server --help | grep "AlertScriptsPath" | awk '{ print $2 }' | tr -d "\"")"
PROJETO=Graphical_notifications_Zabbix
URLGIT=https://github.com/sansaoipb/$PROJETO
MODULOS=/var/lib/zabbix
PATHPACKET=/usr/lib/zabbix
PATHSOURCE=/usr/local/share/zabbix
PATHS=$PATHSCRIPTS0
delete=alertscripts
ARRAY=${PATHS[@]/$delete}
PATHSCRIPTS=$ARRAY
if [ ! -e $MODULOS ] ; then
sudo mkdir -p $MODULOS
fi
if [ ! -e $PATHSCRIPTS ] ; then
sudo mkdir -p $PATHSCRIPTS
fi
if [ -e $PATHPACKET ] ; then
if [ ! -e $PATHSCRIPTS0 ] ; then
sudo ln -s $PATHPACKET/alertscripts/ $PATHPACKET/externalscripts/ $PATHSCRIPTS
fi
sudo chown -R zabbix:zabbix $PATHPACKET
else
if [ ! -e $PATHSCRIPTS0 ] ; then
sudo ln -s $PATHSOURCE/alertscripts/ $PATHSOURCE/externalscripts/ $PATHSCRIPTS
fi
sudo chown -R zabbix:zabbix $PATHSOURCE
fi
cd /tmp/ ; sudo chown -R zabbix:zabbix $MODULOS ; sudo -H -u zabbix /usr/bin/pip3 install wheel requests urllib3 pyrogram tgcrypto pycryptodome --user -U
if [ ! -e $PROJETO ] ; then
git clone -b beta $URLGIT
fi
if [ ! -e "$PATHSCRIPTS0/configScripts.properties" ] ; then
sudo cp -R /tmp/$PROJETO/configScripts.properties $PATHSCRIPTS0
fi
cd /tmp/$PROJETO/ ; sudo cp -R notificacoes* $PATHSCRIPTS0 ; cd $PATHSCRIPTS0 ; sudo chmod +x *.py ; dos2unix *.py ; sudo rm -rf /tmp/$PROJETO/ ; sudo chown -R zabbix:zabbix $PATHSCRIPTS $PATHSCRIPTS0
echo ""
echo "Execute o comando abaixo para editar o arquivo de configuração:"
echo ""
echo "cd $PATHSCRIPTS0 ; sudo -u zabbix vim configScripts.properties"
echo ""
echo "e vamos começar com os envios"
echo ""
sudo rm -rf /tmp/notificacoes.sh