proinfodata 5.37 KB
Newer Older
1
#!/bin/bash
2
# Copyright (C) 2009-2012 Centro de Computacao Cientifica e Software Livre
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
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of proinfodata
#
# proinfodata is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.

# This script will ask some configurations needed by the agent

# Web service used to get the information about the school
WEBSERVICE="http://seed.c3sl.ufpr.br:8888/axis/services/Seed2InstallService"

# Time the user have to read error messages, in seconds
TIMETOREAD=3

SEED_HOME=/opt/seed_mec

# INEP file
INEPFILE="${SEED_HOME}/SEED2/client/conf/inep"
34 35
MD5INEPFILE="${SEED_HOME}/SEED2/.md5sum/client/conf/inep"
BACKUPINEPFILE="${SEED_HOME}/SEED2/.backup/client/conf/inep"
36 37 38

# Proxy file
PROXYFILE="${SEED_HOME}/SEED2/client/conf/proxy"
39 40
MD5PROXYFILE="${SEED_HOME}/SEED2/.md5sum/client/conf/proxy"
BACKUPPROXYFILE="${SEED_HOME}/SEED2/.backup/client/conf/proxy"
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

# If INEP was already set, exit.
if test $(cat ${INEPFILE} 2> /dev/null | wc -l) -ne 0 ; then
    exit 0
fi

# Create a temp file to store some dialog answers.
ans=$(mktemp)

# test_exit exits if the given argument is equal to 255.
# This is used to test if the user pressed the ESC key.
function test_exit() {
    if test $1 -eq 255 ; then
        # Remove ans file.
        rm -f ${ans}
        # Start it again and exit.
        $0
        exit 0
    fi
}

DIALOG="dialog --backtitle PROINFODATA --shadow --title"

# Want to do it?
if ! ${DIALOG} PROINFODATA --yesno 'O agente de acompanhamento do projeto
PROINFODATA foi instalado com sucesso nesta máquina. Para torná-lo
funcional, entretanto, é necessário fornecer informações sobre as
configurações de proxy, além do número INEP da escola. Pressione ESC a
qualquer momento para retornar a esta tela. Deseja continuar?' 0 0 ; then
    # The user didn't say 'yes'.
    exit 0
fi

# Ask for proxy configuration.
${DIALOG}  proxy --yesno 'Você possui informações de proxy?' 0 0
has_proxy=$?
test_exit ${has_proxy}

if test ${has_proxy} -eq 0; then
    declare -a formans
    ${DIALOG} proxy --form 'Preencha as informações de proxy:' 12 55 5 \
        "Host:" 1 1 "" 1 20 100 100 \
        "Porta:" 2 1 "" 2 20 100 100 \
        "Usuario:" 3 1 "" 3 20 100 100 \
        2> ${ans}
    test_exit $?

    i=0
    while read line; do
        formans[${i}]=${line}
        (( i++ ))
    done < ${ans}

    phost=${formans[0]}
    pport=${formans[1]}
    puid=${formans[2]}


    equalpass=1
    while test ${equalpass} -ne 0 ; do
        ${DIALOG} proxy --insecure --passwordform 'Preencha a senha do
proxy, se necessário:' 12 55 5 \
            "Senha:" 1 1 "" 1 20 100 100 \
            "Confirmar Senha:" 2 1 "" 2 20 100 100 \
            2> ${ans}
        test_exit $?

        i=0
        while read line; do
            formans[${i}]=${line}
            (( i++ ))
        done < ${ans}

        if [[ "${formans[0]}" != "${formans[1]}" ]]; then
            ${DIALOG} proxy --sleep ${TIMETOREAD} --infobox "As senhas
não conferem!" 0 0
        else
            equalpass=0
        fi
    done
    ppasswd=${formans[0]}
else
    phost=
    pport=
    puid=
    ppasswd=
fi

valid=1
while test ${valid} -ne 0; do

    # Ask INEP number.
    ${DIALOG} INEP --item-help --inputbox "Qual o número INEP de sua
escola?" 0 0 2> ${ans}
    test_exit $?
    INEP=$(cat ${ans})

    ${DIALOG} INEP --infobox "Aguarde, verificando INEP..." 0 0

    # Verify.
    clientans=$(mktemp)
    /usr/local/bin/getSchoolInfo "${WEBSERVICE}" "${INEP}" "${phost}" \
"${pport}" "${puid}" "${ppasswd}" > ${clientans}
    clientret=$?
    if test ${clientret} -ne 0 ; then
        ${DIALOG} INEP --sleep ${TIMETOREAD} --infobox "INEP ou proxy
inválido!" 0 0
        rm -f ${clientans}
    else
        school=$(head -n 1 ${clientans})
        zip=$(head -n 3 ${clientans} | tail -n 1)
        state=$(head -n 4 ${clientans} | tail -n 1)
        city=$(head -n 5 ${clientans} | tail -n 1)
        rm -f ${clientans}
        ${DIALOG} Confirmação --yesno "\
INEP: ${INEP} \n\
Estado: ${state} \n\
Cidade: ${city} \n\
Escola: ${school} \n\
CEP: ${zip} \n\
Essas informações estão corretas?
" 0 0
        valid=$?
        test_exit ${valid}
    fi
done

# Remove the ans file.
rm -f ${ans}

171
# Set variables
172 173 174 175 176 177
echo "${INEP}" > ${INEPFILE}
echo "phost=${phost}" > ${PROXYFILE}
echo "pport=${pport}" >> ${PROXYFILE}
echo "puid=${puid}" >> ${PROXYFILE}
echo "ppasswd=${ppasswd}" >> ${PROXYFILE}

178 179 180 181 182 183 184 185
# Generate md5 hashs for the files
md5sum ${INEPFILE} | cut -d' ' -f1 > ${MD5INEPFILE}
md5sum ${PROXYFILE} | cut -d' ' -f1 > ${MD5PROXYFILE}

# Backup the files
cp ${INEPFILE} ${BACKUPINEPFILE}
cp ${PROXYFILE} ${BACKUPPROXYFILE}

186 187 188 189 190 191
chown seed_mec:seed_mec ${INEPFILE}
chown seed_mec:seed_mec ${PROXYFILE}

${DIALOG} Finalização --msgbox "Os dados foram recebidos com sucesso." 0 0

exit 0