From ef1197049631838fe1745e3ea5890c73a43b044f Mon Sep 17 00:00:00 2001 From: Konstantinos Spartalis Date: Tue, 5 May 2026 23:57:10 +0300 Subject: [PATCH 1/9] first test --- .../OPNsense/Core/Api/FirmwareController.php | 2 + .../mvc/app/models/OPNsense/Core/Firmware.xml | 1 + .../mvc/app/views/OPNsense/Core/firmware.volt | 77 +++++++++++++++++-- src/opnsense/scripts/firmware/config.sh | 14 ++++ src/opnsense/scripts/firmware/reinstall.sh | 13 +++- src/opnsense/scripts/firmware/update.sh | 13 +++- src/opnsense/scripts/firmware/upgrade.sh | 6 ++ 7 files changed, 114 insertions(+), 12 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php index 8c3a5ce3faa..9d4537383b7 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php @@ -769,6 +769,8 @@ public function upgradestatusAction() $result['status'] = 'done'; } elseif (strpos($cmd_result, '***REBOOT***') !== false) { $result['status'] = 'reboot'; + } elseif (strpos($cmd_result, '***SHUTDOWN***') !== false) { + $result['status'] = 'shutdown'; } return $result; diff --git a/src/opnsense/mvc/app/models/OPNsense/Core/Firmware.xml b/src/opnsense/mvc/app/models/OPNsense/Core/Firmware.xml index f10e9bd4e73..0a877f44591 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Core/Firmware.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Core/Firmware.xml @@ -9,6 +9,7 @@ + diff --git a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt index 7acd66bd63d..0cd2bda2f9a 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt @@ -190,6 +190,17 @@ }); } + /** + * save power off preference to the backend + */ + function setShutdownPreference(enabled, callback) + { + var confopt = { 'firmware': { 'shutdown': enabled ? '1' : '0' } }; + ajaxCall('/api/core/firmware/set', confopt, function () { + if (callback) callback(); + }); + } + /** * perform package action that requires reboot confirmation */ @@ -199,14 +210,17 @@ // reboot required, inform the user. BootstrapDialog.show({ type:BootstrapDialog.TYPE_WARNING, - title: "{{ lang._('Reboot required') }}", - message: "{{ lang._('The firewall will reboot directly after this set reinstall.') }}", + title: "{{ lang._('Reboot/ Power off required') }}", + message: "{{ lang._('The firewall will reboot directly after this set reinstall.') }}" + '

', buttons: [{ label: "{{ lang._('OK') }}", cssClass: 'btn-warning', action: function(dialogRef){ + let doShutdown = $('#reinstall_shutdown_cb').is(':checked'); dialogRef.close(); - backend(pkg_act + "/" + pkg_name); + setShutdownPreference(doShutdown, function () { + backend(pkg_act + "/" + pkg_name); + }); } },{ label: "{{ lang._('Cancel') }}", @@ -241,27 +255,53 @@ function upgrade_ui(major) { if (major !== true && $.status_reboot != "1") { - backend('update'); + setShutdownPreference(false, function () { + backend('update'); + }); } else { let reboot_msg = "{{ lang._('The firewall will reboot directly after this firmware update.') }}"; if (major === true) { reboot_msg = "{{ lang._('The firewall will download all firmware sets and reboot multiple times for this upgrade. All operating system files and packages will be reinstalled as a consequence. This may take several minutes to complete.') }}"; } + reboot_msg += '

'; // reboot required, inform the user. + let countdownSeconds = 30; + let countdownTimer = null; BootstrapDialog.show({ type:BootstrapDialog.TYPE_WARNING, - title: "{{ lang._('Reboot required') }}", + title: "{{ lang._('Reboot/ Power off required') }}", message: reboot_msg, + onshown: function(dialogRef) { + let $btn = dialogRef.getButton('btn-reboot'); + countdownTimer = setInterval(function () { + countdownSeconds--; + $btn.text('{{ lang._("Confirm") }} (' + countdownSeconds + ')'); + if (countdownSeconds <= 0) { + clearInterval(countdownTimer); + $btn.trigger('click'); + } + }, 1000); + }, + onhidden: function() { + if (countdownTimer) clearInterval(countdownTimer); + }, buttons: [{ - label: "{{ lang._('OK') }}", + id: 'btn-reboot', + label: '{{ lang._("Restart") }} (' + countdownSeconds + ')', cssClass: 'btn-warning', action: function(dialogRef){ + if (countdownTimer) clearInterval(countdownTimer); + let doShutdown = $('#upgrade_shutdown_cb').is(':checked'); dialogRef.close(); - backend(major === true ? 'upgrade' : 'update'); + setShutdownPreference(doShutdown, function () { + backend(major === true ? 'upgrade' : 'update'); + }); } },{ label: "{{ lang._('Cancel') }}", action: function(dialogRef){ + if (countdownTimer) clearInterval(countdownTimer); dialogRef.close(); } }] @@ -314,6 +354,14 @@ setTimeout(rebootWait, 45000); }, }); + } else if (data['status'] == 'shutdown') { + BootstrapDialog.show({ + type:BootstrapDialog.TYPE_INFO, + title: "{{ lang._('Shutting down after update') }}", + closable: false, + message: "{{ lang._('The system is shutting down. You chose to power off instead of reboot. The system will need to be started manually.') }}" + + ' ', + }); } else { // schedule next poll setTimeout(trackStatus, 500); @@ -681,6 +729,7 @@ $("#firmware_type").find('option').remove(); $("#firmware_flavour").find('option').remove(); $("#firmware_reboot").prop('checked', fwconf['reboot'] == '1'); + $("#firmware_shutdown").prop('checked', fwconf['shutdown'] == '1'); $("#firmware_aux").prop('checked', fwconf['aux'] == '1'); $.each(fwopts.mirrors, function(key, value) { @@ -732,7 +781,7 @@ } $("#firmware_flavour").selectpicker('refresh'); $("#firmware_flavour").change(); - if (fwconf['flavour'] !== '' || fwconf['reboot'] === '1' || fwconf['aux'] === '1') { + if (fwconf['flavour'] !== '' || fwconf['reboot'] === '1' || fwconf['shutdown'] === '1' || fwconf['aux'] === '1') { $("i.fa-toggle-off#show_advanced_firmware").click(); } @@ -779,6 +828,7 @@ confopt.flavour = $("#firmware_flavour_value").val(); confopt.type = $("#firmware_type").val(); confopt.reboot = $("#firmware_reboot").is(":checked") ? '1' : '0'; + confopt.shutdown = $("#firmware_shutdown").is(":checked") ? '1' : '0'; confopt.aux = $("#firmware_aux").is(":checked") ? '1' : '0'; confopt.subscription = $("#firmware_subscription").val(); ajaxCall('/api/core/firmware/set', { 'firmware': confopt }, function (data, status) { @@ -1061,6 +1111,17 @@ + + {{ lang._('Power off') }} + + + {{ lang._('Prefer power off instead of reboot after an update') }} + + + + {{ lang._('Repository') }} diff --git a/src/opnsense/scripts/firmware/config.sh b/src/opnsense/scripts/firmware/config.sh index ab0d4af93d4..c2c661967dc 100755 --- a/src/opnsense/scripts/firmware/config.sh +++ b/src/opnsense/scripts/firmware/config.sh @@ -163,6 +163,20 @@ output_reboot() /usr/local/etc/rc.reboot } +output_shutdown() +{ + KEEP_LOG=${1} + + echo '***SHUTDOWN***' >> ${LOCKFILE} + + if [ -n "${KEEP_LOG}" ]; then + cp ${LOCKFILE} ${LOGFILE} + fi + + sleep 5 + /usr/local/etc/rc.halt +} + # if output is requested clear file and set new request right away if [ -n "${REQUEST}" ]; then output_request "${REQUEST}" diff --git a/src/opnsense/scripts/firmware/reinstall.sh b/src/opnsense/scripts/firmware/reinstall.sh index f16bb088651..00ca4f73622 100755 --- a/src/opnsense/scripts/firmware/reinstall.sh +++ b/src/opnsense/scripts/firmware/reinstall.sh @@ -30,12 +30,17 @@ REQUEST="REINSTALL" . /usr/local/opnsense/scripts/firmware/config.sh PACKAGE=${1} +PREFER_SHUTDOWN=$(/usr/local/sbin/pluginctl -g system.firmware.shutdown) if [ "${PACKAGE}" = "base" ]; then if opnsense-update -Tb; then # force reinstall intended if output_cmd opnsense-update -bf; then - output_reboot + if [ "${PREFER_SHUTDOWN}" = "1" ]; then + output_shutdown + else + output_reboot + fi fi else # for locked message only @@ -45,7 +50,11 @@ elif [ "${PACKAGE}" = "kernel" ]; then if opnsense-update -Tk; then # force reinstall intended if output_cmd opnsense-update -kf; then - output_reboot + if [ "${PREFER_SHUTDOWN}" = "1" ]; then + output_shutdown + else + output_reboot + fi fi else # for locked message only diff --git a/src/opnsense/scripts/firmware/update.sh b/src/opnsense/scripts/firmware/update.sh index 74acde9a5be..96e8ca692cd 100755 --- a/src/opnsense/scripts/firmware/update.sh +++ b/src/opnsense/scripts/firmware/update.sh @@ -45,6 +45,7 @@ fi # read reboot flag and record current package name and version state ALWAYS_REBOOT=$(/usr/local/sbin/pluginctl -g system.firmware.reboot) +PREFER_SHUTDOWN=$(/usr/local/sbin/pluginctl -g system.firmware.shutdown) PKGS_HASH=$(${PKG} query %n-%v 2> /dev/null | sha256) UPDATE_FAILED= @@ -71,13 +72,21 @@ fi # if we can update base, we'll do that as well if opnsense-update ${FORCE} -bk -c; then if output_cmd opnsense-update ${FORCE} -bk; then - output_reboot keep-log + if [ "${PREFER_SHUTDOWN}" = "1" ]; then + output_shutdown keep-log + else + output_reboot keep-log + fi fi fi if [ "${ALWAYS_REBOOT}" = "1" ]; then if [ "${PKGS_HASH}" != "$(${PKG} query %n-%v 2> /dev/null | sha256)" ]; then - output_reboot keep-log + if [ "${PREFER_SHUTDOWN}" = "1" ]; then + output_shutdown keep-log + else + output_reboot keep-log + fi fi fi diff --git a/src/opnsense/scripts/firmware/upgrade.sh b/src/opnsense/scripts/firmware/upgrade.sh index aea4e5733fe..d5dab206848 100755 --- a/src/opnsense/scripts/firmware/upgrade.sh +++ b/src/opnsense/scripts/firmware/upgrade.sh @@ -30,12 +30,18 @@ REQUEST="UPGRADE" . /usr/local/opnsense/scripts/firmware/config.sh if output_cmd opnsense-update -u; then + PREFER_SHUTDOWN=$(/usr/local/sbin/pluginctl -g system.firmware.shutdown) if output_cmd /usr/local/etc/rc.syshook upgrade; then # pending kernel applies before reboot if output_cmd opnsense-update -K -c; then output_cmd opnsense-update -K fi output_reboot keep-log + if [ "${PREFER_SHUTDOWN}" = "1" ]; then + output_shutdown keep-log + else + output_reboot keep-log + fi fi output_txt "The upgrade was aborted due to an error." From 812a238a8d12472cadee3b80cf484bf61eb1a3b1 Mon Sep 17 00:00:00 2001 From: Konstantinos Spartalis Date: Wed, 6 May 2026 01:52:54 +0300 Subject: [PATCH 2/9] bored of amending --- .../app/controllers/OPNsense/Core/Api/FirmwareController.php | 2 +- src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt | 2 +- src/opnsense/scripts/shell/firmware.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php index 9d4537383b7..ef05779d68a 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php @@ -323,7 +323,7 @@ public function statusAction() $response['status_msg'] = sprintf( '%s %s', $response['status_msg'], - gettext('This update requires a reboot.') + gettext('This update requires a reboot/ power off.') ); } $response['status_reboot'] = $active_reboot; diff --git a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt index 0cd2bda2f9a..1e73eabb909 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt @@ -288,7 +288,7 @@ }, buttons: [{ id: 'btn-reboot', - label: '{{ lang._("Restart") }} (' + countdownSeconds + ')', + label: '{{ lang._("Confirm") }} (' + countdownSeconds + ')', cssClass: 'btn-warning', action: function(dialogRef){ if (countdownTimer) clearInterval(countdownTimer); diff --git a/src/opnsense/scripts/shell/firmware.sh b/src/opnsense/scripts/shell/firmware.sh index eb2a472d7dd..4ad4d7a47dd 100755 --- a/src/opnsense/scripts/shell/firmware.sh +++ b/src/opnsense/scripts/shell/firmware.sh @@ -75,7 +75,7 @@ if [ -n "${RELEASE}" ]; then PROMPT="${RELEASE}/${PROMPT}" elif CHANGELOG=$(${LAUNCHER} -u reboot); then - echo "This update requires a reboot." + echo "This update requires a reboot/ power off." echo fi From f6fe53846c4c6b0980f3280d7b849b53f69f01bb Mon Sep 17 00:00:00 2001 From: Konstantinos Spartalis Date: Wed, 6 May 2026 02:27:04 +0300 Subject: [PATCH 3/9] . --- src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt | 7 ++++++- src/opnsense/scripts/firmware/upgrade.sh | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt index 1e73eabb909..4c91b452a95 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt @@ -212,6 +212,9 @@ type:BootstrapDialog.TYPE_WARNING, title: "{{ lang._('Reboot/ Power off required') }}", message: "{{ lang._('The firewall will reboot directly after this set reinstall.') }}" + '

', + onshown: function(dialogRef) { + $('#reinstall_shutdown_cb').prop('checked', $.shutdown_pref === true); + }, buttons: [{ label: "{{ lang._('OK') }}", cssClass: 'btn-warning', @@ -264,7 +267,7 @@ reboot_msg = "{{ lang._('The firewall will download all firmware sets and reboot multiple times for this upgrade. All operating system files and packages will be reinstalled as a consequence. This may take several minutes to complete.') }}"; } reboot_msg += '

'; + '{{ lang._("Power off instead of reboot") }}'; // reboot required, inform the user. let countdownSeconds = 30; let countdownTimer = null; @@ -273,6 +276,7 @@ title: "{{ lang._('Reboot/ Power off required') }}", message: reboot_msg, onshown: function(dialogRef) { + $('#upgrade_shutdown_cb').prop('checked', $.shutdown_pref === true); let $btn = dialogRef.getButton('btn-reboot'); countdownTimer = setInterval(function () { countdownSeconds--; @@ -730,6 +734,7 @@ $("#firmware_flavour").find('option').remove(); $("#firmware_reboot").prop('checked', fwconf['reboot'] == '1'); $("#firmware_shutdown").prop('checked', fwconf['shutdown'] == '1'); + $.shutdown_pref = fwconf['shutdown'] == '1'; $("#firmware_aux").prop('checked', fwconf['aux'] == '1'); $.each(fwopts.mirrors, function(key, value) { diff --git a/src/opnsense/scripts/firmware/upgrade.sh b/src/opnsense/scripts/firmware/upgrade.sh index d5dab206848..e4e38f0624c 100755 --- a/src/opnsense/scripts/firmware/upgrade.sh +++ b/src/opnsense/scripts/firmware/upgrade.sh @@ -36,7 +36,6 @@ if output_cmd opnsense-update -u; then if output_cmd opnsense-update -K -c; then output_cmd opnsense-update -K fi - output_reboot keep-log if [ "${PREFER_SHUTDOWN}" = "1" ]; then output_shutdown keep-log else From 74f4f329249d648d1372acc11d644dfa0b73d19a Mon Sep 17 00:00:00 2001 From: Konstantinos Spartalis Date: Wed, 6 May 2026 02:44:14 +0300 Subject: [PATCH 4/9] remove general setting + some light deduplication --- .../mvc/app/views/OPNsense/Core/firmware.volt | 20 +------------------ src/opnsense/scripts/firmware/config.sh | 15 ++++++++++++++ src/opnsense/scripts/firmware/reinstall.sh | 12 ++--------- src/opnsense/scripts/firmware/update.sh | 13 ++---------- src/opnsense/scripts/firmware/upgrade.sh | 7 +------ 5 files changed, 21 insertions(+), 46 deletions(-) diff --git a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt index 4c91b452a95..d616af11dc7 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt @@ -212,9 +212,6 @@ type:BootstrapDialog.TYPE_WARNING, title: "{{ lang._('Reboot/ Power off required') }}", message: "{{ lang._('The firewall will reboot directly after this set reinstall.') }}" + '

', - onshown: function(dialogRef) { - $('#reinstall_shutdown_cb').prop('checked', $.shutdown_pref === true); - }, buttons: [{ label: "{{ lang._('OK') }}", cssClass: 'btn-warning', @@ -276,7 +273,6 @@ title: "{{ lang._('Reboot/ Power off required') }}", message: reboot_msg, onshown: function(dialogRef) { - $('#upgrade_shutdown_cb').prop('checked', $.shutdown_pref === true); let $btn = dialogRef.getButton('btn-reboot'); countdownTimer = setInterval(function () { countdownSeconds--; @@ -733,8 +729,6 @@ $("#firmware_type").find('option').remove(); $("#firmware_flavour").find('option').remove(); $("#firmware_reboot").prop('checked', fwconf['reboot'] == '1'); - $("#firmware_shutdown").prop('checked', fwconf['shutdown'] == '1'); - $.shutdown_pref = fwconf['shutdown'] == '1'; $("#firmware_aux").prop('checked', fwconf['aux'] == '1'); $.each(fwopts.mirrors, function(key, value) { @@ -786,7 +780,7 @@ } $("#firmware_flavour").selectpicker('refresh'); $("#firmware_flavour").change(); - if (fwconf['flavour'] !== '' || fwconf['reboot'] === '1' || fwconf['shutdown'] === '1' || fwconf['aux'] === '1') { + if (fwconf['flavour'] !== '' || fwconf['reboot'] === '1' || fwconf['aux'] === '1') { $("i.fa-toggle-off#show_advanced_firmware").click(); } @@ -833,7 +827,6 @@ confopt.flavour = $("#firmware_flavour_value").val(); confopt.type = $("#firmware_type").val(); confopt.reboot = $("#firmware_reboot").is(":checked") ? '1' : '0'; - confopt.shutdown = $("#firmware_shutdown").is(":checked") ? '1' : '0'; confopt.aux = $("#firmware_aux").is(":checked") ? '1' : '0'; confopt.subscription = $("#firmware_subscription").val(); ajaxCall('/api/core/firmware/set', { 'firmware': confopt }, function (data, status) { @@ -1116,17 +1109,6 @@ - - {{ lang._('Power off') }} - - - {{ lang._('Prefer power off instead of reboot after an update') }} - - - - {{ lang._('Repository') }} diff --git a/src/opnsense/scripts/firmware/config.sh b/src/opnsense/scripts/firmware/config.sh index c2c661967dc..506aa95688e 100755 --- a/src/opnsense/scripts/firmware/config.sh +++ b/src/opnsense/scripts/firmware/config.sh @@ -149,6 +149,21 @@ output_done() exit 0 } +output_restart_action() +{ + KEEP_LOG=${1} + + PREFER_SHUTDOWN=$(/usr/local/sbin/pluginctl -g system.firmware.shutdown) + + /usr/local/sbin/pluginctl -s system.firmware.shutdown 0 + + if [ "${PREFER_SHUTDOWN}" = "1" ]; then + output_shutdown "${KEEP_LOG}" + else + output_reboot "${KEEP_LOG}" + fi +} + output_reboot() { KEEP_LOG=${1} diff --git a/src/opnsense/scripts/firmware/reinstall.sh b/src/opnsense/scripts/firmware/reinstall.sh index 00ca4f73622..c94629d0d42 100755 --- a/src/opnsense/scripts/firmware/reinstall.sh +++ b/src/opnsense/scripts/firmware/reinstall.sh @@ -30,17 +30,13 @@ REQUEST="REINSTALL" . /usr/local/opnsense/scripts/firmware/config.sh PACKAGE=${1} -PREFER_SHUTDOWN=$(/usr/local/sbin/pluginctl -g system.firmware.shutdown) if [ "${PACKAGE}" = "base" ]; then if opnsense-update -Tb; then # force reinstall intended if output_cmd opnsense-update -bf; then if [ "${PREFER_SHUTDOWN}" = "1" ]; then - output_shutdown - else - output_reboot - fi + output_restart_action fi else # for locked message only @@ -50,11 +46,7 @@ elif [ "${PACKAGE}" = "kernel" ]; then if opnsense-update -Tk; then # force reinstall intended if output_cmd opnsense-update -kf; then - if [ "${PREFER_SHUTDOWN}" = "1" ]; then - output_shutdown - else - output_reboot - fi + output_restart_action fi else # for locked message only diff --git a/src/opnsense/scripts/firmware/update.sh b/src/opnsense/scripts/firmware/update.sh index 96e8ca692cd..05e7942af77 100755 --- a/src/opnsense/scripts/firmware/update.sh +++ b/src/opnsense/scripts/firmware/update.sh @@ -45,7 +45,6 @@ fi # read reboot flag and record current package name and version state ALWAYS_REBOOT=$(/usr/local/sbin/pluginctl -g system.firmware.reboot) -PREFER_SHUTDOWN=$(/usr/local/sbin/pluginctl -g system.firmware.shutdown) PKGS_HASH=$(${PKG} query %n-%v 2> /dev/null | sha256) UPDATE_FAILED= @@ -72,21 +71,13 @@ fi # if we can update base, we'll do that as well if opnsense-update ${FORCE} -bk -c; then if output_cmd opnsense-update ${FORCE} -bk; then - if [ "${PREFER_SHUTDOWN}" = "1" ]; then - output_shutdown keep-log - else - output_reboot keep-log - fi + output_restart_action keep-log fi fi if [ "${ALWAYS_REBOOT}" = "1" ]; then if [ "${PKGS_HASH}" != "$(${PKG} query %n-%v 2> /dev/null | sha256)" ]; then - if [ "${PREFER_SHUTDOWN}" = "1" ]; then - output_shutdown keep-log - else - output_reboot keep-log - fi + output_restart_action keep-log fi fi diff --git a/src/opnsense/scripts/firmware/upgrade.sh b/src/opnsense/scripts/firmware/upgrade.sh index e4e38f0624c..cccca30d75c 100755 --- a/src/opnsense/scripts/firmware/upgrade.sh +++ b/src/opnsense/scripts/firmware/upgrade.sh @@ -30,17 +30,12 @@ REQUEST="UPGRADE" . /usr/local/opnsense/scripts/firmware/config.sh if output_cmd opnsense-update -u; then - PREFER_SHUTDOWN=$(/usr/local/sbin/pluginctl -g system.firmware.shutdown) if output_cmd /usr/local/etc/rc.syshook upgrade; then # pending kernel applies before reboot if output_cmd opnsense-update -K -c; then output_cmd opnsense-update -K fi - if [ "${PREFER_SHUTDOWN}" = "1" ]; then - output_shutdown keep-log - else - output_reboot keep-log - fi + output_restart_action keep-log fi output_txt "The upgrade was aborted due to an error." From 545bfb014c6e20a45bca3e93566baaf5241f56a1 Mon Sep 17 00:00:00 2001 From: Konstantinos Spartalis Date: Wed, 6 May 2026 03:08:48 +0300 Subject: [PATCH 5/9] minor UI --- src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt index d616af11dc7..580139c170d 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt @@ -896,7 +896,7 @@ - +
From a3490cbcaeb6f96c4a9d363f475cee5ee5cd0011 Mon Sep 17 00:00:00 2001 From: Konstantinos Spartalis Date: Wed, 6 May 2026 03:18:43 +0300 Subject: [PATCH 6/9] blindness --- src/opnsense/scripts/firmware/reinstall.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/opnsense/scripts/firmware/reinstall.sh b/src/opnsense/scripts/firmware/reinstall.sh index c94629d0d42..f7e9e396b4f 100755 --- a/src/opnsense/scripts/firmware/reinstall.sh +++ b/src/opnsense/scripts/firmware/reinstall.sh @@ -35,7 +35,6 @@ if [ "${PACKAGE}" = "base" ]; then if opnsense-update -Tb; then # force reinstall intended if output_cmd opnsense-update -bf; then - if [ "${PREFER_SHUTDOWN}" = "1" ]; then output_restart_action fi else From 5e987563b2e60da89790838eb178505cb4747e62 Mon Sep 17 00:00:00 2001 From: Konstantinos Spartalis Date: Wed, 6 May 2026 12:20:17 +0300 Subject: [PATCH 7/9] not persistent and API friendly --- .../OPNsense/Core/Api/FirmwareController.php | 6 ++++ .../mvc/app/models/OPNsense/Core/Firmware.xml | 1 - .../mvc/app/views/OPNsense/Core/firmware.volt | 34 ++++++------------- src/opnsense/scripts/firmware/config.sh | 8 +++-- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php index ef05779d68a..bcc8c0af789 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php @@ -461,6 +461,8 @@ public function poweroffAction() */ public function updateAction() { + if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') { + touch('/tmp/firmware_shutdown.flag'); $backend = new Backend(); $response = []; if ($this->request->isPost()) { @@ -482,6 +484,8 @@ public function updateAction() */ public function upgradeAction() { + if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') { + touch('/tmp/firmware_shutdown.flag'); $backend = new Backend(); $response = []; if ($this->request->isPost()) { @@ -568,6 +572,8 @@ public function auditAction() */ public function reinstallAction($pkg_name) { + if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') { + touch('/tmp/firmware_shutdown.flag'); $backend = new Backend(); $response = []; diff --git a/src/opnsense/mvc/app/models/OPNsense/Core/Firmware.xml b/src/opnsense/mvc/app/models/OPNsense/Core/Firmware.xml index 0a877f44591..f10e9bd4e73 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Core/Firmware.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Core/Firmware.xml @@ -9,7 +9,6 @@ - diff --git a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt index 580139c170d..f1fabebb80f 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt @@ -131,8 +131,11 @@ /** * perform backend action and install poller to update status */ - function backend(type) { + function backend(type, data) { $.upgrade_check = type == 'check'; + if (data === undefined) { + data = {}; + } $('#update_status').html(''); $('#updatelist').hide(); @@ -140,7 +143,7 @@ $('#updatetab > a').tab('show'); $('#updatetab_progress').addClass("fa fa-spinner fa-pulse"); - ajaxCall('/api/core/firmware/' + type, {}, function () { + ajaxCall('/api/core/firmware/' + type, data, function () { setTimeout(trackStatus, 500); }); } @@ -190,17 +193,6 @@ }); } - /** - * save power off preference to the backend - */ - function setShutdownPreference(enabled, callback) - { - var confopt = { 'firmware': { 'shutdown': enabled ? '1' : '0' } }; - ajaxCall('/api/core/firmware/set', confopt, function () { - if (callback) callback(); - }); - } - /** * perform package action that requires reboot confirmation */ @@ -216,11 +208,9 @@ label: "{{ lang._('OK') }}", cssClass: 'btn-warning', action: function(dialogRef){ - let doShutdown = $('#reinstall_shutdown_cb').is(':checked'); + let doShutdown = $('#reinstall_shutdown_cb').is(':checked') ? '1' : '0'; dialogRef.close(); - setShutdownPreference(doShutdown, function () { - backend(pkg_act + "/" + pkg_name); - }); + backend(pkg_act + "/" + pkg_name, {'shutdown': doShutdown}); } },{ label: "{{ lang._('Cancel') }}", @@ -255,9 +245,7 @@ function upgrade_ui(major) { if (major !== true && $.status_reboot != "1") { - setShutdownPreference(false, function () { - backend('update'); - }); + backend('update'); } else { let reboot_msg = "{{ lang._('The firewall will reboot directly after this firmware update.') }}"; if (major === true) { @@ -292,11 +280,9 @@ cssClass: 'btn-warning', action: function(dialogRef){ if (countdownTimer) clearInterval(countdownTimer); - let doShutdown = $('#upgrade_shutdown_cb').is(':checked'); + let doShutdown = $('#upgrade_shutdown_cb').is(':checked') ? '1' : '0'; dialogRef.close(); - setShutdownPreference(doShutdown, function () { - backend(major === true ? 'upgrade' : 'update'); - }); + backend(major === true ? 'upgrade' : 'update', {'shutdown': doShutdown}); } },{ label: "{{ lang._('Cancel') }}", diff --git a/src/opnsense/scripts/firmware/config.sh b/src/opnsense/scripts/firmware/config.sh index 506aa95688e..832186cf093 100755 --- a/src/opnsense/scripts/firmware/config.sh +++ b/src/opnsense/scripts/firmware/config.sh @@ -152,10 +152,12 @@ output_done() output_restart_action() { KEEP_LOG=${1} + PREFER_SHUTDOWN=0 - PREFER_SHUTDOWN=$(/usr/local/sbin/pluginctl -g system.firmware.shutdown) - - /usr/local/sbin/pluginctl -s system.firmware.shutdown 0 + if [ -f /tmp/firmware_shutdown.flag ]; then + PREFER_SHUTDOWN=1 + rm -f /tmp/firmware_shutdown.flag + fi if [ "${PREFER_SHUTDOWN}" = "1" ]; then output_shutdown "${KEEP_LOG}" From 0fde4b106544aa8dcceaafcacd7f61d25b6af732 Mon Sep 17 00:00:00 2001 From: Konstantinos Spartalis Date: Wed, 6 May 2026 12:43:46 +0300 Subject: [PATCH 8/9] . --- .../OPNsense/Core/Api/FirmwareController.php | 30 +++++++++---------- .../mvc/app/views/OPNsense/Core/firmware.volt | 7 ++--- src/opnsense/scripts/firmware/config.sh | 7 +---- src/opnsense/scripts/firmware/reinstall.sh | 4 +-- src/opnsense/scripts/firmware/update.sh | 12 ++++++-- src/opnsense/scripts/firmware/upgrade.sh | 10 ++++++- 6 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php index bcc8c0af789..cbb4e282fcf 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php @@ -461,19 +461,20 @@ public function poweroffAction() */ public function updateAction() { - if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') { - touch('/tmp/firmware_shutdown.flag'); $backend = new Backend(); $response = []; if ($this->request->isPost()) { $this->getLogger('audit')->notice(sprintf("[Firmware] User %s executed a firmware update", $this->getUserName())); $backend->configdRun('firmware flush'); - $response['msg_uuid'] = trim($backend->configdRun('firmware update', true)); + + $cmd = 'firmware update'; + if ($this->request->getPost('shutdown') === '1') { + $cmd .= ' shutdown'; + } + + $response['msg_uuid'] = trim($backend->configdRun($cmd, true)); $response['status'] = 'ok'; - } else { - $response['status'] = 'failure'; } - return $response; } @@ -484,19 +485,20 @@ public function updateAction() */ public function upgradeAction() { - if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') { - touch('/tmp/firmware_shutdown.flag'); $backend = new Backend(); $response = []; if ($this->request->isPost()) { $this->getLogger('audit')->notice(sprintf("[Firmware] User %s executed a firmware upgrade", $this->getUserName())); $backend->configdRun('firmware flush'); - $response['msg_uuid'] = trim($backend->configdRun('firmware upgrade', true)); + + $cmd = 'firmware upgrade'; + if ($this->request->getPost('shutdown') === '1') { + $cmd .= ' shutdown'; + } + + $response['msg_uuid'] = trim($backend->configdRun($cmd, true)); $response['status'] = 'ok'; - } else { - $response['status'] = 'failure'; } - return $response; } @@ -572,8 +574,6 @@ public function auditAction() */ public function reinstallAction($pkg_name) { - if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') { - touch('/tmp/firmware_shutdown.flag'); $backend = new Backend(); $response = []; @@ -775,7 +775,7 @@ public function upgradestatusAction() $result['status'] = 'done'; } elseif (strpos($cmd_result, '***REBOOT***') !== false) { $result['status'] = 'reboot'; - } elseif (strpos($cmd_result, '***SHUTDOWN***') !== false) { + } elseif (strpos($cmd_result, '***POWER OFF***') !== false) { $result['status'] = 'shutdown'; } diff --git a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt index f1fabebb80f..0322bc1116f 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt @@ -202,15 +202,14 @@ // reboot required, inform the user. BootstrapDialog.show({ type:BootstrapDialog.TYPE_WARNING, - title: "{{ lang._('Reboot/ Power off required') }}", - message: "{{ lang._('The firewall will reboot directly after this set reinstall.') }}" + '

', + title: "{{ lang._('Reboot required') }}", + message: "{{ lang._('The firewall will reboot directly after this set reinstall.') }}", buttons: [{ label: "{{ lang._('OK') }}", cssClass: 'btn-warning', action: function(dialogRef){ - let doShutdown = $('#reinstall_shutdown_cb').is(':checked') ? '1' : '0'; dialogRef.close(); - backend(pkg_act + "/" + pkg_name, {'shutdown': doShutdown}); + backend(pkg_act + "/" + pkg_name); } },{ label: "{{ lang._('Cancel') }}", diff --git a/src/opnsense/scripts/firmware/config.sh b/src/opnsense/scripts/firmware/config.sh index 832186cf093..ae28169c5ab 100755 --- a/src/opnsense/scripts/firmware/config.sh +++ b/src/opnsense/scripts/firmware/config.sh @@ -152,12 +152,7 @@ output_done() output_restart_action() { KEEP_LOG=${1} - PREFER_SHUTDOWN=0 - - if [ -f /tmp/firmware_shutdown.flag ]; then - PREFER_SHUTDOWN=1 - rm -f /tmp/firmware_shutdown.flag - fi + PREFER_SHUTDOWN=${2:-0} if [ "${PREFER_SHUTDOWN}" = "1" ]; then output_shutdown "${KEEP_LOG}" diff --git a/src/opnsense/scripts/firmware/reinstall.sh b/src/opnsense/scripts/firmware/reinstall.sh index f7e9e396b4f..f16bb088651 100755 --- a/src/opnsense/scripts/firmware/reinstall.sh +++ b/src/opnsense/scripts/firmware/reinstall.sh @@ -35,7 +35,7 @@ if [ "${PACKAGE}" = "base" ]; then if opnsense-update -Tb; then # force reinstall intended if output_cmd opnsense-update -bf; then - output_restart_action + output_reboot fi else # for locked message only @@ -45,7 +45,7 @@ elif [ "${PACKAGE}" = "kernel" ]; then if opnsense-update -Tk; then # force reinstall intended if output_cmd opnsense-update -kf; then - output_restart_action + output_reboot fi else # for locked message only diff --git a/src/opnsense/scripts/firmware/update.sh b/src/opnsense/scripts/firmware/update.sh index 05e7942af77..f7e466ee007 100755 --- a/src/opnsense/scripts/firmware/update.sh +++ b/src/opnsense/scripts/firmware/update.sh @@ -29,6 +29,14 @@ REQUEST="UPDATE" . /usr/local/opnsense/scripts/firmware/config.sh +PREFER_SHUTDOWN=0 +for arg in "$@"; do + if [ "$arg" = "shutdown" ]; then + PREFER_SHUTDOWN=1 + break + fi +done + CMD=${1} FORCE= @@ -71,13 +79,13 @@ fi # if we can update base, we'll do that as well if opnsense-update ${FORCE} -bk -c; then if output_cmd opnsense-update ${FORCE} -bk; then - output_restart_action keep-log + output_restart_action keep-log ${PREFER_SHUTDOWN} fi fi if [ "${ALWAYS_REBOOT}" = "1" ]; then if [ "${PKGS_HASH}" != "$(${PKG} query %n-%v 2> /dev/null | sha256)" ]; then - output_restart_action keep-log + output_restart_action keep-log ${PREFER_SHUTDOWN} fi fi diff --git a/src/opnsense/scripts/firmware/upgrade.sh b/src/opnsense/scripts/firmware/upgrade.sh index cccca30d75c..d0dcf30311b 100755 --- a/src/opnsense/scripts/firmware/upgrade.sh +++ b/src/opnsense/scripts/firmware/upgrade.sh @@ -29,13 +29,21 @@ REQUEST="UPGRADE" . /usr/local/opnsense/scripts/firmware/config.sh +PREFER_SHUTDOWN=0 +for arg in "$@"; do + if [ "$arg" = "shutdown" ]; then + PREFER_SHUTDOWN=1 + break + fi +done + if output_cmd opnsense-update -u; then if output_cmd /usr/local/etc/rc.syshook upgrade; then # pending kernel applies before reboot if output_cmd opnsense-update -K -c; then output_cmd opnsense-update -K fi - output_restart_action keep-log + output_restart_action keep-log ${PREFER_SHUTDOWN} fi output_txt "The upgrade was aborted due to an error." From 745a2c4e2a7e8d3b4a0aaeff26546c92b3a7765d Mon Sep 17 00:00:00 2001 From: Konstantinos Spartalis Date: Wed, 6 May 2026 12:43:46 +0300 Subject: [PATCH 9/9] . --- .../OPNsense/Core/Api/FirmwareController.php | 30 +++++++++---------- .../mvc/app/views/OPNsense/Core/firmware.volt | 7 ++--- src/opnsense/scripts/firmware/config.sh | 9 ++---- src/opnsense/scripts/firmware/reinstall.sh | 4 +-- src/opnsense/scripts/firmware/update.sh | 12 ++++++-- src/opnsense/scripts/firmware/upgrade.sh | 10 ++++++- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php index bcc8c0af789..cbb4e282fcf 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Core/Api/FirmwareController.php @@ -461,19 +461,20 @@ public function poweroffAction() */ public function updateAction() { - if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') { - touch('/tmp/firmware_shutdown.flag'); $backend = new Backend(); $response = []; if ($this->request->isPost()) { $this->getLogger('audit')->notice(sprintf("[Firmware] User %s executed a firmware update", $this->getUserName())); $backend->configdRun('firmware flush'); - $response['msg_uuid'] = trim($backend->configdRun('firmware update', true)); + + $cmd = 'firmware update'; + if ($this->request->getPost('shutdown') === '1') { + $cmd .= ' shutdown'; + } + + $response['msg_uuid'] = trim($backend->configdRun($cmd, true)); $response['status'] = 'ok'; - } else { - $response['status'] = 'failure'; } - return $response; } @@ -484,19 +485,20 @@ public function updateAction() */ public function upgradeAction() { - if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') { - touch('/tmp/firmware_shutdown.flag'); $backend = new Backend(); $response = []; if ($this->request->isPost()) { $this->getLogger('audit')->notice(sprintf("[Firmware] User %s executed a firmware upgrade", $this->getUserName())); $backend->configdRun('firmware flush'); - $response['msg_uuid'] = trim($backend->configdRun('firmware upgrade', true)); + + $cmd = 'firmware upgrade'; + if ($this->request->getPost('shutdown') === '1') { + $cmd .= ' shutdown'; + } + + $response['msg_uuid'] = trim($backend->configdRun($cmd, true)); $response['status'] = 'ok'; - } else { - $response['status'] = 'failure'; } - return $response; } @@ -572,8 +574,6 @@ public function auditAction() */ public function reinstallAction($pkg_name) { - if ($this->request->isPost() && $this->request->getPost('shutdown') === '1') { - touch('/tmp/firmware_shutdown.flag'); $backend = new Backend(); $response = []; @@ -775,7 +775,7 @@ public function upgradestatusAction() $result['status'] = 'done'; } elseif (strpos($cmd_result, '***REBOOT***') !== false) { $result['status'] = 'reboot'; - } elseif (strpos($cmd_result, '***SHUTDOWN***') !== false) { + } elseif (strpos($cmd_result, '***POWER OFF***') !== false) { $result['status'] = 'shutdown'; } diff --git a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt index f1fabebb80f..0322bc1116f 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Core/firmware.volt @@ -202,15 +202,14 @@ // reboot required, inform the user. BootstrapDialog.show({ type:BootstrapDialog.TYPE_WARNING, - title: "{{ lang._('Reboot/ Power off required') }}", - message: "{{ lang._('The firewall will reboot directly after this set reinstall.') }}" + '

', + title: "{{ lang._('Reboot required') }}", + message: "{{ lang._('The firewall will reboot directly after this set reinstall.') }}", buttons: [{ label: "{{ lang._('OK') }}", cssClass: 'btn-warning', action: function(dialogRef){ - let doShutdown = $('#reinstall_shutdown_cb').is(':checked') ? '1' : '0'; dialogRef.close(); - backend(pkg_act + "/" + pkg_name, {'shutdown': doShutdown}); + backend(pkg_act + "/" + pkg_name); } },{ label: "{{ lang._('Cancel') }}", diff --git a/src/opnsense/scripts/firmware/config.sh b/src/opnsense/scripts/firmware/config.sh index 832186cf093..87e7c6e6520 100755 --- a/src/opnsense/scripts/firmware/config.sh +++ b/src/opnsense/scripts/firmware/config.sh @@ -152,12 +152,7 @@ output_done() output_restart_action() { KEEP_LOG=${1} - PREFER_SHUTDOWN=0 - - if [ -f /tmp/firmware_shutdown.flag ]; then - PREFER_SHUTDOWN=1 - rm -f /tmp/firmware_shutdown.flag - fi + PREFER_SHUTDOWN=${2:-0} if [ "${PREFER_SHUTDOWN}" = "1" ]; then output_shutdown "${KEEP_LOG}" @@ -184,7 +179,7 @@ output_shutdown() { KEEP_LOG=${1} - echo '***SHUTDOWN***' >> ${LOCKFILE} + echo '***POWER OFF***' >> ${LOCKFILE} if [ -n "${KEEP_LOG}" ]; then cp ${LOCKFILE} ${LOGFILE} diff --git a/src/opnsense/scripts/firmware/reinstall.sh b/src/opnsense/scripts/firmware/reinstall.sh index f7e9e396b4f..f16bb088651 100755 --- a/src/opnsense/scripts/firmware/reinstall.sh +++ b/src/opnsense/scripts/firmware/reinstall.sh @@ -35,7 +35,7 @@ if [ "${PACKAGE}" = "base" ]; then if opnsense-update -Tb; then # force reinstall intended if output_cmd opnsense-update -bf; then - output_restart_action + output_reboot fi else # for locked message only @@ -45,7 +45,7 @@ elif [ "${PACKAGE}" = "kernel" ]; then if opnsense-update -Tk; then # force reinstall intended if output_cmd opnsense-update -kf; then - output_restart_action + output_reboot fi else # for locked message only diff --git a/src/opnsense/scripts/firmware/update.sh b/src/opnsense/scripts/firmware/update.sh index 05e7942af77..f7e466ee007 100755 --- a/src/opnsense/scripts/firmware/update.sh +++ b/src/opnsense/scripts/firmware/update.sh @@ -29,6 +29,14 @@ REQUEST="UPDATE" . /usr/local/opnsense/scripts/firmware/config.sh +PREFER_SHUTDOWN=0 +for arg in "$@"; do + if [ "$arg" = "shutdown" ]; then + PREFER_SHUTDOWN=1 + break + fi +done + CMD=${1} FORCE= @@ -71,13 +79,13 @@ fi # if we can update base, we'll do that as well if opnsense-update ${FORCE} -bk -c; then if output_cmd opnsense-update ${FORCE} -bk; then - output_restart_action keep-log + output_restart_action keep-log ${PREFER_SHUTDOWN} fi fi if [ "${ALWAYS_REBOOT}" = "1" ]; then if [ "${PKGS_HASH}" != "$(${PKG} query %n-%v 2> /dev/null | sha256)" ]; then - output_restart_action keep-log + output_restart_action keep-log ${PREFER_SHUTDOWN} fi fi diff --git a/src/opnsense/scripts/firmware/upgrade.sh b/src/opnsense/scripts/firmware/upgrade.sh index cccca30d75c..d0dcf30311b 100755 --- a/src/opnsense/scripts/firmware/upgrade.sh +++ b/src/opnsense/scripts/firmware/upgrade.sh @@ -29,13 +29,21 @@ REQUEST="UPGRADE" . /usr/local/opnsense/scripts/firmware/config.sh +PREFER_SHUTDOWN=0 +for arg in "$@"; do + if [ "$arg" = "shutdown" ]; then + PREFER_SHUTDOWN=1 + break + fi +done + if output_cmd opnsense-update -u; then if output_cmd /usr/local/etc/rc.syshook upgrade; then # pending kernel applies before reboot if output_cmd opnsense-update -K -c; then output_cmd opnsense-update -K fi - output_restart_action keep-log + output_restart_action keep-log ${PREFER_SHUTDOWN} fi output_txt "The upgrade was aborted due to an error."