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

1.1       harris41    1: #!/usr/bin/python
                      2: 
                      3: import sys, os, signal
                      4: signal.signal(signal.SIGINT, signal.SIG_DFL)
                      5: 
                      6: #
                      7: # For anaconda in reconfig mode
                      8: #
1.2     ! harris41    9: sys.path.append('../reconfiglib/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'
                    156: 
                    157: #
                    158: # must specify install or reconfig mode
                    159: #
                    160: if (progmode == None):
                    161:     print "Must specify either --reconfig or --method for program mode"
                    162:     sys.exit(1)
                    163: 
                    164: #
                    165: # if not just reconfiguring box, must have install method
                    166: #
                    167: if (not reconfigOnly  and not method):
                    168:     print "no install method specified"
                    169:     sys.exit(1)
                    170: 
                    171: if (debug):
                    172:     import pdb
                    173:     pdb.set_trace()
                    174: #
                    175: # don't let a developer reinstall their box unknowingly
                    176: #
                    177: if (not reconfigOnly and not test and not localInstall and os.getpid() > 50):
                    178:     print "you're running me on a live system! that's incredibly stupid."
                    179:     sys.exit(1)
                    180: 
                    181: import rpm
                    182: import lilo
                    183: from todo import ToDo
                    184: import isys
                    185: from installclass import DefaultInstall
                    186: from installclass import ReconfigStation
                    187: from kickstart import Kickstart
                    188: 
                    189: #
                    190: # override display mode if machine cannot nicely run X
                    191: #
                    192: if (not test):
                    193:     if (iutil.memInstalled() < 30000):
                    194: 	forced_display_mode = 't'
                    195: 
                    196: #
                    197: # if in reconfig mode set display mode based on inittab default runlevel
                    198: #
                    199: # but always let command line specified mode override defaults
                    200: #
                    201: if (forced_display_mode == None):
                    202:     if (reconfigOnly != 0):
                    203:         if (iutil.getDefaultRunlevel() == '5' and
                    204:             os.access("/etc/X11/XF86Config", os.R_OK)):
                    205:                 display_mode = 'g'
                    206:         else:
                    207:                 display_mode = 't'
                    208:     else:
                    209:         display_mode = 'g'
                    210: else:
                    211:     display_mode = forced_display_mode
                    212: 
                    213: #
                    214: # startup X server is we're not already running under an X session
                    215: #
                    216: if (display_mode == 'g' and not os.environ.has_key('DISPLAY')):
                    217:     import xserver
                    218:     try:
                    219:         if (reconfigOnly == 0):
                    220:             result = xserver.startX ()
                    221:         else:
                    222:             result = xserver.start_existing_X ()
                    223:             
                    224:     except RuntimeError:
                    225: 	print "X startup failed, falling back to text mode"
                    226:         display_mode = 't'
                    227:     else:
                    228:         (mouseInfo, x) = (result)
                    229: 
                    230: #
                    231: # setup links required by graphical mode if installing and verify display mode
                    232: #
                    233: if (display_mode == 'g'):
                    234:     if not test and not localInstall and not reconfigOnly:
                    235:         for i in ( "imrc", "im_palette.pal", "gtk" ):
                    236:             try:
                    237:                 os.symlink ("../mnt/source/RedHat/instimage/etc/" + i, "/etc/" + i)
                    238:             except:
                    239:                 pass
                    240:     from gui import InstallInterface
                    241: elif (display_mode == 't'):
                    242:     from text import InstallInterface
                    243: else:
                    244:     sys.exit(1)
                    245: 
                    246: if traceOnly:
                    247:     # prints a list of all the modules imported
                    248:     import pdb
                    249:     import image
                    250:     import harddrive
                    251:     import urlinstall
                    252:     import mimetools
                    253:     import mimetypes
                    254:     import syslogd
                    255:     if display_mode == 't':
                    256:         from newtpyfsedit import fsedit        
                    257:     for module in sys.__dict__['modules'].keys ():
                    258:         if module not in [ "__builtin__", "__main__" ]:
                    259:             foo = repr (sys.__dict__['modules'][module])
                    260:             bar = string.split (foo, "'")
                    261:             if len (bar) > 3:
                    262:                 print bar[3]
                    263:         
                    264:     sys.exit(0)
                    265: 
                    266: # imports after setting up the path
                    267: if not reconfigOnly:
                    268:     if (method[0:5] == "dir:/"):
                    269:         from image import InstallMethod
                    270:         method = InstallMethod(method[5:])
                    271:     elif (method[0:6] == "ftp://" or method[0:7] == "http://"):
                    272:         from urlinstall import InstallMethod
                    273:         method = InstallMethod(method)
                    274:     elif (method[0:5] == "hd://"):
                    275:         method = method[5:]
                    276:         i = string.index(method, '/')
                    277:         dir = method[i:]
                    278:         driveAndType = method[0:i]
                    279:         
                    280:         i = string.index(driveAndType, ":")
                    281:         drive = driveAndType[0:i]
                    282:         type = driveAndType[i + 1:]
                    283:         
                    284:         from harddrive import InstallMethod
                    285:         method = InstallMethod(drive, type, dir)
                    286:     else:
                    287:         print "unknown install method:", method
                    288:         sys.exit(1)
                    289: 
                    290: #
                    291: # do some final sanity checking before going off into the great wide wonder
                    292: #
                    293: if reconfigOnly and method != None:
                    294:     print "Conflicting options: cannot reconfig and install simultaneously!\n"
                    295:     sys.exit(1)
                    296: intf = InstallInterface()
                    297: 
                    298: # set the default actions
                    299: installPackages = 1
                    300: setupFilesystems = 1
                    301: 
                    302: if localInstall:
                    303:     installPackages = 1
                    304:     setupFilesystems = 0
                    305: if test:
                    306:     installPackages = 0
                    307:     setupFilesystems = 0
                    308: if forceMount:
                    309:     setupFilesystems = 1
                    310: 
                    311: if kickstart:
                    312:     instClass = Kickstart(kickstart)
                    313:     os.unlink(kickstart)
                    314: elif reconfigOnly:
                    315:     instClass = ReconfigStation(expert)
                    316: else:
                    317:     instClass = DefaultInstall(expert)
                    318: 
                    319: if lang:
                    320:     instClass.addToSkipList("language")
                    321:     instClass.setLanguage(lang)
                    322:             
                    323: if keymap:
                    324:     instClass.addToSkipList("keyboard")
                    325:     instClass.setKeyboard(keymap)
                    326: 
                    327: if iutil.getArch() == "sparc":
                    328:     import kudzu
                    329:     mice = kudzu.probe (kudzu.CLASS_MOUSE, kudzu.BUS_UNSPEC, kudzu.PROBE_ONE);
                    330:     if mice:
                    331: 	(mouseDev, driver, descr) = mice[0]
                    332: 	if mouseDev == 'sunmouse':
                    333: 	    instClass.addToSkipList("mouse")
                    334: 	    instClass.setMouseType("Sun - Mouse", "sunmouse")
                    335: 
                    336: if reconfigOnly:
                    337:     installPackages = 0
                    338:     setupFilesystems = 0
                    339:     rootPath = '/'
                    340:     
                    341: try:
                    342:     todo = ToDo(intf, method, rootPath, installSystem = installPackages,
                    343:                 setupFilesystems = setupFilesystems, mouse = mouseInfo,
                    344:                 instClass = instClass, x = x, expert = expert,
                    345:                 serial = serial, reconfigOnly = reconfigOnly, test = test,
                    346:                 extraModules = extraModules)
                    347:     intf.run(todo, test = test)
                    348: except:
                    349:     (type, value, tb) = sys.exc_info()
                    350:     from string import joinfields
                    351:     list = traceback.format_exception (type, value, tb)
                    352:     text = joinfields (list, "")
                    353:     rc = intf.exceptionWindow (_("Exception Occurred"), text)
                    354:     intf.__del__ ()
                    355:     if rc:
                    356:         import pdb
                    357:         pdb.post_mortem (tb)
                    358:     os._exit (1)
                    359: 
                    360: if not todo.reconfigOnly:
                    361:     todo.fstab.umountFilesystems(rootPath, ignoreErrors = 1)
                    362: 
                    363: del intf

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