2014-04-07 12:38:09 +00:00
|
|
|
# anaconda: The Red Hat Linux Installation program
|
|
|
|
#
|
|
|
|
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
|
|
|
|
# Red Hat, Inc. All rights reserved.
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
# Author(s): Brent Fox <bfox@redhat.com>
|
|
|
|
# Mike Fulbright <msf@redhat.com>
|
|
|
|
# Jakub Jelinek <jakub@redhat.com>
|
|
|
|
# Jeremy Katz <katzj@redhat.com>
|
|
|
|
# Chris Lumens <clumens@redhat.com>
|
|
|
|
# Paul Nasrat <pnasrat@redhat.com>
|
|
|
|
# Erik Troan <ewt@rpath.com>
|
|
|
|
# Matt Wilson <msw@rpath.com>
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2015-03-23 11:36:12 +00:00
|
|
|
import stat
|
|
|
|
from glob import glob
|
2014-04-07 12:38:09 +00:00
|
|
|
from tempfile import mkstemp
|
2015-03-23 11:36:12 +00:00
|
|
|
import threading
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
from pyanaconda.bootloader import get_bootloader
|
|
|
|
from pyanaconda import constants
|
2015-03-23 11:36:12 +00:00
|
|
|
from pyanaconda import iutil
|
2016-04-10 04:00:00 +00:00
|
|
|
from pyanaconda.iutil import open # pylint: disable=redefined-builtin
|
2014-04-07 12:38:09 +00:00
|
|
|
from pyanaconda import addons
|
|
|
|
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger("anaconda")
|
|
|
|
stdoutLog = logging.getLogger("anaconda.stdout")
|
|
|
|
|
|
|
|
class Anaconda(object):
|
|
|
|
def __init__(self):
|
|
|
|
from pyanaconda import desktop
|
|
|
|
|
|
|
|
self._bootloader = None
|
|
|
|
self.canReIPL = False
|
|
|
|
self.desktop = desktop.Desktop()
|
|
|
|
self.dir = None
|
|
|
|
self.displayMode = None
|
2016-04-10 04:00:00 +00:00
|
|
|
self.gui_startup_failed = False
|
2014-04-07 12:38:09 +00:00
|
|
|
self.id = None
|
|
|
|
self._instClass = None
|
|
|
|
self._intf = None
|
|
|
|
self.isHeadless = False
|
|
|
|
self.ksdata = None
|
|
|
|
self.mediaDevice = None
|
|
|
|
self.methodstr = None
|
|
|
|
self.opts = None
|
|
|
|
self._payload = None
|
|
|
|
self.proxy = None
|
|
|
|
self.proxyUsername = None
|
|
|
|
self.proxyPassword = None
|
|
|
|
self.reIPLMessage = None
|
|
|
|
self.rescue_mount = True
|
|
|
|
self.rootParts = None
|
|
|
|
|
|
|
|
self.stage2 = None
|
|
|
|
self._storage = None
|
|
|
|
self.updateSrc = None
|
|
|
|
self.mehConfig = None
|
|
|
|
|
|
|
|
# *sigh* we still need to be able to write this out
|
|
|
|
self.xdriver = None
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
# Data for inhibiting the screensaver
|
|
|
|
self.dbus_session_connection = None
|
|
|
|
self.dbus_inhibit_id = None
|
|
|
|
|
|
|
|
# This is used to synchronize Gtk.main calls between the graphical
|
|
|
|
# interface and error dialogs. Whoever gets to their initialization code
|
|
|
|
# first will lock gui_initializing
|
|
|
|
self.gui_initialized = threading.Lock()
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
@property
|
|
|
|
def bootloader(self):
|
|
|
|
if not self._bootloader:
|
|
|
|
self._bootloader = get_bootloader()
|
|
|
|
|
|
|
|
return self._bootloader
|
|
|
|
|
|
|
|
@property
|
|
|
|
def instClass(self):
|
|
|
|
if not self._instClass:
|
|
|
|
from pyanaconda.installclass import DefaultInstall
|
|
|
|
self._instClass = DefaultInstall()
|
|
|
|
|
|
|
|
return self._instClass
|
|
|
|
|
|
|
|
def _getInterface(self):
|
|
|
|
return self._intf
|
|
|
|
|
|
|
|
def _setInterface(self, v):
|
|
|
|
# "lambda cannot contain assignment"
|
|
|
|
self._intf = v
|
|
|
|
|
|
|
|
def _delInterface(self):
|
|
|
|
del self._intf
|
|
|
|
|
|
|
|
intf = property(_getInterface, _setInterface, _delInterface)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def payload(self):
|
|
|
|
# Try to find the packaging payload class. First try the install
|
|
|
|
# class. If it doesn't give us one, fall back to the default.
|
|
|
|
if not self._payload:
|
|
|
|
klass = self.instClass.getBackend()
|
|
|
|
|
|
|
|
if not klass:
|
|
|
|
from pyanaconda.flags import flags
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
if self.ksdata.ostreesetup.seen:
|
|
|
|
from pyanaconda.packaging.rpmostreepayload import RPMOSTreePayload
|
|
|
|
klass = RPMOSTreePayload
|
|
|
|
elif flags.livecdInstall:
|
2014-04-07 12:38:09 +00:00
|
|
|
from pyanaconda.packaging.livepayload import LiveImagePayload
|
|
|
|
klass = LiveImagePayload
|
|
|
|
elif self.ksdata.method.method == "liveimg":
|
|
|
|
from pyanaconda.packaging.livepayload import LiveImageKSPayload
|
|
|
|
klass = LiveImageKSPayload
|
|
|
|
else:
|
2016-04-10 04:00:00 +00:00
|
|
|
from pyanaconda.packaging.dnfpayload import DNFPayload
|
|
|
|
klass = DNFPayload
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
self._payload = klass(self.ksdata)
|
|
|
|
|
|
|
|
return self._payload
|
|
|
|
|
|
|
|
@property
|
|
|
|
def protected(self):
|
|
|
|
specs = []
|
|
|
|
if os.path.exists("/run/initramfs/livedev") and \
|
|
|
|
stat.S_ISBLK(os.stat("/run/initramfs/livedev")[stat.ST_MODE]):
|
|
|
|
specs.append(os.readlink("/run/initramfs/livedev"))
|
|
|
|
|
|
|
|
if self.methodstr and self.methodstr.startswith("hd:"):
|
|
|
|
specs.append(self.methodstr[3:].split(":", 3)[0])
|
|
|
|
|
|
|
|
if self.stage2 and self.stage2.startswith("hd:"):
|
|
|
|
specs.append(self.stage2[3:].split(":", 3)[0])
|
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
# zRAM swap devices need to be protected
|
|
|
|
for zram_dev in glob("/dev/zram*"):
|
|
|
|
specs.append(zram_dev)
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
return specs
|
|
|
|
|
|
|
|
@property
|
|
|
|
def storage(self):
|
|
|
|
if not self._storage:
|
|
|
|
import blivet
|
2016-04-10 04:00:00 +00:00
|
|
|
import blivet.arch
|
|
|
|
|
|
|
|
import gi
|
|
|
|
gi.require_version("BlockDev", "1.0")
|
|
|
|
|
|
|
|
from gi.repository import BlockDev as blockdev
|
2014-04-07 12:38:09 +00:00
|
|
|
self._storage = blivet.Blivet(ksdata=self.ksdata)
|
|
|
|
|
|
|
|
if self.instClass.defaultFS:
|
|
|
|
self._storage.setDefaultFSType(self.instClass.defaultFS)
|
|
|
|
|
2016-04-10 04:00:00 +00:00
|
|
|
if blivet.arch.isS390():
|
|
|
|
# want to make sure s390 plugin is loaded
|
|
|
|
if "s390" not in blockdev.get_available_plugin_names():
|
|
|
|
plugin = blockdev.PluginSpec()
|
|
|
|
plugin.name = blockdev.Plugin.S390
|
|
|
|
plugin.so_name = None
|
|
|
|
blockdev.reinit([plugin], reload=False)
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
return self._storage
|
|
|
|
|
|
|
|
def dumpState(self):
|
|
|
|
from meh import ExceptionInfo
|
|
|
|
from meh.dump import ReverseExceptionDump
|
|
|
|
from inspect import stack as _stack
|
|
|
|
from traceback import format_stack
|
|
|
|
|
|
|
|
# Skip the frames for dumpState and the signal handler.
|
|
|
|
stack = _stack()[2:]
|
|
|
|
stack.reverse()
|
|
|
|
exn = ReverseExceptionDump(ExceptionInfo(None, None, stack),
|
|
|
|
self.mehConfig)
|
|
|
|
|
|
|
|
# gather up info on the running threads
|
|
|
|
threads = "\nThreads\n-------\n"
|
2016-04-10 04:00:00 +00:00
|
|
|
|
|
|
|
# Every call to sys._current_frames() returns a new dict, so it is not
|
|
|
|
# modified when threads are created or destroyed. Iterating over it is
|
|
|
|
# thread safe.
|
2015-05-30 11:20:59 +00:00
|
|
|
for thread_id, frame in sys._current_frames().items():
|
2014-04-07 12:38:09 +00:00
|
|
|
threads += "\nThread %s\n" % (thread_id,)
|
|
|
|
threads += "".join(format_stack(frame))
|
|
|
|
|
|
|
|
# dump to a unique file
|
|
|
|
(fd, filename) = mkstemp(prefix="anaconda-tb-", dir="/tmp")
|
|
|
|
dump_text = exn.traceback_and_object_dump(self)
|
|
|
|
dump_text += threads
|
2016-04-10 04:00:00 +00:00
|
|
|
dump_text_bytes = dump_text.encode("utf-8")
|
|
|
|
iutil.eintr_retry_call(os.write, fd, dump_text_bytes)
|
|
|
|
iutil.eintr_ignore(os.close, fd)
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
# append to a given file
|
|
|
|
with open("/tmp/anaconda-tb-all.log", "a+") as f:
|
|
|
|
f.write("--- traceback: %s ---\n" % filename)
|
|
|
|
f.write(dump_text + "\n")
|
|
|
|
|
|
|
|
def initInterface(self, addon_paths=None):
|
|
|
|
if self._intf:
|
|
|
|
raise RuntimeError("Second attempt to initialize the InstallInterface")
|
|
|
|
|
|
|
|
if self.displayMode == 'g':
|
|
|
|
from pyanaconda.ui.gui import GraphicalUserInterface
|
2015-05-30 11:20:59 +00:00
|
|
|
# Run the GUI in non-fullscreen mode, so live installs can still
|
|
|
|
# use the window manager
|
2014-04-07 12:38:09 +00:00
|
|
|
self._intf = GraphicalUserInterface(self.storage, self.payload,
|
2015-05-30 11:20:59 +00:00
|
|
|
self.instClass, gui_lock=self.gui_initialized,
|
|
|
|
fullscreen=False)
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
# needs to be refreshed now we know if gui or tui will take place
|
|
|
|
addon_paths = addons.collect_addon_paths(constants.ADDON_PATHS,
|
|
|
|
ui_subdir="gui")
|
|
|
|
elif self.displayMode in ['t', 'c']: # text and command line are the same
|
|
|
|
from pyanaconda.ui.tui import TextUserInterface
|
|
|
|
self._intf = TextUserInterface(self.storage, self.payload,
|
|
|
|
self.instClass)
|
|
|
|
|
|
|
|
# needs to be refreshed now we know if gui or tui will take place
|
|
|
|
addon_paths = addons.collect_addon_paths(constants.ADDON_PATHS,
|
|
|
|
ui_subdir="tui")
|
|
|
|
else:
|
|
|
|
raise RuntimeError("Unsupported displayMode: %s" % self.displayMode)
|
|
|
|
|
|
|
|
if addon_paths:
|
|
|
|
self._intf.update_paths(addon_paths)
|
|
|
|
|
2016-04-10 04:00:00 +00:00
|
|
|
def writeXdriver(self, root=None):
|
2014-04-07 12:38:09 +00:00
|
|
|
# this should go away at some point, but until it does, we
|
|
|
|
# need to keep it around.
|
|
|
|
if self.xdriver is None:
|
|
|
|
return
|
|
|
|
if root is None:
|
2015-03-23 11:36:12 +00:00
|
|
|
root = iutil.getSysroot()
|
2014-04-07 12:38:09 +00:00
|
|
|
if not os.path.isdir("%s/etc/X11" %(root,)):
|
2015-03-23 11:36:12 +00:00
|
|
|
os.makedirs("%s/etc/X11" %(root,), mode=0o755)
|
2014-04-07 12:38:09 +00:00
|
|
|
f = open("%s/etc/X11/xorg.conf" %(root,), 'w')
|
|
|
|
f.write('Section "Device"\n\tIdentifier "Videocard0"\n\tDriver "%s"\nEndSection\n' % self.xdriver)
|
|
|
|
f.close()
|