2019-10-10 00:52:42 -04:00
#!/bin/bash
# Change directory to the script root directory
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
SOURCE = " ${ BASH_SOURCE [0] } "
while [ -h " $SOURCE " ] ; do # resolve $SOURCE until the file is no longer a symlink
2022-02-02 11:16:01 +01:00
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
SOURCE = " $( readlink " $SOURCE " ) "
[ [ $SOURCE != /* ] ] && SOURCE = " $DIR / $SOURCE " # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
2019-10-10 00:52:42 -04:00
done
DIR = " $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
2022-11-02 14:28:14 +01:00
run( ) {
# run the helper process which keep the listener alive
while :;
do
cp -f " $DIR " /run-helper.sh.template " $DIR " /run-helper.sh
" $DIR " /run-helper.sh $*
returnCode = $?
if [ [ $returnCode -eq 2 ] ] ; then
echo "Restarting runner..."
else
echo "Exiting runner..."
exit 0
fi
done
}
runWithManualTrap( ) {
# Set job control
set -m
trap 'kill -INT -$PID' INT TERM
# run the helper process which keep the listener alive
while :;
do
cp -f " $DIR " /run-helper.sh.template " $DIR " /run-helper.sh
" $DIR " /run-helper.sh $* &
PID = $!
2024-03-04 11:32:21 +01:00
wait $PID
2022-11-02 14:28:14 +01:00
returnCode = $?
if [ [ $returnCode -eq 2 ] ] ; then
echo "Restarting runner..."
else
echo "Exiting runner..."
# Unregister signal handling before exit
trap - INT TERM
# wait for last parts to be logged
wait $PID
2022-11-28 17:33:01 +01:00
exit $returnCode
2022-11-02 14:28:14 +01:00
fi
done
}
2023-03-08 18:29:55 +01:00
function updateCerts( ) {
local sudo_prefix = ""
local user_id = ` id -u`
if [ $user_id -ne 0 ] ; then
if [ [ ! -x " $( command -v sudo) " ] ] ; then
echo "Warning: failed to update certificate store: sudo is required but not found"
return 1
else
sudo_prefix = "sudo"
fi
fi
if [ [ -x " $( command -v update-ca-certificates) " ] ] ; then
eval $sudo_prefix "update-ca-certificates"
elif [ [ -x " $( command -v update-ca-trust) " ] ] ; then
eval $sudo_prefix "update-ca-trust"
else
echo "Warning: failed to update certificate store: update-ca-certificates or update-ca-trust not found. This can happen if you're using a different runner base image."
return 1
fi
}
if [ [ ! -z " $RUNNER_UPDATE_CA_CERTS " ] ] ; then
updateCerts
fi
2022-11-02 14:28:14 +01:00
if [ [ -z " $RUNNER_MANUALLY_TRAP_SIG " ] ] ; then
2022-11-02 18:13:40 -04:00
run $*
2022-11-02 14:28:14 +01:00
else
2022-11-02 18:13:40 -04:00
runWithManualTrap $*
2024-03-04 11:32:21 +01:00
fi