# For license conditions see the license file or http://eu-egee.org/license.html
 #
 ################################################################################
-# glite-lb-config v. 2.0.0
+# glite-lb-config v. 2.0.1
 #
 # Post-installation script for configuring the gLite Logging and Bookkeping Server
 # Robert Harakaly < robert.harakaly@cern.ch >
     def __init__(self):
         self.mysql = MySQL.Mysql()
         self.verbose = 0
-        self.version = "2.0.0"
+        self.version = "2.0.1"
         self.name = "glite-lb"
         self.friendly_name = "gLite Logging and Bookkeeping"
         params['module.version'] = self.version
         os.chmod("%s/hostkey.pem" % lb_cert_path, 0400)
         glib.printOkMessage()
 
-        # Create the MySQL database
-        print "\nCreate/Verify the %s database" % params['lb.database.name']
+        #--------------------------------------------------------
+        # Configure MySQL
+        #--------------------------------------------------------
+
+        # start MySQL
         self.mysql.stop()
         time.sleep(5)
-        self.mysql.start()
+        self.mysql.start()                
+
+        # Set root password
+        mysql_root_password = params['mysql.root.password']
+        if mysql_root_password != "":
+            self.mysql.setpassword(mysql_root_password)
+
+        # Create the MySQL database
+        print "\nCreate/Verify the %s database" % params['lb.database.name']
         
         if not os.path.exists('/tmp/mysql.sock'):
             os.symlink('/var/lib/mysql/mysql.sock', '/tmp/mysql.sock')
 
         # Check if database exists
-        if self.mysql.existsDB(params['lb.database.name']) != 0:
+        if self.mysql.existsDB(params['lb.database.name'],mysql_root_password) != 0:
             # Create database
             print ('\n==> Creating MySQL %s database\n' % params['lb.database.name'])
     
     
             file.writelines(text)
             file.close()
-            os.system('/usr/bin/mysql < /tmp/mysql_ct')
+            os.system('/usr/bin/mysql -p%s < /tmp/mysql_ct' % mysql_root_password)
             os.system('/bin/rm /tmp/mysql_ct')
             
             #Starting and stopping the database before the index creation
 # Set all environment variables
 #-------------------------------------------------------------------------------
 
+def loadDefaults(params):
+
+    params['GLITE_LOCATION'] = "/opt/glite"
+    params['GLITE_LOCATION'] = "/opt/glite"
+    params['mysql.root.password'] = ""
+    params['lb.database.name'] = "lbserver20"
+    params['lb.database.username'] = "lbserver"
+
 def set_env():
 
     # gLite
     
     # Load parameters
     params = {}
+    loadDefaults(params)
     try:
         opts, args = getopt.getopt(sys.argv[1:], '', ['siteconfig='])
         for o, a in opts:
 
                        parameter. Leave it empty of comment it out to use the same as 'glite.user.name'"
                        value="changeme"/>
                
+           <mysql.root.password
+               description="The mysql root password"
+               value="changeme"/>
+       
                <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
                <!-- Advanced parameters - Change them if you know what you're doing -->
                <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
                        description="Enable check of host certificates"
                        value="true"/>
 
-               <!-- MySQL DB -->
-               <lb.database.name
-                       description="The mySQL database name to create for storing LB data
-                       In this version it must be set to the given value"
-                       value="lbserver20"/>
-
+               <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
+               <!-- System parameters - You should leave these alone -->
+               <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->               
+       
                <lb.index.list
                        description="Definitions of indices on all the currently supported indexed system attributes">
                        
 
                </lb.index.list>
                        
-               <lb.database.username
-                       description="The username to be used to access the local mySQL server
-                       In this version it must be set to the given value"
-                       value="lbserver"/>
-                       
-               <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
-               <!-- System parameters - You should leave these alone -->
-               <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->               
-       
        </parameters>
 
        <!--RGMA service publishing: log server -->
 
                echo Done!
                echo
                echo Before using the gLite LB, please create or update the configuration
-               echo file /opt/glite/etc/config/glite-lb.cfg.xml
+               echo files /opt/glite/etc/config/glite-lb.cfg.xml
+               echo and /opt/glite/etc/config/glite-global.cfg.xml
                echo and run the configuration script
                echo /opt/glite/etc/config/scripts/glite-lb-config.py.
                echo A template is provided in
                echo /opt/glite/etc/config/templates/glite-lb.cfg.xml
+               echo Alternatively site configuration files can be used
        else
                echo
                echo An error occurred while installing the LB RPMS.
        echo For more information refer to the gLite Installation and User Guides
        echo or to the gLite web site \(http:\/\/www.glite.org\)
        echo Please report problems and comments to the gLite Team at
-       echo project-eu-egee-glite-bugs@cern.ch
+       echo glite-bugs@cern.ch
 
        cd ..
 }