summaryrefslogtreecommitdiffstats
path: root/todo.py
blob: d59576fcfcb130f7fd3b3e6a1d31aff9422daa43 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# For an install to proceed, the following todo fields must be filled in
#
#	mount list (unless todo.runLive)		addMount()
#	lilo boot.b installation (may be None)		liloLocation()

import rpm, os
import util, isys
from lilo import LiloConfiguration

def instCallback(what, amount, total, key, data):
    if (what == rpm.RPMCALLBACK_INST_OPEN_FILE):
	(h, method) = key
	data.setPackage(h[rpm.RPMTAG_NAME])
	data.setPackageScale(0, 1)
	fn = method.getFilename(h)
	d = os.open(fn, os.O_RDONLY)
	return d
    elif (what == rpm.RPMCALLBACK_INST_PROGRESS):
	data.setPackageScale(amount, total)

class ToDo:

    def umountFilesystems(self):
	if (not self.setupFilesystems): return 

	self.mounts.sort(mountListCmp)
	self.mounts.reverse()
	for n in self.mounts:
	    isys.umount(n)

    def makeFilesystems(self):
	if (not self.setupFilesystems): return 

	self.mounts.sort(mountListCmp)
	for n in self.mounts:
	    (device, mntpoint, format) = n
	    if not format: continue
	    w = self.intf.waitWindow("Formatting", 
			"Formatting %s filesystem..." % (mntpoint,))
	    util.execWithRedirect("mke2fs", [ "mke2fs", device ],
				  stdout = None, searchPath = 1)
	    w.pop()

    def mountFilesystems(self):
	if (not self.setupFilesystems): return 

	for n in self.mounts:
	    (device, mntpoint, format) = n
	    isys.mount(device, self.instPath + mntpoint)

    def doInstall(self):
	# make sure we have the header list and comps file
	self.headerList()
	self.compsList()

	self.makeFilesystems()
	self.mountFilesystems()

	if not self.installSystem: 
	    return

	os.mkdir(self.instPath + '/var')
	os.mkdir(self.instPath + '/var/lib')
	os.mkdir(self.instPath + '/var/lib/rpm')

	db = rpm.opendb(1, self.instPath)
	ts = rpm.TransactionSet(self.instPath, db)

	for p in self.hdList.selected():
	    ts.add(p.h, (p.h, self.method))

	ts.order()
	p = self.intf.packageProgessWindow()
	ts.run(0, 0, instCallback, p)

	self.installLilo()

	util.execWithRedirect(self.instPath + '/sbin/lilo' , [ "lilo", 
				"-r", self.instPath ], stdout = None)

    def installLilo(self):
	if not self.liloDevice: return

	# FIXME: make an initrd here

	l = LiloConfiguration()
	l.addEntry("boot", self.liloDevice)
	l.addEntry("map", "/boot/map")
	l.addEntry("install", "/boot/boot.b")
	l.addEntry("prompt")
	l.addEntry("timeout", "50")

	sl = LiloConfiguration()
	sl.addEntry("label", "linux")

	for n in self.mounts:
	    (dev, fs, reformat) = n
	    if fs == '/':
		sl.addEntry("root", dev)
	sl.addEntry("read-only")

	kernelFile = '/boot/vmlinuz-' +  \
		str(self.kernelPackage[rpm.RPMTAG_VERSION]) + "-" + \
		str(self.kernelPackage[rpm.RPMTAG_RELEASE])
	    
	l.addImage(kernelFile, sl)
	l.write(self.instPath + "/etc/lilo.conf")

    def addMount(self, device, location, reformat = 1):
	self.mounts.append((device, location, reformat))

    def freeHeaders(self):
	if (self.hdList):
	    self.hdList = None

    def headerList(self):
	if (not self.hdList):
	    w = self.intf.waitWindow("Reading", 
			"Reading package information...")
	    self.hdList = self.method.readHeaders()
	    w.pop()
	return self.hdList

    def liloLocation(self, device):
	self.liloDevice = device

    def compsList(self):
	if (not self.comps):
	    self.headerList()
	    self.comps = self.method.readComps(self.hdList)
	self.comps['Base'].select(1)
	self.kernelPackage = self.hdList['kernel']

	if (self.hdList.has_key('kernel-smp') and isys.smpAvailable()):
	    self.hdList['kernel'].selected = 0
	    self.hdList['kernel-smp'].selected = 1
	    self.kernelPackage = self.hdList['kernel-smp']

	return self.comps

    def __init__(self, intf, method, rootPath, setupFilesystems = 1,
		 installSystem = 1, create):
	self.intf = intf
	self.method = method
	self.mounts = []
	self.hdList = None
	self.comps = None
	self.instPath = rootPath
	self.setupFilesystems = setupFilesystems
	self.installSystem = installSystem
	pass

def mountListCmp(first, second):
    mnt1 = first[1]
    mnt2 = first[2]
    if (first < second):
	return -1
    elif (first == second):
	return 0
    return 1