#
# slc.py
#
# Jaroslaw.Polok@cern.ch
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from installclass import BaseInstallClass
from constants import *
from product import *
from flags import flags
import os
import types

import installmethod
import yuminstall
import iutil

from kickstart import AnacondaKSScript

import logging
log = logging.getLogger("anaconda")

class InstallClass(BaseInstallClass):
 id = "slc"
 name = N_("Scientific Linux CERN")
 _description = N_("The default installation of %s for CERN environment. "
                     "You can optionally select a different set of software "
                     "now.")
 _descriptionFields = (productName,)
 sortPriority = 11111
		     
 bootloaderTimeoutDefault = 5
 #bootloaderExtraArgs = "crashkernel=auto" <- in 6.2 anaconda this gets chunked character by character ???

 hidden = 0

 tasks = [
	      (N_("Software Development Workstation (CERN Recommended Setup)"),
              ["base", "core", "debugging", "cern-addons", "cern-addons-x11",
               "directory-client", "java-platform", "network-file-system-client",
               "performance", "perl-runtime", "server-platform",
               "fonts", "print-client", "console-internet", "hardware-monitoring",
               "basic-desktop", "desktop-debugging", "desktop-platform",
               "general-desktop", "graphical-admin-tools", "input-methods",
               "legacy-x", "x11", "internet-browser", "internet-applications", "graphics", "emacs", "tex",
               "remote-desktop-clients", "virtualization", "virtualization-client",
               "scientific", "office-suite", 
               "virtualization-platform",
               "desktop-platform-devel", "development", "eclipse",
               "server-platform-devel", "technical-writing",
               "additional-devel", "openafs-client" ]),
              (N_("Desktop"),
              ["base", "core", "debugging",
               "directory-client", "java-platform", "network-file-system-client",
               "server-platform", "cern-addons", "cern-addons-x11",
               "fonts", "print-client", 
               "basic-desktop", "desktop-debugging", "desktop-platform",
               "general-desktop", "graphical-admin-tools", "input-methods",
               "legacy-x", "x11", "internet-browser", "internet-applications", "office-suite",
               "remote-desktop-clients", "openafs-client" ]),
              (N_("Minimal Desktop"),
              ["base", "core", "debugging", "cern-addons", "cern-addons-x11",
               "directory-client", "java-platform", "network-file-system-client",
               "server-platform",
               "fonts", "print-client",
               "basic-desktop", "desktop-debugging", "desktop-platform",
               "input-methods",
               "legacy-x", "x11", "internet-browser", 
               "remote-desktop-clients", "openafs-client" ]),
             (N_("Web Development Workstation"),
              ["base", "core", "debugging",
               "directory-client", "java-platform", "network-file-system-client",
               "perl-runtime", "server-platform", "cern-addons", "cern-addons-x11",
               "fonts", "print-client", 
               "basic-desktop", "desktop-debugging", "desktop-platform",
               "general-desktop", "graphical-admin-tools", "input-methods",
               "legacy-x", "x11", "internet-browser", "internet-applications", "graphics", "emacs",
               "desktop-platform-devel", "development", "eclipse",
               "server-platform-devel",
               "web-server", "web-servlet", "php", "turbogears",
               "mysql-client", "postgresql-client",
               "additional-devel",
               "remote-desktop-clients", "openafs-client" ]),
	      (N_("Basic Server"),
              ["base", "console-internet", "core", "debugging", "cern-addons",
               "directory-client", "hardware-monitoring", "java-platform", 
               "large-systems", "network-file-system-client",
               "performance", "perl-runtime", "server-platform", "openafs-client" ]),
             (N_("Database Server"),
              ["base", "console-internet", "core", "debugging", "cern-addons", 
               "directory-client", "hardware-monitoring", "java-platform", 
               "large-systems", "network-file-system-client",
               "performance", "perl-runtime", "server-platform",
               "mysql-client", "mysql", "postgresql-client", "postgresql",
               "system-admin-tools", "openafs-client" ]),
             (N_("Web Server"),
              ["base", "console-internet", "core", "debugging", "cern-addons", 
               "directory-client", "java-platform", 
               "network-file-system-client",
               "performance", "perl-runtime", "server-platform",
               "web-server", "web-servlet", "php", "turbogears",
               "mysql-client", "postgresql-client", "openafs-client" ]),
             (N_("Virtual Host"),
              ["base", "console-internet", "core", "debugging", "cern-addons", 
               "directory-client", "hardware-monitoring", "java-platform", 
               "large-systems", "network-file-system-client",
               "performance", "perl-runtime", "server-platform",
               "virtualization", "virtualization-client",
               "virtualization-platform", "openafs-client" ]),
             (N_("Minimal"),
              ["core", "cern-addons", "openafs-client"])]

 def __init__(self):
        BaseInstallClass.__init__(self)		     

 def setInstallData(self, anaconda):
	self.postScripts = []

        BaseInstallClass.setInstallData(self, anaconda)
        BaseInstallClass.setDefaultPartitioning(self,anaconda.id.storage, anaconda.platform)
#        BaseInstallClass.setTimezoneInfo("Europe/Zurich",1)
        anaconda.id.timezone.setTimezoneInfo("Europe/Zurich",1)  
	log.info("preset TimezoneInfo: Europe/Zurich") 
        anaconda.id.auth = "--useshadow  --passalgo=sha512 --enablemd5  --enablekrb5"

        # AFS will not start if not ..
        # in 6.5 anaconda somehow these are not chrooted to /mnt/sysimage ??
        postactions = [ ("/sbin/restorecon /afs","/bin/sh",1),
                        ("/usr/sbin/chroot /mnt/sysimage/ /sbin/restorecon /afs","/bin/sh",1),
		      ]

        for (script, interp, chroot) in postactions:
            self.postScripts.append(AnacondaKSScript(script, interp, chroot))


 def getBackend(self):
        if flags.livecdInstall:
            import livecd
            return livecd.LiveCDCopyBackend
        else:
            return yuminstall.YumBackend

 def setGroupSelection(self, anaconda):
        BaseInstallClass.setGroupSelection(self, anaconda)

 def postAction(self, anaconda):
     for script in self.postScripts:
           script.run(anaconda.rootPath, flags.serial)

