From 6e609ec72fe8b56332524647f0e5a92bfea1da55 Mon Sep 17 00:00:00 2001 From: Ricardo Tavares de Oliveira <rto07@c3sl.ufpr.br> Date: Thu, 27 May 2010 15:24:26 -0300 Subject: [PATCH] package: Created a directory structure to struct the debian package This directory structure contains some (not all) files that will be inside the debian package. It contains: - DEBIAN/*: {post,pre}{inst,rm} scripts; - etc/init.d/proinfodata: A text-based script to ask the user the INEP number and proxy configuration; - etc/rc2.d/S88proinfodata: A symbolic link to ../init.d/proinfodata. Acked-by: Danilo K. S. Yorinori <danilok@c3sl.ufpr.br> Acked-by: Diego Giovane Pasqualin <dgp06@c3sl.ufpr.br> Signed-off-by: Ricardo Tavares de Oliveira <rto07@c3sl.ufpr.br> --- proinfodatadeb/package/DEBIAN/control | 15 ++ proinfodatadeb/package/DEBIAN/postinst | 32 ++++ proinfodatadeb/package/DEBIAN/preinst | 49 +++++ proinfodatadeb/package/DEBIAN/prerm | 33 ++++ proinfodatadeb/package/etc/init.d/proinfodata | 180 ++++++++++++++++++ .../package/etc/rc2.d/S88proinfodata | 1 + 6 files changed, 310 insertions(+) create mode 100644 proinfodatadeb/package/DEBIAN/control create mode 100755 proinfodatadeb/package/DEBIAN/postinst create mode 100755 proinfodatadeb/package/DEBIAN/preinst create mode 100755 proinfodatadeb/package/DEBIAN/prerm create mode 100755 proinfodatadeb/package/etc/init.d/proinfodata create mode 120000 proinfodatadeb/package/etc/rc2.d/S88proinfodata diff --git a/proinfodatadeb/package/DEBIAN/control b/proinfodatadeb/package/DEBIAN/control new file mode 100644 index 0000000..8fe9430 --- /dev/null +++ b/proinfodatadeb/package/DEBIAN/control @@ -0,0 +1,15 @@ +Package: proinfodata +Version: 1.1.0 +Maintainer: <proinfodata@c3sl.ufpr.br> +Architecture: i386 +Depends: dialog, wget, passwd, libc6 +Description: Agent of PROINFODATA project + + Coleta de dados do projeto ProInfo/MEC de inclusão digital nas escolas + públicas brasileiras (PROINFODATA) is a project supported by Ministério da + Educação e Cultura (MEC) that collects some information about computer + laboratories at public schools in Brazil and make these data avaiable + through a website. + + This agent periodically collects the data of the computer that it is + installed and sends them to a webservice running on internet. diff --git a/proinfodatadeb/package/DEBIAN/postinst b/proinfodatadeb/package/DEBIAN/postinst new file mode 100755 index 0000000..52701b5 --- /dev/null +++ b/proinfodatadeb/package/DEBIAN/postinst @@ -0,0 +1,32 @@ +#!/bin/bash +# Copyright (C) 2004-2010 Centro de Computacao Cientifica e Software Livre +# 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 is the postinst of proinfodata + +SEED_MEC_HOME="/opt/seed_mec" + +# Make sure the owner of ~seed_mec is seed_mec +chown -R seed_mec:seed_mec "${SEED_MEC_HOME}" + +# Run the agent for the first time +su -c "bash ${SEED_MEC_HOME}/SEED2/agent.sh" seed_mec + +exit 0 diff --git a/proinfodatadeb/package/DEBIAN/preinst b/proinfodatadeb/package/DEBIAN/preinst new file mode 100755 index 0000000..3090654 --- /dev/null +++ b/proinfodatadeb/package/DEBIAN/preinst @@ -0,0 +1,49 @@ +#!/bin/bash -e +# Copyright (C) 2004-2010 Centro de Computacao Cientifica e Software Livre +# 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 is the preinst of proinfodata + +SEED_MEC_HOME="/opt/seed_mec" + + +# This function shows some error message and aborts execution +abort() { + printf "error: fatal: $1\n" + exit 1 +} + +# Create seed_mec group +if ! groupadd -fr seed_mec; then + abort "error while creating the group seed_mec." +fi + + +# Create seed_mec user +mkdir -p ${SEED_MEC_HOME} + +TMPSKEL=$(mktemp -d) +if ! useradd -rm -g seed_mec -s /bin/bash -d "${SEED_MEC_HOME}" \ + -k "${TMPSKEL}" seed_mec; then + abort "error while creating the user seed_mec." +fi +rmdir ${TMPSKEL} + +exit 0 diff --git a/proinfodatadeb/package/DEBIAN/prerm b/proinfodatadeb/package/DEBIAN/prerm new file mode 100755 index 0000000..b6b7555 --- /dev/null +++ b/proinfodatadeb/package/DEBIAN/prerm @@ -0,0 +1,33 @@ +#!/bin/bash +# Copyright (C) 2004-2010 Centro de Computacao Cientifica e Software Livre +# 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 is the prerm of proinfodata + +# Delete the crontab of seed_mec +crontab -u seed_mec -r + +# Delete user seed_mec +userdel -r seed_mec + +# Delete group seed_mec +groupdel seed_mec + +exit 0 diff --git a/proinfodatadeb/package/etc/init.d/proinfodata b/proinfodatadeb/package/etc/init.d/proinfodata new file mode 100755 index 0000000..3f512e9 --- /dev/null +++ b/proinfodatadeb/package/etc/init.d/proinfodata @@ -0,0 +1,180 @@ +#!/bin/bash +# Copyright (C) 2004-2010 Centro de Computacao Cientifica e Software Livre +# 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" + +# Proxy file +PROXYFILE="${SEED_HOME}/SEED2/client/conf/proxy" + + +# 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} + + +echo "${INEP}" > ${INEPFILE} +echo "phost=${phost}" > ${PROXYFILE} +echo "pport=${pport}" >> ${PROXYFILE} +echo "puid=${puid}" >> ${PROXYFILE} +echo "ppasswd=${ppasswd}" >> ${PROXYFILE} + +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 diff --git a/proinfodatadeb/package/etc/rc2.d/S88proinfodata b/proinfodatadeb/package/etc/rc2.d/S88proinfodata new file mode 120000 index 0000000..996547f --- /dev/null +++ b/proinfodatadeb/package/etc/rc2.d/S88proinfodata @@ -0,0 +1 @@ +../init.d/proinfodata \ No newline at end of file -- GitLab