library/roles/smartgears/dataminer_app/templates/algorithms-updater.j2: Make the script more tolerant to the garbage present in the algorithm files.

This commit is contained in:
Andrea Dell'Amico 2017-10-06 18:16:52 +02:00
parent b6703aa9b1
commit 07d50186ab
1 changed files with 15 additions and 8 deletions

View File

@ -14,7 +14,7 @@ LOG_FILE=${LOG_DIR}/algorithms_updater.log
ALGORITHMS_INSTALLED_FILE=${LOG_DIR}/already_installed_algorithms.txt
ALGORITHMS_INSTALLED_SORTED_FILE=${LOG_DIR}/already_installed_algorithms_sorted.txt
LOCK_FILE=${LOG_DIR}/.algorithms_updater.lock
ALGO_DIR={{ dataminer_wps_algorithms_dest }}
ALGO_DIR={{ dataminer_wps_algorithms_dest }}/${INFRA_REFERENCE}
RUNNING_JOB=
RUNNING_JOB_RETVAL=
@ -75,8 +75,11 @@ function algorithms_updater() {
echo "" >> $ALGORITHMS_TEMP_SCRIPT.head
awk -F \| '{ print $2 "|" $6 "|" $8 }' $ALGORITHMS_FILE > $ALGORITHMS_TEMP_SCRIPT.algorithmslist
sed -i -e 's/<notextile>//g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist
sed -i -e 's/<\/notextile>"//g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist
sed -i -e 's/<\/notextile>//g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist
sed -i -e 's/\ N\ /\ Y\ /g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist
sed -i -e 's/\[/\ /g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist
sed -i -e 's/\]/\ /g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist
if [ ! -f $ALGORITHMS_INSTALLED_FILE ] ; then
touch $ALGORITHMS_INSTALLED_FILE
fi
@ -85,7 +88,9 @@ function algorithms_updater() {
while read algo ; do
ALGO_PRESENT=
ALGO_NAME=$( echo "$algo" | awk -F \| '{ print $1 }' )
ALGO_BODY=$( echo "$algo" | awk -F \| '{ print $2 }' )
ALGO_BODY_PRE=$( echo "$algo" | awk -F \| '{ print $2 }' )
ALGO_BODY="${ALGO_BODY_PRE} ${INFRA_REFERENCE}/software"
ALGO_BODY=$( sed "s/'/ /g" <<< ${ALGO_BODY} )
ALGO_DATE=$( echo "$algo" | awk -F \| '{ print $3 }' )
ALGO_TIMESTAMP=$( date +%s -d "$ALGO_DATE" 2>/dev/null )
if [ $? -ne 0 ] ; then
@ -96,15 +101,16 @@ function algorithms_updater() {
if [ $ALGO_PRESENT -ne 0 ] ; then
echo "logger 'algorithms-updater: New algorithm $ALGO_NAME'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "logger 'algorithms-updater: running the add command of algorithm $ALGO_NAME'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "logger 'algorithms-updater: the add command string is $ALGO_BODY'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "logger 'algorithms-updater: the add command string is ${ALGO_BODY}'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "RETVAL=" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo '-------------------------------------------'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'Adding algorithm $ALGO_NAME'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'With command $ALGO_BODY'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'With command ${ALGO_BODY}'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "$ALGO_BODY" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "cd ${ADD_ALGORITHM_DIR}" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "${ALGO_BODY}" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo 'RETVAL=$?' >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'Done.'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
@ -123,15 +129,16 @@ function algorithms_updater() {
if [ $? -ne 0 ] || [ $ALGO_LOCAL_TIMESTAMP -ne $ALGO_TIMESTAMP ]; then
echo "logger 'algorithms-updater: algorithm $ALGO_NAME is already present but a newer version exists'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "logger 'algorithms-updater: running the add command of algorithm $ALGO_NAME'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "logger 'algorithms-updater: the add command string is $ALGO_BODY'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "logger 'algorithms-updater: the add command string is ${ALGO_BODY}'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "RETVAL=" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo '-------------------------------------------'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'Adding algorithm $ALGO_NAME'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'With command $ALGO_BODY'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'With command ${ALGO_BODY}'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "$ALGO_BODY" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "cd ${ADD_ALGORITHM_DIR}" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "${ALGO_BODY}" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo 'RETVAL=$?' >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'Done.'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_