From a2a42361a64d285da0188fce602855618f16876a Mon Sep 17 00:00:00 2001
From: Edileuton Henrique de Oliveira <eho09@c3sl.ufpr.br>
Date: Thu, 14 Nov 2013 10:09:01 -0200
Subject: [PATCH] build: Copy the bootstrap-install.sh file from buildpackage
 to build

Signed-off-by: Edileuton Henrique de Oliveira <eho09@c3sl.ufpr.br>
---
 build/bootstraps/bootstrap-install.sh | 51 ++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 13 deletions(-)

diff --git a/build/bootstraps/bootstrap-install.sh b/build/bootstraps/bootstrap-install.sh
index c9d178f..470dcec 100755
--- a/build/bootstraps/bootstrap-install.sh
+++ b/build/bootstraps/bootstrap-install.sh
@@ -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" \
@@ -156,17 +162,22 @@ else
     SEED_MEC_HOME="/opt/seed_mec"
 fi
 AGENT_DIR="${SEED_MEC_HOME}/SEED2"
-LASTEXEC="${AGENT_DIR}/tmp/lastExec.tmp"
+LASTEXEC="${AGENT_DIR}/tmp/last-exec.tmp"
+NETLASTEXEC="${AGENT_DIR}/tmp/net-last-exec.tmp"
 LOGFILE=/tmp/collected-information.log
 # Save stdout to file descriptor 3 and redirect all output to $LOGFILE
 exec 3>&1 &> ${LOGFILE}
 
-# Check if lastExec.tmp exist then save its content to prevent that
+# Check if last-exec.tmp exist then save its content to prevent that
 # agent send a inventory more than once per day
 if test -f ${LASTEXEC}; then 
 	LASTEXECBACKUP=$(cat ${LASTEXEC})
 fi
- 
+
+if test -f ${NETLASTEXEC}; then 
+	NETLASTEXECBACKUP=$(cat ${NETLASTEXEC})
+fi
+
 # Remove any previous installation of the agent
 rm -rf "${AGENT_DIR}"
 /usr/sbin/userdel -r seed_mec
@@ -219,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
 
 # ------------------------------------------------------------------------------
@@ -253,10 +274,14 @@ fi
 # Export a variable to inform the agent that this is its first execution
 export FIRST_EXECUTION=1
 
-# Restore lastExec.tmp
+# Restore last-exec.tmp
 if ! test -z ${LASTEXECBACKUP};then  
 	echo ${LASTEXECBACKUP} > ${LASTEXEC}
 fi
+# Restore net-last-exec.tmp
+if ! test -z ${NETLASTEXECBACKUP};then  
+	echo ${NETLASTEXECBACKUP} > ${NETLASTEXEC}
+fi
 
 # Run the agent and check if its execution went alright, exiting in case of
 # error
-- 
GitLab