enhance config-services script a bit

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-15 22:22:37 +01:00
parent 1e816de8cf
commit efe54d8b56
2 changed files with 59 additions and 26 deletions

View File

@@ -237,7 +237,7 @@ class Action
}
} while (! empty($sysservice));
// 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';
}
} else {
@@ -256,6 +256,10 @@ class Action
echo PHP_EOL;
CmdLineHandler::printsucc("You can now apply this config running:" . PHP_EOL . "php " . __FILE__ . " --froxlor-dir=" . dirname(dirname(__DIR__)) . " --apply=" . $output);
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)

View File

@@ -169,6 +169,35 @@ abstract class CmdLineHandler
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 = "")
{
print $msg . PHP_EOL;