From eb6cbc0164fbff9f2ed453b834e1e41ae485a8d4 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Fri, 19 Feb 2021 11:29:38 +0100 Subject: [PATCH] firmware: single spot for update/upgrade code #4718 --- src/etc/rc.firmware.subr | 52 +++--------------------- src/opnsense/scripts/firmware/update.sh | 24 ++++++----- src/opnsense/scripts/firmware/upgrade.sh | 18 ++++---- src/opnsense/scripts/shell/firmware.sh | 2 +- 4 files changed, 29 insertions(+), 67 deletions(-) diff --git a/src/etc/rc.firmware.subr b/src/etc/rc.firmware.subr index 532a5d0e2..06d7edfd8 100755 --- a/src/etc/rc.firmware.subr +++ b/src/etc/rc.firmware.subr @@ -27,13 +27,10 @@ set -e -LOCKFILE="/tmp/pkg_upgrade.progress" -PIPEFILE="/tmp/pkg_upgrade.pipe" RELEASE=$(opnsense-update -vR) -TEE="/usr/bin/tee -a" -if [ "${1}" = "upgrade" ]; then - : # ok, unconditional major upgrade +if [ "${1}" = "upgrade" -a -n "${2}" ]; then + RELEASE=${2} elif [ "${1}" = "ALLOW_RISKY_MAJOR_UPGRADE" -a -n "${RELEASE}" ]; then : # ok, conditional major upgrade else @@ -41,47 +38,10 @@ else RELEASE= fi -: > ${LOCKFILE} -rm -f ${PIPEFILE} -mkfifo ${PIPEFILE} - if [ -z "${RELEASE}" ]; then - # XXX essentially this is a copy of update.sh - echo "***GOT REQUEST TO UPDATE***" >> ${LOCKFILE} - - # figure out the release type from config - SUFFIX="-$(pluginctl -g system.firmware.type)" - if [ "${SUFFIX}" = "-" ]; then - SUFFIX= - fi - - # upgrade all packages if possible - (opnsense-update -pt "opnsense${SUFFIX}" 2>&1) | ${TEE} ${LOCKFILE} - - # trigger a webgui restart to cope with changes - (/usr/local/etc/rc.restart_webgui 2>&1) | ${TEE} ${LOCKFILE} - - # if we can update base, we'll do that as well - ${TEE} ${LOCKFILE} < ${PIPEFILE} & - if opnsense-update -c > ${PIPEFILE} 2>&1; then - ${TEE} ${LOCKFILE} < ${PIPEFILE} & - if opnsense-update -bk > ${PIPEFILE} 2>&1; then - echo '***REBOOT***' >> ${LOCKFILE} - sleep 5 - /usr/local/etc/rc.reboot - fi - fi + # already locked here, ok to call without launcher.sh + /usr/local/opnsense/scripts/firmware/update.sh else - # XXX essentially this is a copy of upgrade.sh - echo "***GOT REQUEST TO UPGRADE***" >> ${LOCKFILE} - - # upgrade to a major release - ${TEE} ${LOCKFILE} < ${PIPEFILE} & - if opnsense-update -u > ${PIPEFILE} 2>&1; then - echo '***REBOOT***' >> ${LOCKFILE} - sleep 5 - /usr/local/etc/rc.reboot - fi + # already locked here, ok to call without launcher.sh + /usr/local/opnsense/scripts/firmware/upgrade.sh fi - -echo '***DONE***' >> ${LOCKFILE} diff --git a/src/opnsense/scripts/firmware/update.sh b/src/opnsense/scripts/firmware/update.sh index 4fefc3152..a9f420790 100755 --- a/src/opnsense/scripts/firmware/update.sh +++ b/src/opnsense/scripts/firmware/update.sh @@ -25,12 +25,13 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -PKG_PROGRESS_FILE=/tmp/pkg_upgrade.progress +LOCKFILE="/tmp/pkg_upgrade.progress" +PIPEFILE="/tmp/pkg_upgrade.pipe" +TEE="/usr/bin/tee -a" -# Truncate upgrade progress file -: > ${PKG_PROGRESS_FILE} +: > ${LOCKFILE} -echo "***GOT REQUEST TO UPDATE***" >> ${PKG_PROGRESS_FILE} +echo "***GOT REQUEST TO UPDATE***" >> ${LOCKFILE} # figure out the release type from config SUFFIX="-$(pluginctl -g system.firmware.type)" @@ -39,19 +40,20 @@ if [ "${SUFFIX}" = "-" ]; then fi # upgrade all packages if possible -opnsense-update -pt "opnsense${SUFFIX}" >> ${PKG_PROGRESS_FILE} 2>&1 +(opnsense-update -pt "opnsense${SUFFIX}" 2>&1) | ${TEE} ${LOCKFILE} # restart the web server -/usr/local/etc/rc.restart_webgui >> ${PKG_PROGRESS_FILE} 2>&1 +(/usr/local/etc/rc.restart_webgui 2>&1) | ${TEE} ${LOCKFILE} # if we can update base, we'll do that as well -if opnsense-update -c >> ${PKG_PROGRESS_FILE} 2>&1; then - if opnsense-update -bk >> ${PKG_PROGRESS_FILE} 2>&1; then - echo '***REBOOT***' >> ${PKG_PROGRESS_FILE} - # give the frontend some time to figure out that a reboot is coming +${TEE} ${LOCKFILE} < ${PIPEFILE} & +if opnsense-update -c > ${PIPEFILE} 2>&1; then + ${TEE} ${LOCKFILE} < ${PIPEFILE} & + if opnsense-update -bk > ${PIPEFILE} 2>&1; then + echo '***REBOOT***' >> ${LOCKFILE} sleep 5 /usr/local/etc/rc.reboot fi fi -echo '***DONE***' >> ${PKG_PROGRESS_FILE} +echo '***DONE***' >> ${LOCKFILE} diff --git a/src/opnsense/scripts/firmware/upgrade.sh b/src/opnsense/scripts/firmware/upgrade.sh index 2c620051d..fd76a3994 100755 --- a/src/opnsense/scripts/firmware/upgrade.sh +++ b/src/opnsense/scripts/firmware/upgrade.sh @@ -25,19 +25,19 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -PKG_PROGRESS_FILE=/tmp/pkg_upgrade.progress +LOCKFILE="/tmp/pkg_upgrade.progress" +PIPEFILE="/tmp/pkg_upgrade.pipe" +TEE="/usr/bin/tee -a" -# Truncate upgrade progress file -: > ${PKG_PROGRESS_FILE} +: > ${LOCKFILE} -echo "***GOT REQUEST TO UPGRADE***" >> ${PKG_PROGRESS_FILE} +echo "***GOT REQUEST TO UPGRADE***" >> ${LOCKFILE} -# perform first half of major upgrade (download all + kernel install) -if opnsense-update -u >> ${PKG_PROGRESS_FILE} 2>&1; then - echo '***REBOOT***' >> ${PKG_PROGRESS_FILE} - # give the frontend some time to figure out that a reboot is coming +${TEE} ${LOCKFILE} < ${PIPEFILE} & +if opnsense-update -u > ${PIPEFILE} 2>&1; then + echo '***REBOOT***' >> ${LOCKFILE} sleep 5 /usr/local/etc/rc.reboot fi -echo '***DONE***' >> ${PKG_PROGRESS_FILE} +echo '***DONE***' >> ${LOCKFILE} diff --git a/src/opnsense/scripts/shell/firmware.sh b/src/opnsense/scripts/shell/firmware.sh index cf3988b36..bfb8de643 100755 --- a/src/opnsense/scripts/shell/firmware.sh +++ b/src/opnsense/scripts/shell/firmware.sh @@ -63,7 +63,7 @@ case ${YN} in [yY]) ;; ${RELEASE:-y}) - ARGS="upgrade" + ARGS="upgrade ${RELEASE}" ;; [sS]) echo