summaryrefslogtreecommitdiffstats
path: root/booty/sparc.py
blob: 5b379b90c479e160e6fd489cb2d397b9ac32d833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
import os

from booty import BootyNoKernelWarning
from bootloaderInfo import *

class sparcBootloaderInfo(bootloaderInfo):
    def writeSilo(self, instRoot, bl, kernelList,
                chainList, defaultDev, justConfigFile):

        try:
            bootDev = self.storage.fsset.mountpoints["/boot"]

            mf = '/silo.message'
            cf = "/boot/silo.conf"
            mfdir = '/boot'
            cfPath = ""
            if not os.path.isdir(instRoot + "/boot"):
                os.mkdir(instRoot + "/boot")
        except KeyError:
            bootDev = self.storage.fsset.rootDevice

            cf = "/etc/silo.conf"
            mfdir = '/etc'
            cfPath = "/boot"

        f = open(instRoot + mfdir + mf, "w+")
        f.write("Welcome to %s!\nHit <TAB> for boot options\n\n" % productName)
        f.close()
        os.chmod(instRoot + mfdir + mf, 0600)

        f = open(instRoot + cf, "w+")
        f.write("# silo.conf generated by anaconda\n\n")

        f.write("#boot=%s\n" % (bootDev.path,))
        f.write("message=%s\n" % (mf,))
        f.write("timeout=%s\n" % (self.timeout or 50))

        (name, partNum) = getDiskPart(bootDev, self.storage)
        partno = partNum + 1
        f.write("partition=%s\n" % (partno,))

        if self.password:
            f.write("password=%s\n" % (self.password,))
            f.write("restricted\n")

        f.write("default=%s\n" % (kernelList[0][0],))
        f.write("\n")

        rootDev = self.storage.fsset.rootDevice

        for (label, longlabel, version) in kernelList:
            kernelTag = "-" + version
            kernelFile = "%s/vmlinuz%s" % (cfPath, kernelTag)

            f.write("image=%s\n" % (kernelFile,))
            f.write("\tlabel=%s\n" % (label,))
            f.write("\tread-only\n")

            initrd = self.makeInitrd(kernelTag)
            if os.access(instRoot + initrd, os.R_OK):
                f.write("\tinitrd=%s/initrd%s.img\n" % (cfPath, kernelTag))

            append = "%s" % (self.args.get(),)

            realroot = rootDev.fstabSpec
            if rootIsDevice(realroot):
                f.write("\troot=%s\n" % (realroot,))
            else:
                if len(append) > 0:
                    append = "%s root=%s" % (append, realroot)
                else:
                    append = "root=%s" % (realroot,)

            if len(append) > 0:
                f.write("\tappend=\"%s\"\n" % (append,))
            f.write("\n")

        f.close()
        os.chmod(instRoot + cf, 0600)

        # FIXME: hack to make sure things are written to disk
        import isys
        isys.sync()
        isys.sync()
        isys.sync()

        backup = "%s/backup.b" % (cfPath,)
        sbinargs = ["/sbin/silo", "-f", "-C", cf, "-S", backup]
        # TODO!!!  FIXME!!!  XXX!!!
        # butil is not defined!!!  - assume this is in rhpl now?
        if butil.getSparcMachine() == "sun4u":
            sbinargs += ["-u"]
        else:
            sbinargs += ["-U"]

        if not flags.test:
            rc = iutil.execWithRedirect(sbinargs[0],
                                        sbinargs[1:],
                                        stdout = "/dev/tty5",
                                        stderr = "/dev/tty5",
                                        root = instRoot)
            if rc:
                return rc

        if (not os.access(instRoot + "/etc/silo.conf", os.R_OK) and
            os.access(instRoot + "/boot/etc/silo.conf", os.R_OK)):
            os.symlink("../boot/etc/silo.conf",
                       instRoot + "/etc/silo.conf")

        return 0

    def setPassword(self, val, isCrypted = 1):
        # silo just handles the password unencrypted
        self.password = val

    def write(self, instRoot, bl, kernelList, chainList,
            defaultDev, justConfig):
        if len(kernelList) >= 1:
            return self.writeSilo(instRoot, bl, kernelList, chainList,
                                  defaultDev, justConfig)
        else:
            raise BootyNoKernelWarning

    def __init__(self, instData):
        bootloaderInfo.__init__(self, instData)
        self.useSiloVal = 1
        self.kernelLocation = "/boot"
        self._configdir = "/etc"
        self._configname = "silo.conf"