Initial Commit

parents
1.1.30
#!/bin/bash
# gerar.sh
# Copyright (c) 2006 by Bruno Ribas <ribas@ufpr.br>
DIRTMP=$(mktemp -d)
VERSAO=$(cat VERSAO)
#arrumar versao
#$1 tipo de incremento
MAJOR=$(echo $VERSAO| cut -d'.' -f1)
MINOR=$(echo $VERSAO| cut -d'.' -f2)
REVISION=$(echo $VERSAO| cut -d'.' -f3)
case $1 in
Minor)
((MINOR++))
REVISION=0
;;
Major)
((MAJOR++))
MINOR=0
REVISION=0
;;
help)
echo "Uso: $0 Major|Minor|Revision"
echo ' Major - Altera versao Major'
echo ' Minor - Altera versao Minor'
exit
;;
*)
((REVISION++))
;;
esac
VERSAO="${MAJOR}.${MINOR}.${REVISION}"
echo "$VERSAO" > VERSAO
#Compila a documentacao do pacote no diretorio doc/
#cd doc/
#hevea -text *.tex
#hevea -text *.tex
#cd ../
cp -r pacote $DIRTMP
#Copia a documentacao compilada para dentro do pacote.
#cp doc/*.txt $DIRTMP/pacote/usr/share/doc/prd-*
cd $DIRTMP
find . -name ".svn" -exec rm -rf {} \; &>/dev/null
sed -i -e "s/Version:/Version: $VERSAO/" pacote/DEBIAN/control
fakeroot dpkg -b pacote .
cd -
cp $DIRTMP/*deb .
rm -rf $DIRTMP
# vim:tabstop=4:shiftwidth=4:encoding=iso-8859-1
Package: le-proinfodata
Version:
Maintainer: <proinfodata@c3sl.ufpr.br>
Architecture: i386
Section: main
Priority: important
Depends: dialog, wget, passwd
Description: Agent of PROINFODATA project designed for the LE 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.
#!/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
# Remove seed_mec from the KDM user list
kwriteconfig --file /etc/kde4/kdm/kdmrc --group X-*-Greeter \
--key HiddenUsers seed_mec
exit 0
#!/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 le-proinfodata
#
# le-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.
# Files to divert
DIVERTS="
/etc/init/kdm.conf \
/etc/init/tty1.conf
"
if [[ "$1" != "upgrade" ]]; then
for file in $DIVERTS; do
rm -f ${file}
dpkg-divert --package le-proinfodata --remove --rename \
--divert ${file}{.real,}
done
fi
#!/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 -f 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 -r -m -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}
# Files to divert
DIVERTS="
/etc/init/kdm.conf \
/etc/init/tty1.conf
"
# Divert files
for file in $DIVERTS; do
dpkg-divert --package le-proinfodata --add --rename \
--divert ${file}{.real,}
done
exit 0
#!/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
# kdm - KDE Display Manager
#
# The display manager service manages the X servers running on the
# system, providing login and auto-login services
description "K Display Manager"
author "Richard Johnson"
start on (filesystem
and started dbus
and (graphics-device-added fb0 PRIMARY_DEVICE_FOR_DISPLAY=1
or drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
or stopped udevtrigger))
stop on runlevel [016]
emits starting-dm
env XORGCONFIG=/etc/X11/xorg.conf
script
# Does the INEP file exist?
INEPFILE=/opt/seed_mec/SEED2/client/conf/inep
if ! test -f ${INEPFILE} -a -n "$(cat ${INEPFILE})"; then
init 3
plymouth --quit
init 2
sleep 1
/usr/sbin/le-askINEP.sh
fi
if [ -n "$UPSTART_EVENTS" ]
then
[ ! -f /etc/X11/default-display-manager -o "$(cat /etc/X11/default-display-manager 2>/dev/null)" = "/usr/bin/kdm" ] || { stop; exit 0; }
# Check kernel command-line for inhibitors
for ARG in $(cat /proc/cmdline)
do
case "${ARG}" in
text|-s|s|S|single)
plymouth quit || : # We have the ball here
exit 0
;;
esac
done
fi
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG LANGUAGE
elif [ -r /etc/environment ]; then
. /etc/environment
export LANG LANGUAGE
fi
export XORGCONFIG
exec kdm
end script
# tty1 - getty
#
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]
respawn
INEPFILE=/opt/seed_mec/SEED2/client/conf/inep
# Do not open getty if a dialog is about to be shown
if test -f ${INEPFILE} -a -n "$(cat ${INEPFILE})"; then
exec /sbin/getty -8 38400 tty1
fi
This diff is collapsed.
#!/bin/bash
# Copyright (C) 2004-2009 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of collect-agent
#
# collect-agent 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.
#
# Exit status:
#
# 0 - Successfully
# 1 - Error to rotate log file
# 2 - Error to edit crontab
# 3 - Error when updating
# 4 - Error to collect or send data
# 5 - INEP not found
#------------------------------------------------------------------------------
# function: rotateLogFile
# If the log file is out-of-date (set by $2), the savelog(1) will execute
# to rotate log file.
# Parameters:
# $1: log file name
# $2: time in days to expire
# $3: save $3 versions of the log file
function rotateLogFile()
{
find "${LOGDIR}" -type f -name "$1" -atime +$2 -exec savelog -c $3 {} \; ||
return 1
return 0
}
#------------------------------------------------------------------------------
# function: checkUpdate
# check for available updates and do downloads of the updates.
function checkUpdate()
{
updateLink="$(${CLIENT} --update)"
if test $? -eq 4; then
test -f "${TMPDIR}/SEED2-update.run" || rm -f ${TMPDIR}/SEED2-update.run
tryWget ${updateLink} \
-O ${TMPDIR}/SEED2-update.run || return 1
cd ${TMPDIR}
bash ${TMPDIR}/SEED2-update.run || return 1
rm -f ${TMPDIR}/SEED2-update.run
return 4
fi
return 0
}
#------------------------------------------------------------------------------
# function: schedule
# check scheduling in the crontab of current user, and insert schedule
# this agent in the crontab if not inserted.
function schedule()
{
if test -f "${CLIENTCONFDIR}/inep"; then
MIN=$(( $(sed "s/[^0-9]//g" ${CLIENTCONFDIR}/inep) % 60 ))
else
MIN=$(( $RANDOM % 60 ))
fi
userCron="$(printf\
"${MIN} ${SCHEDULE}\n${NETSCHEDULE}\n@reboot ${PREFIX}/agent.sh\n")"
if test "$(crontab -l)" != "${userCron}"; then
printf "${userCron}\n\n" | crontab - || return 1
fi
return 0
}
#------------------------------------------------------------------------------
# function: elapsedTime
# Check if elapsed ${DELAY} seconds since the last execution.
# return true or false.
function elapsedTime()
{
test -f "${TMPDIR}/lastExec.tmp" || return 0
atSeconds=$(date +%s)
oldSeconds=$(cat ${TMPDIR}/lastExec.tmp)
(( (${atSeconds}-${oldSeconds}) >= ${DELAY} ))
return $?
}
declare PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 3
source ${PREFIX}/client/common.sh
exec 1>> ${LOGFILE} 2>&1
if ! rotateLogFile '*.log' ${DAYSTOEXPIRELOG} 12; then
date +"%F %T - Error while rolling log file."
exit 1
fi
date +"%F %T - Agent started."
if ! schedule; then
date +"%F %T - Error to edit crontab."
exit 2
fi
checkUpdate
updateStatus=$?
test ${updateStatus} -eq 4 && exit 0
if test ${updateStatus} -eq 1; then
date +"%F %T - Error while updating agent."
exit 3
fi
if ! test -f ${CLIENTCONFDIR}/inep -a -n "$(cat ${CLIENTCONFDIR}/inep)"; then
date +"%F %T - INEP not found in ${CLIENTCONFDIR}/inep, waiting configuration."
exit 5
fi
if elapsedTime; then
if ! bash ${PREFIX}/collect-data.sh; then
date +"%F %T - Error at collect system data or send data."
date +"%F %T - Agent terminated with fails."
exit 4
fi
# Records the time of execution current to the use of function elapsedTime.
date +%s > ${TMPDIR}/lastExec.tmp
fi
date +"%F %T - Agent terminated sucessfull."
exit 0
#!/bin/bash
# Copyright (C) 2004-2009 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of client, it is used to store common functions
#
# common.sh 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.
#------------------------------------------------------------------------------
# function: getProxyConf
# Load the proxy configuration.
function getProxyConf()
{
if ! test -z "${PREFIX}"; then
PROXYCONF="${PREFIX}/client/conf/proxy"
else
PROXYCONF="${dirname}/conf/proxy"
fi
phost=$(grep "^phost=" ${PROXYCONF} | cut -f2 -d=)
pport=$(grep "^pport=" ${PROXYCONF} | cut -f2 -d=)
puid=$(grep "^puid=" ${PROXYCONF} | cut -f2 -d=)
ppasswd=$(grep "^ppasswd=" ${PROXYCONF} | cut -f2 -d=)
if test -n "${phost}"; then
phost="--phost=${phost}"
fi
if test -n "${pport}"; then
pport="--pport=${pport}"
fi
if test -n "${puid}"; then
puid="--puid=${puid}"
fi
if test -n "${ppasswd}"; then
ppasswd="--ppasswd=${ppasswd}"
fi
}
function tryWget(){
getProxyConf
if test -z "$phost"; then
PROXY=""
else
PROXY="http://${phost}:${pport}"
fi
if which wget &>/dev/null; then
WGETBIN="$(which wget)"
else
WGETBIN="${PREFIX}/bin/wget"
fi
http_proxy="${PROXY}" ${WGETBIN} --tries=${UPDATETRIES} \
--timeout=${UPDATETIMEOUT} \
--proxy-user="${puid}" \
--proxy-password="${ppasswd}" \
$* || return 1
}
#!/bin/bash
# Run.sh
# Copyright (C) 2004-2009 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of client
#
# client 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.
dirname=$(dirname $0)
basename=$(basename ${dirname})
bindir=${dirname}/bin
inepRE="^[A-Z]{2}?[[:digit:]]{8}$"
# Redirects all error output to log file
exec 2>> ${dirname}/run.log
# Timestamp
date +"%F %T" >> ${dirname}/run.log
# Get common functions
source ${dirname}/common.sh
# Get MAC address from collect-parser mac-address script
mac=$(bash ${dirname}/../scripts/collect/mac-address/number.string)
url="--url=http://seed.c3sl.ufpr.br/tomcat/axis/Seed2.jws"
inep=$(cat ${dirname}/conf/inep)
# Check INEP integrity: the egrep test verifies if INEP is valid, returning
# an empty string if it isn't. The first test checks if INEP is empty before
# doing the second test. If it isn't empty, the regular expression occurs.
# Otherwise, the INEP is accepted and the program continues with the
# execution. In short, the test allows empty and valid INEPs.
if test -n "${inep}" -a -z "$(egrep ${inepRE} <<< ${inep})"; then
echo "INEP format error." >> ${dirname}/run.log
exit 100
fi
getProxyConf
proxy="${phost} ${pport} ${puid} ${ppasswd}"
inep="--inep=${inep}"
mac="--mac=${mac}"
# Execution
if test $# -gt 1; then
echo "Run.sh call: wrong number of parameters ($#)." \
>> ${dirname}/run.log
exit 101
elif test $# -eq 0; then
${bindir}/client ${url} ${inep} ${mac} ${proxy} >> ${dirname}/run.log
elif [[ $1 == "--update" ]]; then
retstr=$(${bindir}/client $1 ${url} ${proxy})
retval=$?
if test ${retval} -eq 4; then
echo "$retstr" | tee -a ${dirname}/run.log
fi
exit $retval
elif [[ $1 == "--inventory" ]]; then
${bindir}/client $1 ${url} ${inep} ${proxy} >> ${dirname}/run.log
else
echo "Run.sh call: wrong parameter (\"$1\")." >> ${dirname}/run.log
exit 102
fi
#general
#the var $PREFIX content the absolute path of agent.
DATADIR=${PREFIX}/data
LOGDIR=${PREFIX}/log
XMLFILENAME=${DATADIR}/collect-data.xml
SCRIPTSDIR=${PREFIX}/scripts
CLIENT=${PREFIX}/client/run.sh
CLIENTCONFDIR=${PREFIX}/client/conf
LOGFILE=${LOGDIR}/collect.log
TMPDIR=${PREFIX}/tmp
NETMONITOR=${PREFIX}/net/network-monitor.sh
SCHEDULE="* * * * ${PREFIX}/integrity-checker.sh && ${PREFIX}/agent.sh"
NETSCHEDULE="0-59 * * * * ${NETMONITOR}"
UPDATETRIES=3
UPDATETIMEOUT=100
DELAY=86400 #24 hours
DAYSTOEXPIRELOG=31 #1 month
LD_LIBRARY_PATH=${PREFIX}/lib/lib:${LD_LIBRARY_PATH}
XMLPARSER=${PREFIX}/bin/collect-parser
#!/bin/bash
# Copyright (C) 2004-2009 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of collect-agent
#
# collect-agent 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.
#------------------------------------------------------------------------------
# function: message
# Treat out stream of the error.
# argument $1: Id of the error.
# argument $2: Out Stream (default stderr)
function message()
{
stream="/proc/self/fd/1"
test -n "$2" && stream="$2"
case $1 in
1)
printf "Usage: ${SCRIPTPATH} {start|stop}\n" > ${stream}
;;
2)
printf "This Daemon already running.\n" > ${stream}