From f46ea6f3a9eaadc182c4fa2aaafdcb9f7819c90e Mon Sep 17 00:00:00 2001 From: Thom Pol Date: Thu, 25 Feb 2021 00:00:31 +0100 Subject: [PATCH] Only install UAU when argument is given and add extra subarguments (#25) --- lib/class.ISPConfig.inc.php | 37 +++++++++++++++++++++----- lib/os/class.ISPConfigDebianOS.inc.php | 15 ++++++++++- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/lib/class.ISPConfig.inc.php b/lib/class.ISPConfig.inc.php index 77a3a56..ad90ecc 100644 --- a/lib/class.ISPConfig.inc.php +++ b/lib/class.ISPConfig.inc.php @@ -188,19 +188,42 @@ class ISPConfig { if ($_GET['use-php'] === 'system') { return $_GET['use-php']; } else { - $use_php = explode(',',$_GET['use-php']); + $use_php = explode(',',$_GET['use-php']); $php_versions = array_intersect($use_php, $available_php_versions); if(!empty($php_versions)) { return $php_versions; } else { return false; - } + } } } else { return $available_php_versions; } } + public static function wantsUnattendedUpgrades() { + if(isset($_GET['unattended-upgrades']) && $_GET['unattended-upgrades']) { + return true; + } else { + return false; + } + } + + public static function getUnattendedUpgradesOptions() { + if(isset($_GET['unattended-upgrades']) && $_GET['unattended-upgrades']) { + if ($_GET['unattended-upgrades'] === '') { + return $_GET['unattended-upgrades']; + } else { + $unattendedupgrades_options = explode(',',$_GET['unattended-upgrades']); + if(!empty($unattendedupgrades_options)) { + return $unattendedupgrades_options; + } else { + return false; + } + } + } + } + public static function getISPConfigChannel() { if(isset($_GET['channel']) && $_GET['channel']) { return $_GET['channel']; @@ -246,7 +269,7 @@ Possible arguments are: --use-unbound ->Use unbound instead of bind9 for local resolving. Only allowed if --no-dns is set. --use-php ->Use specific PHP versions, comma separated, instead of installing multiple PHP, e.g. --use-php=7.4,8.0 (5.6, 7.0, 7.1, 7.2, 7.3, 7.4 and 8.0 available). ->--use-php=system disables the sury repository and just installs the system\'s default PHP version. - ->ommiting the argument (use all versions) + ->ommiting the argument (use all versions) --use-ftp-ports ->This option sets the passive port range for pure-ftpd. You have to specify the port range separated by hyphen, e. g. --use-ftp-ports=40110-40210. ->If not provided the passive port range will not be configured. --no-web ->Do not use ISPConfig on this server to manage webserver setting and don\'t install nginx/apache or pureftpd. This will also prevent installing an ISPConfig UI and implies --no-roundcube as well as --no-pma @@ -259,8 +282,8 @@ Possible arguments are: --no-mailman ->Do not install Mailman mailing list manager. --no-quota ->Disable file system quota --no-ntp ->Disable NTP setup - --no-unattended-upgrades - ->Do not install UnattendedUpgrades. + --unattended-upgrades + ->Install UnattendedUpgrades. You can add extra arguments for automatic cleanup and automatic reboots when necessary with --unattended-upgrades=autoclean,reboot (or only one of them). --i-know-what-i-am-doing ->Prevent the autoinstaller to ask for confirmation before continuing to reconfigure the server. '; @@ -279,8 +302,8 @@ Possible arguments are: $valid_args = array( 'help', 'debug', 'interactive', - 'use-nginx', 'use-amavis', 'use-php', 'use-unbound', 'use-ftp-ports', 'channel', 'lang', - 'no-web', 'no-mail', 'no-dns', 'no-firewall', 'no-roundcube', 'no-pma', 'no-mailman', 'no-quota', 'no-ntp', 'no-local-dns', 'no-unattended-upgrades', + 'use-nginx', 'use-amavis', 'use-php', 'use-unbound', 'use-ftp-ports', 'channel', 'lang', 'unattended-upgrades', + 'no-web', 'no-mail', 'no-dns', 'no-firewall', 'no-roundcube', 'no-pma', 'no-mailman', 'no-quota', 'no-ntp', 'no-local-dns', 'i-know-what-i-am-doing' ); diff --git a/lib/os/class.ISPConfigDebianOS.inc.php b/lib/os/class.ISPConfigDebianOS.inc.php index 1d92ee1..47aee97 100644 --- a/lib/os/class.ISPConfigDebianOS.inc.php +++ b/lib/os/class.ISPConfigDebianOS.inc.php @@ -317,6 +317,19 @@ class ISPConfigDebianOS extends ISPConfigBaseOS { // Enable UnattendUpgrades to run every day $unattendedupgrades = 'APT::Periodic::Update-Package-Lists "1";' . "\n" . 'APT::Periodic::Unattended-Upgrade "1";'; file_put_contents('/etc/apt/apt.conf.d/20auto-upgrades', $unattendedupgrades); + + // Enable extra options if set in the arguments + $unattendedupgrades_options = ISPConfig::getUnattendedUpgradesOptions(); + if (!empty($unattendedupgrades_options)) { + if (in_array("autoclean", $unattendedupgrades_options)) { + $unattendedupgrades = "\n" . 'UnattendedUpgrades: APT::Periodic::AutocleanInterval "7";' . "\n" . 'Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";' . "\n" . 'Unattended-Upgrade::Remove-Unused-Dependencies "true";'; + file_put_contents('/etc/apt/apt.conf.d/20auto-upgrades', $unattendedupgrades, FILE_APPEND | LOCK_EX); + } + if (in_array("reboot", $unattendedupgrades_options)) { + $unattendedupgrades = "\n" . 'Unattended-Upgrade::Automatic-Reboot "true";' . "\n" . 'Unattended-Upgrade::Automatic-Reboot-Time "03:30";'; + file_put_contents('/etc/apt/apt.conf.d/20auto-upgrades', $unattendedupgrades, FILE_APPEND | LOCK_EX); + } + } } protected function shallCompileJailkit() { @@ -1104,7 +1117,7 @@ mailman-unsubscribe: "|/var/lib/mailman/mail/mailman unsubscribe mailman"'; $this->fixDbconfigCommon(); - if(ISPConfig::shallInstall('unattended-upgrades')) { + if(ISPConfig::wantsUnattendedUpgrades()) { $this->installUnattendedUpgrades(); } -- GitLab