From d2f9efcd694278d32d9fa1ed65233f89a16d9f0d Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Tue, 16 Nov 2021 13:21:10 +0100 Subject: [PATCH] firmware: allow launcher to operate on a random sleep if requested To make verbatim script passthrough work we also need to introduce a scripting option to reach the random sleep option afterwards. We add a random delay of up to 25 minutes to the cron based operations in order to give the update servers more room to breathe. --- src/etc/rc.firmware | 2 +- src/opnsense/scripts/firmware/launcher.sh | 35 +++++++++++++++++-- .../conf/actions.d/actions_firmware.conf | 10 ++++-- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/etc/rc.firmware b/src/etc/rc.firmware index c933b9cbb..fc54fa95d 100755 --- a/src/etc/rc.firmware +++ b/src/etc/rc.firmware @@ -27,6 +27,6 @@ SUBR=/usr/local/etc/rc.firmware.subr -if ! /usr/local/opnsense/scripts/firmware/launcher.sh ${SUBR} "${@}"; then +if ! /usr/local/opnsense/scripts/firmware/launcher.sh -s ${SUBR} "${@}"; then echo "A firmware action is currently in progress." fi diff --git a/src/opnsense/scripts/firmware/launcher.sh b/src/opnsense/scripts/firmware/launcher.sh index d8f617c75..c696f5fe0 100755 --- a/src/opnsense/scripts/firmware/launcher.sh +++ b/src/opnsense/scripts/firmware/launcher.sh @@ -43,8 +43,39 @@ update upgrade " -SELECTED=${1} -shift +DO_RANDOM= +DO_SCRIPT= + +while getopts r:s: OPT; do + case ${OPT} in + r) + DO_RANDOM="-r $(jot -r 1 1 ${OPTARG})" + ;; + s) + # make sure the script exists + if [ ! -f "${OPTARG}" ]; then + exit 1 + fi + DO_SCRIPT="-s ${OPTARG}" + ;; + *) + # ignore unknown + ;; + esac +done + +shift $((${OPTIND} - 1)) + +if [ -n "${DO_SCRIPT}" ]; then + SELECTED=${DO_SCRIPT#"-s "} +else + SELECTED=${1} + shift +fi + +if [ -n "${DO_RANDOM}" ]; then + sleep ${DO_RANDOM#"-r "} +fi if [ -f "${SELECTED}" ]; then ${FLOCK} ${LOCKFILE} ${SELECTED} "${@}" diff --git a/src/opnsense/service/conf/actions.d/actions_firmware.conf b/src/opnsense/service/conf/actions.d/actions_firmware.conf index 8a4d19947..cdf0c01fe 100644 --- a/src/opnsense/service/conf/actions.d/actions_firmware.conf +++ b/src/opnsense/service/conf/actions.d/actions_firmware.conf @@ -9,6 +9,12 @@ command:/usr/local/opnsense/scripts/firmware/launcher.sh check parameters:%s type:script message:Running firmware update status + +[poll] +command:/usr/local/opnsense/scripts/firmware/launcher.sh -r 1500 check +parameters:%s +type:script +message:Running firmware update status via cron description:Firmware update check [flush] @@ -200,8 +206,8 @@ type:script message:issued firmware power off [auto-update] -command:/usr/local/etc/rc.firmware +command:/usr/local/etc/rc.firmware -r 1500 description:Automatic firmware update parameters:%s type:script -message:attempting automatic firmware update +message:Attempting automatic firmware update via cron