Commit 0f20b7ca authored by Marius Burkard's avatar Marius Burkard

- colorize output in installer

parent ac7375f1
......@@ -57,19 +57,21 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
error_reporting(E_ALL|E_STRICT);
require_once realpath(dirname(__FILE__)) . '/lib/classes/libbashcolor.inc.php';
define('INSTALLER_RUN', true);
//** The banner on the command line
echo "\n\n".str_repeat('-', 80)."\n";
echo " _____ ___________ _____ __ _ ____
|_ _/ ___| ___ \ / __ \ / _(_) /__ \
| | \ `--.| |_/ / | / \/ ___ _ __ | |_ _ __ _ _/ /
| | `--. \ __/ | | / _ \| '_ \| _| |/ _` | |_ |
_| |_/\__/ / | | \__/\ (_) | | | | | | | (_| | ___\ \
\___/\____/\_| \____/\___/|_| |_|_| |_|\__, | \____/
echo PXBashColor::getString( "<darkgrey>
<strong> _____ ___________</strong> _____ __ _ ____
<strong>|_ _/ ___| ___ \</strong> / __ \ / _(_) /__ \
<strong> | | \ `--.| |_/ /</strong> | / \/ ___ _ __ | |_ _ __ _ _/ /
<strong> | | `--. \ __/</strong> | | / _ \| '_ \| _| |/ _` | |_ |
<strong> _| |_/\__/ / | </strong> | \__/\ (_) | | | | | | | (_| | ___\ \
<strong> \___/\____/\_| </strong> \____/\___/|_| |_|_| |_|\__, | \____/
__/ |
|___/ ";
|___/ </darkgrey>");
echo "\n".str_repeat('-', 80)."\n";
echo "\n\n>> Initial configuration \n\n";
......@@ -148,12 +150,12 @@ $retval=shell_exec("which which");
if (empty($retval)) die ("ISPConfig requieres which \n");
swriteln($inst->lng(' Following will be a few questions for primary configuration so be careful.'));
swriteln($inst->lng(' Default values are in [brackets] and can be accepted with <ENTER>.'));
swriteln($inst->lng(' Tap in "quit" (without the quotes) to stop the installer.'."\n\n"));
swriteln($inst->lng(' Default values are in <strong>[brackets]</strong> and can be accepted with <em><ENTER></em>.'));
swriteln($inst->lng(' Tap in "<em>quit</em>" (without the quotes) to stop the installer.'."\n\n"));
//** Check log file is writable (probably not root or sudo)
if(!is_writable(dirname(ISPC_LOG_FILE))){
die("ERROR: Cannot write to the ".dirname(ISPC_LOG_FILE)." directory. Are you root or sudo ?\n\n");
die(PXBashColor::getString("<strong><red>[ERROR]</red></strong> Cannot write to the ".dirname(ISPC_LOG_FILE)." directory. Are you root or sudo ?\n\n"));
}
if(is_dir('/root/ispconfig') || is_dir('/home/admispconfig')) {
......
<?php
/*
(c) 2017 by Marius Burkard, pixcept KG
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
abstract class PXBashColor {
private static $markers = array(
'black' => 30,
'red' => 31,
'green' => 32,
'yellow' => 33,
'blue' => 34,
'magenta' => 35,
'cyan' => 36,
'lightgrey' => 37,
'default' => 39,
'darkgrey' => 90,
'lightred' => 91,
'lightgreen' => 92,
'lightyellow' => 93,
'lightblue' => 94,
'lightmagenta' => 95,
'lightcyan' => 96,
'white' => 97,
'bg:black' => 40,
'bg:red' => 41,
'bg:green' => 42,
'bg:yellow' => 43,
'bg:blue' => 44,
'bg:magenta' => 45,
'bg:cyan' => 46,
'bg:lightgrey' => 47,
'bg:default' => 49,
'bg:darkgrey' => 100,
'bg:lightred' => 101,
'bg:lightgreen' => 102,
'bg:lightyellow' => 103,
'bg:lightblue' => 104,
'bg:lightmagenta' => 105,
'bg:lightcyan' => 106,
'bg:white' => 107,
'bold' => 1,
'dim' => 2,
'italic' => 3,
'underlined' => 4,
'blink' => 5,
'invert' => 7,
'hidden' => 8
);
private static function getCode($active) {
$code = "\033[0;";
if(count($active) > 0) {
$tmp = array();
for($i = 0; $i < count($active); $i++) {
$tmp[] = self::$markers[$active[$i]];
}
sort($tmp);
$code .= implode(';', $tmp);
unset($tmp);
} else {
$code .= "0";
}
$code .= "m";
return $code;
}
public static function getString($string, $ignore_unknown_tags = false) {
$active = array();
$echo_string = "";
while(preg_match('/<(\/?(?:bg:)?\w+)>/i', $string, $match, PREG_OFFSET_CAPTURE)) {
$pos = $match[0][1];
$tag = $match[1][0];
$len = strlen($match[0][0]);
$close = false;
if(substr($tag, 0, 1) == '/') {
$close = true;
$tag = substr($tag, 1);
}
$key = $tag;
if($key == 'strong' || $key == 'b') $key = 'bold';
elseif($key == 'em' || $key == 'i') $key = 'italic';
elseif($key == 'u') $key = 'underlined';
elseif($key == 'inv') $key = 'invert';
if(!array_key_exists($key, self::$markers)) {
if($ignore_unknown_tags == false) {
throw new Exception('unknown tag: ' . $tag);
} else {
$echo_string .= self::getCode($active);
$echo_string .= substr($string, 0, $pos + $len);
$string = substr($string, $pos + $len);
continue;
}
}
if($pos > 0) {
$echo_string .= self::getCode($active);
$echo_string .= substr($string, 0, $pos);
}
if($close == true) {
$last = end($active);
if($key != $last) {
throw new Exception('unbalanced tag: ' . $tag . ' (' . $last . ' expected), ' . var_export($active, true));
}
array_pop($active);
} else {
array_push($active, $key);
}
$string = substr($string, $pos + $len);
}
if($string != '') {
$echo_string .= self::getCode($active);
$echo_string .= $string;
}
$echo_string .= "\e[0m";
return $echo_string;
}
}
\ No newline at end of file
......@@ -32,6 +32,8 @@ error_reporting(E_ALL|E_STRICT);
$FILE = realpath('../install.php');
require_once realpath(dirname(__FILE__)) . '/classes/libbashcolor.inc.php';
//** Get distribution identifier
//** IMPORTANT!
// This is the same code as in server/lib/classes/monitor_tools.inc.php
......@@ -214,7 +216,7 @@ function get_distname() {
$distconfid = 'debian90';
$distid = 'debian60';
$distbaseid = 'debian';
swriteln("Operating System: Debian 9.0 (Stretch) or compatible\n");
swriteln("Operating System: <strong>Debian 9.0 (Stretch)</strong> or compatible\n");
} elseif(strstr(trim(file_get_contents('/etc/debian_version')), '/sid')) {
$distname = 'Debian';
$distver = 'Testing';
......@@ -379,7 +381,7 @@ function swrite($text = '') {
}
function swriteln($text = '') {
echo $text."\n";
echo PXBashColor::getString($text, true)."\n";
}
function ilog($msg){
......
Markdown is supported
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