Ejemplo n.º 1
0
class InstallData:
    def reset(self):
        # Reset everything except:
        #
        # - The install language
        # - The keyboard

        self.instClass = None
        self.network = network.Network()
        self.firewall = firewall.Firewall()
        self.security = security.Security()
        self.timezone = timezone.Timezone()
        self.timezone.setTimezoneInfo(
            self.instLanguage.getDefaultTimeZone(self.anaconda.rootPath))
        self.users = None
        self.rootPassword = {"isCrypted": False, "password": "", "lock": False}
        self.auth = "--enableshadow --passalgo=sha512"
        self.desktop = desktop.Desktop()
        self.upgrade = None
        if flags.cmdline.has_key("preupgrade"):
            self.upgrade = True
        self.storage = storage.Storage(self.anaconda)
        self.bootloader = booty.getBootloader(self)
        self.upgradeRoot = None
        self.rootParts = None
        self.upgradeSwapInfo = None
        self.escrowCertificates = {}

        if self.anaconda.isKickstart:
            self.firstboot = FIRSTBOOT_SKIP
        else:
            self.firstboot = FIRSTBOOT_DEFAULT

        # XXX I still expect this to die when kickstart is the data store.
        self.ksdata = None

    def setInstallProgressClass(self, c):
        self.instProgress = c

    def setDisplayMode(self, display_mode):
        self.displayMode = display_mode

    # expects a Keyboard object
    def setKeyboard(self, keyboard):
        self.keyboard = keyboard

    # expects 0/1
    def setHeadless(self, isHeadless):
        self.isHeadless = isHeadless

    def setKsdata(self, ksdata):
        self.ksdata = ksdata

    # if upgrade is None, it really means False.  we use None to help the
    # installer ui figure out if it's the first time the user has entered
    # the examine_gui screen.   --dcantrell
    def getUpgrade(self):
        if self.upgrade == None:
            return False
        else:
            return self.upgrade

    def setUpgrade(self, bool):
        self.upgrade = bool

    # Reads the auth string and returns a string indicating our desired
    # password encoding algorithm.
    def getPassAlgo(self):
        if self.auth.find("--enablemd5") != -1 or \
           self.auth.find("--passalgo=md5") != -1:
            return 'md5'
        elif self.auth.find("--passalgo=sha256") != -1:
            return 'sha256'
        elif self.auth.find("--passalgo=sha512") != -1:
            return 'sha512'
        else:
            return None

    def _addFingerprint(self):
        import rpm

        iutil.resetRpmDb(self.anaconda.rootPath)
        ts = rpm.TransactionSet(self.anaconda.rootPath)
        return ts.dbMatch('provides', 'fprintd-pam').count()

    def write(self):
        self.instLanguage.write(self.anaconda.rootPath)

        self.anaconda.writeXdriver(self.anaconda.rootPath)

        if not self.isHeadless:
            self.keyboard.write(self.anaconda.rootPath)

        self.timezone.write(self.anaconda.rootPath)

        args = ["--update", "--nostart"] + shlex.split(self.auth)
        if self._addFingerprint():
            args += ["--enablefingerprint"]

        try:
            iutil.execWithRedirect("/usr/sbin/authconfig",
                                   args,
                                   stdout="/dev/tty5",
                                   stderr="/dev/tty5",
                                   root=self.anaconda.rootPath)
        except RuntimeError, msg:
            log.error("Error running %s: %s", args, msg)

        self.network.write()
        self.network.copyConfigToPath(instPath=self.anaconda.rootPath)
        self.network.disableNMForStorageDevices(
            self.anaconda, instPath=self.anaconda.rootPath)
        self.network.autostartFCoEDevices(self.anaconda,
                                          instPath=self.anaconda.rootPath)
        self.firewall.write(self.anaconda.rootPath)
        self.security.write(self.anaconda.rootPath)
        self.desktop.write(self.anaconda.rootPath)

        self.users = users.Users()

        # make sure crypt_style in libuser.conf matches the salt we're using
        users.createLuserConf(self.anaconda.rootPath,
                              algoname=self.getPassAlgo())

        # User should already exist, just without a password.
        self.users.setRootPassword(self.rootPassword["password"],
                                   self.rootPassword["isCrypted"],
                                   self.rootPassword["lock"],
                                   algo=self.getPassAlgo())

        services = list(self.storage.services)

        if self.network.hasActiveIPoIBDevice():
            services.append("rdma")

        if self.anaconda.isKickstart:
            services.extend(self.ksdata.services.enabled)

            for svc in self.ksdata.services.disabled:
                iutil.execWithRedirect("/sbin/chkconfig", [svc, "off"],
                                       stdout="/dev/tty5",
                                       stderr="/dev/tty5",
                                       root=self.anaconda.rootPath)

            for gd in self.ksdata.group.groupList:
                if not self.users.createGroup(
                        name=gd.name, gid=gd.gid, root=self.anaconda.rootPath):
                    log.error("Group %s already exists, not creating." %
                              gd.name)

            for ud in self.ksdata.user.userList:
                if not self.users.createUser(name=ud.name,
                                             password=ud.password,
                                             isCrypted=ud.isCrypted,
                                             groups=ud.groups,
                                             homedir=ud.homedir,
                                             shell=ud.shell,
                                             uid=ud.uid,
                                             algo=self.getPassAlgo(),
                                             lock=ud.lock,
                                             root=self.anaconda.rootPath,
                                             gecos=ud.gecos):
                    log.error("User %s already exists, not creating." %
                              ud.name)

        for svc in services:
            iutil.execWithRedirect("/sbin/chkconfig", [svc, "on"],
                                   stdout="/dev/tty5",
                                   stderr="/dev/tty5",
                                   root=self.anaconda.rootPath)
Ejemplo n.º 2
0
        except:
            pass

    # This is the one place we do all kickstart file parsing.
    if opts.ksfile:
        anaconda.isKickstart = True

        kickstart.preScriptPass(anaconda, opts.ksfile)
        ksdata = kickstart.parseKickstart(anaconda, opts.ksfile)
        opts.rescue = opts.rescue or ksdata.rescue.rescue

    if flags.sshd:
        # we need to have a libuser.conf that points to the installer root for
        # sshpw, but after that we start sshd, we need one that points to the
        # install target.
        luserConf = users.createLuserConf(instPath="")
        if anaconda.isKickstart:
            handleSshPw(ksdata)
        startSsh()
        del(os.environ["LIBUSER_CONF"])

    users.createLuserConf(anaconda.rootPath)

    if opts.rescue:
        anaconda.rescue = True

        import rescue, instdata

        anaconda.id = instdata.InstallData(anaconda, [], opts.display_mode)

        if anaconda.isKickstart:
Ejemplo n.º 3
0
        except:
            pass

    # This is the one place we do all kickstart file parsing.
    if opts.ksfile:
        anaconda.isKickstart = True

        kickstart.preScriptPass(anaconda, opts.ksfile)
        ksdata = kickstart.parseKickstart(anaconda, opts.ksfile)
        opts.rescue = opts.rescue or ksdata.rescue.rescue

    if flags.sshd:
        # we need to have a libuser.conf that points to the installer root for
        # sshpw, but after that we start sshd, we need one that points to the
        # install target.
        luserConf = users.createLuserConf(instPath="")
        if anaconda.isKickstart:
            handleSshPw(ksdata)
        startSsh()
        del (os.environ["LIBUSER_CONF"])

    users.createLuserConf(anaconda.rootPath)

    if opts.rescue:
        anaconda.rescue = True

        import rescue, instdata

        anaconda.id = instdata.InstallData(anaconda, [], opts.display_mode)

        if anaconda.isKickstart:
Ejemplo n.º 4
0
class InstallData:
    def reset(self):
        # Reset everything except:
        #
        #	- The mouse
        #	- The install language
        #	- The keyboard

        self.instClass = None
        self.network = network.Network()
        self.iscsi = iscsi.iscsi()
        self.zfcp = zfcp.ZFCP()
        self.firewall = firewall.Firewall()
        self.security = security.Security()
        self.timezone = timezone.Timezone()
        self.users = None
        self.rootPassword = {"isCrypted": False, "password": ""}
        self.auth = "--enableshadow --enablemd5"
        self.desktop = desktop.Desktop()
        self.upgrade = None
        # XXX move fsset and/or diskset into Partitions object?
        self.fsset.reset()
        self.diskset = partedUtils.DiskSet(self.anaconda)
        self.partitions = partitions.Partitions()
        self.bootloader = bootloader.getBootloader()
        self.dependencies = []
        self.dbpath = None
        self.upgradeRoot = None
        self.rootParts = None
        self.upgradeSwapInfo = None
        self.upgradeDeps = ""
        self.upgradeRemove = []
        self.upgradeInfoFound = None

        if rhpl.getArch() == "s390":
            self.firstboot = FIRSTBOOT_SKIP
        else:
            self.firstboot = FIRSTBOOT_DEFAULT

    # XXX I expect this to die in the future when we have a single data
    # class and translate ksdata into that instead.
        self.ksdata = None

    def setInstallProgressClass(self, c):
        self.instProgress = c

    def setDisplayMode(self, display_mode):
        self.displayMode = display_mode

    # expects a Keyboard object
    def setKeyboard(self, keyboard):
        self.keyboard = keyboard

    # expects a Mouse object
    def setMouse(self, mouse):
        self.mouse = mouse

    # expects a VideoCardInfo object
    def setVideoCard(self, video):
        self.videocard = video

    # expects a Monitor object
    def setMonitor(self, monitor):
        self.monitor = monitor

    # expects an XSetup object
    def setXSetup(self, xsetup):
        self.xsetup = xsetup

    # expects 0/1
    def setHeadless(self, isHeadless):
        self.isHeadless = isHeadless

    def setKsdata(self, ksdata):
        self.ksdata = ksdata

    # if upgrade is None, it really means False.  we use None to help the
    # installer ui figure out if it's the first time the user has entered
    # the examine_gui screen.   --dcantrell
    def getUpgrade(self):
        if self.upgrade == None:
            return False
        else:
            return self.upgrade

    def setUpgrade(self, bool):
        self.upgrade = bool

    def getSalt(self):
        if self.auth.find("--enablemd5") != -1 or \
           self.auth.find("--passalgo=md5") != -1:
            return 'md5'
        elif self.auth.find("--passalgo=sha256") != -1:
            return 'sha256'
        elif self.auth.find("--passalgo=sha512") != -1:
            return 'sha512'
        else:
            return None

    def write(self):
        self.instLanguage.write(self.anaconda.rootPath)

        if not self.isHeadless:
            self.keyboard.write(self.anaconda.rootPath)

        self.timezone.write(self.anaconda.rootPath)

        args = ["--update", "--nostart"] + self.auth.split()

        try:
            if not flags.test:
                iutil.execWithRedirect("/usr/sbin/authconfig",
                                       args,
                                       stdout=None,
                                       stderr=None,
                                       root=self.anaconda.rootPath)
            else:
                log.error("Would have run: %s", args)
        except RuntimeError, msg:
            log.error("Error running %s: %s", args, msg)

        self.firewall.write(self.anaconda.rootPath)
        self.security.write(self.anaconda.rootPath)

        self.users = users.Users()

        # make sure crypt_style in libuser.conf matches the salt we're using
        users.createLuserConf(self.anaconda.rootPath, saltname=self.getSalt())

        # User should already exist, just without a password.
        self.users.setRootPassword(self.rootPassword["password"],
                                   self.rootPassword["isCrypted"],
                                   salt=self.getSalt())

        # Make sure multipathd is set to run for mpath installs (#243421)
        if flags.mpath:
            svc = 'multipathd'

            if self.anaconda.isKickstart:
                try:
                    hasSvc = self.ksdata.services["enabled"].index(svc)
                except:
                    self.ksdata.services["enabled"].append(svc)
            else:
                iutil.execWithRedirect("/sbin/chkconfig", [svc, "on"],
                                       stdout="/dev/tty5",
                                       stderr="/dev/tty5",
                                       root=self.anaconda.rootPath)

        if self.anaconda.isKickstart:
            for svc in self.ksdata.services["disabled"]:
                iutil.execWithRedirect("/sbin/chkconfig", [svc, "off"],
                                       stdout="/dev/tty5",
                                       stderr="/dev/tty5",
                                       root=self.anaconda.rootPath)

            for svc in self.ksdata.services["enabled"]:
                iutil.execWithRedirect("/sbin/chkconfig", [svc, "on"],
                                       stdout="/dev/tty5",
                                       stderr="/dev/tty5",
                                       root=self.anaconda.rootPath)

            for ud in self.ksdata.userList:
                if self.users.createUser(ud.name,
                                         ud.password,
                                         ud.isCrypted,
                                         ud.groups,
                                         ud.homedir,
                                         ud.shell,
                                         ud.uid,
                                         root=self.anaconda.rootPath,
                                         salt=self.getSalt()) == None:
                    log.error("User %s already exists, not creating." %
                              ud.name)

        if self.anaconda.id.instClass.installkey and os.path.exists(
                self.anaconda.rootPath + "/etc/sysconfig/rhn"):
            f = open(self.anaconda.rootPath + "/etc/sysconfig/rhn/install-num",
                     "w+")
            f.write("%s\n" % (self.anaconda.id.instClass.installkey, ))
            f.close()
            os.chmod(self.anaconda.rootPath + "/etc/sysconfig/rhn/install-num",
                     0600)