update/software/service-files/run-software-scripts
caio-volpato f5c0ba9da4 Fix script execution not being triggered
When installing a release, the script was not getting executed,
on software.log we couldn't see the script output.

This is happening because run-software-scripts bash script is called
as follows `run-software-scripts preinstall` (or postinstall).
The run-software-scripts looks for executable files within PATCH_SCRIPTDIR/$1
but PATCH_SCRIPTDIR wasn't defined anywhere so it couldn't find the scripts.

This fix declares the PATCH_SCRIPTDIR, so the scripts are found
and executed as expected.

The legacy implementation (sw-patch) has a very similar mechanism and the
PATCH_SCRIPTDIR properly declared
7847f7087e/sw-patch/bin/patch-functions (L15)

Another minor issue is that the run-software-scripts doesn't properly
report when there are no scripts, creating a false impression that
the script was executed.

Test Plan:
SUCCESS: preinstall and postinstall script execution is triggered properly.
SUCCESS: run-software-scripts <folder_name> properly logs when no scripts are present

Closes-bug: 2070391

Change-Id: I91f315d29171a19f9b5c8c09db7c40465dcb49b6
Signed-off-by: caio-volpato <caio.volpato@windriver.com>
2024-06-25 16:02:00 +00:00

68 lines
1.4 KiB
Bash

#!/bin/bash
#
# Copyright (c) 2023-2024 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
. /etc/software/software-functions
if [ -z "$1" ]
then
loginfo "No input parameter provided to identify script type."
exit 0
fi
declare DIR="${PATCH_SCRIPTDIR}/${1}"
declare SCRIPTS=$(find $DIR -type f -executable | sort)
if [ ${#SCRIPTS} -eq 0 ]
then
loginfo "No in-service patch scripts found at the directory ${DIR}"
exit 0
fi
declare -i NUM_SCRIPTS=$(echo "$SCRIPTS" | wc -l)
loginfo "Running $NUM_SCRIPTS in-service patch scripts"
declare SCRIPTLOG=/var/log/software.log
cat <<EOF >>$SCRIPTLOG
############################################################
`date "+%FT%T.%3N"`: Running $NUM_SCRIPTS install patch scripts:
$SCRIPTS
############################################################
EOF
declare -i FAILURES=0
for cmd in $SCRIPTS
do
cat <<EOF >>$SCRIPTLOG
############################################################
`date "+%FT%T.%3N"`: Running $cmd
EOF
bash -x $cmd >>$SCRIPTLOG 2>&1
rc=$?
if [ $rc -ne $PATCH_STATUS_OK ]
then
let -i FAILURES++
fi
cat <<EOF >>$SCRIPTLOG
`date "+%FT%T.%3N"`: Completed running $cmd (rc=$rc)
############################################################
EOF
done
cat <<EOF >>$SCRIPTLOG
`date "+%FT%T.%3N"`: Completed running scripts with $FAILURES failures
############################################################
EOF
exit $FAILURES