collect: Fix #1326 Network usage collect does not work on openSUSE and Fedora

Signed-off-by: default avatarEdileuton Henrique de Oliveira <eho09@c3sl.ufpr.br>
parent 0c4b2a08
......@@ -109,9 +109,15 @@ collect_information(){
cat ${AGENT_DIR}/client/run.sh
printf "\n\n----------------------------------\n\n"
printf " agent.sh\n%b" \
printf " update.sh\n%b" \
" ========\n\n"
cat ${AGENT_DIR}/agent.sh
cat ${AGENT_DIR}/update.sh
printf " inventory.sh\n%b" \
" ========\n\n"
printf "\n\n----------------------------------\n\n"
cat ${AGENT_DIR}/inventory.sh
printf "\n\n----------------------------------\n\n"
printf " Collect agent log\n%b" \
......@@ -224,16 +230,26 @@ if ! test -n "${PROJECTOR}" -o -f "/usr/sbin/projetor" -o \
# Remove any possible line containing a rule for seed_mec user before adding
# root permissions in the sudoers file
TMPFILE=$(mktemp)
sed '/^seed_mec[\t ]*ALL=(ALL/d' /etc/sudoers > "${TMPFILE}"
mv "${TMPFILE}" /etc/sudoers
chmod 440 /etc/sudoers
# Add root permissions to seed_mec user, without the need of password
if ! $(echo -e "seed_mec\tALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers)
then
sed '/^\(Defaults:\)\?seed_mec/d' /etc/sudoers > "${TMPFILE}"
# Add root permissions to datasid
echo -e "seed_mec\tALL=(ALL) NOPASSWD: ALL" >> "${TMPFILE}"
# Remove on Fedora the requirement of tty for sudo
if grep -q "Fedora" /etc/issue; then
echo -e 'Defaults:seed_mec\t!requiretty' >> "${TMPFILE}"
fi
# Check if modified sudoers file is valid and apply it
if ! visudo -cf "${TMPFILE}" || ! mv "${TMPFILE}" /etc/sudoers \
|| ! chmod 440 /etc/sudoers; then
printf "FALHA!\n" >&3
printf "ERRO: Falha ao adicionar permissões de super-usuário %b" \
"ao usuário seed_mec.\n" >&3
"ao usuário seed_mec.\n"
rm -f "${TMPFILE}"
exit 3
fi
rm -f "${TMPFILE}"
fi
# ------------------------------------------------------------------------------
......
......@@ -28,7 +28,7 @@ function check_traffic_date()
# If there is no TRAFFIC (probably its the first run), then just create a
# new one.
if ! test -f "$TRAFFIC"; then
echo $(date +%F) > $TRAFFIC
echo $(date +%F) > $TRAFFIC
return
fi
......@@ -46,6 +46,7 @@ function check_traffic_date()
# Finally, create a new TRAFFIC (keeping the previous one as
# PREVIOUS_TRAFFIC) if the dates doesnt match.
if test $CURRENT_DATE -ne $TRAFFIC_DATE; then
mkdir -p "./previous"
cp $TRAFFIC $PREVIOUS_TRAFFIC
echo $(date +%F) > $TRAFFIC
fi
......@@ -76,7 +77,7 @@ PROJECT=$PREFIX/../scripts/collect/project/source.int
# Verify if this is not an UCA Classmate, UCA Server nor Projector ProInfo. If
# it is, do not collect network data and exit. Also exit if the user is not in
# the sudoers(1)
if test "$(bash $PROJECT)" != "0" || ! sudo -v &> /dev/null; then
if test "$(bash $PROJECT)" != "0" &> /dev/null; then
exit 0
fi
......@@ -86,7 +87,7 @@ cd $PREFIX
TRAFFIC="./traffic.txt"
# Collected data on the last day before the machine is disconnected
PREVIOUS_TRAFFIC="./previous-traffic.txt"
PREVIOUS_TRAFFIC="./previous/traffic-$(date +%F).txt"
# Stored interfaces from the last run
INTERFACES="./interfaces.txt"
......@@ -99,8 +100,7 @@ IPTABLES=$(which iptables)
test $? -ne 0 && IPTABLES="/sbin/iptables"
test -x $IP || exit 1
test -x $IPTABLES || exit 1
test -x $IPTABLES || (IPTABLES="/usr/sbin/iptables" && test -x $IPTABLES) || exit 1
#------------------------------------------------------------------------------
# Calculate bytes and packets counts and print to TRAFFIC
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment