enhance config-services script a bit
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -81,7 +81,7 @@ class ConfigServicesCmd extends CmdLineHandler
|
|||||||
// self::println("-d\t\t\tenable debug output");
|
// self::println("-d\t\t\tenable debug output");
|
||||||
self::println("-h\t\t\tsame as --help");
|
self::println("-h\t\t\tsame as --help");
|
||||||
self::println("");
|
self::println("");
|
||||||
|
|
||||||
die(); // end of execution
|
die(); // end of execution
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ class Action
|
|||||||
{
|
{
|
||||||
$this->_checkConfigParam(true);
|
$this->_checkConfigParam(true);
|
||||||
$this->_parseConfig();
|
$this->_parseConfig();
|
||||||
|
|
||||||
require FROXLOR_INSTALL_DIR . '/lib/tables.inc.php';
|
require FROXLOR_INSTALL_DIR . '/lib/tables.inc.php';
|
||||||
require FROXLOR_INSTALL_DIR . '/lib/functions.php';
|
require FROXLOR_INSTALL_DIR . '/lib/functions.php';
|
||||||
require FROXLOR_INSTALL_DIR . '/lib/classes/settings/class.Settings.php';
|
require FROXLOR_INSTALL_DIR . '/lib/classes/settings/class.Settings.php';
|
||||||
@@ -123,11 +123,11 @@ class Action
|
|||||||
require FROXLOR_INSTALL_DIR . '/lib/classes/config/class.ConfigParser.php';
|
require FROXLOR_INSTALL_DIR . '/lib/classes/config/class.ConfigParser.php';
|
||||||
require FROXLOR_INSTALL_DIR . '/lib/classes/config/class.ConfigService.php';
|
require FROXLOR_INSTALL_DIR . '/lib/classes/config/class.ConfigService.php';
|
||||||
require FROXLOR_INSTALL_DIR . '/lib/classes/config/class.ConfigDaemon.php';
|
require FROXLOR_INSTALL_DIR . '/lib/classes/config/class.ConfigDaemon.php';
|
||||||
|
|
||||||
if (array_key_exists("import-settings", $this->_args)) {
|
if (array_key_exists("import-settings", $this->_args)) {
|
||||||
$this->_importSettings();
|
$this->_importSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists("create", $this->_args)) {
|
if (array_key_exists("create", $this->_args)) {
|
||||||
$this->_createConfig();
|
$this->_createConfig();
|
||||||
} elseif (array_key_exists("apply", $this->_args)) {
|
} elseif (array_key_exists("apply", $this->_args)) {
|
||||||
@@ -165,7 +165,7 @@ class Action
|
|||||||
$_daemons_config = array(
|
$_daemons_config = array(
|
||||||
'distro' => ""
|
'distro' => ""
|
||||||
);
|
);
|
||||||
|
|
||||||
$config_dir = FROXLOR_INSTALL_DIR . '/lib/configfiles/';
|
$config_dir = FROXLOR_INSTALL_DIR . '/lib/configfiles/';
|
||||||
// show list of available distro's
|
// show list of available distro's
|
||||||
$distros = glob($config_dir . '*.xml');
|
$distros = glob($config_dir . '*.xml');
|
||||||
@@ -180,10 +180,10 @@ class Action
|
|||||||
// store in tmp array
|
// store in tmp array
|
||||||
$distributions_select_data[$dist_display] = str_replace(".xml", "", strtolower(basename($_distribution)));
|
$distributions_select_data[$dist_display] = str_replace(".xml", "", strtolower(basename($_distribution)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort by distribution name
|
// sort by distribution name
|
||||||
ksort($distributions_select_data);
|
ksort($distributions_select_data);
|
||||||
|
|
||||||
// list all distributions
|
// list all distributions
|
||||||
$mask = "|%-50.50s |%-50.50s |\n";
|
$mask = "|%-50.50s |%-50.50s |\n";
|
||||||
printf($mask, str_repeat("-", 50), str_repeat("-", 50));
|
printf($mask, str_repeat("-", 50), str_repeat("-", 50));
|
||||||
@@ -194,19 +194,19 @@ class Action
|
|||||||
}
|
}
|
||||||
printf($mask, str_repeat("-", 50), str_repeat("-", 50));
|
printf($mask, str_repeat("-", 50), str_repeat("-", 50));
|
||||||
echo PHP_EOL;
|
echo PHP_EOL;
|
||||||
|
|
||||||
while (! in_array($_daemons_config['distro'], $distributions_select_data)) {
|
while (! in_array($_daemons_config['distro'], $distributions_select_data)) {
|
||||||
$_daemons_config['distro'] = CmdLineHandler::getInput("choose distribution", "stretch");
|
$_daemons_config['distro'] = CmdLineHandler::getInput("choose distribution", "stretch");
|
||||||
}
|
}
|
||||||
|
|
||||||
// go through all services and let user check whether to include it or not
|
// go through all services and let user check whether to include it or not
|
||||||
$configfiles = new ConfigParser($config_dir . '/' . $_daemons_config['distro'] . ".xml");
|
$configfiles = new ConfigParser($config_dir . '/' . $_daemons_config['distro'] . ".xml");
|
||||||
$services = $configfiles->getServices();
|
$services = $configfiles->getServices();
|
||||||
|
|
||||||
foreach ($services as $si => $service) {
|
foreach ($services as $si => $service) {
|
||||||
echo PHP_EOL . "--- " . strtoupper($si) . " ---" . PHP_EOL . PHP_EOL;
|
echo PHP_EOL . "--- " . strtoupper($si) . " ---" . PHP_EOL . PHP_EOL;
|
||||||
$_daemons_config[$si] = "";
|
$_daemons_config[$si] = "";
|
||||||
|
|
||||||
$daemons = $service->getDaemons();
|
$daemons = $service->getDaemons();
|
||||||
$mask = "|%-50.50s |%-50.50s |\n";
|
$mask = "|%-50.50s |%-50.50s |\n";
|
||||||
printf($mask, str_repeat("-", 50), str_repeat("-", 50));
|
printf($mask, str_repeat("-", 50), str_repeat("-", 50));
|
||||||
@@ -237,7 +237,7 @@ class Action
|
|||||||
}
|
}
|
||||||
} while (! empty($sysservice));
|
} while (! empty($sysservice));
|
||||||
// add 'cron' as fixed part (doesn't hurt if it exists)
|
// add 'cron' as fixed part (doesn't hurt if it exists)
|
||||||
if (!in_array('cron', $_daemons_config[$si])) {
|
if (! in_array('cron', $_daemons_config[$si])) {
|
||||||
$_daemons_config[$si][] = 'cron';
|
$_daemons_config[$si][] = 'cron';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -247,7 +247,7 @@ class Action
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo PHP_EOL . PHP_EOL;
|
echo PHP_EOL . PHP_EOL;
|
||||||
$daemons_config = json_encode($_daemons_config);
|
$daemons_config = json_encode($_daemons_config);
|
||||||
$output = CmdLineHandler::getInput("choose output-filename", "/tmp/froxlor-config-" . date('Ymd') . ".json");
|
$output = CmdLineHandler::getInput("choose output-filename", "/tmp/froxlor-config-" . date('Ymd') . ".json");
|
||||||
@@ -256,6 +256,10 @@ class Action
|
|||||||
echo PHP_EOL;
|
echo PHP_EOL;
|
||||||
CmdLineHandler::printsucc("You can now apply this config running:" . PHP_EOL . "php " . __FILE__ . " --froxlor-dir=" . dirname(dirname(__DIR__)) . " --apply=" . $output);
|
CmdLineHandler::printsucc("You can now apply this config running:" . PHP_EOL . "php " . __FILE__ . " --froxlor-dir=" . dirname(dirname(__DIR__)) . " --apply=" . $output);
|
||||||
echo PHP_EOL;
|
echo PHP_EOL;
|
||||||
|
$proceed = CmdLineHandler::getYesNo("Do you want to apply the config now? [y/N]", 0);
|
||||||
|
if ($proceed) {
|
||||||
|
passthru("php " . __FILE__ . " --froxlor-dir=" . dirname(dirname(__DIR__)) . " --apply=" . $output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCompleteDistroName($cparser)
|
private function getCompleteDistroName($cparser)
|
||||||
@@ -292,10 +296,10 @@ class Action
|
|||||||
} elseif (! is_readable($this->_args["apply"])) {
|
} elseif (! is_readable($this->_args["apply"])) {
|
||||||
throw new Exception("Given config file cannot be read ('" . $this->_args["apply"] . "')");
|
throw new Exception("Given config file cannot be read ('" . $this->_args["apply"] . "')");
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = file_get_contents($this->_args["apply"]);
|
$config = file_get_contents($this->_args["apply"]);
|
||||||
$decoded_config = json_decode($config, true);
|
$decoded_config = json_decode($config, true);
|
||||||
|
|
||||||
if (array_key_exists("list-daemons", $this->_args)) {
|
if (array_key_exists("list-daemons", $this->_args)) {
|
||||||
$mask = "|%-50.50s |%-50.50s |\n";
|
$mask = "|%-50.50s |%-50.50s |\n";
|
||||||
printf($mask, str_repeat("-", 50), str_repeat("-", 50));
|
printf($mask, str_repeat("-", 50), str_repeat("-", 50));
|
||||||
@@ -317,18 +321,18 @@ class Action
|
|||||||
echo PHP_EOL;
|
echo PHP_EOL;
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$only_daemon = null;
|
$only_daemon = null;
|
||||||
if (array_key_exists("daemon", $this->_args)) {
|
if (array_key_exists("daemon", $this->_args)) {
|
||||||
$only_daemon = $this->_args['daemon'];
|
$only_daemon = $this->_args['daemon'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($decoded_config)) {
|
if (! empty($decoded_config)) {
|
||||||
$config_dir = FROXLOR_INSTALL_DIR . '/lib/configfiles/';
|
$config_dir = FROXLOR_INSTALL_DIR . '/lib/configfiles/';
|
||||||
$configfiles = new ConfigParser($config_dir . '/' . $decoded_config['distro'] . ".xml");
|
$configfiles = new ConfigParser($config_dir . '/' . $decoded_config['distro'] . ".xml");
|
||||||
$services = $configfiles->getServices();
|
$services = $configfiles->getServices();
|
||||||
$replace_arr = $this->_getReplacerArray();
|
$replace_arr = $this->_getReplacerArray();
|
||||||
|
|
||||||
foreach ($services as $si => $service) {
|
foreach ($services as $si => $service) {
|
||||||
echo PHP_EOL . "--- Configuring: " . strtoupper($si) . " ---" . PHP_EOL . PHP_EOL;
|
echo PHP_EOL . "--- Configuring: " . strtoupper($si) . " ---" . PHP_EOL . PHP_EOL;
|
||||||
if (! isset($decoded_config[$si]) || $decoded_config[$si] == 'x') {
|
if (! isset($decoded_config[$si]) || $decoded_config[$si] == 'x') {
|
||||||
@@ -342,7 +346,7 @@ class Action
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CmdLineHandler::println("Configuring '" . $di . "'");
|
CmdLineHandler::println("Configuring '" . $di . "'");
|
||||||
|
|
||||||
if (! empty($only_daemon) && $only_daemon != $di) {
|
if (! empty($only_daemon) && $only_daemon != $di) {
|
||||||
CmdLineHandler::printwarn("Skipping " . $di . " configuration as desired");
|
CmdLineHandler::printwarn("Skipping " . $di . " configuration as desired");
|
||||||
continue;
|
continue;
|
||||||
@@ -402,7 +406,7 @@ class Action
|
|||||||
} elseif (Settings::Get('phpfpm.enabled') == '1' && Settings::Get('phpfpm.tmpdir') != '') {
|
} elseif (Settings::Get('phpfpm.enabled') == '1' && Settings::Get('phpfpm.tmpdir') != '') {
|
||||||
$customer_tmpdir = Settings::Get('phpfpm.tmpdir');
|
$customer_tmpdir = Settings::Get('phpfpm.tmpdir');
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to convert namserver hosts to ip's
|
// try to convert namserver hosts to ip's
|
||||||
$ns_ips = "";
|
$ns_ips = "";
|
||||||
if (Settings::Get('system.nameservers') != '') {
|
if (Settings::Get('system.nameservers') != '') {
|
||||||
@@ -415,10 +419,10 @@ class Action
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Database::needSqlData();
|
Database::needSqlData();
|
||||||
$sql = Database::getSqlData();
|
$sql = Database::getSqlData();
|
||||||
|
|
||||||
$replace_arr = array(
|
$replace_arr = array(
|
||||||
'<SQL_UNPRIVILEGED_USER>' => $sql['user'],
|
'<SQL_UNPRIVILEGED_USER>' => $sql['user'],
|
||||||
'<SQL_UNPRIVILEGED_PASSWORD>' => $sql['passwd'],
|
'<SQL_UNPRIVILEGED_PASSWORD>' => $sql['passwd'],
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ abstract class CmdLineHandler
|
|||||||
*/
|
*/
|
||||||
private function _createAction()
|
private function _createAction()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Test for help-switch
|
// Test for help-switch
|
||||||
if (empty(self::$args) || array_key_exists("help", self::$args) || array_key_exists("h", self::$args)) {
|
if (empty(self::$args) || array_key_exists("help", self::$args) || array_key_exists("h", self::$args)) {
|
||||||
static::printHelp();
|
static::printHelp();
|
||||||
@@ -140,20 +140,20 @@ abstract class CmdLineHandler
|
|||||||
}
|
}
|
||||||
// check if no unknown parameters are present
|
// check if no unknown parameters are present
|
||||||
foreach (self::$args as $arg => $value) {
|
foreach (self::$args as $arg => $value) {
|
||||||
|
|
||||||
if (is_numeric($arg)) {
|
if (is_numeric($arg)) {
|
||||||
throw new Exception("Unknown parameter '" . $value . "' in argument list");
|
throw new Exception("Unknown parameter '" . $value . "' in argument list");
|
||||||
} elseif (! in_array($arg, static::$params) && ! in_array($arg, static::$switches)) {
|
} elseif (! in_array($arg, static::$params) && ! in_array($arg, static::$switches)) {
|
||||||
throw new Exception("Unknown parameter '" . $arg . "' in argument list");
|
throw new Exception("Unknown parameter '" . $arg . "' in argument list");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set debugger switch
|
// set debugger switch
|
||||||
if (isset(self::$args["d"]) && self::$args["d"] == true) {
|
if (isset(self::$args["d"]) && self::$args["d"] == true) {
|
||||||
// Debugger::getInstance()->setEnabled(true);
|
// Debugger::getInstance()->setEnabled(true);
|
||||||
// Debugger::getInstance()->debug("debug output enabled");
|
// Debugger::getInstance()->debug("debug output enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new static::$action_class(self::$args);
|
return new static::$action_class(self::$args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,6 +169,35 @@ abstract class CmdLineHandler
|
|||||||
return mb_strtolower($result);
|
return mb_strtolower($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getYesNo($prompt = "#", $default = null)
|
||||||
|
{
|
||||||
|
$value = null;
|
||||||
|
$_v = null;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
$_v = self::getInput($prompt);
|
||||||
|
|
||||||
|
if (strtolower($_v) == 'y' || strtolower($_v) == 'yes') {
|
||||||
|
$value = 1;
|
||||||
|
break;
|
||||||
|
} elseif (strtolower($_v) == 'n' || strtolower($_v) == 'no') {
|
||||||
|
$value = 0;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if ($_v == '' && $default != null) {
|
||||||
|
$value = $default;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
echo "Sorry, response " . $_v . " not understood. Please enter 'yes' or 'no'\n";
|
||||||
|
$value = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
public static function println($msg = "")
|
public static function println($msg = "")
|
||||||
{
|
{
|
||||||
print $msg . PHP_EOL;
|
print $msg . PHP_EOL;
|
||||||
|
|||||||
Reference in New Issue
Block a user