-
Notifications
You must be signed in to change notification settings - Fork 0
/
instala_coletor.sh
195 lines (159 loc) · 4.75 KB
/
instala_coletor.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
##########################################################################
# Title : Instala Coletor
# Author : Luciano Vilela Dourado <luciano.dourado@pgt.mpt.gov.br>
# Date : 2009-05-05
# Requires : wget rpm
##########################################################################
# Description
#
##########################################################################
PN=`basename $0`
VER='1.0'
REG_INSTALACAO=
SERVIDOR=http://homologacao.pgt.mpt.gov.br/svn/documentacao/trunk/Coletor-Client
ARQ_COLETOR=Coletor-Client-1.0.one-jar.jar
VERSAO_JAVA=1.5.0_18
VERSAO_ARQUIVO_JAVA=1_5_0_18
ARQ_JAVA=jre-${VERSAO_ARQUIVO_JAVA}-linux-i586.rpm
DIR_COLETOR=/var/www/MPTDigital/coletor
#WGET="wget -q "
WGET="wget -UMozilla/5.0 "
#REPOINI=http://homologacao.pgt.mpt.gov.br/svn/documentacao/trunk/GeracaoPacote/conf
#MPTDIGITAL_REPO=MPTDigital-Repo-1.0-0.0.2.noarch.rpm
function configuraEnv() {
LOG "Configurando o ambiente Java"
grep "#Configuracao Java" /etc/profile > /dev/null
if [ "$?" -eq "1" ]
then
cat << EOF >> /etc/profile
#Configuracao Java
JAVA_HOME=/usr/java/jre${VERSAO_JAVA}
PATH=${JAVA_HOME}/bin:\$PATH
export JAVA_HOME PATH
EOF
fi
}
function configuraCron() {
CRON=`$WGET ${SERVIDOR}/crontab.txt -O - | grep $REG_INSTALACAO | cut -d";" -f2`
if [ ! -z "$CRON" ]
then
crontab -l > crontab.temp
grep ${ARQ_COLETOR} crontab.temp > /dev/null
if [ "$?" -eq "1" ]
then
LOG "Configurando a crontab"
DATACRON=`date "+%d/%m/%Y %H:%M:%S"`
cat << EOF >> crontab.temp
#
#Configuracao do Coletor em $DATACRON
#
$CRON /usr/java/jre${VERSAO_JAVA}/bin/java -client -jar $DIR_COLETOR/${ARQ_COLETOR}
EOF
crontab crontab.temp
fi
unset DATACRON
rm -f crontab.temp
fi
}
function instalaJava() {
LOG "Instalando Java"
LOG "Baixando ${SERVIDOR}/${ARQ_JAVA}"
$WGET ${SERVIDOR}/${ARQ_JAVA}
if [ "$?" -eq "0" ]
then
rpm -ivh $ARQ_JAVA
else
LOG "Ocorreu um erro realizar a instalacao do Java"
fi
rm -f $ARQ_JAVA
}
function instalaColetor() {
LOG "Instalando coletor"
if [ ! -d $DIR_COLETOR ]
then
LOG "Criando diretorio $DIR_COLETOR"
mkdir $DIR_COLETOR
fi
DIR_ORIGEM=$PWD
cd $DIR_COLETOR
if [ -f "$DIR_COLETOR/${ARQ_COLETOR}" ]
then
DATA_LOG=`date "+%Y%m%d_%H%M%S"`
LOG "Renomeando ${ARQ_COLETOR} para ${ARQ_COLETOR}_${DATA_LOG}"
mv "$DIR_COLETOR/${ARQ_COLETOR}" "$DIR_COLETOR/${ARQ_COLETOR}_${DATA_LOG}"
fi
LOG "Baixando do Coletor do servidor ${SERVIDOR}/${ARQ_COLETOR}"
LOG $WGET ${SERVIDOR}/${ARQ_COLETOR}
$WGET ${SERVIDOR}/${ARQ_COLETOR}
if [ -f /etc/mptdigital.conf ]
then
LOG "Carregando configuracoes regionais de /etc/mtpdigital.conf"
. /etc/mptdigital.conf
if [ ! -d /var/www/MPTDigital/bancoDocumento/documentos/docs ]
then
LOG "ERROR ---- Diretorio de documento do Banco de documento nao foi encontrado"
fi
LOG "Configurando o coletor com as informacoes da Regional"
cat << EOF | /usr/java/jre${VERSAO_JAVA}/bin/java -client -jar $DIR_COLETOR/${ARQ_COLETOR}
s
$NUMREG
com.mysql.jdbc.Driver
$MYUSER
$MYPASS
jdbc:mysql://localhost/${DBNAME}
/var/www/MPTDigital/bancoDocumento/documentos/docs
S
n
EOF
fi
cd $DIR_ORIGEM
}
function usage() {
echo >&2 "$PN - Instalador do Coletor versao, $VER
usage: $PN [-i regional] [-cmd comando] [-h]
-cmd comando
usage
configuraEnv
configuraCron
instalaJava
instalaColetor
install ( Faz o processamento completo de instalacao )
clean ( Desistala todo os pacotes do Coletor - Em desenvolvimento)
-h: imprime essa mensagem
"
exit 1
}
function install() {
instalaJava
configuraEnv
instalaColetor
configuraCron
}
function LOG() {
echo `date "+%d/%m/%Y %H:%M:%S"` $@
}
##
# Tratamento de paramentos de entrada
##
while [ $# -gt 0 ]
do
case "$1" in
-i) shift; REG_INSTALACAO=$1;;
-cmd) shift; COMANDO=$1;;
--) shift; break;;
-h) usage;;
-*) usage;;
*) break;; # First file name
esac
shift
done
if [ -z "$REG_INSTALACAO" ]
then
usage
exit 1
fi
if [ ! -z "$COMANDO" ]
then
$COMANDO
fi