home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / bin / anaconda next >
Encoding:
Text File  |  2000-03-08  |  9.2 KB  |  359 lines

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