Skip to content
Snippets Groups Projects
Commit ef3ac993 authored by Edileuton Henrique de Oliveira's avatar Edileuton Henrique de Oliveira
Browse files

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

parent 0c4b2a08
Branches
No related tags found
No related merge requests found
...@@ -109,9 +109,15 @@ collect_information(){ ...@@ -109,9 +109,15 @@ collect_information(){
cat ${AGENT_DIR}/client/run.sh cat ${AGENT_DIR}/client/run.sh
printf "\n\n----------------------------------\n\n" printf "\n\n----------------------------------\n\n"
printf " agent.sh\n%b" \ printf " update.sh\n%b" \
" ========\n\n" " ========\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 "\n\n----------------------------------\n\n"
printf " Collect agent log\n%b" \ printf " Collect agent log\n%b" \
...@@ -224,16 +230,26 @@ if ! test -n "${PROJECTOR}" -o -f "/usr/sbin/projetor" -o \ ...@@ -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 # Remove any possible line containing a rule for seed_mec user before adding
# root permissions in the sudoers file # root permissions in the sudoers file
TMPFILE=$(mktemp) TMPFILE=$(mktemp)
sed '/^seed_mec[\t ]*ALL=(ALL/d' /etc/sudoers > "${TMPFILE}" sed '/^\(Defaults:\)\?seed_mec/d' /etc/sudoers > "${TMPFILE}"
mv "${TMPFILE}" /etc/sudoers
chmod 440 /etc/sudoers # Add root permissions to datasid
# Add root permissions to seed_mec user, without the need of password echo -e "seed_mec\tALL=(ALL) NOPASSWD: ALL" >> "${TMPFILE}"
if ! $(echo -e "seed_mec\tALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers)
then # 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" \ 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 exit 3
fi fi
rm -f "${TMPFILE}"
fi fi
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
......
...@@ -46,6 +46,7 @@ function check_traffic_date() ...@@ -46,6 +46,7 @@ function check_traffic_date()
# Finally, create a new TRAFFIC (keeping the previous one as # Finally, create a new TRAFFIC (keeping the previous one as
# PREVIOUS_TRAFFIC) if the dates doesnt match. # PREVIOUS_TRAFFIC) if the dates doesnt match.
if test $CURRENT_DATE -ne $TRAFFIC_DATE; then if test $CURRENT_DATE -ne $TRAFFIC_DATE; then
mkdir -p "./previous"
cp $TRAFFIC $PREVIOUS_TRAFFIC cp $TRAFFIC $PREVIOUS_TRAFFIC
echo $(date +%F) > $TRAFFIC echo $(date +%F) > $TRAFFIC
fi fi
...@@ -76,7 +77,7 @@ PROJECT=$PREFIX/../scripts/collect/project/source.int ...@@ -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 # 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 # it is, do not collect network data and exit. Also exit if the user is not in
# the sudoers(1) # the sudoers(1)
if test "$(bash $PROJECT)" != "0" || ! sudo -v &> /dev/null; then if test "$(bash $PROJECT)" != "0" &> /dev/null; then
exit 0 exit 0
fi fi
...@@ -86,7 +87,7 @@ cd $PREFIX ...@@ -86,7 +87,7 @@ cd $PREFIX
TRAFFIC="./traffic.txt" TRAFFIC="./traffic.txt"
# Collected data on the last day before the machine is disconnected # 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 # Stored interfaces from the last run
INTERFACES="./interfaces.txt" INTERFACES="./interfaces.txt"
...@@ -99,8 +100,7 @@ IPTABLES=$(which iptables) ...@@ -99,8 +100,7 @@ IPTABLES=$(which iptables)
test $? -ne 0 && IPTABLES="/sbin/iptables" test $? -ne 0 && IPTABLES="/sbin/iptables"
test -x $IP || exit 1 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 # Calculate bytes and packets counts and print to TRAFFIC
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment