Skip to content

Instantly share code, notes, and snippets.

@rubiojr
Created May 17, 2011 13:44
Show Gist options
  • Save rubiojr/976489 to your computer and use it in GitHub Desktop.
Save rubiojr/976489 to your computer and use it in GitHub Desktop.
Minimal Anaconda Installer
#!/usr/bin/python
#
# anaconda: The Red Hat Linux Installation program
#
# (in alphabetical order...)
#
# 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>
#
# ... And many others
#
# Copyright 1999-2007 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.
#
# This toplevel file is a little messy at the moment...
import sys, os, re
from optparse import OptionParser
# keep up with process ID of miniwm if we start it
miniwm_pid = None
# start miniWM
def startMiniWM(root='/'):
(rd, wr) = os.pipe()
childpid = os.fork()
if not childpid:
if os.access("./mini-wm", os.X_OK):
cmd = "./mini-wm"
elif os.access(root + "/usr/bin/mini-wm", os.X_OK):
cmd = root + "/usr/bin/mini-wm"
else:
return None
os.dup2(wr, 1)
os.close(wr)
args = [cmd, '--display', ':1']
os.execv(args[0], args)
sys.exit (1)
else:
# We need to make sure that mini-wm is the first client to
# connect to the X server (see bug #108777). Wait for mini-wm
# to write back an acknowledge token.
os.read(rd, 1)
return childpid
# function to handle X startup special issues for anaconda
def doStartupX11Actions():
global miniwm_pid
# now start up mini-wm
try:
miniwm_pid = startMiniWM()
except:
miniwm_pid = None
# test to setup dpi
# cant do this if miniwm didnt run because otherwise when
# we open and close an X connection in the xutils calls
# the X server will exit since this is the first X
# connection (if miniwm isnt running)
if miniwm_pid is not None:
import xutils
try:
if xutils.screenWidth() > 640:
dpi = "96"
else:
dpi = "75"
xutils.setRootResource('Xcursor.size', '24')
xutils.setRootResource('Xcursor.theme', 'Bluecurve')
xutils.setRootResource('Xcursor.theme_core', 'true')
xutils.setRootResource('Xft.antialias', '1')
xutils.setRootResource('Xft.dpi', dpi)
xutils.setRootResource('Xft.hinting', '1')
xutils.setRootResource('Xft.hintstyle', 'hintslight')
xutils.setRootResource('Xft.rgba', 'none')
except:
sys.stderr.write("X SERVER STARTED, THEN FAILED");
raise RuntimeError, "X server failed to start"
def doShutdownX11Actions():
global miniwm_pid
if miniwm_pid is not None:
try:
os.kill(miniwm_pid, 15)
os.waitpid(miniwm_pid, 0)
except:
pass
def parseOptions():
def resolution_cb (option, opt_str, value, parser):
global runres_override
parser.values.runres = value
runres_override = True
def rootpath_cb (option, opt_str, value, parser):
if value.startswith("cd:"):
flags.livecd = True
value = value[3:]
parser.values.rootPath = os.path.abspath(value)
flags.setupFilesystems = False
flags.rootpath = True
op = OptionParser()
# Interface
op.add_option("-C", "--cmdline", dest="display_mode", action="store_const", const="c")
op.add_option("-G", "--graphical", dest="display_mode", action="store_const", const="g")
op.add_option("-T", "--text", dest="display_mode", action="store_const", const="t")
# Network
op.add_option("--noipv4", action="store_true", default=False)
op.add_option("--noipv6", action="store_true", default=False)
# Method of operation
op.add_option("--autostep", action="store_true", default=False)
op.add_option("-d", "--debug", dest="debug", action="store_true", default=False)
op.add_option("--expert", action="store_true", default=False)
op.add_option("--kickstart", dest="ksfile")
op.add_option("-m", "--method", default=None)
op.add_option("--rescue", dest="rescue", action="store_true", default=False)
op.add_option("-r", "--rootpath", action="callback", callback=rootpath_cb, dest="rootPath",
default="/mnt/sysimage", nargs=1, type="string")
op.add_option("-t", "--test", action="store_true", default=False)
op.add_option("--targetarch", dest="targetArch", nargs=1, type="string")
# Display
op.add_option("--headless", dest="isHeadless", action="store_true", default=False)
op.add_option("--lowres", dest="runres", action="store_const", const="640x480")
op.add_option("--nofb")
op.add_option("--resolution", action="callback", callback=resolution_cb, dest="runres",
default="800x600", nargs=1, type="string")
op.add_option("--serial", action="store_true", default=False)
op.add_option("--usefbx", dest="xdriver", action="store_const", const="fbdev")
op.add_option("--virtpconsole")
op.add_option("--vnc", action="store_true", default=False)
op.add_option("--vncconnect")
op.add_option("--xdriver", dest="xdriver", action="store", type="string", default=None)
# Language
op.add_option("--keymap")
op.add_option("--kbdtype")
op.add_option("--lang")
# Obvious
op.add_option("--loglevel")
op.add_option("--syslog")
op.add_option("--noselinux", dest="selinux", action="store_false", default=True)
op.add_option("--selinux", action="store_true")
op.add_option("--nompath", dest="mpath", action="store_false", default=False)
op.add_option("--mpath", action="store_true")
op.add_option("--nodmraid", dest="dmraid", action="store_false", default=True)
op.add_option("--dmraid", action="store_true")
op.add_option("--noibft", dest="ibft", action="store_false", default=True)
op.add_option("--ibft", action="store_true")
op.add_option("--noiscsi", dest="iscsi", action="store_false", default=False)
op.add_option("--iscsi", action="store_true")
# Miscellaneous
op.add_option("--module", action="append", default=[])
op.add_option("--nomount", dest="rescue_nomount", action="store_true", default=False)
op.add_option("--updates", dest="updateSrc", action="store", type="string")
op.add_option("--dlabel", action="store_true", default=False)
return op.parse_args()
def setupPythonPath():
# For anaconda in test mode
if (os.path.exists('isys')):
sys.path.append('isys')
sys.path.append('textw')
sys.path.append('iw')
else:
sys.path.append('/usr/lib/anaconda')
sys.path.append('/usr/lib/anaconda/textw')
sys.path.append('/usr/lib/anaconda/iw')
if (os.path.exists('booty')):
sys.path.append('booty')
sys.path.append('booty/edd')
else:
sys.path.append('/usr/lib/booty')
sys.path.append('/usr/share/system-config-date')
def probeHW(opts, x_already_set, xserver):
#
# Probe what is available for X and setup a hardware state
#
# try to probe interesting hw
skipmouseprobe = not (not os.environ.has_key('DISPLAY') or flags.setupFilesystems)
xserver.probeHW(skipMouseProbe=skipmouseprobe, forceDriver=opts.xdriver)
# if the len(videocards) is zero, then let's assume we're isHeadless
if len(xserver.videohw.videocards) == 0:
stdoutLog.info (_("No video hardware found, assuming headless"))
opts.isHeadless = 1
else:
# setup a X hw state for use later with configuration.
try:
xserver.setHWState()
except Exception, e:
stdoutLog.error (_("Unable to instantiate a X hardware state object."))
# keyboard
xserver.keyboard = keyboard.Keyboard()
if opts.keymap:
xserver.keyboard.set(opts.keymap)
def setupGraphicalLinks():
for i in ( "imrc", "im_palette.pal", "gtk-2.0", "pango", "fonts",
"fb.modes"):
try:
if os.path.exists("/mnt/runtime/etc/%s" %(i,)):
os.symlink ("../mnt/runtime/etc/" + i, "/etc/" + i)
except:
pass
if __name__ == "__main__":
setupPythonPath()
(opts, args) = parseOptions()
import logging
from anaconda_log import logger, logLevelMap
log = logging.getLogger("anaconda")
stdoutLog = logging.getLogger("anaconda.stdout")
import signal, traceback, string, isys, iutil, time
import xsetup
import rhpxl.xhwstate
import rhpxl.xserver
import rhpxl.monitor
iutil.makeCharDeviceNodes()
import rhpl.keyboard as keyboard
x_already_set = 0
if os.environ.has_key('DISPLAY'):
x_already_set = 1
else:
x_already_set = 0
xserver = rhpxl.xserver.XServer()
xserver.resolution = "640x480"
probeHW(opts, x_already_set, xserver)
rhpxl.xhwstate.get_valid_resolution(xserver)
xserver_pid = None
if os.access("/tmp/ramfs", os.W_OK):
xserver.logfile = "/tmp/ramfs/X.log"
try:
xserver.generateConfig()
xserver.addExtraScreen("Anaconda")
xserver.display = ":1"
xserver.serverflags.extend(["-screen", "Anaconda", "-br"])
xserver_pid = xserver.startX(xStartedCB=doStartupX11Actions)
except RuntimeError:
stdoutLog.warning(" X startup failed, falling back to text mode")
opts.display_mode = 't'
graphical_failed = 1
time.sleep(2)
import gtk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment