# # packages.py: package management - mainly package installation # # Erik Troan # Matt Wilson # Michael Fulbright # Jeremy Katz # # Copyright 2001-2006 Red Hat, Inc. # # This software may be freely redistributed under the terms of the GNU # library public license. # # You should have received a copy of the GNU Library Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # import iutil import isys import os import timer import time import sys import string import language import fsset import kudzu import shutil from flags import flags from product import * from constants import * from installmethod import FileCopyException import rhpl from rhpl.translate import _ import rhpl.arch import logging log = logging.getLogger("anaconda") def doPostAction(anaconda): anaconda.id.instClass.postAction(anaconda, flags.serial) def firstbootConfiguration(anaconda): if anaconda.id.firstboot == FIRSTBOOT_RECONFIG: f = open(anaconda.rootPath + '/etc/reconfigSys', 'w+') f.close() elif anaconda.id.firstboot == FIRSTBOOT_SKIP: f = open(anaconda.rootPath + '/etc/sysconfig/firstboot', 'w+') f.write('RUN_FIRSTBOOT=NO') f.close() return def writeKSConfiguration(anaconda): log.info("Writing autokickstart file") if not flags.test: fn = anaconda.rootPath + "/root/anaconda-ks.cfg" else: fn = "/tmp/anaconda-ks.cfg" anaconda.id.writeKS(fn) def copyAnacondaLogs(anaconda): log.info("Copying anaconda logs") for (fn, dest) in (("/tmp/anaconda.log", "anaconda.log"), ("/tmp/syslog", "anaconda.syslog"), ("/tmp/ramfs/X.log", "anaconda.xlog")): if os.access(fn, os.R_OK): try: shutil.copyfile(fn, "%s/var/log/%s" %(anaconda.rootPath, dest)) os.chmod("%s/var/log/%s" %(anaconda.rootPath, dest), 0600) except: pass def writeXConfiguration(anaconda): testmode = flags.test # comment out to test if testmode: return # end code to comment to test # uncomment to test writing X config in test mode # try: # os.mkdir("/tmp/etc") # except: # pass # try: # os.mkdir("/tmp/etc/X11") # except: # pass # instPath = '/' # end code for test writing if anaconda.id.xsetup.skipx: return card = anaconda.id.videocard.primaryCard() if not card: return log.info("Writing X configuration") if not testmode: fn = anaconda.rootPath else: fn = "/tmp/" anaconda.id.xsetup.write(fn+"/etc/X11", anaconda.id.mouse, anaconda.id.keyboard) anaconda.id.desktop.write(anaconda.rootPath) def doMigrateFilesystems(anaconda): if anaconda.dir == DISPATCH_BACK: return DISPATCH_NOOP if anaconda.id.fsset.haveMigratedFilesystems(): return DISPATCH_NOOP anaconda.id.fsset.migrateFilesystems (anaconda.rootPath) # if we're upgrading, we may need to do lvm device node hackery if anaconda.id.upgrade: anaconda.id.fsset.makeLVMNodes(anaconda.rootPath, trylvm1 = 1) def turnOnFilesystems(anaconda): if anaconda.dir == DISPATCH_BACK: log.info("unmounting filesystems") anaconda.id.fsset.umountFilesystems(anaconda.rootPath) return if flags.setupFilesystems: if not anaconda.id.upgrade: anaconda.id.partitions.doMetaDeletes(anaconda.id.diskset) anaconda.id.fsset.setActive(anaconda.id.diskset) if not anaconda.id.fsset.isActive(): anaconda.id.diskset.savePartitions () anaconda.id.fsset.checkBadblocks(anaconda.rootPath) if not anaconda.id.fsset.volumesCreated: anaconda.id.fsset.createLogicalVolumes(anaconda.rootPath) anaconda.id.fsset.formatSwap(anaconda.rootPath) anaconda.id.fsset.turnOnSwap(anaconda.rootPath) anaconda.id.fsset.makeFilesystems (anaconda.rootPath) anaconda.id.fsset.mountFilesystems (anaconda) def setupTimezone(anaconda): # we don't need this on an upgrade or going backwards if anaconda.id.upgrade or anaconda.dir == DISPATCH_BACK: return # dont do this in test mode! if flags.test or flags.rootpath: return os.environ["TZ"] = anaconda.id.timezone.tz tzfile = "/usr/share/zoneinfo/" + anaconda.id.timezone.tz if not os.access(tzfile, os.R_OK): log.error("unable to set timezone") else: try: shutil.copyfile(tzfile, "/etc/localtime") except OSError, (errno, msg): log.error("Error copying timezone (from %s): %s" %(tzfile, msg)) if rhpl.getArch() == "s390": return args = [ "--hctosys" ] if anaconda.id.timezone.utc: args.append("-u") elif anaconda.id.timezone.arc: args.append("-a") try: iutil.execWithRedirect("/usr/sbin/hwclock", args, stdin = None, stdout = "/dev/tty5", stderr = "/dev/tty5") except RuntimeError: log.error("Failed to set clock") # FIXME: this is a huge gross hack. hard coded list of files # created by anaconda so that we can not be killed by selinux def setFileCons(anaconda): import partRequests if flags.selinux: log.info("setting SELinux contexts for anaconda created files") files = ["/etc/rpm/platform", "/etc/rpm/macros", "/etc/lilo.conf.anaconda", "/lib64", "/usr/lib64", "/etc/blkid.tab", "/etc/blkid.tab.old", "/etc/mtab", "/etc/fstab", "/etc/resolv.conf", "/etc/modprobe.conf", "/etc/modprobe.conf~", "/var/log/wtmp", "/var/run/utmp", "/dev/log", "/var/lib/rpm", "/", "/etc/raidtab", "/etc/mdadm.conf", "/etc/hosts", "/etc/sysconfig/network"] vgs = [] for entry in anaconda.id.partitions.requests: if isinstance(entry, partRequests.VolumeGroupRequestSpec): vgs.append("/dev/%s" %(entry.volumeGroupName,)) # ugh, this is ugly for dir in ["/etc/sysconfig/network-scripts/", "/var/lib/rpm", "/etc/lvm", "/dev/mapper"] + vgs: def addpath(x): return dir + "/" + x if not os.path.isdir(anaconda.rootPath + dir): continue dirfiles = os.listdir(anaconda.rootPath + dir) files.extend(map(addpath, dirfiles)) files.append(dir) # blah, to work in a chroot, we need to actually be inside so the # regexes will work child = os.fork() if (not child): os.chroot(anaconda.rootPath) for f in files: if not os.access("%s" %(f,), os.R_OK): log.warning("%s doesn't exist" %(f,)) continue ret = isys.resetFileContext(f) log.info("set fc of %s to %s" %(f, ret)) os._exit(0) try: os.waitpid(child, 0) except OSError, (num, msg): pass return #Recreate initrd for use when driver disks add modules def recreateInitrd (kernelTag, instRoot): log.info("recreating initrd for %s" % (kernelTag,)) iutil.execWithRedirect("/sbin/new-kernel-pkg", [ "--mkinitrd", "--depmod", "--install", kernelTag ], stdout = None, stderr = None, searchPath = 1, root = instRoot) def regKeyScreen(anaconda): if anaconda.dir == DISPATCH_BACK: return DISPATCH_NOOP while 1: rc = anaconda.intf.entryWindow(_("Enter Registration Key"), _("Please enter the registration key for your version of %s.") %(productName,), _("Key:")) try: anaconda.id.instClass.handleRegKey(rc, anaconda.intf) except Exception, e: log.info("exception handling regkey: %s" %(e,)) continue break # FIXME: currently, we only allow this screen to ever be hit _once_ anaconda.dispatch.skipStep("regkey", permanent = 1) return def betaNagScreen(anaconda): publicBetas = { "Red Hat Linux": "Red Hat Linux Public Beta", "Red Hat Enterprise Linux": "Red Hat Enterprise Linux Public Beta", "Fedora Core": "Fedora Core" } if anaconda.dir == DISPATCH_BACK: return DISPATCH_NOOP fileagainst = None for (key, val) in publicBetas.items(): if productName.startswith(key): fileagainst = val if fileagainst is None: fileagainst = "%s Beta" %(productName,) while 1: rc = anaconda.intf.messageWindow( _("Warning! This is pre-release software!"), _("Thank you for downloading this " "pre-release of %s.\n\n" "This is not a final " "release and is not intended for use " "on production systems. The purpose of " "this release is to collect feedback " "from testers, and it is not suitable " "for day to day usage.\n\n" "To report feedback, please visit:\n\n" " %s\n\n" "and file a report against '%s'.\n") %(productName, bugzillaUrl, fileagainst), type="custom", custom_icon="warning", custom_buttons=[_("_Exit"), _("_Install anyway")]) if not rc: if flags.rootpath: msg = _("The installer will now exit...") buttons = [_("_Back"), _("_Exit")] else: msg = _("Your system will now be rebooted...") buttons = [_("_Back"), _("_Reboot")] rc = anaconda.intf.messageWindow( _("Rebooting System"), msg, type="custom", custom_icon="warning", custom_buttons=buttons) if rc: sys.exit(0) else: break # FIXME: this is a kind of poor way to do this, but it will work for now def selectPackageConditionals(grpset, grp): xmlgrp = grpset.compsxml.groups[grp.basename] for package in xmlgrp.pkgConditionals.keys(): req = xmlgrp.pkgConditionals[package] if not grpset.hdrlist.has_key(package): log.warning ("Missing %s which is in a conditional" %(package,)) continue # add to the deps in the dependencies structure for the # package. this should take care of whenever we're # selected grpset.hdrlist[req].addDeps([package], main = 0) if grpset.hdrlist[req].isSelected(): grpset.hdrlist[package].select() grpset.hdrlist[package].usecount += grpset.hdrlist[req].usecount - 1 grp.selectDeps([package], uses = grpset.hdrlist[req].usecount) # Loop over all the selected groups and make sure all the conditionals are # met. def fixupConditionals(grpset): for grp in grpset.groups: if grpset.groups[grp].isSelected(): selectPackageConditionals(grpset, grpset.groups[grp]) def selectLanguageSupportGroups(grpset, instLanguage): if not grpset.groups.has_key("language-support"): return langs = [] for l in language.expandLangs (instLanguage.getDefault()): langs.append(l) grp = grpset.groups["language-support"] for (pid, pdict) in grp.packages.items(): if pdict['meta'] != 1: continue if not grpset.groups.has_key(pid): continue group = grpset.groups[pid] if group.langonly is not None and group.langonly in langs: grp.selectPackage(pid) grp.usecount = grp.usecount + 1 selectPackageConditionals(grpset, group) if grp.usecount > 0: grpset.groups["language-support"].select()