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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
#
# instdata.py - central store for all configuration data needed to install
#
# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Author(s): Erik Troan <ewt@redhat.com>
#
import os
import stat
import string
import language
import network
import firewall
import security
import timezone
import desktop
import fsset
import bootloader
import partitions
import partedUtils
import iscsi
import zfcp
import urllib
import iutil
import isys
import users
import shlex
from flags import *
from constants import *
from rhpl.simpleconfig import SimpleConfigFile
import rhpl.keyboard as keyboard
from pykickstart.version import versionToString, DEVEL
import logging
log = logging.getLogger("anaconda")
# Collector class for all data related to an install/upgrade.
class InstallData:
def reset(self):
# Reset everything except:
#
# - The install language
# - The keyboard
self.instClass = None
self.network = network.Network()
self.iscsi = iscsi.iscsi()
self.zfcp = zfcp.ZFCP()
self.firewall = firewall.Firewall()
self.security = security.Security()
self.timezone = timezone.Timezone()
self.timezone.setTimezoneInfo(self.instLanguage.getDefaultTimeZone())
self.users = None
self.rootPassword = { "isCrypted": False, "password": "", "lock": False }
self.auth = "--enableshadow --passalgo=sha512"
self.desktop = desktop.Desktop()
self.upgrade = None
if flags.cmdline.has_key("preupgrade"):
self.upgrade = True
# XXX move fsset and/or diskset into Partitions object?
self.fsset.reset()
self.diskset = partedUtils.DiskSet(self.anaconda)
self.partitions = partitions.Partitions(self.anaconda)
self.bootloader = bootloader.getBootloader()
self.upgradeRoot = None
self.rootParts = None
self.upgradeSwapInfo = None
if iutil.isS390() or self.anaconda.isKickstart:
self.firstboot = FIRSTBOOT_SKIP
else:
self.firstboot = FIRSTBOOT_DEFAULT
# XXX I still expect this to die when kickstart is the data store.
self.ksdata = None
# We don't have install methods anymore, but put things that depend on
# the methodstr here.
if os.path.exists("/dev/live") and \
stat.S_ISBLK(os.stat("/dev/live")[stat.ST_MODE]):
target = os.readlink("/dev/live")
self.partitions.protected = [target]
elif self.anaconda.methodstr and self.anaconda.methodstr.startswith("hd:"):
method = self.anaconda.methodstr[3:]
device = method.split(":", 3)[0]
if device.startswith("LABEL="):
device = isys.getDeviceByToken("LABEL", device[6:])
elif device.startswith("UUID="):
device = isys.getDeviceByToken("UUID", device[5:])
if device.startswith("/dev/"):
device = device[5:]
self.partitions.protected = [device]
def setInstallProgressClass(self, c):
self.instProgress = c
def setDisplayMode(self, display_mode):
self.displayMode = display_mode
# expects a Keyboard object
def setKeyboard(self, keyboard):
self.keyboard = keyboard
# expects 0/1
def setHeadless(self, isHeadless):
self.isHeadless = isHeadless
def setKsdata(self, ksdata):
self.ksdata = ksdata
# if upgrade is None, it really means False. we use None to help the
# installer ui figure out if it's the first time the user has entered
# the examine_gui screen. --dcantrell
def getUpgrade (self):
if self.upgrade == None:
return False
else:
return self.upgrade
def setUpgrade (self, bool):
self.upgrade = bool
# Reads the auth string and returns a string indicating our desired
# password encoding algorithm.
def getPassAlgo(self):
if self.auth.find("--enablemd5") != -1 or \
self.auth.find("--passalgo=md5") != -1:
return 'md5'
elif self.auth.find("--passalgo=sha256") != -1:
return 'sha256'
elif self.auth.find("--passalgo=sha512") != -1:
return 'sha512'
else:
return None
def write(self):
self.instLanguage.write (self.anaconda.rootPath)
self.anaconda.writeXdriver(self.anaconda.rootPath)
if not self.isHeadless:
self.keyboard.write (self.anaconda.rootPath)
self.timezone.write (self.anaconda.rootPath)
args = ["--update", "--nostart"] + shlex.split(self.auth)
try:
if not flags.test:
iutil.execWithRedirect("/usr/sbin/authconfig", args,
stdout = "/dev/tty5", stderr = "/dev/tty5",
root = self.anaconda.rootPath)
else:
log.error("Would have run: %s", args)
except RuntimeError, msg:
log.error("Error running %s: %s", args, msg)
self.network.write (self.anaconda.rootPath)
self.firewall.write (self.anaconda.rootPath)
self.security.write (self.anaconda.rootPath)
self.desktop.write(self.anaconda.rootPath)
self.users = users.Users()
# make sure crypt_style in libuser.conf matches the salt we're using
users.createLuserConf(self.anaconda.rootPath,
algoname=self.getPassAlgo())
# User should already exist, just without a password.
self.users.setRootPassword(self.rootPassword["password"],
self.rootPassword["isCrypted"],
self.rootPassword["lock"],
algo=self.getPassAlgo())
if self.anaconda.isKickstart:
for svc in self.ksdata.services.disabled:
iutil.execWithRedirect("/sbin/chkconfig",
[svc, "off"],
stdout="/dev/tty5", stderr="/dev/tty5",
root=self.anaconda.rootPath)
for svc in self.ksdata.services.enabled:
iutil.execWithRedirect("/sbin/chkconfig",
[svc, "on"],
stdout="/dev/tty5", stderr="/dev/tty5",
root=self.anaconda.rootPath)
for ud in self.ksdata.user.userList:
if not self.users.createUser(name=ud.name,
password=ud.password,
isCrypted=ud.isCrypted,
groups=ud.groups,
homedir=ud.homedir,
shell=ud.shell,
uid=ud.uid,
algo=self.getPassAlgo(),
lock=ud.lock,
root=self.anaconda.rootPath):
log.error("User %s already exists, not creating." % ud.name)
def writeKS(self, filename):
f = open(filename, "w")
f.write("# Kickstart file automatically generated by anaconda.\n\n")
f.write("#version=%s\n" % versionToString(DEVEL))
if self.upgrade:
f.write("upgrade\n");
else:
f.write("install\n");
if self.instClass.skipkey:
f.write("key --skip\n")
elif self.instClass.installkey:
f.write("key %s\n" %(self.instClass.installkey,))
if self.anaconda.stage2:
m = self.anaconda.stage2
if m.startswith("cdrom:"):
f.write("cdrom\n")
elif m.startswith("hd:"):
if m.count(":") == 3:
(part, fs, dir) = string.split(m[3:], ":")
else:
(part, dir) = string.split(m[3:])
f.write("harddrive --partition=%s --dir=%s\n" % (part, dir))
elif m.startswith("nfs:"):
if m.count(":") == 3:
(server, opts, dir) = string.split(m[4:], ":")
f.write("nfs --server=%s --opts=%s --dir=%s" % (server, opts, dir))
else:
(server, dir) = string.split(m[4:], ":")
f.write("nfs --server=%s --dir=%s\n" % (server, dir))
elif m.startswith("ftp://") or m.startswith("http://"):
f.write("url --url=%s\n" % urllib.unquote(m))
self.instLanguage.writeKS(f)
if not self.isHeadless:
self.keyboard.writeKS(f)
self.network.writeKS(f)
self.zfcp.writeKS(f)
if self.rootPassword["isCrypted"]:
args = " --iscrypted %s" % self.rootPassword["password"]
else:
args = " --iscrypted %s" % users.cryptPassword(self.rootPassword["password"], algo=self.getPassAlgo())
if self.rootPassword["lock"]:
args += " --lock"
f.write("rootpw %s\n" % args)
# Some kickstart commands do not correspond to any anaconda UI
# component. If this is a kickstart install, we need to make sure
# the information from the input file ends up in the output file.
if self.anaconda.isKickstart:
f.write(self.ksdata.user.__str__())
f.write(self.ksdata.services.__str__())
f.write(self.ksdata.reboot.__str__())
self.firewall.writeKS(f)
if self.auth.strip() != "":
f.write("authconfig %s\n" % self.auth)
self.security.writeKS(f)
self.timezone.writeKS(f)
self.bootloader.writeKS(f)
self.partitions.writeKS(f)
if self.backend is not None:
self.backend.writeKS(f)
self.backend.writePackagesKS(f, self.anaconda)
# Also write out any scripts from the input ksfile.
if self.anaconda.isKickstart:
for s in self.ksdata.scripts:
f.write(s.__str__())
# make it so only root can read, could have password
os.chmod(filename, 0600)
def __init__(self, anaconda, extraModules, displayMode, backend = None):
self.displayMode = displayMode
self.instLanguage = language.Language(self.displayMode)
self.keyboard = keyboard.Keyboard()
self.backend = backend
self.anaconda = anaconda
self.monitor = None
self.videocard = None
self.isHeadless = 0
self.extraModules = extraModules
self.fsset = fsset.FileSystemSet()
self.reset()
|