? cliinstaller.patch
? config.php
? stringnames.patch
? test.sh
? install/lang/en_utf8/installerchanged.php
Index: backup/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/backup/lib.php,v
retrieving revision 1.93
diff -u -r1.93 lib.php
--- backup/lib.php	31 Oct 2007 19:04:33 -0000	1.93
+++ backup/lib.php	18 Dec 2007 21:34:55 -0000
@@ -326,7 +326,7 @@
     /// This function upgrades the backup tables, if necessary
     /// It's called from admin/index.php, also backup.php and restore.php
 
-        global $CFG, $db;
+    global $CFG, $db, $interative;
 
         require_once ("$CFG->dirroot/backup/version.php");  // Get code versions
 
@@ -336,12 +336,16 @@
             $navlinks[] = array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc');
             $navigation = build_navigation($navlinks);
 
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
             print_header($strdatabaseupgrades, $strdatabaseupgrades, $navigation, "",
                     upgrade_get_javascript(), false, "&nbsp;", "&nbsp;");
+        }
 
             upgrade_log_start();
             print_heading('backup');
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
             $db->debug=true;
+        }
 
         /// Both old .sql files and new install.xml are supported
         /// but we priorize install.xml (XMLDB) if present
@@ -351,8 +355,9 @@
             } else if (file_exists($CFG->dirroot . '/backup/db/' . $CFG->dbtype . '.sql')) {
                 $status = modify_database($CFG->dirroot . '/backup/db/' . $CFG->dbtype . '.sql'); //Old method
             }
-
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
             $db->debug = false;
+        }
             if ($status) {
                 if (set_config("backup_version", $backup_version) and set_config("backup_release", $backup_release)) {
                     //initialize default backup settings now
@@ -360,9 +365,18 @@
                     apply_default_settings($adminroot->locate('backups'));
                     notify(get_string("databasesuccess"), "green");
                     notify(get_string("databaseupgradebackups", "", $backup_version), "green");
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                     print_continue($continueto);
                     print_footer('none');
                     exit;
+                } else if ( CLI_UPGRADE && ($interative > CLI_SEMI ) ) {
+                    console_write(STDOUT,'askcontinue');
+                    if (read_boolean()){
+                        return ;
+                    }else {
+                        console_write(STDERR,'','',false);
+                    }
+                }
                 } else {
                     error("Upgrade of backup system failed! (Could not update version in config table)");
                 }
@@ -408,22 +422,34 @@
         /// Then, the new function if exists and the old one was ok
             $newupgrade_status = true;
             if ($newupgrade && function_exists($newupgrade_function) && $oldupgrade_status) {
+            if (!defined('CLI_UPGRADE') || !CLI_UPGRADE) {
                 $db->debug = true;
+            }
                 $newupgrade_status = $newupgrade_function($CFG->backup_version);
             } else if ($newupgrade) {
                 notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' .
                         '/backup/db/upgrade.php');
             }
-
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE) {
             $db->debug=false;
+        }
         /// Now analyze upgrade results
             if ($oldupgrade_status && $newupgrade_status) {    // No upgrading failed
                 if (set_config("backup_version", $backup_version) and set_config("backup_release", $backup_release)) {
                     notify(get_string("databasesuccess"), "green");
                     notify(get_string("databaseupgradebackups", "", $backup_version), "green");
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE) {
                     print_continue($continueto);
                     print_footer('none');
                     exit;
+                } else if (CLI_UPGRADE) {
+                    console_write(STDOUT,'askcontinue');
+                    if (read_boolean()){
+                        return ;
+                    }else {
+                        console_write(STDERR,'','',false);
+                    }
+                }
                 } else {
                     error("Upgrade of backup system failed! (Could not update version in config table)");
                 }
Index: install/stringnames.txt
===================================================================
RCS file: /cvsroot/moodle/moodle/install/stringnames.txt,v
retrieving revision 1.3
diff -u -r1.3 stringnames.txt
--- install/stringnames.txt	7 Sep 2007 02:20:50 -0000	1.3
+++ install/stringnames.txt	18 Dec 2007 21:34:55 -0000
@@ -1,8 +1,21 @@
+aborting
+abortinstallation
 admindirerror
 admindirname
+admindirsetting
 admindirsettinghead
 admindirsettingsub
+adminemail
+adminfirstname
+admininfo
+adminlastname
+adminpassword
+adminusername
+askcontinue
+availabledbtypes
+availablelangs
 bypassed
+cannotconnecttodb
 cannotcreatelangdir
 cannotcreatetempdir
 cannotdownloadcomponents
@@ -13,22 +26,36 @@
 cannotunzipfile
 caution
 check
+checkingphpsettings
+chooselanguage
 chooselanguagehead
 chooselanguagesub
 closewindow
+compatibilitysettings
 compatibilitysettingshead
 compatibilitysettingssub
 componentisuptodate
+configfilecreated
+configfiledoesnotexist
 configfilenotwritten
 configfilewritten
+configurationcomplete
 configurationcompletehead
 configurationcompletesub
+configurationfileexist
 continue
+creatingconfigfile
 curlrecommended
 customcheck
 database
+databasecreationsettings
 databasecreationsettingshead
 databasecreationsettingssub
+databasehost
+databasename
+databasepass
+databasesettings
+databasesettingsformoodle
 databasesettingshead
 databasesettingssub
 databasesettingssub_mssql
@@ -38,27 +65,35 @@
 databasesettingssub_oci8po
 databasesettingssub_odbc_mssql
 databasesettingssub_postgres7
+databasetype
+databaseuser
 dataroot
 datarooterror
 dbconnectionerror
 dbcreationerror
 dbhost
+dbpass
 dbprefix
 dbtype
 dbwrongencoding
 dbwronghostserver
 dbwrongnlslang
 dbwrongprefix
+directorysettings
 directorysettingshead
 directorysettingssub
 dirroot
 dirrooterror
+disagreelicense
 download
 downloadedfilecheckfailed
 downloadlanguagebutton
 downloadlanguagehead
 downloadlanguagenotneeded
+downloadlanguagepack
 downloadlanguagesub
+downloadsuccess
+doyouagree
 environmenterrortodo
 environmenthead
 environmentrecommendcustomcheck
@@ -70,24 +105,44 @@
 environmentsub
 environmentxmlerror
 error
+errorsinenvironment
 fail
 fileuploads
 fileuploadserror
+fileuploadshelp
 gdversion
 gdversionerror
 gdversionhelp
 globalsquotes
 globalsquoteserror
+globalsquoteshelp
 help
 iconvrecommended
 info
+inputdatadirectory
+inputwebadress
+inputwebdirectory
 installation
+installationiscomplete
+invalidargumenthelp
+invalidemail
+invalidhost
+invalidint
+invalidintrange
 invalidmd5
+invalidpath
+invalidsetelement
+invalidtextvalue
+invalidurl
+invalidvalueforlanguage
+invalidyesno
 langdownloaderror
 langdownloadok
 language
+locationanddirectories
 magicquotesruntime
 magicquotesruntimeerror
+magicquotesruntimehelp
 mbstringrecommended
 memorylimit
 memorylimiterror
@@ -95,25 +150,27 @@
 missingrequiredfield
 moodledocslink
 mssql
-mssql_n
 mssqlextensionisnotpresentinphp
+mssql_n
 mysql
-mysqli
 mysql416bypassed
 mysql416required
 mysqlextensionisnotpresentinphp
+mysqli
 mysqliextensionisnotpresentinphp
 name
+newline
 next
 oci8po
 ociextensionisnotpresentinphp
-odbc_mssql
 odbcextensionisnotpresentinphp
+odbc_mssql
 ok
 opensslrecommended
 parentlanguage
 pass
 password
+pearargerror
 pgsqlextensionisnotpresentinphp
 php50restricted
 phpversion
@@ -123,23 +180,50 @@
 previous
 qtyperqpwillberemoved
 qtyperqpwillberemovedanyway
+releasenoteslink
 remotedownloadnotallowed
 report
 restricted
 safemode
 safemodeerror
+safemodehelp
+selectlanguage
 serverchecks
 sessionautostart
 sessionautostarterror
+sessionautostarthelp
+sitefullname
+siteinfo
+sitenewsitems
+siteshortname
+sitesummary
 skipdbencodingtest
 status
-this_direction
+tableprefix
 thischarset
 thisdirection
+this_direction
 thislanguage
 unicoderecommended
 unicoderequired
+unsafedirname
+upgradingactivitymodule
+upgradingbackupdb
+upgradingblocksdb
+upgradingblocksplugin
+upgradingcompleted
+upgradingcourseformatplugin
+upgradingenrolplugin
+upgradinggradeexportplugin
+upgradinggradeimportplugin
+upgradinggradereportplugin
+upgradinglocaldb
+upgradingmessageoutputpluggin
+upgradingqtypeplugin
+upgradingrpcfunctions
+usagehelp
 user
+versionerror
 welcomep10
 welcomep20
 welcomep30
@@ -147,8 +231,11 @@
 welcomep50
 welcomep60
 welcomep70
+welcometext
+writetoconfigfilefaild
 wrongdestpath
 wrongsourcebase
 wrongzipfilename
 wwwroot
 wwwrooterror
+yourchoice
Index: lang/en_utf8/install.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/install.php,v
retrieving revision 1.15
diff -u -r1.15 install.php
--- lang/en_utf8/install.php	21 Aug 2007 10:41:03 -0000	1.15
+++ lang/en_utf8/install.php	18 Dec 2007 21:34:55 -0000
@@ -17,18 +17,33 @@
     renaming the admin directory in your installation, and putting that 
     new name here.  For example: <br /> <br /><b>moodleadmin</b><br /> <br />
     This will fix admin links in Moodle.';
+$string['adminemail'] = 'Email :';
+$string['adminfirstname'] = 'First Name :';
+$string['admininfo'] = 'Administrator Details';
+$string['adminlastname'] = 'Last Name :';
+$string['adminpassword'] = 'Password :';
+$string['adminusername'] = 'Username :';
+$string['askcontinue'] = 'Continue (yes/no) :';
+$string['availabledbtypes']='\nAvailable db types \n';
+$string['availablelangs']='List of available languages \n';
+$string['cannotconnecttodb'] = 'Cannot connect to db \n';
 $string['caution'] = 'Caution';
+$string['checkingphpsettings']='\n\nChecking PHP Settings\n\n';
 $string['chooselanguage'] = 'Choose a language';
 $string['chooselanguagehead'] = 'Choose a language';
 $string['chooselanguagesub'] = 'Please choose a language for the installation ONLY. You will be able to choose site and user languages on a later screen.';
 $string['compatibilitysettings'] = 'Checking your PHP settings ...';
 $string['compatibilitysettingshead'] = 'Checking your PHP settings ...';
 $string['compatibilitysettingssub'] = 'Your server should pass all these tests to make Moodle run properly';
+$string['configfilecreated'] = 'Configuration file successfully created\n ';
+$string['configfiledoesnotexist'] = 'Configuration file does not exist !!!';
 $string['configfilenotwritten'] = 'The installer script was not able to automatically create a config.php file containing your chosen settings, probably because the Moodle directory is not writeable. You can manually copy the following code into a file named config.php within the root directory of Moodle.';
 $string['configfilewritten'] = 'config.php has been successfully created';
 $string['configurationcomplete'] = 'Configuration completed';
 $string['configurationcompletehead'] = 'Configuration completed';
 $string['configurationcompletesub'] = 'Moodle made an attempt to save your configuration in a file in the root of your Moodle installation.';
+$string['configurationfileexist']='Configuration file already exist!\n';
+$string['creatingconfigfile'] =' Creating configuration file ...\n';
 $string['database'] = 'Database';
 $string['databasecreationsettings'] = 'Now you need to configure the database settings where most Moodle data
     will be stored.  This database will be created automatically by the installer
@@ -49,6 +64,9 @@
        <b>User:</b> fixed to \"root\" by the installer<br />
        <b>Password:</b> your database password<br />
        <b>Tables Prefix:</b> optional prefix to use for all table names';
+$string['databasehost']='Database host :';
+$string['databasename']='Database name : ';
+$string['databasepass']='Database password :';
 $string['databasesettings'] = 'Now you need to configure the database where most Moodle data
     will be stored.  This database must already have been created
     and a username and password created to access it.<br />
@@ -59,6 +77,7 @@
        <b>User:</b> your database username<br />
        <b>Password:</b> your database password<br />
        <b>Tables Prefix:</b> optional prefix to use for all table names';
+$string['databasesettingsformoodle']='\n\nDatabase settings for Moodle\n\n';
 $string['databasesettingshead'] = 'Now you need to configure the database where most Moodle data
     will be stored.  This database must already have been created
     and a username and password created to access it.';
@@ -110,6 +129,8 @@
        <b>User:</b> your database username<br />
        <b>Password:</b> your database password<br />
        <b>Tables Prefix:</b> prefix to use for all table names (mandatory)';
+$string['databasetype']='Database type :';
+$string['databaseuser']='Database user :';
 $string['dataroot'] = 'Data Directory';
 $string['datarooterror'] = 'The \'Data Directory\' you specified could not be found or created.  Either correct the path or create that directory manually.';
 $string['dbconnectionerror'] = 'We could not connect to the database you specified. Please check your database settings.';
@@ -122,6 +143,7 @@
 $string['dbwronghostserver'] = 'You must follow \"Host\" rules as explained above.';
 $string['dbwrongnlslang'] = 'The NLS_LANG environment variable in your web server must use the AL32UTF8 charset. See PHP documentation about how to configure OCI8 properly.';
 $string['dbwrongprefix'] = 'You must follow \"Tables Prefix\" rules as explained above.';
+$string['disagreelicense'] = 'Upgrade cannot proceed due to disagreement to GPL!';
 $string['directorysettings'] = '<p>Please confirm the locations of this Moodle installation.</p>
 
 <p><b>Web Address:</b>
@@ -163,9 +185,13 @@
 $string['downloadlanguagebutton'] = 'Download the &quot;$a&quot; language pack';
 $string['downloadlanguagehead'] = 'Download language pack';
 $string['downloadlanguagenotneeded'] = 'You may continue the installation process using the default language pack, \"$a\".';
+$string['downloadlanguagepack']='\n\nDo you want to download language pack now(yes/no) :';
 $string['downloadlanguagesub'] = 'You now have the option of downloading a language pack and continuing the installation process in this language.<br /><br />If you are unable to download the language pack, the installation process will continue in English. (Once the installation process is complete, you will have the opportunity to download and install additional language packs.)';
+$string['downloadsuccess'] = 'Language Pack Downloaded Successfuly';
+$string['doyouagree'] = 'Do you agree ? (yes/no):';
 $string['environmenthead'] = 'Checking your environment ...';
 $string['environmentsub'] = 'We are checking if the various components of your system meet the system requirements';
+$string['errorsinenvironment'] ='Errors in the environment !\n';
 $string['fail'] = 'Fail';
 $string['fileuploads'] = 'File Uploads';
 $string['fileuploadserror'] = 'This should be on';
@@ -200,9 +226,28 @@
    <blockquote>php_value magic_quotes_gpc On</blockquote>
    <blockquote>php_value register_globals Off</blockquote>
 </p>';
+$string['inputdatadirectory']='Data Directory :';
+$string['inputwebadress']='Web address :';
+$string['inputwebdirectory']='Moodle Directory :';
 $string['installation'] = 'Installation';
+$string['installationiscomplete'] = 'Installtion is completed !\n';
+$string['invalidargumenthelp']='
+    Error: Invalid argument(s)
+    Usage: \$php cliupgrade.php OPTIONS
+    Use --help option to get more help\n';
+$string['invalidemail'] = 'Invalid Email';
+$string['invalidhost'] = 'Invalid Host ';
+$string['invalidint']='Error: value is not an integer \n';
+$string['invalidintrange'] = 'Error: Value is outside valid range\n';
+$string['invalidpath'] = 'Invalid Path ';
+$string['invalidsetelement']= 'Error: Value given is not in the given options \n';
+$string['invalidtextvalue'] = 'Invalid Text Value';
+$string['invalidurl'] = 'Invalid URL ';
+$string['invalidvalueforlanguage']='Invalid value for --lang option. Type --help for more help\n';
+$string['invalidyesno'] = 'Error: value is not a valid yes/no argument \n';
 $string['langdownloaderror'] = 'Unfortunately the language \"$a\" was not installed. The installation process will continue in English.';
 $string['langdownloadok'] = 'The language \"$a\" was installed successfully. The installation process will continue in this language.';
+$string['locationanddirectories']= '\n\nLocation and directories \n\n';
 $string['magicquotesruntime'] = 'Magic Quotes Run Time';
 $string['magicquotesruntimeerror'] = 'This should be off';
 $string['magicquotesruntimehelp'] = '<p>Magic quotes runtime should be turned off for Moodle to function properly.</p>
@@ -254,6 +299,7 @@
 <p>You must upgrade PHP or move to a host with a newer version of PHP!<br/>
 (In case of 5.0.x you could also downgrade to 4.4.x version)</p>';
 $string['postgres7'] = 'PostgreSQL (postgres7)';
+$string['releasenoteslink'] = 'For information about this version of Moodle, please see Release Notes at $a';
 $string['safemode'] = 'Safe Mode';
 $string['safemodeerror'] = 'Moodle may have trouble with safe mode on';
 $string['safemodehelp'] = '<p>Moodle may have a variety of problems with safe mode on, not least is that 
@@ -263,12 +309,64 @@
    to just find a new web hosting company for your Moodle site.</p>
    
 <p>You can try continuing the install if you like, but expect a few problems later on.</p>';
+$string['selectlanguage']='\n\nSelecting a language for installation\n';
 $string['sessionautostart'] = 'Session Auto Start';
 $string['sessionautostarterror'] = 'This should be off';
 $string['sessionautostarthelp'] = '<p>Moodle requires session support and will not function without it.</p>
 
 <p>Sessions can be enabled in the php.ini file ... look for the session.auto_start parameter.</p>';
+$string['sitefullname'] = 'Site full name :';
+$string['siteinfo'] = 'Site Details';
+$string['sitenewsitems'] = 'News Items :';
+$string['siteshortname'] = 'Site short name :';
+$string['sitesummary'] ='Site summary :';
 $string['skipdbencodingtest'] = 'Skip DB Encoding Test';
+$string['tableprefix']='Table prefix :';
+$string['unsafedirname'] = 'Error: Unsafe characters in directory name. valid characters are a-zA-Z0-9_-\n';
+$string['upgradingactivitymodule']= 'Upgrading Activity Module';
+$string['upgradingbackupdb'] = 'Upgrading Backup Database';
+$string['upgradingblocksdb'] = 'Upgrading Blocks Database';
+$string['upgradingblocksplugin'] = 'Upgrading Blocks Plugin';
+$string['upgradingcompleted'] = 'Upgrading completed...\n';
+$string['upgradingcourseformatplugin'] = 'Upgrading Course Format Pluggin';
+$string['upgradingenrolplugin'] = 'Upgrading Enrol Plugin';
+$string['upgradinggradeexportplugin'] = 'Upgrading Grade Export Plugin';
+$string['upgradinggradeimportplugin'] = 'Upgrading Grame Import Plugin';
+$string['upgradinggradereportplugin'] = 'Upgrading Grade Report Plugin';
+$string['upgradinglocaldb'] = 'Upgrading Local Database';
+$string['upgradingmessageoutputpluggin'] = 'Upgrading Message Output Plugin';
+$string['upgradingqtypeplugin'] = 'Upgrading Question/type Plugin';
+$string['upgradingrpcfunctions'] = 'Upgrading RPC Functions';
+$string['usagehelp']='
+Synopsis:
+\$php cliupgrade.php OPTIONS\n
+OPTIONS
+--lang              Valid installed language for installation. Default is English(en)
+--webaddr           Web address for the Moodle site
+--moodledir         Location of the moodle web folder
+--datadir           Location of the moodle data folder (should not be web visible)
+--dbtype            Database type. Default it mysql
+--dbhost            Database host. Default localhost
+--dbname            Database name. Default is moodle
+--dbuser            Database user. Default is blank
+--dbpass            Database password. Default is blank
+--prefix            Table prefix for above database tables. Default is mdl
+--verbose           0 No output, 1 Summarized output(Default), 2 Detailed output
+--interactivelevel  0 Non interactive, 1 semi interactive(Default), 2 interactive
+--agreelicense      Yes(Default) or No
+--confirmrelease    Yes(Default) or No
+--sitefullname      Full name for the site. Default is : Moodle Site (Please Change Site Name!!)
+--siteshortname     Short name for the site. Default is moodle
+--sitesummary       Summary of the site. Default is blank 
+--adminfirstname    First name of the admin. Default is Admin
+--adminlastname     Last name of the admin. Default is User
+--adminusername     Username for the admin. Default is admin
+--adminpassword     Password for the admin. Default is admin
+--adminemail        Email address of admin. Default is root@localhost
+--help              print out this help\n
+Usage:
+\$php cliupgrade.php --lang=en --webaddr=http://www.example.com --moodledir=/var/www/html/moodle --datadir=/var/moodledata --dbtype=mysql --dbhost=localhost --dbname=moodle --dbuser=root --prefix=mdl --agreelicense=yes --confirmrelease=yes --sitefullname=\"Example Moodle Site\" --siteshortname=moodle --sitesummary=siteforme --adminfirstname=Admin --adminlastname=User --adminusername=admin --adminpassword=admin --adminemail=admin@example.com --verbose=1 --interactivelevel=2 \n';
+$string['versionerror'] = 'User aborted due to version Error ';
 $string['welcomep10'] = '$a->installername ($a->installerversion)';
 $string['welcomep20'] = 'You are seeing this page because you have successfully installed and 
     launched the <strong>$a->packname $a->packversion</strong> package in your computer. Congratulations!';
@@ -283,7 +381,10 @@
     configure and set up <strong>Moodle</strong> on your computer. You may accept the default 
     settings or, optionally, amend them to suit your own needs.';
 $string['welcomep70'] = 'Click the \"Next\" button below to continue with the set up of <strong>Moodle</strong>.';
+$string['welcometext']='\n\n---Welcome to moodle commandline installer---\n\n';
+$string['writetoconfigfilefaild'] = 'Error: Write to config file failed ';
 $string['wwwroot'] = 'Web address';
 $string['wwwrooterror'] = 'The \'Web Address\' does not appear to be valid - this Moodle installation doesn\'t appear to be there. The value below has been reset.';
+$string['yourchoice']='\nYour choice :';
 
 ?>
Index: lib/accesslib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v
retrieving revision 1.446
diff -u -r1.446 accesslib.php
--- lib/accesslib.php	18 Dec 2007 20:51:07 -0000	1.446
+++ lib/accesslib.php	18 Dec 2007 21:34:56 -0000
@@ -2277,12 +2277,17 @@
 
         if (!$context->id = insert_record('context', $context)) {
             // better something than nothing - let's hope it will work somehow
-            if (!defined('SYSCONTEXTID')) {
+            // DONT do it if we're cli because it's IMMUNTABLE.  Doing it during web installer works because
+            // each step is a new request
+            if (!defined('SYSCONTEXTID') && !defined('CLI_UPGRADE')) {
                 define('SYSCONTEXTID', 1);
+                $context->id   = SYSCONTEXTID;
+                $context->path = '/'.SYSCONTEXTID;
+            } else {
+                $context->id   = 0;
+                $context->path = '/0';
             }
             debugging('Can not create system context');
-            $context->id   = SYSCONTEXTID;
-            $context->path = '/'.SYSCONTEXTID;
             return $context;
         }
     }
Index: lib/adminlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/adminlib.php,v
retrieving revision 1.163
diff -u -r1.163 adminlib.php
--- lib/adminlib.php	14 Dec 2007 21:22:38 -0000	1.163
+++ lib/adminlib.php	18 Dec 2007 21:34:57 -0000
@@ -49,7 +49,7 @@
  * @param string $return The url to prompt the user to continue to
  */
 function upgrade_plugins($type, $dir, $return) {
-    global $CFG, $db;
+    global $CFG, $db, $interactive;
 
 /// Let's know if the header has been printed, so the funcion is being called embedded in an outer page
     $embedded = defined('HEADER_PRINTED');
@@ -123,7 +123,9 @@
             $updated_plugins = true;
             upgrade_log_start();
             print_heading($dir.'/'. $plugin->name .' plugin needs upgrading');
-            $db->debug = true;
+            if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
+                $db->debug = true;
+            }
             @set_time_limit(0);  // To allow slow databases to complete the long SQL
 
             if ($CFG->$pluginversion == 0) {    // It's a new install of this plugin
@@ -137,8 +139,9 @@
                 } else {
                     $status = true;
                 }
-
-                $db->debug = false;
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
+                    $db->debug = false;
+                }
             /// Continue with the instalation, roles and other stuff
                 if ($status) {
                 /// OK so far, now update the plugins record
@@ -174,7 +177,9 @@
             /// First, the old function if exists
                 $oldupgrade_status = true;
                 if ($oldupgrade && function_exists($oldupgrade_function)) {
-                    $db->debug = true;
+                    if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
+                        $db->debug = true;
+                    }
                     $oldupgrade_status = $oldupgrade_function($CFG->$pluginversion);
                 } else if ($oldupgrade) {
                     notify ('Upgrade function ' . $oldupgrade_function . ' was not available in ' .
@@ -184,14 +189,17 @@
             /// Then, the new function if exists and the old one was ok
                 $newupgrade_status = true;
                 if ($newupgrade && function_exists($newupgrade_function) && $oldupgrade_status) {
-                    $db->debug = true;
+                    if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
+                        $db->debug = true;
+                    }
                     $newupgrade_status = $newupgrade_function($CFG->$pluginversion);
                 } else if ($newupgrade) {
                     notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' .
                              $fullplug . '/db/upgrade.php');
                 }
-
-                $db->debug=false;
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
+                    $db->debug=false;
+                }
             /// Now analyze upgrade results
                 if ($oldupgrade_status && $newupgrade_status) {    // No upgrading failed
                     // OK so far, now update the plugins record
@@ -205,7 +213,9 @@
                     notify('Upgrading '. $plugin->name .' from '. $CFG->$pluginversion .' to '. $plugin->version .' FAILED!');
                 }
             }
-            echo '<hr />';
+            if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
+                echo '<hr />';
+            }
         } else {
             upgrade_log_start();
             error('Version mismatch: '. $plugin->name .' can\'t downgrade '. $CFG->$pluginversion .' -> '. $plugin->version .' !');
@@ -215,9 +225,18 @@
     upgrade_log_finish();
 
     if ($updated_plugins && !$embedded) {
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
         print_continue($return);
         print_footer('none');
         die;
+        } else if (CLI_UPGRADE && ($interactive > CLI_SEMI )) {
+            console_write(STDOUT,'askcontinue');
+            if (read_boolean()){
+                return ;
+            }else {
+                console_write(STDERR,'','',false);
+            }
+        }
     }
 }
 
@@ -231,7 +250,7 @@
  */
 function upgrade_activity_modules($return) {
 
-    global $CFG, $db;
+    global $CFG, $db, $interactive;
 
     if (!$mods = get_list_of_plugins('mod') ) {
         error('No modules installed!');
@@ -311,6 +330,7 @@
                             upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
                 }
                 upgrade_log_start();
+
                 print_heading($module->name .' module needs upgrading');
 
             /// Run de old and new upgrade functions for the module
@@ -320,7 +340,9 @@
             /// First, the old function if exists
                 $oldupgrade_status = true;
                 if ($oldupgrade && function_exists($oldupgrade_function)) {
+                    if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE) {
                     $db->debug = true;
+                    }
                     $oldupgrade_status = $oldupgrade_function($currmodule->version, $module);
                     if (!$oldupgrade_status) {
                         notify ('Upgrade function ' . $oldupgrade_function .
@@ -334,14 +356,17 @@
             /// Then, the new function if exists and the old one was ok
                 $newupgrade_status = true;
                 if ($newupgrade && function_exists($newupgrade_function) && $oldupgrade_status) {
+                    if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                     $db->debug = true;
+                    }
                     $newupgrade_status = $newupgrade_function($currmodule->version, $module);
                 } else if ($newupgrade && $oldupgrade_status) {
                     notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' .
                              $mod . ': ' . $fullmod . '/db/upgrade.php');
                 }
-
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                 $db->debug=false;
+                }
             /// Now analyze upgrade results
                 if ($oldupgrade_status && $newupgrade_status) {    // No upgrading failed
                     // OK so far, now update the modules record
@@ -351,7 +376,9 @@
                     }
                     remove_dir($CFG->dataroot . '/cache', true); // flush cache
                     notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
+                    if (!defined('CLI_UPGRADE') || !CLI_UPGRADE) {
                     echo '<hr />';
+                    }
                 } else {
                     notify('Upgrading '. $module->name .' from '. $currmodule->version .' to '. $module->version .' FAILED!');
                 }
@@ -371,14 +398,19 @@
 
         } else {    // module not installed yet, so install it
             if (!$updated_modules) {
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                 print_header($strmodulesetup, $strmodulesetup,
                         build_navigation(array(array('name' => $strmodulesetup, 'link' => null, 'type' => 'misc'))), '',
                         upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
             }
+            }
             upgrade_log_start();
             print_heading($module->name);
             $updated_modules = true;
+            // To avoid unnecessary output from the SQL queries in the CLI version
+            if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE ) {
             $db->debug = true;
+            }
             @set_time_limit(0);  // To allow slow databases to complete the long SQL
 
         /// Both old .sql files and new install.xml are supported
@@ -389,7 +421,9 @@
                 $status = modify_database($fullmod .'/db/'. $CFG->dbtype .'.sql'); //Old method
             }
 
+            if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
             $db->debug = false;
+            }
 
         /// Continue with the installation, roles and other stuff
             if ($status) {
@@ -412,7 +446,9 @@
                     }
 
                     notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
+                    if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE ) {
                     echo '<hr />';
+                    }
                 } else {
                     error($module->name .' module could not be added to the module list!');
                 }
@@ -428,7 +464,6 @@
             $submoduleupgrade();
         }
 
-
     /// Run any defaults or final code that is necessary for this module
 
         if ( is_readable($fullmod .'/defaults.php')) {
@@ -448,9 +483,18 @@
     upgrade_log_finish(); // finish logging if started
 
     if ($updated_modules) {
+        if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE ) {
         print_continue($return);
         print_footer('none');
         die;
+        } else if ( CLI_UPGRADE && ($interactive > CLI_SEMI) ) {
+            console_write(STDOUT,'askcontinue');
+            if (read_boolean()){
+                return ;
+            }else {
+                console_write(STDERR,'','',false);
+            }
+        }
     }
 }
 
@@ -554,7 +598,7 @@
     return $linktoscrolltoerrors;
 }
 
-function create_admin_user() {
+function create_admin_user($user_input=NULL) {
     global $CFG, $USER;
 
     if (empty($CFG->rolesactive)) {   // No admin user yet.
@@ -572,6 +616,9 @@
         $user->maildisplay  = 1;
         $user->timemodified = time();
 
+        if ($user_input) {
+            $user = $user_input;
+        }
         if (!$user->id = insert_record('user', $user)) {
             error('SERIOUS ERROR: Could not create admin user record !!!');
         }
@@ -596,7 +643,9 @@
         $USER->newadminuser = 1;
         load_all_capabilities();
 
+        if (!defined('CLI_UPGRADE')||!CLI_UPGRADE) {
         redirect("$CFG->wwwroot/user/editadvanced.php?id=$user->id");  // Edit thyself
+        }
     } else {
         error('Can not create admin!');
     }
Index: lib/blocklib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/blocklib.php,v
retrieving revision 1.130
diff -u -r1.130 blocklib.php
--- lib/blocklib.php	19 Oct 2007 17:53:23 -0000	1.130
+++ lib/blocklib.php	18 Dec 2007 21:34:57 -0000
@@ -1036,20 +1036,22 @@
 /// This function upgrades the blocks tables, if necessary
 /// It's called from admin/index.php
 
-    global $CFG, $db;
+    global $CFG, $db, $interactive;
 
     require_once ($CFG->dirroot .'/blocks/version.php');  // Get code versions
 
     if (empty($CFG->blocks_version)) {                  // Blocks have never been installed.
         $strdatabaseupgrades = get_string('databaseupgrades');
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
         print_header($strdatabaseupgrades, $strdatabaseupgrades,
                 build_navigation(array(array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc'))), '',
                 upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
-
+        }
         upgrade_log_start();
         print_heading('blocks');
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
         $db->debug=true;
-
+        }
     /// Both old .sql files and new install.xml are supported
     /// but we priorize install.xml (XMLDB) if present
         $status = false;
@@ -1058,15 +1060,25 @@
         } else if (file_exists($CFG->dirroot . '/blocks/db/' . $CFG->dbtype . '.sql')) {
             $status = modify_database($CFG->dirroot . '/blocks/db/' . $CFG->dbtype . '.sql'); //Old method
         }
-
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
         $db->debug = false;
+        }
         if ($status) {
             if (set_config('blocks_version', $blocks_version)) {
                 notify(get_string('databasesuccess'), 'notifysuccess');
                 notify(get_string('databaseupgradeblocks', '', $blocks_version), 'notifysuccess');
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                 print_continue($continueto);
                 print_footer('none');
                 exit;
+                } else if (CLI_UPGRADE && ($interactive > CLI_SEMI) ) {
+                    console_write(STDOUT,'askcontinue');
+                    if (read_boolean()){
+                        return ;
+                    }else {
+                        console_write(STDERR,'','',false);
+                    }
+                }
             } else {
                 error('Upgrade of blocks system failed! (Could not update version in config table)');
             }
@@ -1089,10 +1101,12 @@
 
     if ($blocks_version > $CFG->blocks_version) {       // Upgrade tables
         $strdatabaseupgrades = get_string('databaseupgrades');
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
         print_header($strdatabaseupgrades, $strdatabaseupgrades,
                 build_navigation(array(array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript());
-
+        }
         upgrade_log_start();
+
         print_heading('blocks');
 
     /// Run de old and new upgrade functions for the module
@@ -1102,7 +1116,9 @@
     /// First, the old function if exists
         $oldupgrade_status = true;
         if ($oldupgrade && function_exists($oldupgrade_function)) {
+            if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
             $db->debug = true;
+            }
             $oldupgrade_status = $oldupgrade_function($CFG->blocks_version);
         } else if ($oldupgrade) {
             notify ('Upgrade function ' . $oldupgrade_function . ' was not available in ' .
@@ -1112,22 +1128,27 @@
     /// Then, the new function if exists and the old one was ok
         $newupgrade_status = true;
         if ($newupgrade && function_exists($newupgrade_function) && $oldupgrade_status) {
+            if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
             $db->debug = true;
+            }
             $newupgrade_status = $newupgrade_function($CFG->blocks_version);
         } else if ($newupgrade) {
             notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' .
                      '/blocks/db/upgrade.php');
         }
-
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
         $db->debug=false;
+        }
     /// Now analyze upgrade results
         if ($oldupgrade_status && $newupgrade_status) {    // No upgrading failed
             if (set_config('blocks_version', $blocks_version)) {
                 notify(get_string('databasesuccess'), 'notifysuccess');
                 notify(get_string('databaseupgradeblocks', '', $blocks_version), 'notifysuccess');
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                 print_continue($continueto);
                 print_footer('none');
                 exit;
+                }
             } else {
                 error('Upgrade of blocks system failed! (Could not update version in config table)');
             }
@@ -1146,7 +1167,7 @@
 //into blocks table or do all the upgrade process if newer
 function upgrade_blocks_plugins($continueto) {
 
-    global $CFG, $db;
+    global $CFG, $db, $interactive;
 
     $blocktitles = array();
     $invalidblocks = array();
@@ -1255,12 +1276,15 @@
             } else if ($currblock->version < $block->version) {
                 if (empty($updated_blocks)) {
                     $strblocksetup    = get_string('blocksetup');
+                    if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                     print_header($strblocksetup, $strblocksetup,
                             build_navigation(array(array('name' => $strblocksetup, 'link' => null, 'type' => 'misc'))), '',
                             upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
+                    }
                 }
                 $updated_blocks = true;
                 upgrade_log_start();
+
                 print_heading('New version of '.$blocktitle.' ('.$block->name.') exists');
                 @set_time_limit(0);  // To allow slow databases to complete the long SQL
 
@@ -1271,7 +1295,9 @@
             /// First, the old function if exists
                 $oldupgrade_status = true;
                 if ($oldupgrade && function_exists($oldupgrade_function)) {
+                    if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                     $db->debug = true;
+                    }
                     $oldupgrade_status = $oldupgrade_function($currblock->version, $block);
                 } else if ($oldupgrade) {
                     notify ('Upgrade function ' . $oldupgrade_function . ' was not available in ' .
@@ -1281,14 +1307,17 @@
             /// Then, the new function if exists and the old one was ok
                 $newupgrade_status = true;
                 if ($newupgrade && function_exists($newupgrade_function) && $oldupgrade_status) {
+                    if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                     $db->debug = true;
+                    }
                     $newupgrade_status = $newupgrade_function($currblock->version, $block);
                 } else if ($newupgrade) {
                     notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' .
                              $fullblock . '/db/upgrade.php');
                 }
-
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                 $db->debug=false;
+                }
             /// Now analyze upgrade results
                 if ($oldupgrade_status && $newupgrade_status) {    // No upgrading failed
 
@@ -1310,7 +1339,9 @@
                 } else {
                     notify('Upgrading block '. $block->name .' from '. $currblock->version .' to '. $block->version .' FAILED!');
                 }
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                 echo '<hr />';
+                }
             } else {
                 upgrade_log_start();
                 error('Version mismatch: block '. $block->name .' can\'t downgrade '. $currblock->version .' -> '. $block->version .'!');
@@ -1332,18 +1363,26 @@
             if($conflictblock !== false && $conflictblock !== NULL) {
                 // Duplicate block titles are not allowed, they confuse people
                 // AND PHP's associative arrays ;)
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                 error('<strong>Naming conflict</strong>: block <strong>'.$block->name.'</strong> has the same title with an existing block, <strong>'.$conflictblock.'</strong>!');
+                } else if (CLI_UPGRADE) {
+                    error('Naming conflict: block "'.$block->name.'" has the same title with an existing block, "'.$conflictblock.'"!');
+                }
             }
             if (empty($updated_blocks)) {
                 $strblocksetup    = get_string('blocksetup');
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE) {
                 print_header($strblocksetup, $strblocksetup,
                         build_navigation(array(array('name' => $strblocksetup, 'link' => null, 'type' => 'misc'))), '',
                         upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
             }
+            }
             $updated_blocks = true;
             upgrade_log_start();
             print_heading($block->name);
+            if (!defined('CLI_UPGRADE')||!CLI_UPGRADE) {
             $db->debug = true;
+            }
             @set_time_limit(0);  // To allow slow databases to complete the long SQL
 
         /// Both old .sql files and new install.xml are supported
@@ -1356,8 +1395,9 @@
             } else {
                 $status = true;
             }
-
+            if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
             $db->debug = false;
+            }
             if ($status) {
                 if ($block->id = insert_record('block', $block)) {
                     $blockobj->after_install();
@@ -1368,7 +1408,9 @@
 
                     events_update_definition($component);
                     notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess');
+                    if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE) {
                     echo '<hr />';
+                    }
                 } else {
                     error($block->name .' block could not be added to the block list!');
                 }
@@ -1410,9 +1452,18 @@
     upgrade_log_finish();
 
     if (!empty($updated_blocks)) {
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE) {
         print_continue($continueto);
         print_footer('none');
         die;
+        } else if ( CLI_UPGRADE && ($interactive > CLI_SEMI) ) {
+            console_write(STDOUT,'askcontinue');
+            if (read_boolean()){
+                return ;
+            }else {
+                console_write(STDERR,'','',false);
+            }
+        }
     }
 }
 
Index: lib/dmllib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/dmllib.php,v
retrieving revision 1.124
diff -u -r1.124 dmllib.php
--- lib/dmllib.php	13 Dec 2007 18:02:31 -0000	1.124
+++ lib/dmllib.php	18 Dec 2007 21:34:57 -0000
@@ -65,8 +65,10 @@
     $olddebug = $db->debug;
 
     if (!$feedback) {
+        if ( !defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
         $db->debug = false;
     }
+    }
 
     if ($CFG->version >= 2006101007) { //Look for trailing ; from Moodle 1.7.0
         $command = trim($command);
@@ -97,7 +99,11 @@
         return true;
     } else {
         if ($feedback) {
+            if ( defined('CLI_UPGRADE') && CLI_UPGRADE ) {
+                notify (get_string('error'));
+            } else {
             notify('<strong>' . get_string('error') . '</strong>');
+            }
         }
         // these two may go to difference places
         debugging($db->ErrorMsg() .'<br /><br />'. s($command));
Index: lib/locallib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/locallib.php,v
retrieving revision 1.10
diff -u -r1.10 locallib.php
--- lib/locallib.php	17 Aug 2007 19:09:19 -0000	1.10
+++ lib/locallib.php	18 Dec 2007 21:34:57 -0000
@@ -90,26 +90,43 @@
 
     if ($local_version > $CFG->local_version) { // upgrade!
         $strdatabaseupgrades = get_string('databaseupgrades');
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
         print_header($strdatabaseupgrades, $strdatabaseupgrades,
             build_navigation(array(array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript());
+        }
 
         upgrade_log_start();
         require_once ($CFG->dirroot .'/local/db/upgrade.php');
 
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
         $db->debug=true;
+        }
         if (xmldb_local_upgrade($CFG->local_version)) {
+            if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
             $db->debug=false;
+            }
             if (set_config('local_version', $local_version)) {
                 notify(get_string('databasesuccess'), 'notifysuccess');
                 notify(get_string('databaseupgradelocal', '', $local_version), 'notifysuccess');
+                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                 print_continue($continueto);
                 print_footer('none');
                 exit;
+                } else if (CLI_UPGRADE && ($interactive > CLI_SEMI) ) {
+                    console_write(STDOUT,'askcontinue');
+                    if (read_boolean()){
+                        return ;
+                    }else {
+                        console_write(STDERR,'','',false);
+                    }
+                }
             } else {
                 error('Upgrade of local database customisations failed! (Could not update version in config table)');
             }
         } else {
+            if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
             $db->debug=false;
+            }
             error('Upgrade failed!  See local/version.php');
         }
 
Index: lib/setup.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/setup.php,v
retrieving revision 1.213
diff -u -r1.213 setup.php
--- lib/setup.php	28 Oct 2007 14:20:21 -0000	1.213
+++ lib/setup.php	18 Dec 2007 21:34:58 -0000
@@ -115,10 +115,11 @@
 /// Connect to the database using adodb
 
 /// Some defines required BEFORE including AdoDB library
+    if ( !defined('ADODB_ASSOC_CASE')) {
     define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
                                     //(only meaningful for oci8po, it's the default
                                     //for other DB drivers so this won't affect them)
-
+    }
     require_once($CFG->libdir .'/adodb/adodb.inc.php'); // Database access functions
 
     $db = &ADONewConnection($CFG->dbtype);
Index: lib/weblib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/weblib.php,v
retrieving revision 1.1008
diff -u -r1.1008 weblib.php
--- lib/weblib.php	18 Dec 2007 17:18:19 -0000	1.1008
+++ lib/weblib.php	18 Dec 2007 21:34:58 -0000
@@ -2326,6 +2326,16 @@
 
     $heading = format_string($heading); // Fix for MDL-8582
 
+    if (defined('CLI_UPGRADE') && CLI_UPGRADE ) {
+        $output = $heading;
+        if ($return) {
+            return $output;
+        } else {
+            console_write(STDOUT,$output,'',false);
+            return;
+        }
+    }
+
 /// This makes sure that the header is never repeated twice on a page
     if (defined('HEADER_PRINTED')) {
         debugging('print_header() was called more than once - this should not happen.  Please check the code for this page closely. Note: error() and redirect() are now safe to call after print_header().');
@@ -3759,18 +3769,33 @@
  * @param int $size The size to set the font for text display.
  */
 function print_heading($text, $align='', $size=2, $class='main', $return=false) {
+    global $verbose;
     if ($align) {
         $align = ' style="text-align:'.$align.';"';
     }
     if ($class) {
         $class = ' class="'.$class.'"';
     }
+    if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
     $output = "<h$size $align $class>".stripslashes_safe($text)."</h$size>";
+    } else if ( CLI_UPGRADE ) {
+        $output = stripslashes_safe($text);
+        if ($size == 1) {
+            $output = '=>'.$output;
+        } else if ($size == 2) {
+            $output = '-->'.$output;
+        }
+    }
 
     if ($return) {
         return $output;
     } else {
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
         echo $output;
+        } else if (CLI_UPGRADE && ($verbose > CLI_NO) ) {
+            console_write(STDOUT,$output,'',false);
+            print_newline();
+        }
     }
 }
 
@@ -5693,6 +5718,11 @@
     global $CFG, $SESSION, $THEME;
     $message = clean_text($message);   // In case nasties are in here
 
+    if (defined('CLI_UPGRADE') || CLI_UPGRADE) {
+        console_write(STDERR,$message,'',false);
+        die ;
+    }
+
     if (defined('FULLME') && FULLME == 'cron') {
         // Errors in cron should be mtrace'd.
         mtrace($message);
@@ -6148,13 +6178,19 @@
  * @param bool $return whether to return an output string or echo now
  */
 function notify($message, $style='notifyproblem', $align='center', $return=false) {
+    global $db;
+
     if ($style == 'green') {
         $style = 'notifysuccess';  // backward compatible with old color system
     }
 
     $message = clean_text($message);
-
+    if(!defined('CLI_UPGRADE')||!CLI_UPGRADE) {
     $output = '<div class="'.$style.'" style="text-align:'. $align .'">'. $message .'</div>'."\n";
+    } else if (CLI_UPGRADE && $db->debug) {
+        $output = '++'.$message.'++';
+        return ;
+    }
 
     if ($return) {
         return $output;
