Annotation of loncom/anaconda/RedHat/instimage/usr/bin/loncapaconfig, revision 1.4

1.4     ! harris41    1: #!../bin/python
1.1       harris41    2: 
                      3: import sys, os, signal
                      4: signal.signal(signal.SIGINT, signal.SIG_DFL)
                      5: 
                      6: #
                      7: # For anaconda in reconfig mode
                      8: #
1.3       harris41    9: sys.path.append('../lib/anaconda')
1.1       harris41   10: 
                     11: # For anaconda in test mode
                     12: if (os.path.exists('rpmmodule')):
                     13:     sys.path.append('rpmmodule')
                     14:     sys.path.append('libfdisk')
                     15:     sys.path.append('balkan')
                     16:     sys.path.append('kudzu')
                     17:     sys.path.append('gnome-map')
                     18:     sys.path.append('isys')
                     19: 
                     20: os.environ['HOME'] = '/tmp'
                     21: 
                     22: # Python passed my path as argv[0]!
                     23: # if sys.argv[0][-7:] == "syslogd":
                     24: if len(sys.argv) > 1:
                     25:     if sys.argv[1] == "--syslogd":
                     26:         from syslogd import Syslogd
                     27:         root = sys.argv[2]
                     28:         output = sys.argv[3]
                     29:         syslog = Syslogd (root, open (output, "w+"))
                     30: 
                     31: import gettext_rh
                     32: import traceback
                     33: import string
                     34: 
                     35: import isys
                     36: import iutil
                     37: 
                     38: setverPath = None
                     39: 
                     40: gettext_rh.bindtextdomain("anaconda", "/usr/share/locale")
                     41: gettext_rh.textdomain("anaconda")
                     42: _ = gettext_rh.gettext
                     43: 
                     44: (args, extra) = isys.getopt(sys.argv[1:], 'GTRtdr:fm:', 
                     45:           [ 'gui', 'text', 'reconfig', 'test', 'debug',
                     46:             'method=', 'rootpath=',
                     47: 	    'testpath=', 'mountfs', 'traceonly', 'kickstart=',
                     48:             'lang=', 'keymap=', 'kbdtype=', 'module=',
                     49: 	    'expert', 'serial' ])
                     50: 
                     51: # save because we're about to munge argv
                     52: [execname] = string.split(sys.argv[0], '/')[-1:]
                     53: 
                     54: # remove the arguments - gnome_init doesn't understand them
                     55: for arg in sys.argv[1:]:
                     56:     sys.argv.remove (arg)
                     57: sys.argc = 1
                     58: 
                     59: #
                     60: # default root to install into if doing a normal install
                     61: #
                     62: rootPath = '/mnt/sysimage'
                     63: 
                     64: extraModules = []
                     65: 
                     66: # display mode is either 'g' for graphical or 't' for text
                     67: display_mode = 'g'
                     68: forced_display_mode = None
                     69: 
                     70: # booleans - value is 0 for false or non-zero for true
                     71: # test           - in test mode?
                     72: # debug          - in debug mode?
                     73: # serial         - install via serial port (?)
                     74: # expert         - in expert mode?
                     75: # traceOnly      - print out loaded modules
                     76: # forceMount     - ? used ?
                     77: # localInstall   - install to chroot
                     78: # reconfigOnly   - allow user to reconfig installed box w/o reinstall
                     79: test = 0
                     80: debug = 0
                     81: serial = 0
                     82: expert = 0
                     83: traceOnly = 0
                     84: forceMount = 0
                     85: localInstall = 0
                     86: reconfigOnly = 0
                     87: 
                     88: #
                     89: # x          - xserver info (?)
                     90: # lang       - language to use for install/machine default
                     91: # method     - install method (not used if reconfigOnly is true)
                     92: # keymap     - kbd map
                     93: # kbdtype    - type of keyboard (84 key, 101 key, etc)
                     94: # kickstart  - ?
                     95: # mouseInfo  - type of mouse
                     96: # progmode   - either 'reconfig' or 'install'
                     97: #
                     98: x = None
                     99: lang = None
                    100: method = None
                    101: keymap = None
                    102: kbdtpye = None
                    103: kickstart = None
                    104: mouseInfo = None
                    105: progmode = None
                    106: 
                    107: #
                    108: # parse off command line arguments
                    109: #
                    110: for n in args:
                    111:     (str, arg) = n
                    112: 
                    113:     if (str == '-G' or str == '--gui'):
                    114: 	forced_display_mode = 'g'
                    115:     elif (str == '-T' or str == '--text'):
                    116: 	forced_display_mode = 't'
                    117:     elif (str == '-R' or str == '--reconfig'):
                    118: 	reconfigOnly = 1
                    119:         progmode = 'reconfig'
                    120:     elif (str == '-t' or str == '--test'):
                    121: 	test = 1
                    122:     elif (str == '--module'):
                    123: 	(path, subdir, name) = string.split(arg, ":")
                    124: 	extraModules.append((path, subdir, name))
                    125:     elif (str == '-m' or str == '--method'):
                    126: 	method = arg
                    127:         reconfigOnly = 0
                    128:         progmode = 'install'
                    129:     elif (str == '-d' or str == '--debug'):
                    130: 	debug = 1
                    131:     elif (str == '--kickstart'):
                    132: 	kickstart = arg
                    133: 	forced_display_mode = 't'
                    134:     elif (str == '-r' or str == '--rootpath'):
                    135: 	rootPath = arg
                    136: 	localInstall = 1
                    137:     elif (str == '--mountfs'):
                    138: 	forceMount = 1
                    139:     elif (str == '--traceonly'):
                    140: 	traceOnly = 1
                    141:     elif (str == '--expert'):
                    142: 	expert = 1
                    143:     elif (str == '--serial'):
                    144: 	serial = 1
                    145:     elif (str == '--lang'):
                    146:         lang = arg
                    147:     elif (str == '--keymap'):
                    148:         keymap = arg
                    149:     elif (str == '--kbdtype'):
                    150:         kbdtype = arg
                    151: 
                    152: # Make sure that display mode is only text for now
                    153: # since graphical interface code is not yet updated.
                    154: display_mode = 't'
                    155: forced_display_mode = 't'
1.3       harris41  156: 
                    157: # Settings to make sure this script is only ever used
                    158: # for reconfiguration.
                    159: reconfigOnly = 1
                    160: progmode = 'reconfig'
1.1       harris41  161: 
                    162: #
                    163: # must specify install or reconfig mode
                    164: #
                    165: if (progmode == None):
                    166:     print "Must specify either --reconfig or --method for program mode"
                    167:     sys.exit(1)
                    168: 
                    169: #
                    170: # if not just reconfiguring box, must have install method
                    171: #
                    172: if (not reconfigOnly  and not method):
                    173:     print "no install method specified"
                    174:     sys.exit(1)
                    175: 
                    176: if (debug):
                    177:     import pdb
                    178:     pdb.set_trace()
                    179: #
                    180: # don't let a developer reinstall their box unknowingly
                    181: #
                    182: if (not reconfigOnly and not test and not localInstall and os.getpid() > 50):
                    183:     print "you're running me on a live system! that's incredibly stupid."
                    184:     sys.exit(1)
                    185: 
                    186: import rpm
                    187: import lilo
                    188: from todo import ToDo
                    189: import isys
                    190: from installclass import DefaultInstall
                    191: from installclass import ReconfigStation
                    192: from kickstart import Kickstart
                    193: 
                    194: #
                    195: # override display mode if machine cannot nicely run X
                    196: #
                    197: if (not test):
                    198:     if (iutil.memInstalled() < 30000):
                    199: 	forced_display_mode = 't'
                    200: 
                    201: #
                    202: # if in reconfig mode set display mode based on inittab default runlevel
                    203: #
                    204: # but always let command line specified mode override defaults
                    205: #
                    206: if (forced_display_mode == None):
                    207:     if (reconfigOnly != 0):
                    208:         if (iutil.getDefaultRunlevel() == '5' and
                    209:             os.access("/etc/X11/XF86Config", os.R_OK)):
                    210:                 display_mode = 'g'
                    211:         else:
                    212:                 display_mode = 't'
                    213:     else:
                    214:         display_mode = 'g'
                    215: else:
                    216:     display_mode = forced_display_mode
                    217: 
                    218: #
                    219: # startup X server is we're not already running under an X session
                    220: #
                    221: if (display_mode == 'g' and not os.environ.has_key('DISPLAY')):
                    222:     import xserver
                    223:     try:
                    224:         if (reconfigOnly == 0):
                    225:             result = xserver.startX ()
                    226:         else:
                    227:             result = xserver.start_existing_X ()
                    228:             
                    229:     except RuntimeError:
                    230: 	print "X startup failed, falling back to text mode"
                    231:         display_mode = 't'
                    232:     else:
                    233:         (mouseInfo, x) = (result)
                    234: 
                    235: #
                    236: # setup links required by graphical mode if installing and verify display mode
                    237: #
                    238: if (display_mode == 'g'):
                    239:     if not test and not localInstall and not reconfigOnly:
                    240:         for i in ( "imrc", "im_palette.pal", "gtk" ):
                    241:             try:
                    242:                 os.symlink ("../mnt/source/RedHat/instimage/etc/" + i, "/etc/" + i)
                    243:             except:
                    244:                 pass
                    245:     from gui import InstallInterface
                    246: elif (display_mode == 't'):
                    247:     from text import InstallInterface
                    248: else:
                    249:     sys.exit(1)
                    250: 
                    251: if traceOnly:
                    252:     # prints a list of all the modules imported
                    253:     import pdb
                    254:     import image
                    255:     import harddrive
                    256:     import urlinstall
                    257:     import mimetools
                    258:     import mimetypes
                    259:     import syslogd
                    260:     if display_mode == 't':
                    261:         from newtpyfsedit import fsedit        
                    262:     for module in sys.__dict__['modules'].keys ():
                    263:         if module not in [ "__builtin__", "__main__" ]:
                    264:             foo = repr (sys.__dict__['modules'][module])
                    265:             bar = string.split (foo, "'")
                    266:             if len (bar) > 3:
                    267:                 print bar[3]
                    268:         
                    269:     sys.exit(0)
                    270: 
                    271: # imports after setting up the path
                    272: if not reconfigOnly:
                    273:     if (method[0:5] == "dir:/"):
                    274:         from image import InstallMethod
                    275:         method = InstallMethod(method[5:])
                    276:     elif (method[0:6] == "ftp://" or method[0:7] == "http://"):
                    277:         from urlinstall import InstallMethod
                    278:         method = InstallMethod(method)
                    279:     elif (method[0:5] == "hd://"):
                    280:         method = method[5:]
                    281:         i = string.index(method, '/')
                    282:         dir = method[i:]
                    283:         driveAndType = method[0:i]
                    284:         
                    285:         i = string.index(driveAndType, ":")
                    286:         drive = driveAndType[0:i]
                    287:         type = driveAndType[i + 1:]
                    288:         
                    289:         from harddrive import InstallMethod
                    290:         method = InstallMethod(drive, type, dir)
                    291:     else:
                    292:         print "unknown install method:", method
                    293:         sys.exit(1)
                    294: 
                    295: #
                    296: # do some final sanity checking before going off into the great wide wonder
                    297: #
                    298: if reconfigOnly and method != None:
                    299:     print "Conflicting options: cannot reconfig and install simultaneously!\n"
                    300:     sys.exit(1)
                    301: intf = InstallInterface()
                    302: 
                    303: # set the default actions
                    304: installPackages = 1
                    305: setupFilesystems = 1
                    306: 
                    307: if localInstall:
                    308:     installPackages = 1
                    309:     setupFilesystems = 0
                    310: if test:
                    311:     installPackages = 0
                    312:     setupFilesystems = 0
                    313: if forceMount:
                    314:     setupFilesystems = 1
                    315: 
                    316: if kickstart:
                    317:     instClass = Kickstart(kickstart)
                    318:     os.unlink(kickstart)
                    319: elif reconfigOnly:
                    320:     instClass = ReconfigStation(expert)
                    321: else:
                    322:     instClass = DefaultInstall(expert)
                    323: 
                    324: if lang:
                    325:     instClass.addToSkipList("language")
                    326:     instClass.setLanguage(lang)
                    327:             
                    328: if keymap:
                    329:     instClass.addToSkipList("keyboard")
                    330:     instClass.setKeyboard(keymap)
                    331: 
                    332: if iutil.getArch() == "sparc":
                    333:     import kudzu
                    334:     mice = kudzu.probe (kudzu.CLASS_MOUSE, kudzu.BUS_UNSPEC, kudzu.PROBE_ONE);
                    335:     if mice:
                    336: 	(mouseDev, driver, descr) = mice[0]
                    337: 	if mouseDev == 'sunmouse':
                    338: 	    instClass.addToSkipList("mouse")
                    339: 	    instClass.setMouseType("Sun - Mouse", "sunmouse")
                    340: 
                    341: if reconfigOnly:
                    342:     installPackages = 0
                    343:     setupFilesystems = 0
                    344:     rootPath = '/'
                    345:     
                    346: try:
                    347:     todo = ToDo(intf, method, rootPath, installSystem = installPackages,
                    348:                 setupFilesystems = setupFilesystems, mouse = mouseInfo,
                    349:                 instClass = instClass, x = x, expert = expert,
                    350:                 serial = serial, reconfigOnly = reconfigOnly, test = test,
                    351:                 extraModules = extraModules)
                    352:     intf.run(todo, test = test)
                    353: except:
                    354:     (type, value, tb) = sys.exc_info()
                    355:     from string import joinfields
                    356:     list = traceback.format_exception (type, value, tb)
                    357:     text = joinfields (list, "")
                    358:     rc = intf.exceptionWindow (_("Exception Occurred"), text)
                    359:     intf.__del__ ()
                    360:     if rc:
                    361:         import pdb
                    362:         pdb.post_mortem (tb)
                    363:     os._exit (1)
                    364: 
                    365: if not todo.reconfigOnly:
                    366:     todo.fstab.umountFilesystems(rootPath, ignoreErrors = 1)
                    367: 
                    368: del intf

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>