summaryrefslogtreecommitdiffstats
path: root/utils/hash.h
diff options
context:
space:
mode:
authorJeremy Katz <katzj@redhat.com>2002-12-03 20:48:03 +0000
committerJeremy Katz <katzj@redhat.com>2002-12-03 20:48:03 +0000
commitd7f878ecd0370b3edfb5da143189d9141d92660a (patch)
treec7abac1c6c103cdcdcae2b2385adf2c7f167f081 /utils/hash.h
parentfda8f4f2f7522b2155a2b0547d0b89dacf10563b (diff)
translations for the loader returnbefore-loader-switch
Diffstat (limited to 'utils/hash.h')
0 files changed, 0 insertions, 0 deletions
='#n103'>103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
#
# rescue.py - anaconda rescue mode setup
#
# Mike Fulbright <msf@redhat.com>
# Jeremy Katz <katzj@redhat.com>
#
# Copyright 2001-2004 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 upgrade
from snack import *
from constants_text import *
from text import WaitWindow, OkCancelWindow, ProgressWindow, stepToClasses
from flags import flags
import sys
import os
import isys
import iutil
import fsset
import shutil
import fcntl
import termios

from rhpl.translate import _

import logging
log = logging.getLogger("anaconda")

class RescueInterface:
    def waitWindow(self, title, text):
	return WaitWindow(self.screen, title, text)

    def progressWindow(self, title, text, total):
	return ProgressWindow(self.screen, title, text, total)
	
    def messageWindow(self, title, text, type = "ok"):
	if type == "ok":
	    ButtonChoiceWindow(self.screen, _(title), _(text),
			       buttons = [ _("OK") ])
        elif type == "yesno":
            btnlist = [TEXT_YES_BUTTON, TEXT_NO_BUTTON]
	    rc = ButtonChoiceWindow(self.screen, _(title), _(text),
			       buttons=btnlist)
            if rc == "yes":
                return 1
            else:
                return 0
	else:
	    return OkCancelWindow(self.screen, _(title), _(text))

    def __init__(self, screen):
	self.screen = screen

# XXX grub-install is stupid and uses df output to figure out
# things when installing grub.  make /etc/mtab be at least
# moderately useful.  
def makeMtab(instPath, theFsset):
    child = os.fork()
    if (not child):
        os.chroot(instPath)
        f = open("/etc/mtab", "w+")
        f.write(theFsset.mtab())
        f.close()
        os._exit(0)

# make sure they have a resolv.conf in the chroot
def makeResolvConf(instPath):
    if not os.access("/etc/resolv.conf", os.R_OK):
        return
    
    if os.access("%s/etc/resolv.conf" %(instPath,), os.R_OK):
        f = open("%s/etc/resolv.conf" %(instPath,), "r")
        buf = f.read()
        f.close()
    else:
        buf = ""

    # already have a nameserver line, don't worry about it
    if buf.find("nameserver") != -1:
        return

    f = open("/etc/resolv.conf", "r")
    buf = f.read()
    f.close()

    # no nameserver, we can't do much about it
    if buf.find("nameserver") == -1:
        return

    shutil.copyfile("%s/etc/resolv.conf" %(instPath,),
                    "%s/etc/resolv.conf.bak" %(instPath,))
    f = open("%s/etc/resolv.conf" %(instPath,), "w+")
    f.write(buf)
    f.close()

# XXX
#     probably belongs somewhere else
#
def methodUsesNetworking(methodstr):
    for m in ['http://', 'ftp://', 'nfs:/', 'nfsiso:/']:
	if methodstr.startswith(m):
	    return 1
    return 0

# XXX
#     hack to write out something useful for networking and start interfaces
#
def startNetworking(network, intf):

    # do lo first
    try:
	os.system("/usr/sbin/ifconfig lo 127.0.0.1")
    except:
	log.error("Error trying to start lo in rescue.py::startNetworking()")

    # start up dhcp interfaces first
    dhcpGotNS = 0
    devs = network.netdevices.keys()
    devs.sort()
    for devname in devs:
	dev = network.netdevices[devname]
	waitwin = intf.waitWindow(_("Starting Interface"),
				  _("Attempting to start %s") % (dev.get('device'),))
	log.info("Attempting to start %s", dev.get('device'))
	if dev.get('bootproto') == "dhcp":
	    try:
		ns = isys.pumpNetDevice(dev.get('device'))
		if ns:
		    if not dhcpGotNS:
			dhcpGotNS = 1

			f = open("/etc/resolv.conf", "w")
			f.write("nameserver %s\n" % ns)
			f.close()
	    except:
		log.error("Error trying to start %s in rescue.py::startNetworking()", dev.get('device'))
	elif dev.get('ipaddr') and dev.get('netmask') and network.gateway is not None:
	    try:
		isys.configNetDevice(dev.get('device'),
				     dev.get('ipaddr'),
				     dev.get('netmask'),
				     network.gateway)
	    except:
		log.error("Error trying to start %s in rescue.py::startNetworking()", dev.get('device'))

	waitwin.pop()
	
    # write out resolv.conf if dhcp didnt get us one
    if not dhcpGotNS:
        f = open("/etc/resolv.conf", "w")

	if network.domains != ['localdomain'] and network.domains:
	    f.write("search %s\n" % (string.joinfields(network.domains, ' '),))

        for ns in network.nameservers():
            if ns:
                f.write("nameserver %s\n" % (ns,))

        f.close()

def runShell(screen = None, msg=""):
    if screen:
        screen.suspend()

    print
    if msg:
        print (msg)
    print _("When finished please exit from the shell and your "
            "system will reboot.")
    print

    if os.path.exists("/bin/sh"):
        iutil.execConsole()
    else:
        print "Unable to find /bin/sh to execute!  Not starting shell"
        time.sleep(5)

    if screen:
        screen.finish()

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 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)
		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(instClass)

    # 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' "