From f16d76c399001ddc75fc6d72e37a8e1b64c05594 Mon Sep 17 00:00:00 2001 From: Stephen Beaver Date: Thu, 15 Oct 2015 13:03:15 -0400 Subject: Added "reinstall all packages" functionality (accessed via diag_backup.php) --- src/usr/local/sbin/pfSense-upgrade | 18 +++++++++++- src/usr/local/www/pkg_mgr_install.php | 53 ++++++++++++++++++++++++----------- 2 files changed, 53 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/usr/local/sbin/pfSense-upgrade b/src/usr/local/sbin/pfSense-upgrade index 280baeb..b314e64 100755 --- a/src/usr/local/sbin/pfSense-upgrade +++ b/src/usr/local/sbin/pfSense-upgrade @@ -549,6 +549,17 @@ pkg_delete() { _exec "pkg autoremove" "Removing stale packages" mute ignore_result } +pkg_reinstall_all() { + for _pkg in $(pkg query -e '%a == 0' %n); do + case "${_pkg}" in + "${platform}"-pkg-* ) + echo reinstalling ${_pkg} + pkg_install ${_pkg} 1 + ;; + esac + done +} + pid_file="/var/run/$(basename $0).pid" last_update_file="/var/run/$(basename $0)-last-update" logfile="/cf/conf/upgrade_log.txt" @@ -679,7 +690,12 @@ case "${action}" in pkg_update force ;; install) - pkg_install ${action_pkg} ${force} + if [ ${action_pkg} == "ALL_PACKAGES" ] && [ -n ${force} ]; then + echo "Reinstalling every single package" + pkg_reinstall_all + else + pkg_install ${action_pkg} ${force} + fi ;; delete) pkg_delete ${action_pkg} diff --git a/src/usr/local/www/pkg_mgr_install.php b/src/usr/local/www/pkg_mgr_install.php index c482a79..aaf8a73 100644 --- a/src/usr/local/www/pkg_mgr_install.php +++ b/src/usr/local/www/pkg_mgr_install.php @@ -108,13 +108,20 @@ if ($_REQUEST['ajax']) { // Check to see if our process is still running $pidfile = $g['varrun_path'] . '/' . $g['product_name'] . '-upgrade.pid'; + $running = "running"; + // When we do a reinstallall, it is technically possible that we might catch the system in-between + // packages, hence the de-bounce here if (!isvalidpid($pidfile)) { - $running = "stopped"; - // The log files may not be complete when the process terminates so we need wait - waitfor_string_in_file($_REQUEST['logfilename'] . '.txt', "__RC=", 10); - } else { - $running = "running"; + usleep(100000); + if (!isvalidpid($pidfile)) { + $running = "stopped"; + // The log files may not be complete when the process terminates so we need wait until we see the + // exit status (__RC=x) + waitfor_string_in_file($_REQUEST['logfilename'] . '.txt', "__RC=", 10); + filter_configure(); + send_event("service restart packages"); + } } $pidarray = array('pid' => $running); @@ -303,7 +310,7 @@ if ($_POST['mode'] == 'delete') { $modetxt = gettext("installation"); } -if (!empty($_POST['id']) || $_GET['mode'] == 'showlog' || ($_GET['mode'] == 'installedinfo' && !empty($_GET['pkg']))): +if (!empty($_POST['id']) || $_POST['mode'] == "reinstallall" || $_GET['mode'] == 'showlog' || ($_GET['mode'] == 'installedinfo' && !empty($_GET['pkg']))): // What if the user navigates away from this page and then come back via his/her "Back" button? $pidfile = $g['varrun_path'] . '/' . $g['product_name'] . '-upgrade.pid'; @@ -365,25 +372,31 @@ if ($_GET) { /* Write out configuration to create a backup prior to pkg install. */ write_config(gettext("Creating restore point before package installation.")); + $progbar = true; + switch ($_POST['mode']) { case 'delete': - $pid = mwexec('/usr/local/sbin/pfSense-upgrade -l /tmp/webgui-log.txt -p /tmp/webgui-log.sock -r ' . $pkgid, false, false, true); + mwexec('/usr/local/sbin/pfSense-upgrade -l /tmp/webgui-log.txt -p /tmp/webgui-log.sock -r ' . $pkgid, false, false, true); $start_polling = true; - filter_configure(); break; case 'reinstallall': + if (is_array($config['installedpackages']) && is_array($config['installedpackages']['package'])) { + $progbar = false; // We don't show the progress bar for reinstallall. It would be far too confusing + mwexec('/usr/local/sbin/pfSense-upgrade -l /tmp/webgui-log.txt -p /tmp/webgui-log.sock -i ' . "ALL_PACKAGES" . ' -f', false, false, true); + $start_polling = true; + } + + break; case 'reinstallpkg': - $pid = mwexec('/usr/local/sbin/pfSense-upgrade -l /tmp/webgui-log.txt -p /tmp/webgui-log.sock -i ' . $pkgid . ' -f', false, false, true); - filter_configure(); + mwexec('/usr/local/sbin/pfSense-upgrade -l /tmp/webgui-log.txt -p /tmp/webgui-log.sock -i ' . $pkgid . ' -f', false, false, true); $start_polling = true; break; case 'installed': default: - $pid = mwexec('/usr/local/sbin/pfSense-upgrade -l /tmp/webgui-log.txt -p /tmp/webgui-log.sock -i ' . $pkgid, false, false, true); + mwexec('/usr/local/sbin/pfSense-upgrade -l /tmp/webgui-log.txt -p /tmp/webgui-log.sock -i ' . $pkgid, false, false, true); $start_polling = true; - filter_configure(); break; } @@ -413,7 +426,11 @@ function setProgress(barName, percent) { // Display a success banner function show_success() { $('#final').removeClass("alert-info").addClass("alert-success"); - $('#final').html("" + " " + "" + " " + ""); + if("") + $('#final').html("" + " " + "" + " " + ""); + else + $('#final').html(""); + $('#final').show(); } @@ -461,11 +478,13 @@ function getLogsStatus() { // Update the progress bar progress = 0; - if (json.data) { - setProgress('progressbar', ((json.data.current * 100) / json.data.total)); - progress = json.data.total - json.data.current - } + if("") { + if (json.data) { + setProgress('progressbar', ((json.data.current * 100) / json.data.total)); + progress = json.data.total - json.data.current + } + } // Now we need to determine if the installation/removal was successful, and tell the user. Not as easy as it sounds :) if ((json.pid == "stopped") && (progress == 0) && (json.exitstatus == 0)) { show_success(); -- cgit v1.1