Commit 8cffdd5d authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

Added proinfodata-installer.sh to generate the PROINFODATA agent installer

This script will be used instead of the installed files in /opt/seed_mec. It
clones the buildpackage GIT repository and generates a PROINFODATA installer
without INEP mainly using the buildpackage scripts.
Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
Acked-by: default avatarAryane Ast dos Santos <aras10@c3sl.ufpr.br>
parent 5e8e8fd6
#!/bin/bash
# This script generates the PROINFODATA installer
# Copyright (C) 2010-2012 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.
# This function checks one file integrity
check_file_integrity(){
FILE="$*"
FILEREAL="$(echo ${FILE} | sed "s#^${MD5DIRESC}##g")"
test -f "${AGENT_FILES}/SEED2-run/${FILEREAL}" || return 1
(md5sum "${AGENT_FILES}/SEED2-run/${FILEREAL}" | cut -d' ' -f1 | \
diff - "${FILE}" &> /dev/null) || return 1
}
# ------------------------------------------------------------------------------
PREFIX="$(dirname $(readlink -f $0))"
BPURL="http://git.c3sl.ufpr.br/pub/scm/proinfodata/buildpackage.git"
BPDIR="${PREFIX}/buildpackage"
AUXDIR="${PREFIX}/git"
PIDDEST="${PREFIX}/pacote/tmp"
PIDINSTALLER="${PIDDEST}/agent.run"
FAKEINEP="99999999"
AGENT_FILES="./agent-files"
BOOTSTRAP="bootstrap-install"
MD5DIR="${AGENT_FILES}/SEED2-run/.md5sum"
MD5DIRESC="$(echo ${MD5DIR} | sed "s/\./\\\./g")"
# ------------------------------------------------------------------------------
# Check if the PROINFODATA installer already exists
if test -f "${PIDINSTALLER}"; then
printf "PROINFODATA installer already exists. Skipping generation.\n"
exit 0
fi
# Check if the buildpackage repository directory already exists, cloning it
# otherwise
if ! test -d "${BPDIR}"; then
if ! git clone "${BPURL}" "${BPDIR}"; then
printf "ERROR (1): problems while executing git clone(1).\n"
exit 1
fi
fi
# Change to buildpackage directory
cd "${BPDIR}"
# Ensure the buildpackage repository is updated
if ! git pull; then
printf "ERROR (2): problems while executing git pull(1).\n"
exit 2
fi
# Create auxiliar directory used by the buildpackage scripts
mkdir -p "${AUXDIR}"
# ------------------------------------------------------------------------------
# Compile the wget
printf "\nIf there's no compiled wget, run build-wget...\n"
if ! test -f "${BPDIR}/wget-"*"/src/wget" && ! ./build-wget; then
printf "ERROR (3): problems while building wget.\n"
exit 3
fi
printf "Wget compiled.\n"
# ------------------------------------------------------------------------------
# Get agent files
printf "\nExecuting build-agent-files...\n"
if ! ./build-agent-files; then
printf "ERROR (4): problems while building the agent files.\n"
exit 4
fi
printf "Agent files prepared.\n"
# ------------------------------------------------------------------------------
# Create integrity system
printf "\nCreating integrity system...\n"
if ! ./create-integrity-system; then
printf "ERROR (5): problems while creating the integrity system.\n"
exit 5
fi
printf "Integrity system ready.\n"
# ------------------------------------------------------------------------------
# Generate the PROINFODATA installer
printf "\nBuilding PROINFODATA installation package...\n"
# Change to the agent directory
cd agent
# Check all MD5 files
printf "Checking SEED2-run files integrity... "
for FILE in $(find "${MD5DIR}" -type f); do
if ! check_file_integrity "${FILE}"; then
printf "ERROR (6): problems while building the installation %b" \
"package - file(s) corrupted.\n"
exit 6
fi
done
printf "done.\n"
# Start the tree creation process, removing any possible garbage before
# creating the FAKEINEP specific temporary directory
printf "Creating tree... "
rm -rf "/tmp/${FAKEINEP}"
mkdir -p "/tmp/${FAKEINEP}"
# Copy the agent files to the temporary directory where the installation package
# will be generated
if ! cp -r "${AGENT_FILES}/SEED2-run" "/tmp/${FAKEINEP}/SEED2"; then
printf "ERROR (7): problems while building the installation %b" \
"package - failed to copy agent files.\n"
exit 7
fi
# Copy the bootstrap-install to the temporary directory
if ! cp -r "${AGENT_FILES}/${BOOTSTRAP}" "/tmp/${FAKEINEP}"; then
printf "ERROR (8): problems while building the installation %b%b" \
"package - failed to copy ${BOOTSTRAP} to the " \
"temporary directory.\n"
exit 8
fi
printf "done.\n"
# End of tree creation process
# The tree is ready, we need to compress it now (tar+gz)
printf "Packaging... "
cd "/tmp/${FAKEINEP}"
if ! tar -czf SEED2.tgz SEED2; then
printf "ERROR (9): problems while building the installation %b" \
printf "package - failed to compress the agent package.\n"
exit 9
fi
# Create the tar md5 and compute the bootstrap lines
MD5_CHECK=$(md5sum SEED2.tgz | awk '{print $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}" > agent_${FAKEINEP}.run
# Insert the tar on the package and finish
cat "SEED2.tgz" >> "agent_${FAKEINEP}.run"
mv "agent_${FAKEINEP}.run" "/tmp"
printf "done.\n"
# End of packaging step
# Remove temporary files
printf "Removing temporary files... "
cd ..
rm -rf "${FAKEINEP}" 2> /dev/null
printf "done.\n"
# End of temporary files removal
printf "Installation package generated.\n"
# ------------------------------------------------------------------------------
# Ensure the directory where the PROINFODATA installer should be placed exists
mkdir -p "${PIDDEST}"
# Move the PROINFODATA installer to the correct place
mv "/tmp/agent_${FAKEINEP}.run" "${PIDINSTALLER}"
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