From 13f7b996746395bdc1e87bd183cea0034149e830 Mon Sep 17 00:00:00 2001
From: Erik Alexandre Pucci <eap08@c3sl.ufpr.br>
Date: Tue, 26 Apr 2011 17:09:33 -0300
Subject: [PATCH] build-install-package: Improved/added some comments, messages
 and the code

Signed-off-by: Erik Alexandre Pucci <eap08@c3sl.ufpr.br>
Acked-by: Danilo Kiyoshi Simizu Yorinori <danilok@c3sl.ufpr.br>
Acked-by: Tiago Rodrigo Kepe <trk08@c3sl.ufpr.br>
---
 build-install-package | 44 +++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/build-install-package b/build-install-package
index 359a2f8..f985595 100755
--- a/build-install-package
+++ b/build-install-package
@@ -19,7 +19,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
 # USA.
 
-
 AGENT_FILES="./agent-files"
 BOOTSTRAP="bootstrap-install"
 INEP=$1
@@ -37,15 +36,18 @@ test "$3" = '""' || PPORT=$3
 test "$4" = '""' || PUID=$4
 test "$5" = '""' || PPASSWD=$5
 
-# Check the INEP value
-if test -z ${INEP}; then
-    echo    "error: invalid INEP."
+# Check if $INEP is empty
+if test -z "${INEP}"; then
+    printf "ERROR: Empty INEP.\n"
     exit 1
 fi
 
-# Start the tree creation process
-printf "Creating tree..."
-rm -Rf "/tmp/${INEP}"
+# -----------------------------------------------------------------------------
+# Start the tree creation process, removing any possible garbage before
+# creating the INEP specific temporary directory
+printf "Creating tree... "
+
+rm -rf "/tmp/${INEP}"
 mkdir -p "/tmp/${INEP}"
 
 # Copy the agent files to the temporary directory where the installation package
@@ -55,19 +57,21 @@ if ! cp -r "${AGENT_FILES}/SEED2-run" "/tmp/${INEP}/SEED2"; then
     exit 2
 fi
 
+# Create client conf directory and the inep file with the school INEP
 mkdir -p "/tmp/${INEP}/SEED2/client/conf"
 echo "${INEP}" > "/tmp/${INEP}/SEED2/client/conf/inep"
+
+# Create the md5 files of inep and inep backup
 FILE="/tmp/${INEP}/SEED2/client/conf/inep"
 md5sum "${FILE}" |cut -d' ' -f1 > \
     "/tmp/${INEP}/SEED2/.md5sum/client/conf/inep"
-
 cp -a "${FILE}" "/tmp/${INEP}/SEED2/.backup/client/conf/inep"
 FILE="/tmp/${INEP}/SEED2/.backup/client/conf/inep"
 md5sum "${FILE}" |cut -d' ' -f1 > \
     "/tmp/${INEP}/SEED2/.md5sum/.backup/client/conf/inep"
 
-
-echo "phost=$PHOST" >    "/tmp/${INEP}/SEED2/client/conf/proxy"
+# Create the proxy file with all necessary proxy information, and its md5
+echo "phost=$PHOST" > "/tmp/${INEP}/SEED2/client/conf/proxy"
 echo "pport=$PPORT" >> "/tmp/${INEP}/SEED2/client/conf/proxy"
 echo "puid=$PUID" >> "/tmp/${INEP}/SEED2/client/conf/proxy"
 echo "ppasswd=$PPASSWD" >> "/tmp/${INEP}/SEED2/client/conf/proxy"
@@ -75,6 +79,7 @@ FILE="/tmp/${INEP}/SEED2/client/conf/proxy"
 md5sum "${FILE}" |cut -d' ' -f1 > \
     "/tmp/${INEP}/SEED2/.md5sum/client/conf/proxy"
 
+# Create the backup proxy file and its md5
 cp -a "${FILE}" "/tmp/${INEP}/SEED2/.backup/client/conf/proxy"
 FILE="/tmp/${INEP}/SEED2/.backup/client/conf/proxy"
 md5sum "${FILE}" |cut -d' ' -f1 > \
@@ -88,9 +93,11 @@ if ! cp -r "${AGENT_FILES}/${BOOTSTRAP}" "/tmp/${INEP}"; then
 fi
 
 printf "done.\n"
+# End of tree creation process
 
+# -----------------------------------------------------------------------------
 # The tree is ready, we need to compress it now (tar+gz)
-printf "Packaging..."
+printf "Packaging... "
 
 cd "/tmp/${INEP}"
 if ! tar -czf SEED2.tgz SEED2; then
@@ -100,23 +107,28 @@ fi
 
 # Create the tar md5 and compute the bootstrap lines
 MD5_CHECK=$(md5sum SEED2.tgz | awk '{print $1}')
-LINENUM=$(( $(wc -l "bootstrap-install" | cut -d' ' -f1) + 1 ))
+LINENUM=$(( $(wc -l "${BOOTSTRAP}" | cut -d' ' -f1) + 1 ))
 
 # Edit the bootstrap and start the real package
 sed "s/BOOTSTRAP_LINES=/BOOTSTRAP_LINES=${LINENUM}/g; \
      s/MD5_CHECK=/MD5_CHECK=\"${MD5_CHECK}\"/g" \
-    "bootstrap-install" > agent_${INEP}.run
+    "${BOOTSTRAP}" > agent_${INEP}.run
 
 # Insert the tar on the package and finish
 cat "SEED2.tgz" >> "agent_${INEP}.run"
 mv "agent_${INEP}.run" "/tmp"
-printf "done.\n"
 
+printf "done.\n"
+# End of packaging step
 
+# -----------------------------------------------------------------------------
 # Remove temporary files
-printf "Removing temporary files..."
+printf "Removing temporary files... "
+
 cd ..
 rm -rf "${INEP}" 2> /dev/null
+
 printf "done.\n"
+# End of temporary files removal
 
-echo "All done"
+printf "\nAll done.\n"
-- 
GitLab