Commit bfa56f69 authored by Marius Burkard's avatar Marius Burkard
Browse files

- help page and display function (console width checking)

parent 3c7c9230
......@@ -48,7 +48,12 @@ tar -C /tmp/ispconfig-ai/ -xzf /tmp/ispconfig-ai.tar.gz || (echo "Failed extract
rm -f /tmp/ispconfig-ai.tar.gz ;
cd /tmp/ispconfig-ai ;
${PHP} -q ${BASEDIR}/ispconfig.ai.php $@ && exit 0 || exit 1;
TTY=$(ps ax | grep ^$$ | head -n 1 | awk '{ print $2 }' 2>/dev/null);
if [ "$TTY" != "" ] ; then
${PHP} -q /tmp/ispconfig-ai/ispconfig.ai.php $@ < /dev/${TTY} ;
else
${PHP} -q /tmp/ispconfig-ai/ispconfig.ai.php $@ ;
fi
cd ${CURDIR} ;
rm -rf /tmp/ispconfig-ai ;
\ No newline at end of file
......@@ -51,6 +51,16 @@ class ISPConfig {
}
private static function input() {
$input = fgets(STDIN);
return rtrim($input);
}
public static function ask($prompt) {
print $prompt . ': ';
return self::input();
}
/**
* @param string $class_name
* @throws ISPConfigClassException
......@@ -111,13 +121,59 @@ class ISPConfig {
public static function getScriptName() {
return self::$cli_script;
}
private static function printHelp() {
$message = '
{FW}*
ISPConfig 3 Autoinstaller
{FW}*
Usage: ispc3-ai.sh [<argument>] [...]
This script automatically installs all needed packages for an ISPConfig 3 setup using the guidelines from the "Perfect Server Setup" howtos on www.howtoforge.com.
Possible arguments are:
--help ->Show this help page
--debug ->Enable verbose logging (logs each command with the exit code)
--interactive ->Don\'t install ISPConfig in non-interactive mode. This is needed if you want to use expert mode, e. g. to install a slave server that shall be integrated into an existing multiserver setup.
--use-nginx ->Use nginx webserver instead of apache2
--no-web ->Do not use ISPConfig on this server to manage webserver setting and don\'t install nginx/apache. This will also prevent installing an ISPConfig UI and implies --no-roundcube as well as --no-pma
--no-mail ->Do not use ISPConfig on this server to manage mailserver settings. This will install postfix for sending system mails, but not dovecot and not configure any settings for ISPConfig mail.
--no-dns ->Do not use ISPConfig on this server to manage DNS entries. Bind will be installed for local DNS caching / resolving only.
--no-firewall ->Do not install ufw and tell ISPConfig to not manage firewall settings on this server.
--no-roundcube ->Do not install roundcube webmail.
--no-pma ->Do not install PHPMyAdmin on this server.
--i-know-what-i-am-doing
->Prevent the autoinstaller to ask for confirmation before continuing to reconfigure the server.
';
ISPConfigLog::print($message);
exit;
}
/**
* @throws ISPConfigModuleException
*/
public static function run() {
self::init();
if(isset($_GET['help']) && $_GET['help']) {
self::printHelp();
exit;
}
if(!isset($_GET['i-know-what-i-am-doing']) || !$_GET['i-know-what-i-am-doing']) {
print PXBashColor::getString('<lightred>WARNING!</lightred> This script will reconfigure your complete server!') . "\n";
print 'It should be run on a freshly installed server and all current configuration that you have done will most likely be lost!' . "\n";
$ok = ISPConfig::ask('Type \'yes\' if you really want to continue');
if($ok !== 'yes') {
print PXBashColor::getString('<lightred>ABORTED</lightred>') . "\n";
exit;
}
}
if(isset($_GET['debug']) && $_GET['debug']) {
ISPConfigLog::setLogPriority(ISPConfigLog::PRIO_DEBUG);
}
......
......@@ -48,6 +48,67 @@ class ISPConfigLog {
return true;
}
public static function print($message) {
$lines = explode("\n", $message);
$colw = trim(exec('tput cols'));
if(!$colw) {
$colw = 80;
}
$line_prefix = '';
$match = array();
foreach($lines as $line) {
if(substr($line, 0, 4) === '{FW}') {
$rep = substr($line, 4, 1);
if($rep) {
print str_repeat($rep, $colw);
}
continue;
}
while(preg_match('/^(.*?)\t(.*)$/', $line, $match)) {
$sub = mb_strlen($match[1]) % 4;
$line = $match[1] . str_repeat(' ', 4 - $sub) . $match[2];
}
$line_len = mb_strlen($line);
if(substr($line, 0, 2) !== '->') {
$line_prefix = '';
} else {
$line = substr($line, 2);
}
if($line_prefix == '' && preg_match('/^(\s+-[a-z0-9A-Z\-]+\s+|\s+)->(\S.*?)$/', $line, $match)) {
$line_prefix = str_repeat(' ', mb_strlen($match[1]));
$line = $match[1] . $match[2];
} elseif($line_prefix == '' && $line_len > $colw) {
preg_match('/^(\s*)\S/', $line, $match);
if(isset($match[1])) {
$line_prefix = $match[1];
}
} else {
if(mb_strlen($line_prefix) >= $colw) {
$line_prefix = ' ';
}
$line = $line_prefix . $line;
}
if(mb_strlen($line_prefix) >= $colw) {
$line_prefix = ' ';
}
while(mb_strlen($line) > $colw) {
$tmp = explode("{###}", wordwrap($line, $colw, "{###}", true), 2);
$tmp = array_shift($tmp);
print $tmp . "\n";
$line = $line_prefix . trim(mb_substr($line, mb_strlen($tmp)));
unset($tmp);
if(trim($line) === '') {
break;
}
}
print $line ."\n";
}
}
/**
* @param string $message
* @param int $priority
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment