home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / kickstart.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  10.0 KB  |  398 lines

  1. import isys
  2. import os
  3. from installclass import InstallClass
  4. from installclass import FSEDIT_CLEAR_LINUX
  5. from installclass import FSEDIT_CLEAR_ALL
  6. import sys
  7. import string
  8.  
  9. class Kickstart(InstallClass):
  10.  
  11.     def doRootPw(self, args):
  12.     (args, extra) = isys.getopt(args, '', [ 'iscrypted' ])
  13.  
  14.     isCrypted = 0
  15.     for n in args:
  16.         (str, arg) = n
  17.         if (str == '--iscrypted'):
  18.         isCrypted = 1
  19.  
  20.     if len(extra) != 1:
  21.         raise ValueError, "a single argument is expected to rootPw"
  22.  
  23.     InstallClass.doRootPw(self, extra[0], isCrypted = isCrypted)
  24.     self.addToSkipList("accounts")
  25.  
  26.     def doAuthconfig(self, args):
  27.     (args, extra) = isys.getopt(args, '',
  28.         [ 'enablenis', 'nisdomain=', 'nisserver=', 'useshadow',
  29.           'enablemd5' ])
  30.  
  31.     useNis = 0
  32.     useShadow = 0
  33.     useMd5 = 0
  34.     nisServer = None
  35.     nisDomain = None
  36.     nisBroadcast = 0
  37.     
  38.     for n in args:
  39.         (str, arg) = n
  40.         if (str == '--enablenis'):
  41.         useNis = 1
  42.         elif (str == '--useshadow'):
  43.         useShadow = 1
  44.         elif (str == '--enablemd5'):
  45.         useMd5 = 1
  46.         elif (str == '--nisserver'):
  47.         nisServer = arg
  48.         elif (str == '--nisdomain'):
  49.         nisDomain = arg
  50.  
  51.     if useNis and not nisServer: nisBroadcast = 1
  52.         
  53.     self.setAuthentication(useShadow, useMd5, useNis, nisDomain,
  54.                    nisBroadcast, nisServer)
  55.     self.addToSkipList("authentication")
  56.  
  57.     def doLilo    (self, args):
  58.     (args, extra) = isys.getopt(args, '',
  59.         [ 'append=', 'location=', 'linear' ])
  60.  
  61.     appendLine = None
  62.     location = "mbr"
  63.     linear = 0
  64.  
  65.     for n in args:
  66.         (str, arg) = n
  67.         if str == '--append':
  68.         appendLine = arg
  69.         elif str == '--linear':
  70.         linear = 1
  71.         elif str == '--location':
  72.             if arg == 'mbr' or arg == 'partition':
  73.             location = arg
  74.         elif arg == 'none':
  75.             location = None
  76.         else:
  77.             raise ValueError, ("mbr, partition or none expected for "+
  78.             "lilo command")
  79.  
  80.     self.setLiloInformation(location, linear, appendLine)
  81.     self.addToSkipList("lilo")
  82.  
  83.     def doLiloCheck (self, args):
  84.         drives = isys.hardDriveList ().keys()
  85.     drives.sort(isys.compareDrives)
  86.     device = drives[0]
  87.     isys.makeDevInode(device, '/tmp/' + device)
  88.     fd = os.open('/tmp/' + device, os.O_RDONLY)
  89.     os.unlink('/tmp/' + device)
  90.     block = os.read(fd, 512)
  91.     os.close(fd)
  92.     if block[6:10] == "LILO":
  93.         sys.exit(0)
  94.  
  95.     def doTimezone(self, args):
  96.     (args, extra) = isys.getopt(args, '',
  97.         [ 'utc' ])
  98.  
  99.     isUtc = 0
  100.     
  101.     for n in args:
  102.         (str, arg) = n
  103.         if str == '--utc':
  104.         isUtc = 1
  105.  
  106.     self.setTimezoneInfo(extra[0], asUtc = isUtc)
  107.  
  108.     self.addToSkipList("timezone")
  109.  
  110.  
  111.     def doXconfig(self, args):
  112.     (args, extra) = isys.getopt(args, '',
  113.         [ 'server=', 'card=', 'monitor=', 'hsync=', 'vsync=',
  114.           'startxonboot', 'noprobe' ])
  115.  
  116.     if extra:
  117.         raise ValueError, "unexpected arguments to xconfig command"
  118.  
  119.     server = None
  120.     card = None
  121.     monitor = None
  122.     hsync = None
  123.     vsync = None
  124.         noProbe = 0
  125.     startX = 0
  126.  
  127.     for n in args:
  128.         (str, arg) = n
  129.         if (str == "--noprobe"):
  130.         noProbe = 1
  131.         elif (str == "--server"):
  132.         server = arg
  133.         elif (str == "--card"):
  134.         card = arg
  135.         elif (str == "--monitor"):
  136.         monitor = arg
  137.         elif (str == "--hsync"):
  138.         hsync = arg
  139.         elif (str == "--vsync"):
  140.         vsync = arg
  141.         elif (str == "--startxonboot"):
  142.         startX = 1
  143.  
  144.     self.configureX(server, card, monitor, hsync, vsync, noProbe,
  145.                 startX)
  146.     self.addToSkipList("xconfig")
  147.  
  148.     def doInstall(self, args):
  149.     self.installType = "install"
  150.  
  151.     def doUpgrade(self, args):
  152.     self.installType = "upgrade"
  153.  
  154.     def doNetwork(self, args):
  155.     # nodns is only used by the loader
  156.     (args, extra) = isys.getopt(args, '',
  157.         [ 'bootproto=', 'ip=', 'netmask=', 'gateway=', 'nameserver=',
  158.           'nodns', 'hostname='])
  159.     bootProto = "dhcp"
  160.     ip = None
  161.     netmask = ""
  162.     gateway = ""
  163.     nameserver = ""
  164.     hostname = ""
  165.     for n in args:
  166.         (str, arg) = n
  167.         if str == "--bootproto":
  168.         bootProto = arg
  169.         elif str == "--ip":
  170.         ip = arg
  171.         elif str == "--netmask":
  172.         netmask = arg
  173.         elif str == "--gateway":
  174.         gateway = arg
  175.         elif str == "--nameserver":
  176.         nameserver = arg
  177.         elif str == "--hostname":
  178.         hostname = arg
  179.     self.setNetwork(bootProto, ip, netmask, gateway, nameserver)
  180.     if hostname != "":
  181.         self.setHostname(hostname)
  182.  
  183.     def doLang(self, args):
  184.         self.setLanguage(args[0])
  185.         self.addToSkipList("language")
  186.  
  187.     def doKeyboard(self, args):
  188.         self.setKeyboard(args[0])
  189.         self.addToSkipList("keyboard")
  190.  
  191.     def doZeroMbr(self, args):
  192.     if args[0] == "yes":
  193.         self.setZeroMbr(1)
  194.  
  195.     def doMouse(self, args):
  196.     mouseToMouse = {
  197.          "alpsps/2" : "ALPS - GlidePoint (PS/2)",
  198.          "ascii" : "ASCII - MieMouse (serial)",
  199.          "asciips/2" : "ASCII - MieMouse (PS/2)",
  200.          "atibm" : "ATI - Bus Mouse",
  201.          "generic" : "Generic - 2 Button Mouse (serial)" ,
  202.          "generic3" : "Generic - 3 Button Mouse (serial)" ,
  203.          "genericps/2" : "Generic - 2 Button Mouse (PS/2)" ,
  204.          "generic3ps/2" : "Generic - 3 Button Mouse (PS/2)" ,
  205.          "geniusnm" : "Generic - 2 Button Mouse (PS/2)" ,
  206.          "geniusnmps/2" : "Genius - NetMouse (PS/2)" ,
  207.          "geniusnsps/2" : "Genius - NetScroll (PS/2)" ,
  208.          "thinking" : "" ,
  209.          "thinkingps/2" : "" ,
  210.          "logitech" : "Logitech - C7 Mouse (serial, old C7 type)" ,
  211.          "logitechcc" : "Logitech - CC Series (serial)" ,
  212.          "logibm" : "Logitech - Bus Mouse" ,
  213.          "logimman" : "Logitech - MouseMan/FirstMouse (serial)" ,
  214.          "logimmanps/2" : "Logitech - MouseMan/FirstMouse (PS/2)" ,
  215.          "logimman+" : "Logitech - MouseMan+/FirstMouse+ (serial)" ,
  216.          "logimman+ps/2" : "Logitech - MouseMan+/FirstMouse+ (PS/2)" ,
  217.          "microsoft" : "Microsoft - Compatible Mouse (serial)" ,
  218.          "msnew" : "Microsoft - Rev 2.1A or higher (serial)" ,
  219.          "msintelli" : "Microsoft - IntelliMouse (serial)" ,
  220.          "msintellips/2" : "Microsoft - IntelliMouse (PS/2)" ,
  221.          "msbm" : "Microsoft - Bus Mouse" ,
  222.          "mousesystems" : "Mouse Systems - Mouse (serial)" ,
  223.          "mmseries" : "MM - Series (serial)" ,
  224.          "mmhittab" : "MM - HitTablet (serial)" ,
  225.          "sun" : "Sun - Mouse"
  226.     }
  227.  
  228.     (args, extra) = isys.getopt(args, '', [ 'device=', 'emulthree' ])
  229.         mouseType = "none"
  230.     device = None
  231.     emulThree = 0
  232.  
  233.     for n in args:
  234.         (str, arg) = n
  235.         if str == "--device":
  236.         device = arg
  237.         elif str == "--emulthree":
  238.         emulThree = 1
  239.  
  240.     if extra:
  241.         mouseType = extra[0]
  242.  
  243.     if mouseType != "none":
  244.         self.setMouseType(mouseToMouse[mouseType], device, emulThree)
  245.  
  246.         self.addToSkipList("mouse")
  247.  
  248.     def doReboot(self, args):
  249.         self.addToSkipList("complete")
  250.  
  251.     def doSkipX(self, args):
  252.         self.addToSkipList("xconfig")
  253.  
  254.     def readKickstart(self, file):
  255.     handlers = { 
  256.              "auth"        : self.doAuthconfig    ,
  257.              "authconfig"    : self.doAuthconfig    ,
  258.              "cdrom"        : None            ,
  259.              "clearpart"    : self.doClearPart    ,
  260.              "device"        : None            ,
  261.              "driverdisk"    : None            ,
  262.              "harddrive"    : None            ,
  263.              "install"        : self.doInstall    ,
  264.              "keyboard"        : self.doKeyboard    ,
  265.              "lang"        : self.doLang        ,
  266.              "lilo"        : self.doLilo        ,
  267.              "lilocheck"    : self.doLiloCheck    ,
  268.              "mouse"        : self.doMouse        ,
  269.              "network"        : self.doNetwork    ,
  270.              "nfs"        : None            ,
  271.              "part"        : self.definePartition    ,
  272.              "partition"    : self.definePartition    ,
  273.              "raid"        : self.defineRaid    ,
  274.              "reboot"        : self.doReboot        ,
  275.              "rootpw"        : self.doRootPw        ,
  276.              "skipx"        : self.doSkipX        ,
  277.              "text"        : None            ,
  278.              "timezone"        : self.doTimezone    ,
  279.              "upgrade"        : self.doUpgrade    ,
  280.              "xconfig"        : self.doXconfig    ,
  281.              "xdisplay"        : None            ,
  282.              "zerombr"        : self.doZeroMbr    ,
  283.            }
  284.  
  285.     where = "commands"
  286.     packages = []
  287.     groups = []
  288.     post = ""
  289.     postInChroot = 1
  290.     for n in open(file).readlines():
  291.         if where == "post":
  292.         post = post + n
  293.         else:
  294.         n = n[:len(n) - 1]        # chop
  295.  
  296.         args = isys.parseArgv(n)
  297.         if not args or args[0][0] == '#': continue
  298.  
  299.         if where == "commands":
  300.             cmd = args[0]
  301.             if cmd == "%packages":
  302.             where = "packages"
  303.             elif cmd[0:5] == "%post":
  304.             args = isys.parseArgv(n)
  305.             if len(args) >= 2 and args[1] == "--nochroot":
  306.                 postInChroot = 0
  307.             where = "post"
  308.             elif handlers[cmd]: 
  309.             handlers[cmd](args[1:])
  310.         elif where == "packages":
  311.             if n[0:5] == "%post":
  312.             args = isys.parseArgv(n)
  313.             if len(args) >= 2 and args[1] == "--nochroot":
  314.                 postInChroot = 0
  315.             where = "post"
  316.             elif n[0] == '@':
  317.             n = n[1:]
  318.                         n = string.strip (n)
  319.             groups.append(n)
  320.             else:
  321.                         n = string.strip (n)
  322.             packages.append(n)
  323.  
  324.     self.setGroups(groups)
  325.     self.setPackages(packages)
  326.     self.setPostScript(post, postInChroot)
  327.  
  328.     def doClearPart(self, args):
  329.     if args[0] == '--linux':
  330.         clear = FSEDIT_CLEAR_LINUX
  331.     elif args[0] == '--all':
  332.         clear = FSEDIT_CLEAR_ALL
  333.     self.setClearParts(clear)
  334.  
  335.     def defineRaid(self, args):
  336.     (args, extra) = isys.getopt(args, '', [ 'level=', 'device=' ] )
  337.                     
  338.     for n in args:
  339.         (str, arg) = n
  340.         if str == '--level':
  341.         level = int(arg)
  342.         elif str == "--device":
  343.         raidDev = arg
  344.  
  345.     mntPoint = extra[0]
  346.     extra = extra[1:]
  347.  
  348.     self.addRaidEntry(mntPoint, raidDev, level, extra)
  349.  
  350.     def definePartition(self, args):
  351.     # we just set up the desired partitions -- magic in our base class 
  352.     # does the actual partitioning (no, you don't want to know the 
  353.     # details)
  354.     size = 0
  355.     grow = 0
  356.     maxSize = -1
  357.     device = None
  358.     onPart = None
  359.  
  360.     (args, extra) = isys.getopt(args, '', [ 'size=', 'maxsize=', 
  361.                     'grow', 'onpart=', 'ondisk=' ])
  362.  
  363.     for n in args:
  364.         (str, arg) = n
  365.         if str == '--size':
  366.         size = int(arg)
  367.         elif str == '--maxsize':
  368.         maxSize = int(arg)
  369.         elif str == '--grow':
  370.         grow = 1
  371.         elif str == '--onpart':
  372.         onPart = arg
  373.         elif str == '--ondisk':
  374.         device = arg
  375.  
  376.     if len(extra) != 1:
  377.         raise ValueError, "partition command requires one anonymous argument"
  378.  
  379.     if onPart:
  380.         self.addToFstab(extra[0], onPart)
  381.     else:
  382.         self.addNewPartition(extra[0], size, maxSize, grow, device)
  383.  
  384.     def __init__(self, file):
  385.     InstallClass.__init__(self)
  386.     self.addToSkipList("bootdisk")
  387.         self.addToSkipList("welcome")
  388.         self.addToSkipList("package-selection")
  389.         self.addToSkipList("confirm-install")
  390.         self.addToSkipList("custom-upgrade")
  391.         self.addToSkipList("network")
  392.     self.setEarlySwapOn(1)
  393.     self.partitions = []
  394.  
  395.     self.installType = "install"
  396.     self.readKickstart(file)
  397.  
  398.