Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System patches logic simplifications (resubmit of PR #47) #199

Merged
merged 4 commits into from
Oct 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions sysutils/pfSense-pkg-System_Patches/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# $FreeBSD$

PORTNAME= pfSense-pkg-System_Patches
PORTVERSION= 1.1.4
PORTREVISION= 1
PORTVERSION= 1.1.5
CATEGORIES= sysutils
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
39 changes: 18 additions & 21 deletions sysutils/pfSense-pkg-System_Patches/files/usr/local/pkg/patches.inc
Original file line number Diff line number Diff line change
Expand Up @@ -174,53 +174,50 @@ function bootup_apply_patches() {
$a_patches = &$config['installedpackages']['patches']['item'];

foreach ($a_patches as $patch) {
/* Skip the patch if it should not be automatically applied. */
if (!isset($patch['autoapply'])) {
continue;
}
/* If the patch can be reverted it is already applied, so skip it. */
if (!patch_test_revert($patch)) {
/* Only attempt to apply if it can be applied. */
if (patch_test_apply($patch)) {
patch_apply($patch);
}
/* Skip if it should not be automatically applied;
only attempt to apply if it can be applied;
and if it can be reverted it is presumably already applied, so skip it. */
if (isset($patch['autoapply']) && patch_test_apply($patch) && !patch_test_revert($patch)) {
patch_apply($patch);
}
}
}

function patch_add_shellcmd() {
global $config;
$a_earlyshellcmd = &$config['system']['earlyshellcmd'];
if (!is_array($a_earlyshellcmd)) {
$a_earlyshellcmd = array();

if (!isset($config['system']['earlyshellcmd']) || !is_array($config['system']['earlyshellcmd'])) {
$config['system']['earlyshellcmd'] = array();
}
$a_earlyshellcmd = &$config['system']['earlyshellcmd'];
$found = false;
foreach ($a_earlyshellcmd as $idx => $cmd) {
if (stristr($cmd, "apply_patches.php")) {
$found = true;
}
}
if (!$found) {
// Implicitly creates array if needed
$a_earlyshellcmd[] = "/usr/local/bin/php-cgi -f /usr/local/bin/apply_patches.php";
write_config("System Patches package added a shellcmd");
write_config("System Patches package added an early shellcmd: apply patches");
}
}

function patch_remove_shellcmd() {
global $config;
$a_earlyshellcmd = &$config['system']['earlyshellcmd'];
if (!is_array($a_earlyshellcmd)) {
$a_earlyshellcmd = array();
if (!isset($config['system']['earlyshellcmd']) || !is_array($config['system']['earlyshellcmd'])) {
$config['system']['earlyshellcmd'] = array();
}
$removed = false;
$a_earlyshellcmd = &$config['system']['earlyshellcmd'];
$removed = 0;
foreach ($a_earlyshellcmd as $idx => $cmd) {
if (stristr($cmd, "apply_patches.php")) {
unset($a_earlyshellcmd[$idx]);
$removed = true;
$removed++;
}
}
if ($removed) {
write_config("System Patches package removed a shellcmd");
if ($removed > 0) {
write_config("System Patches package removed {$removed} existing early shellcmd(s): apply patches");
}
}

Expand Down