예제 #1
0
    def __call__ (self, screen, anaconda):
        if anaconda.dir == DISPATCH_BACK:
            # reset storage to catch any changes
            anaconda.id.storage.reset(examine_all=True)

        # we might get here after storage reset that obsoleted
        # root device objects we had found
        if not anaconda.id.rootParts:
            anaconda.id.rootParts = upgrade.findExistingRoots(anaconda,
                                                              flags.cmdline.has_key("upgradeany"))
            upgrade.setUpgradeRoot(anaconda)

        parts = anaconda.id.rootParts

        height = min(len(parts), 11) + 1
        if height == 12:
            scroll = 1
        else:
            scroll = 0
        partList = []
        partList.append(_("Reinstall System"))

	if (anaconda.id.upgrade == None and anaconda.dispatch.stepInSkipList("installtype")) or anaconda.id.upgrade:
            default = 1
        else:
            default = 0

        for (device, desc) in parts:
            partList.append("%s (%s)" %(desc, device.path))

        (button, choice) =  ListboxChoiceWindow(screen, _("System to Upgrade"),
                            _("There seem to be one or more existing Linux installations "
                              "on your system.\n\nPlease choose one to upgrade, "
			      "or select 'Reinstall System' to freshly install "
			      "your system."), partList,
                                                [ TEXT_OK_BUTTON,
                                                  TEXT_BACK_BUTTON ],
                                                width = 55, scroll = scroll,
                                                height = height,
                                                default = default,
                                                help = "upgraderoot")

        if button == TEXT_BACK_CHECK:
            return INSTALL_BACK
        else:
            if choice == 0:
                root = None
            else:
                root = parts[choice - 1]

        if root is not None:
            upgrade.setSteps(anaconda)
            anaconda.id.setUpgrade(True)

            anaconda.id.upgradeRoot = [(root[0], root[1])]
            anaconda.id.rootParts = parts
            anaconda.dispatch.skipStep("installtype", skip = 1)
        else:
            anaconda.dispatch.skipStep("installtype", skip = 0)
            anaconda.id.upgradeRoot = None

        return INSTALL_OK
예제 #2
0
    def getScreen (self, anaconda):
        global seenExamineScreen
        self.anaconda = anaconda

        if not seenExamineScreen:
	    # this is the first time we've entered this screen
	    self.doupgrade = self.anaconda.dispatch.stepInSkipList("installtype")
            seenExamineScreen = True
	else:
	    self.doupgrade = self.anaconda.upgrade

        # we might get here after storage reset that obsoleted
        # root device objects we had found
        if not self.anaconda.rootParts:
            self.anaconda.rootParts = upgrade.findExistingRoots(self.anaconda,
                                                                flags.cmdline.has_key("upgradeany"))
            upgrade.setUpgradeRoot(self.anaconda)

        self.parts = self.anaconda.rootParts

        vbox = gtk.VBox (False, 12)
	vbox.set_border_width (8)

        introLabel = gtk.Label(_("At least one existing installation has been "
                                 "detected on your system.  What would you "
                                 "like to do?"))
        introLabel.set_alignment(0, 0)
        vbox.pack_start(introLabel, False, False)

	r = self.createUpgradeOption()
        self.r = r

	b = self.r.render()
	if self.doupgrade:
	    self.r.setCurrent(UPGRADE_STR)
	else:
	    self.r.setCurrent(REINSTALL_STR)

	self.r.setToggleCallback(self.optionToggled)
        vbox.pack_start(b, False)
        self.root = self.parts[0]

	uplabelstr = _("<b>Which %s installation would you like to recover?</b>") % productName
	self.uplabel = gtk.Label(uplabelstr)
        self.uplabel.set_use_markup(True)
        self.uplabel.set_alignment(0, 0)
        model = gtk.ListStore(str)
	self.upgradecombo = gtk.ComboBox(model)

        cell = gtk.CellRendererText()
        self.upgradecombo.pack_start(cell, True)
        self.upgradecombo.set_attributes(cell, markup=0)

	for (dev, desc) in self.parts:
            iter = model.append()
	    if (desc is None) or len(desc) < 1:
		desc = _("Unknown Linux system")
            model[iter][0] = "<small>%s <i>(installed on %s)</i></small>" %(desc, dev.path)

	# hack hack hackity hack
        alignment = gtk.Alignment(xalign=0.25)
        alignmentBox = gtk.VBox(False, 6)
        alignmentBox.pack_start(self.uplabel, False, False)
        alignmentBox.pack_start(self.upgradecombo, False, False)
        alignment.add(alignmentBox)
        vbox.pack_start(alignment, True, True)

	# set default
	idx = 0
	for p in self.parts:
	    if self.anaconda.upgradeRoot[0][0] == p[0]:
	        self.upgradecombo.set_active(idx)
	        break
	    idx = idx + 1

	self.upgradeOptionsSetSensitivity(self.doupgrade)

        return vbox
예제 #3
0
파일: rescue.py 프로젝트: 274914765/python
def runRescue(anaconda, instClass):
    for file in [ "services", "protocols", "group", "joe", "man.config",
                  "nsswitch.conf", "selinux", "mke2fs.conf" ]:
        try:
            os.symlink('/mnt/runtime/etc/' + file, '/etc/' + file)
        except:
            pass

    # see if they would like networking enabled
    if not network.hasActiveNetDev():
        screen = SnackScreen()

        while True:
            rc = ButtonChoiceWindow(screen, _("Setup Networking"),
                _("Do you want to start the network interfaces on "
                  "this system?"), [_("Yes"), _("No")])

            if rc != string.lower(_("No")):
                anaconda.intf = RescueInterface(screen)

                if not anaconda.intf.enableNetwork(anaconda):
                    anaconda.intf.messageWindow(_("No Network Available"),
                        _("Unable to activate a networking device.  Networking "
                          "will not be available in rescue mode."))
                    break

                startNetworking(anaconda.id.network, anaconda.intf)
                break
            else:
                break

        anaconda.intf = None
        screen.finish()

    # Early shell access with no disk access attempts
    if not anaconda.rescue_mount:
        # the %post should be responsible for mounting all needed file systems
        # NOTE: 1st script must be bash or simple python as nothing else might be available in the rescue image
        if anaconda.isKickstart and anaconda.id.ksdata.scripts:
           from kickstart import runPostScripts
           runPostScripts(anaconda)
        else:
           runShell()

        sys.exit(0)

    screen = SnackScreen()
    anaconda.intf = RescueInterface(screen)

    if anaconda.isKickstart:
        if anaconda.id.ksdata.rescue and anaconda.id.ksdata.rescue.romount:
            readOnly = 1
        else:
            readOnly = 0
    else:
        # prompt to see if we should try and find root filesystem and mount
        # everything in /etc/fstab on that root
        while True:
            rc = ButtonChoiceWindow(screen, _("Rescue"),
                _("The rescue environment will now attempt to find your "
                  "Linux installation and mount it under the directory "
                  "%s.  You can then make any changes required to your "
                  "system.  If you want to proceed with this step choose "
                  "'Continue'.  You can also choose to mount your file systems "
                  "read-only instead of read-write by choosing 'Read-Only'.  "
                  "If you need to activate SAN devices choose 'Advanced'."
                  "\n\n"
                  "If for some reason this process fails you can choose 'Skip' "
                  "and this step will be skipped and you will go directly to a "
                  "command shell.\n\n") % (anaconda.rootPath,),
                  [_("Continue"), _("Read-Only"), _("Skip"), _("Advanced")] )

            if rc == string.lower(_("Skip")):
                runShell(screen)
                sys.exit(0)
            elif rc == string.lower(_("Advanced")):
                addDialog = addDriveDialog(anaconda)
                addDialog.addDriveDialog(screen)
                continue
            elif rc == string.lower(_("Read-Only")):
                readOnly = 1
            else:
                readOnly = 0
            break

    import storage
    storage.storageInitialize(anaconda)

    disks = upgrade.findExistingRoots(anaconda, upgradeany=True)

    if not disks:
        root = None
    elif (len(disks) == 1) or anaconda.isKickstart:
        root = disks[0]
    else:
        height = min (len (disks), 12)
        if height == 12:
            scroll = 1
        else:
            scroll = 0

        devList = []
        for (device, relstr) in disks:
            if getattr(device.format, "label", None):
                devList.append("%s (%s) - %s" % (device.name, device.format.label, relstr))
            else:
                devList.append("%s - %s" % (device.name, relstr))

        (button, choice) = \
            ListboxChoiceWindow(screen, _("System to Rescue"),
                                _("Which device holds the root partition "
                                  "of your installation?"), devList,
                                [ _("OK"), _("Exit") ], width = 30,
                                scroll = scroll, height = height,
                                help = "multipleroot")

        if button == string.lower (_("Exit")):
            root = None
        else:
            root = disks[choice]

    rootmounted = 0

    if root:
        try:
            rc = mountExistingSystem(anaconda, root,
                                     allowDirty = 1, warnDirty = 1,
                                     readOnly = readOnly)

            if rc == -1:
                if anaconda.isKickstart:
                    log.error("System had dirty file systems which you chose not to mount")
                else:
                    ButtonChoiceWindow(screen, _("Rescue"),
                        _("Your system had dirty file systems which you chose not "
                          "to mount.  Press return to get a shell from which "
                          "you can fsck and mount your partitions.  The system "
                          "will reboot automatically when you exit from the "
                          "shell."), [_("OK")], width = 50)
                rootmounted = 0
            else:
                if anaconda.isKickstart:
                    log.info("System has been mounted under: %s" % anaconda.rootPath)
                else:
                    ButtonChoiceWindow(screen, _("Rescue"),
                       _("Your system has been mounted under %(rootPath)s.\n\n"
                         "Press <return> to get a shell. If you would like to "
                         "make your system the root environment, run the command:\n\n"
                         "\tchroot %(rootPath)s\n\nThe system will reboot "
                         "automatically when you exit from the shell.") %
                                       {'rootPath': anaconda.rootPath},
                                       [_("OK")] )
                rootmounted = 1

                # now turn on swap
                if not readOnly:
                    try:
                        anaconda.id.storage.turnOnSwap()
                    except:
                        log.error("Error enabling swap")

                # and /selinux too
                if flags.selinux and os.path.isdir("%s/selinux" %(anaconda.rootPath,)):
                    try:
                        isys.mount("/selinux", "%s/selinux" %(anaconda.rootPath,),
                                   "selinuxfs")
                    except Exception, e:
                        log.error("error mounting selinuxfs: %s" %(e,))

                    fd = open("%s/.autorelabel" % anaconda.rootPath, "w+")
                    fd.close()

                # set a library path to use mounted fs
                libdirs = os.environ["LD_LIBRARY_PATH"].split(":")
                mounted = map(lambda dir: "/mnt/sysimage%s" % dir, libdirs)
                os.environ["LD_LIBRARY_PATH"] = ":".join(libdirs + mounted)

                # find groff data dir
                try:
                    glst = os.listdir("/mnt/sysimage/usr/share/groff")

                    # find a directory which is a numeral, its where
                    # data files are
                    gversion = None
                    for gdir in glst:
                        try:
                            isone = 1
                            for idx in range(0, len(gdir)):
                                if string.find(string.digits + '.', gdir[idx]) == -1:
                                    isone = 0
                                    break
                            if isone:
                                gversion = gdir
                                break
                        except:
                            gversion = None
                            continue
                except:
                    gversion = None

                if gversion is not None:
                    gpath = "/mnt/sysimage/usr/share/groff/"+gversion
                    os.environ["GROFF_FONT_PATH"] = gpath + '/font'
                    os.environ["GROFF_TMAC_PATH"] = "%s:/mnt/sysimage/usr/share/groff/site-tmac" % (gpath + '/tmac',)

                # do we have bash?
                try:
                    if os.access("/usr/bin/bash", os.R_OK):
                        os.symlink ("/usr/bin/bash", "/bin/bash")
                except:
                    pass
        except:
            # This looks horrible, but all it does is catch every exception,
            # and reraise those in the tuple check. This lets programming
            # errors raise exceptions, while any runtime error will
            # still result in a shell
            (exc, val) = sys.exc_info()[0:2]
            log.error(str(exc)+": "+str(val))
            if exc in (IndexError, ValueError, SyntaxError):
                raise exc, val, sys.exc_info()[2]

            if anaconda.isKickstart:
                log.error("An error occurred trying to mount some or all of your system")
            else:
                ButtonChoiceWindow(screen, _("Rescue"),
                    _("An error occurred trying to mount some or all of your "
                      "system. Some of it may be mounted under %s.\n\n"
                      "Press <return> to get a shell. The system will reboot "
                      "automatically when you exit from the shell.") % (anaconda.rootPath,),
                      [_("OK")] )
    else:
        if anaconda.isKickstart and \
               anaconda.id.ksdata.reboot.action in [KS_REBOOT, KS_SHUTDOWN]:
            log.info("No Linux partitions found")
            screen.finish()
            print(_("You don't have any Linux partitions.  Rebooting.\n"))
            sys.exit(0)
        else:
            ButtonChoiceWindow(screen, _("Rescue Mode"),
                               _("You don't have any Linux partitions. Press "
                                 "return to get a shell. The system will reboot "
                                 "automatically when you exit from the shell."),
                               [ _("OK") ], width = 50)

    msgStr = ""

    if rootmounted and not readOnly:
        makeMtab(anaconda.rootPath, anaconda.id.storage)
        try:
            makeResolvConf(anaconda.rootPath)
        except Exception, e:
            log.error("error making a resolv.conf: %s" %(e,))
        msgStr = _("Your system is mounted under the %s directory.") % (anaconda.rootPath,)
        ButtonChoiceWindow(screen, _("Rescue"), msgStr, [_("OK")] )
    def getScreen(self, anaconda):
        self.anaconda = anaconda

        if self.anaconda.id.upgrade == None:
            # this is the first time we've entered this screen
            self.doupgrade = self.anaconda.dispatch.stepInSkipList(
                "installtype")
        else:
            self.doupgrade = self.anaconda.id.upgrade

        if anaconda.dir == DISPATCH_BACK:
            # reset storage to catch any changes since we only reset when
            # moving forward from autopart, not back.
            # temporarily unset storage.clearPartType so that all devices will be
            # found during storage reset
            self.anaconda.id.storage.reset(examine_all=True)

        # we might get here after storage reset that obsoleted
        # root device objects we had found
        if not self.anaconda.id.rootParts:
            self.anaconda.id.rootParts = upgrade.findExistingRoots(
                self.anaconda, flags.cmdline.has_key("upgradeany"))
            upgrade.setUpgradeRoot(self.anaconda)

        self.parts = self.anaconda.id.rootParts

        vbox = gtk.VBox(False, 12)
        vbox.set_border_width(8)

        introLabel = gtk.Label(
            _("At least one existing installation has been "
              "detected on your system.  What would you "
              "like to do?"))
        introLabel.set_alignment(0, 0)
        vbox.pack_start(introLabel, False, False)

        r = self.createUpgradeOption()
        self.r = r

        b = self.r.render()
        if self.doupgrade:
            self.r.setCurrent(UPGRADE_STR)
        else:
            self.r.setCurrent(REINSTALL_STR)

        self.r.setToggleCallback(self.optionToggled)
        vbox.pack_start(b, False)
        self.root = self.parts[0]

        uplabelstr = _(
            "<b>Which %s installation would you like to upgrade?</b>"
        ) % productName
        self.uplabel = gtk.Label(uplabelstr)
        self.uplabel.set_use_markup(True)
        self.uplabel.set_alignment(0, 0)
        model = gtk.ListStore(str)
        self.upgradecombo = gtk.ComboBox(model)

        cell = gtk.CellRendererText()
        self.upgradecombo.pack_start(cell, True)
        self.upgradecombo.set_attributes(cell, markup=0)

        for (dev, desc) in self.parts:
            iter = model.append()
            if (desc is None) or len(desc) < 1:
                desc = _("Unknown Linux system")
            model[iter][0] = "<small>%s <i>(installed on %s)</i></small>" % (
                desc, dev.path)

# hack hack hackity hack
        alignment = gtk.Alignment(xalign=0.25)
        alignmentBox = gtk.VBox(False, 6)
        alignmentBox.pack_start(self.uplabel, False, False)
        alignmentBox.pack_start(self.upgradecombo, False, False)
        alignment.add(alignmentBox)
        vbox.pack_start(alignment, True, True)

        # set default
        idx = 0
        for p in self.parts:
            if self.anaconda.id.upgradeRoot[0][0] == p[0]:
                self.upgradecombo.set_active(idx)
                break
            idx = idx + 1

        self.upgradeOptionsSetSensitivity(self.doupgrade)

        return vbox
예제 #5
0
def runRescue(anaconda):
    for file in [ "services", "protocols", "group", "joe", "man.config",
                  "nsswitch.conf", "selinux", "mke2fs.conf" ]:
        try:
            os.symlink('/mnt/runtime/etc/' + file, '/etc/' + file)
        except:
            pass

    # see if they would like networking enabled
    if not network.hasActiveNetDev():
        screen = SnackScreen()

        while True:
            rc = ButtonChoiceWindow(screen, _("Setup Networking"),
                _("Do you want to start the network interfaces on "
                  "this system?"), [_("Yes"), _("No")])

            if rc != string.lower(_("No")):
                anaconda.intf = RescueInterface(screen)

                if not anaconda.intf.enableNetwork(anaconda):
                    anaconda.intf.messageWindow(_("No Network Available"),
                        _("Unable to activate a networking device.  Networking "
                          "will not be available in rescue mode."))
                    break

                startNetworking(anaconda.network, anaconda.intf)
                break
            else:
                break

        anaconda.intf = None
        screen.finish()

    # Early shell access with no disk access attempts
    if not anaconda.rescue_mount:
        # the %post should be responsible for mounting all needed file systems
        # NOTE: 1st script must be bash or simple python as nothing else might be available in the rescue image
        if anaconda.ksdata and anaconda.ksdata.scripts:
           from kickstart import runPostScripts
           runPostScripts(anaconda)
        else:
           runShell()

        sys.exit(0)

    screen = SnackScreen()
    anaconda.intf = RescueInterface(screen)

    if anaconda.ksdata:
        if anaconda.ksdata.rescue and anaconda.ksdata.rescue.romount:
            readOnly = 1
        else:
            readOnly = 0
    else:
        # prompt to see if we should try and find root filesystem and mount
        # everything in /etc/fstab on that root
        while True:
            rc = ButtonChoiceWindow(screen, _("Rescue"),
                _("The rescue environment will now attempt to find your "
                  "Linux installation and mount it under the directory "
                  "%s.  You can then make any changes required to your "
                  "system.  If you want to proceed with this step choose "
                  "'Continue'.  You can also choose to mount your file systems "
                  "read-only instead of read-write by choosing 'Read-Only'.  "
                  "If you need to activate SAN devices choose 'Advanced'."
                  "\n\n"
                  "If for some reason this process fails you can choose 'Skip' "
                  "and this step will be skipped and you will go directly to a "
                  "command shell.\n\n") % (anaconda.rootPath,),
                  [_("Continue"), _("Read-Only"), _("Skip"), _("Advanced")] )

            if rc == string.lower(_("Skip")):
                runShell(screen)
                sys.exit(0)
            elif rc == string.lower(_("Advanced")):
                addDialog = addDriveDialog(anaconda)
                addDialog.addDriveDialog(screen)
                continue
            elif rc == string.lower(_("Read-Only")):
                readOnly = 1
            else:
                readOnly = 0
            break

    import storage
    storage.storageInitialize(anaconda)

    (disks, notUpgradable) = upgrade.findExistingRoots(anaconda, upgradeany=True)

    if not disks:
        root = None
    elif (len(disks) == 1) or anaconda.ksdata:
        root = disks[0]
    else:
        height = min (len (disks), 12)
        if height == 12:
            scroll = 1
        else:
            scroll = 0

        devList = []
        for (device, relstr) in disks:
            if getattr(device.format, "label", None):
                devList.append("%s (%s) - %s" % (device.name, device.format.label, relstr))
            else:
                devList.append("%s - %s" % (device.name, relstr))

        (button, choice) = \
            ListboxChoiceWindow(screen, _("System to Rescue"),
                                _("Which device holds the root partition "
                                  "of your installation?"), devList,
                                [ _("OK"), _("Exit") ], width = 30,
                                scroll = scroll, height = height,
                                help = "multipleroot")

        if button == string.lower (_("Exit")):
            root = None
        else:
            root = disks[choice]

    rootmounted = 0

    if root:
        try:
            rc = mountExistingSystem(anaconda, root,
                                     allowDirty = 1, warnDirty = 1,
                                     readOnly = readOnly)

            if rc == -1:
                if anaconda.ksdata:
                    log.error("System had dirty file systems which you chose not to mount")
                else:
                    ButtonChoiceWindow(screen, _("Rescue"),
                        _("Your system had dirty file systems which you chose not "
                          "to mount.  Press return to get a shell from which "
                          "you can fsck and mount your partitions.  The system "
                          "will reboot automatically when you exit from the "
                          "shell."), [_("OK")], width = 50)
                rootmounted = 0
            else:
                if anaconda.ksdata:
                    log.info("System has been mounted under: %s" % anaconda.rootPath)
                else:
                    ButtonChoiceWindow(screen, _("Rescue"),
                       _("Your system has been mounted under %(rootPath)s.\n\n"
                         "Press <return> to get a shell. If you would like to "
                         "make your system the root environment, run the command:\n\n"
                         "\tchroot %(rootPath)s\n\nThe system will reboot "
                         "automatically when you exit from the shell.") %
                                       {'rootPath': anaconda.rootPath},
                                       [_("OK")] )
                rootmounted = 1

                # now turn on swap
                if not readOnly:
                    try:
                        anaconda.storage.turnOnSwap()
                    except:
                        log.error("Error enabling swap")

                # and /sys/fs/selinux too
                if flags.selinux and os.path.isdir("%s/sys/fs/selinux" %(anaconda.rootPath,)):
                    try:
                        isys.mount("/sys/fs/selinux", "%s/sys/fs/selinux" %(anaconda.rootPath,),
                                   "selinuxfs")
                    except Exception, e:
                        log.error("error mounting selinuxfs: %s" %(e,))

                    # we have to catch the possible exception
                    # because we support read-only mounting
                    try:
                        fd = open("%s/.autorelabel" % anaconda.rootPath, "w+")
                        fd.close()
                    except Exception, e:
                        log.warning("cannot touch /.autorelabel")

                # set a library path to use mounted fs
                libdirs = os.environ["LD_LIBRARY_PATH"].split(":")
                mounted = map(lambda dir: "/mnt/sysimage%s" % dir, libdirs)
                os.environ["LD_LIBRARY_PATH"] = ":".join(libdirs + mounted)

                # find groff data dir
                try:
                    glst = os.listdir("/mnt/sysimage/usr/share/groff")

                    # find a directory which is a numeral, its where
                    # data files are
                    gversion = None
                    for gdir in glst:
                        try:
                            isone = 1
                            for idx in range(0, len(gdir)):
                                if string.find(string.digits + '.', gdir[idx]) == -1:
                                    isone = 0
                                    break
                            if isone:
                                gversion = gdir
                                break
                        except:
                            gversion = None
                            continue
                except:
                    gversion = None

                if gversion is not None:
                    gpath = "/mnt/sysimage/usr/share/groff/"+gversion
                    os.environ["GROFF_FONT_PATH"] = gpath + '/font'
                    os.environ["GROFF_TMAC_PATH"] = "%s:/mnt/sysimage/usr/share/groff/site-tmac" % (gpath + '/tmac',)

                # do we have bash?
                try:
                    if os.access("/usr/bin/bash", os.R_OK):
                        os.symlink ("/usr/bin/bash", "/bin/bash")
                except:
                    pass
    def __call__(self, screen, anaconda):
        if anaconda.dir == DISPATCH_BACK:
            # reset storage to catch any changes
            anaconda.id.storage.reset(examine_all=True)

        # we might get here after storage reset that obsoleted
        # root device objects we had found
        if not anaconda.id.rootParts:
            anaconda.id.rootParts = upgrade.findExistingRoots(
                anaconda, flags.cmdline.has_key("upgradeany"))
            upgrade.setUpgradeRoot(anaconda)

        parts = anaconda.id.rootParts

        height = min(len(parts), 11) + 1
        if height == 12:
            scroll = 1
        else:
            scroll = 0
        partList = []
        partList.append(_("Reinstall System"))

        if (anaconda.id.upgrade == None
                and anaconda.dispatch.stepInSkipList("installtype")
            ) or anaconda.id.upgrade:
            default = 1
        else:
            default = 0

        for (device, desc) in parts:
            partList.append("%s (%s)" % (desc, device.path))

        (button, choice) = ListboxChoiceWindow(
            screen,
            _("System to Upgrade"),
            _("There seem to be one or more existing Linux installations "
              "on your system.\n\nPlease choose one to upgrade, "
              "or select 'Reinstall System' to freshly install "
              "your system."),
            partList, [TEXT_OK_BUTTON, TEXT_BACK_BUTTON],
            width=55,
            scroll=scroll,
            height=height,
            default=default,
            help="upgraderoot")

        if button == TEXT_BACK_CHECK:
            return INSTALL_BACK
        else:
            if choice == 0:
                root = None
            else:
                root = parts[choice - 1]

        if root is not None:
            upgrade.setSteps(anaconda)
            anaconda.id.setUpgrade(True)

            anaconda.id.upgradeRoot = [(root[0], root[1])]
            anaconda.id.rootParts = parts
            anaconda.dispatch.skipStep("installtype", skip=1)
        else:
            anaconda.dispatch.skipStep("installtype", skip=0)
            anaconda.id.upgradeRoot = None

        return INSTALL_OK
예제 #7
0
def runRescue(anaconda):
    for file in [ "services", "protocols", "group", "joe", "man.config",
                  "nsswitch.conf", "selinux", "mke2fs.conf" ]:
        try:
            os.symlink('/mnt/runtime/etc/' + file, '/etc/' + file)
        except:
            pass

    # see if they would like networking enabled
    if not methodUsesNetworking(anaconda.id.methodstr):
	screen = SnackScreen()

	while 1:
	    rc = ButtonChoiceWindow(screen, _("Setup Networking"),
		_("Do you want to start the network interfaces on "
		  "this system?"), [_("Yes"), _("No")])

	    if rc != string.lower(_("No")):
		anaconda.intf = RescueInterface(screen)

		# need to call sequence of screens, have to look in text.py
		#
		# this code is based on main loop in text.py, and if it
		# or the network step in dispatch.py change significantly
		# then this will certainly break
		#
                pyfile = "network_text"
		classNames = ("NetworkDeviceWindow", "NetworkGlobalWindow")

		lastrc = INSTALL_OK
		step = 0
		anaconda.dir = 1

		while 1:
		    s = "from %s import %s; nextWindow = %s" % \
			(pyfile, classNames[step], classNames[step])
		    exec s

		    win = nextWindow()

                    rc = win(screen, anaconda, showonboot = 0)

		    if rc == INSTALL_NOOP:
			rc = lastrc
			
		    if rc == INSTALL_BACK:
			step = step - 1
			anaconda.dir = - 1
		    elif rc == INSTALL_OK:
			step = step + 1
			anaconda.dir = 1

		    lastrc = rc

		    if step == -1:
			ButtonChoiceWindow(screen, _("Cancelled"),
					   _("I can't go to the previous step "
					     "from here. You will have to try "
					     "again."),
					   buttons=[_("OK")])
                        anaconda.dir = 1
                        step = 0
		    elif step >= len(classNames):
			break

		startNetworking(anaconda.id.network, anaconda.intf, anaconda)
		break
	    else:
		break

	screen.finish()

    # Early shell access with no disk access attempts
    if not anaconda.rescue_mount:
	runShell()
	sys.exit(0)

    # need loopback devices too
    for lpminor in range(8):
	dev = "loop%s" % (lpminor,)
	isys.makeDevInode(dev, "/dev/" + dev)

    screen = SnackScreen()
    anaconda.intf = RescueInterface(screen)
    anaconda.setMethod()

    # prompt to see if we should try and find root filesystem and mount
    # everything in /etc/fstab on that root
    rc = ButtonChoiceWindow(screen, _("Rescue"),
        _("The rescue environment will now attempt to find your "
          "Linux installation and mount it under the directory "
          "%s.  You can then make any changes required to your "
          "system.  If you want to proceed with this step choose "
          "'Continue'.  You can also choose to mount your file systems "
          "read-only instead of read-write by choosing 'Read-Only'."
          "\n\n"
          "If for some reason this process fails you can choose 'Skip' "
          "and this step will be skipped and you will go directly to a "
          "command shell.\n\n") % (anaconda.rootPath,),
          [_("Continue"), _("Read-Only"), _("Skip")] )

    if rc == string.lower(_("Skip")):
        runShell(screen)
        sys.exit(0)
    elif rc == string.lower(_("Read-Only")):
        readOnly = 1
    else:
        readOnly = 0

    disks = upgrade.findExistingRoots(anaconda, upgradeany = 1)

    if not disks:
	root = None
    elif len(disks) == 1:
	root = disks[0]
    else:
	height = min (len (disks), 12)
	if height == 12:
	    scroll = 1
	else:
	    scroll = 0

	partList = []
	for (drive, fs, relstr, label) in disks:
            if label:
	        partList.append("%s (%s)" % (drive, label))
            else:
                partList.append(drive)

	(button, choice) = \
	    ListboxChoiceWindow(screen, _("System to Rescue"),
				_("What partition holds the root partition "
				  "of your installation?"), partList, 
				[ _("OK"), _("Exit") ], width = 30,
				scroll = scroll, height = height,
				help = "multipleroot")

	if button == string.lower (_("Exit")):
	    root = None
	else:
	    root = disks[choice]

    rootmounted = 0

    if root:
	try:
	    fs = fsset.FileSystemSet(anaconda)

	    # only pass first two parts of tuple for root, since third
	    # element is a comment we dont want
	    rc = upgrade.mountRootPartition(anaconda, root[:2], fs,
                                            allowDirty = 1, warnDirty = 1,
                                            readOnly = readOnly)

            if rc == -1:
                ButtonChoiceWindow(screen, _("Rescue"),
                    _("Your system had dirty file systems which you chose not "
                      "to mount.  Press return to get a shell from which "
                      "you can fsck and mount your partitions.  The system "
                      "will reboot automatically when you exit from the "
                      "shell."), [_("OK")], width = 50)
                rootmounted = 0
            else:
                ButtonChoiceWindow(screen, _("Rescue"),
		   _("Your system has been mounted under %s.\n\n"
                     "Press <return> to get a shell. If you would like to "
                     "make your system the root environment, run the command:\n\n"
                     "\tchroot %s\n\nThe system will reboot "
                     "automatically when you exit from the shell.") %
                                   (anaconda.rootPath, anaconda.rootPath),
                                   [_("OK")] )
                rootmounted = 1

		# now turn on swap
		if not readOnly:
		    try:
			fs.turnOnSwap("/")
		    except:
			log.error("Error enabling swap")

                # now that dev is udev, bind mount the installer dev there
                isys.mount("/dev", "%s/dev" %(anaconda.rootPath,), bindMount = 1)

                # and /dev/pts
                isys.mount("/dev/pts", "%s/dev/pts" %(anaconda.rootPath,), bindMount = 1)

                # and /selinux too
                if flags.selinux and os.path.isdir("%s/selinux" %(anaconda.rootPath,)):
                    try:
                        isys.mount("/selinux", "%s/selinux" %(anaconda.rootPath,),
                                   "selinuxfs")
                    except Exception, e:
                        log.error("error mounting selinuxfs: %s" %(e,))

		# set a library path to use mounted fs
		os.environ["LD_LIBRARY_PATH"] =  "/lib:/usr/lib:/usr/X11R6/lib:/lib:/mnt/usr/lib:/mnt/sysimage/lib:/mnt/sysimage/usr/lib:/mnt/sysimage/usr/X11R6/lib"

		# get man pages to work
                os.environ["MANPATH"] = "/mnt/sysimage/usr/share/man:/mnt/sysimage/usr/local/share/man:/usr/share/man:/usr/local/share/man"

		# find groff data dir
		try:
		    glst = os.listdir("/mnt/sysimage/usr/share/groff")

		    # find a directory which is a numeral, its where
		    # data files are
		    gversion = None
		    for gdir in glst:
			try:
			    isone = 1
			    for idx in range(0, len(gdir)):
				if string.find(string.digits + '.', gdir[idx]) == -1:
				    isone = 0
				    break
			    if isone:
				gversion = gdir
				break
				
			except:
			    gversion = None
			    continue
			
		except:
		    gversion = None

		if gversion is not None:
		    gpath = "/mnt/sysimage/usr/share/groff/"+gversion
		    os.environ["GROFF_FONT_PATH"] = gpath + '/font'
		    os.environ["GROFF_TMAC_PATH"] = "%s:/mnt/sysimage/usr/share/groff/site-tmac" % (gpath + '/tmac',)
		    

		# do we have bash?
		try:
		    if os.access("/usr/bin/bash", os.R_OK):
			os.symlink ("/usr/bin/bash", "/bin/bash")
		except:
		    pass
		    
			
	except:
	    # This looks horrible, but all it does is catch every exception,
	    # and reraise those in the tuple check. This lets programming
	    # errors raise exceptions, while any runtime error will
	    # still result in a shell. 
	    (exc, val) = sys.exc_info()[0:2]
            log.error(val)
	    if exc in (IndexError, ValueError, SyntaxError):
		raise exc, val, sys.exc_info()[2]

	    ButtonChoiceWindow(screen, _("Rescue"),
		_("An error occurred trying to mount some or all of your "
		  "system. Some of it may be mounted under %s.\n\n"
		  "Press <return> to get a shell. The system will reboot "
		  "automatically when you exit from the shell.") % (anaconda.rootPath,),
		  [_("OK")] )
    else:
	ButtonChoiceWindow(screen, _("Rescue Mode"),
			   _("You don't have any Linux partitions. Press "
			     "return to get a shell. The system will reboot "
			     "automatically when you exit from the shell."),
			   [ _("OK") ], width = 50)

    msgStr = ""

    if rootmounted and not readOnly:
        makeMtab(anaconda.rootPath, fs)
        try:
            makeResolvConf(anaconda.rootPath)
        except Exception, e:
            log.error("error making a resolv.conf: %s" %(e,))
        msgStr = _("Your system is mounted under the %s directory.") % (anaconda.rootPath,)
예제 #8
0
def runRescue(anaconda):
    for file in [
            "services", "protocols", "group", "joe", "man.config",
            "nsswitch.conf", "selinux", "mke2fs.conf"
    ]:
        try:
            os.symlink('/mnt/runtime/etc/' + file, '/etc/' + file)
        except:
            pass

    # see if they would like networking enabled
    if not methodUsesNetworking(anaconda.id.methodstr):
        screen = SnackScreen()

        while 1:
            rc = ButtonChoiceWindow(
                screen, _("Setup Networking"),
                _("Do you want to start the network interfaces on "
                  "this system?"), [_("Yes"), _("No")])

            if rc != string.lower(_("No")):
                anaconda.intf = RescueInterface(screen)

                # need to call sequence of screens, have to look in text.py
                #
                # this code is based on main loop in text.py, and if it
                # or the network step in dispatch.py change significantly
                # then this will certainly break
                #
                pyfile = "network_text"
                classNames = ("NetworkDeviceWindow", "NetworkGlobalWindow")

                lastrc = INSTALL_OK
                step = 0
                anaconda.dir = 1

                while 1:
                    s = "from %s import %s; nextWindow = %s" % \
                 (pyfile, classNames[step], classNames[step])
                    exec s

                    win = nextWindow()

                    rc = win(screen, anaconda, showonboot=0)

                    if rc == INSTALL_NOOP:
                        rc = lastrc

                    if rc == INSTALL_BACK:
                        step = step - 1
                        anaconda.dir = -1
                    elif rc == INSTALL_OK:
                        step = step + 1
                        anaconda.dir = 1

                    lastrc = rc

                    if step == -1:
                        ButtonChoiceWindow(screen,
                                           _("Cancelled"),
                                           _("I can't go to the previous step "
                                             "from here. You will have to try "
                                             "again."),
                                           buttons=[_("OK")])
                        anaconda.dir = 1
                        step = 0
                    elif step >= len(classNames):
                        break

                startNetworking(anaconda.id.network, anaconda.intf, anaconda)
                break
            else:
                break

        screen.finish()

    # Early shell access with no disk access attempts
    if not anaconda.rescue_mount:
        runShell()
        sys.exit(0)

    # need loopback devices too
    for lpminor in range(8):
        dev = "loop%s" % (lpminor, )
        isys.makeDevInode(dev, "/dev/" + dev)

    screen = SnackScreen()
    anaconda.intf = RescueInterface(screen)
    anaconda.setMethod()

    # prompt to see if we should try and find root filesystem and mount
    # everything in /etc/fstab on that root
    rc = ButtonChoiceWindow(
        screen, _("Rescue"),
        _("The rescue environment will now attempt to find your "
          "Linux installation and mount it under the directory "
          "%s.  You can then make any changes required to your "
          "system.  If you want to proceed with this step choose "
          "'Continue'.  You can also choose to mount your file systems "
          "read-only instead of read-write by choosing 'Read-Only'."
          "\n\n"
          "If for some reason this process fails you can choose 'Skip' "
          "and this step will be skipped and you will go directly to a "
          "command shell.\n\n") % (anaconda.rootPath, ),
        [_("Continue"), _("Read-Only"),
         _("Skip")])

    if rc == string.lower(_("Skip")):
        runShell(screen)
        sys.exit(0)
    elif rc == string.lower(_("Read-Only")):
        readOnly = 1
    else:
        readOnly = 0

    disks = upgrade.findExistingRoots(anaconda, upgradeany=1)

    if not disks:
        root = None
    elif len(disks) == 1:
        root = disks[0]
    else:
        height = min(len(disks), 12)
        if height == 12:
            scroll = 1
        else:
            scroll = 0

        partList = []
        for (drive, fs, relstr, label) in disks:
            if label:
                partList.append("%s (%s)" % (drive, label))
            else:
                partList.append(drive)

        (button, choice) = \
            ListboxChoiceWindow(screen, _("System to Rescue"),
           _("What partition holds the root partition "
             "of your installation?"), partList,
           [ _("OK"), _("Exit") ], width = 30,
           scroll = scroll, height = height,
           help = "multipleroot")

        if button == string.lower(_("Exit")):
            root = None
        else:
            root = disks[choice]

    rootmounted = 0

    if root:
        try:
            fs = fsset.FileSystemSet(anaconda)

            # only pass first two parts of tuple for root, since third
            # element is a comment we dont want
            rc = upgrade.mountRootPartition(anaconda,
                                            root[:2],
                                            fs,
                                            allowDirty=1,
                                            warnDirty=1,
                                            readOnly=readOnly)

            if rc == -1:
                ButtonChoiceWindow(
                    screen,
                    _("Rescue"),
                    _("Your system had dirty file systems which you chose not "
                      "to mount.  Press return to get a shell from which "
                      "you can fsck and mount your partitions.  The system "
                      "will reboot automatically when you exit from the "
                      "shell."), [_("OK")],
                    width=50)
                rootmounted = 0
            else:
                ButtonChoiceWindow(
                    screen, _("Rescue"),
                    _("Your system has been mounted under %s.\n\n"
                      "Press <return> to get a shell. If you would like to "
                      "make your system the root environment, run the command:\n\n"
                      "\tchroot %s\n\nThe system will reboot "
                      "automatically when you exit from the shell.") %
                    (anaconda.rootPath, anaconda.rootPath), [_("OK")])
                rootmounted = 1

                # now turn on swap
                if not readOnly:
                    try:
                        fs.turnOnSwap("/")
                    except:
                        log.error("Error enabling swap")

                # now that dev is udev, bind mount the installer dev there
                isys.mount("/dev",
                           "%s/dev" % (anaconda.rootPath, ),
                           bindMount=1)

                # and /dev/pts
                isys.mount("/dev/pts",
                           "%s/dev/pts" % (anaconda.rootPath, ),
                           bindMount=1)

                # and /selinux too
                if flags.selinux and os.path.isdir("%s/selinux" %
                                                   (anaconda.rootPath, )):
                    try:
                        isys.mount("/selinux",
                                   "%s/selinux" % (anaconda.rootPath, ),
                                   "selinuxfs")
                    except Exception, e:
                        log.error("error mounting selinuxfs: %s" % (e, ))

        # set a library path to use mounted fs
                os.environ[
                    "LD_LIBRARY_PATH"] = "/lib:/usr/lib:/usr/X11R6/lib:/lib:/mnt/usr/lib:/mnt/sysimage/lib:/mnt/sysimage/usr/lib:/mnt/sysimage/usr/X11R6/lib"

                # get man pages to work
                os.environ[
                    "MANPATH"] = "/mnt/sysimage/usr/share/man:/mnt/sysimage/usr/local/share/man:/usr/share/man:/usr/local/share/man"

                # find groff data dir
                try:
                    glst = os.listdir("/mnt/sysimage/usr/share/groff")

                    # find a directory which is a numeral, its where
                    # data files are
                    gversion = None
                    for gdir in glst:
                        try:
                            isone = 1
                            for idx in range(0, len(gdir)):
                                if string.find(string.digits + '.',
                                               gdir[idx]) == -1:
                                    isone = 0
                                    break
                            if isone:
                                gversion = gdir
                                break

                        except:
                            gversion = None
                            continue

                except:
                    gversion = None

                if gversion is not None:
                    gpath = "/mnt/sysimage/usr/share/groff/" + gversion
                    os.environ["GROFF_FONT_PATH"] = gpath + '/font'
                    os.environ[
                        "GROFF_TMAC_PATH"] = "%s:/mnt/sysimage/usr/share/groff/site-tmac" % (
                            gpath + '/tmac', )

        # do we have bash?
                try:
                    if os.access("/usr/bin/bash", os.R_OK):
                        os.symlink("/usr/bin/bash", "/bin/bash")
                except:
                    pass

        except:
            # This looks horrible, but all it does is catch every exception,
            # and reraise those in the tuple check. This lets programming
            # errors raise exceptions, while any runtime error will
            # still result in a shell.
            (exc, val) = sys.exc_info()[0:2]
            log.error(val)
            if exc in (IndexError, ValueError, SyntaxError):
                raise exc, val, sys.exc_info()[2]

            ButtonChoiceWindow(
                screen, _("Rescue"),
                _("An error occurred trying to mount some or all of your "
                  "system. Some of it may be mounted under %s.\n\n"
                  "Press <return> to get a shell. The system will reboot "
                  "automatically when you exit from the shell.") %
                (anaconda.rootPath, ), [_("OK")])
    else:
        ButtonChoiceWindow(screen,
                           _("Rescue Mode"),
                           _("You don't have any Linux partitions. Press "
                             "return to get a shell. The system will reboot "
                             "automatically when you exit from the shell."),
                           [_("OK")],
                           width=50)

    msgStr = ""

    if rootmounted and not readOnly:
        makeMtab(anaconda.rootPath, fs)
        try:
            makeResolvConf(anaconda.rootPath)
        except Exception, e:
            log.error("error making a resolv.conf: %s" % (e, ))
        msgStr = _("Your system is mounted under the %s directory.") % (
            anaconda.rootPath, )