diff options
| author | Tom Zanussi <tom.zanussi@linux.intel.com> | 2014-08-03 09:55:22 -0500 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-08-11 10:53:08 +0100 |
| commit | bd9b9345dd217e0af61ba5f014cbc8450c3895ff (patch) | |
| tree | 473dfc8dd254b6139d4a0284c76ba603dc534830 /scripts/lib | |
| parent | 36f4edec65ec9d739822593a423d88a6418d73d5 (diff) | |
| download | poky-bd9b9345dd217e0af61ba5f014cbc8450c3895ff.tar.gz | |
wic: Remove packaging, config commands
Remove commands related to repos, packaging, configuration
(From OE-Core rev: 2b002ab75473578f06f161be0b48670fba26994e)
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
| -rw-r--r-- | scripts/lib/mic/kickstart/__init__.py | 763 |
1 files changed, 0 insertions, 763 deletions
diff --git a/scripts/lib/mic/kickstart/__init__.py b/scripts/lib/mic/kickstart/__init__.py index 11cdf63279..590bf4728f 100644 --- a/scripts/lib/mic/kickstart/__init__.py +++ b/scripts/lib/mic/kickstart/__init__.py | |||
| @@ -34,54 +34,6 @@ from mic import msger | |||
| 34 | from mic.utils import errors, misc, runner, fs_related as fs | 34 | from mic.utils import errors, misc, runner, fs_related as fs |
| 35 | from custom_commands import wicboot, partition | 35 | from custom_commands import wicboot, partition |
| 36 | 36 | ||
| 37 | |||
| 38 | AUTH_URL_PTN = r"(?P<scheme>.*)://(?P<username>.*)(:?P<password>.*)?@(?P<url>.*)" | ||
| 39 | |||
| 40 | |||
| 41 | class PrepackageSection(kssections.Section): | ||
| 42 | sectionOpen = "%prepackages" | ||
| 43 | |||
| 44 | def handleLine(self, line): | ||
| 45 | if not self.handler: | ||
| 46 | return | ||
| 47 | |||
| 48 | (h, s, t) = line.partition('#') | ||
| 49 | line = h.rstrip() | ||
| 50 | |||
| 51 | self.handler.prepackages.add([line]) | ||
| 52 | |||
| 53 | def handleHeader(self, lineno, args): | ||
| 54 | kssections.Section.handleHeader(self, lineno, args) | ||
| 55 | |||
| 56 | class AttachmentSection(kssections.Section): | ||
| 57 | sectionOpen = "%attachment" | ||
| 58 | |||
| 59 | def handleLine(self, line): | ||
| 60 | if not self.handler: | ||
| 61 | return | ||
| 62 | |||
| 63 | (h, s, t) = line.partition('#') | ||
| 64 | line = h.rstrip() | ||
| 65 | |||
| 66 | self.handler.attachment.add([line]) | ||
| 67 | |||
| 68 | def handleHeader(self, lineno, args): | ||
| 69 | kssections.Section.handleHeader(self, lineno, args) | ||
| 70 | |||
| 71 | def apply_wrapper(func): | ||
| 72 | def wrapper(*kargs, **kwargs): | ||
| 73 | try: | ||
| 74 | func(*kargs, **kwargs) | ||
| 75 | except (OSError, IOError, errors.KsError), err: | ||
| 76 | cfgcls = kargs[0].__class__.__name__ | ||
| 77 | if msger.ask("Failed to apply %s, skip and continue?" % cfgcls): | ||
| 78 | msger.warning("%s" % err) | ||
| 79 | pass | ||
| 80 | else: | ||
| 81 | # just throw out the exception | ||
| 82 | raise | ||
| 83 | return wrapper | ||
| 84 | |||
| 85 | def read_kickstart(path): | 37 | def read_kickstart(path): |
| 86 | """Parse a kickstart file and return a KickstartParser instance. | 38 | """Parse a kickstart file and return a KickstartParser instance. |
| 87 | 39 | ||
| @@ -105,12 +57,8 @@ def read_kickstart(path): | |||
| 105 | class KSHandlers(superclass): | 57 | class KSHandlers(superclass): |
| 106 | def __init__(self): | 58 | def __init__(self): |
| 107 | superclass.__init__(self, mapping=commandMap[using_version]) | 59 | superclass.__init__(self, mapping=commandMap[using_version]) |
| 108 | self.prepackages = ksparser.Packages() | ||
| 109 | self.attachment = ksparser.Packages() | ||
| 110 | 60 | ||
| 111 | ks = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=False) | 61 | ks = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=False) |
| 112 | ks.registerSection(PrepackageSection(ks.handler)) | ||
| 113 | ks.registerSection(AttachmentSection(ks.handler)) | ||
| 114 | 62 | ||
| 115 | try: | 63 | try: |
| 116 | ks.readKickstart(path) | 64 | ks.readKickstart(path) |
| @@ -123,526 +71,6 @@ def read_kickstart(path): | |||
| 123 | 71 | ||
| 124 | return ks | 72 | return ks |
| 125 | 73 | ||
| 126 | class KickstartConfig(object): | ||
| 127 | """A base class for applying kickstart configurations to a system.""" | ||
| 128 | def __init__(self, instroot): | ||
| 129 | self.instroot = instroot | ||
| 130 | |||
| 131 | def path(self, subpath): | ||
| 132 | return self.instroot + subpath | ||
| 133 | |||
| 134 | def _check_sysconfig(self): | ||
| 135 | if not os.path.exists(self.path("/etc/sysconfig")): | ||
| 136 | fs.makedirs(self.path("/etc/sysconfig")) | ||
| 137 | |||
| 138 | def chroot(self): | ||
| 139 | os.chroot(self.instroot) | ||
| 140 | os.chdir("/") | ||
| 141 | |||
| 142 | def call(self, args): | ||
| 143 | if not os.path.exists("%s/%s" %(self.instroot, args[0])): | ||
| 144 | raise errors.KsError("Can't find %s in chroot" % args[0]) | ||
| 145 | subprocess.call(args, preexec_fn = self.chroot) | ||
| 146 | |||
| 147 | def apply(self): | ||
| 148 | pass | ||
| 149 | |||
| 150 | class LanguageConfig(KickstartConfig): | ||
| 151 | """A class to apply a kickstart language configuration to a system.""" | ||
| 152 | @apply_wrapper | ||
| 153 | def apply(self, kslang): | ||
| 154 | self._check_sysconfig() | ||
| 155 | if kslang.lang: | ||
| 156 | f = open(self.path("/etc/sysconfig/i18n"), "w+") | ||
| 157 | f.write("LANG=\"" + kslang.lang + "\"\n") | ||
| 158 | f.close() | ||
| 159 | |||
| 160 | class KeyboardConfig(KickstartConfig): | ||
| 161 | """A class to apply a kickstart keyboard configuration to a system.""" | ||
| 162 | @apply_wrapper | ||
| 163 | def apply(self, kskeyboard): | ||
| 164 | # | ||
| 165 | # FIXME: | ||
| 166 | # should this impact the X keyboard config too? | ||
| 167 | # or do we want to make X be able to do this mapping? | ||
| 168 | # | ||
| 169 | #k = rhpl.keyboard.Keyboard() | ||
| 170 | #if kskeyboard.keyboard: | ||
| 171 | # k.set(kskeyboard.keyboard) | ||
| 172 | #k.write(self.instroot) | ||
| 173 | pass | ||
| 174 | |||
| 175 | class TimezoneConfig(KickstartConfig): | ||
| 176 | """A class to apply a kickstart timezone configuration to a system.""" | ||
| 177 | @apply_wrapper | ||
| 178 | def apply(self, kstimezone): | ||
| 179 | self._check_sysconfig() | ||
| 180 | tz = kstimezone.timezone or "America/New_York" | ||
| 181 | utc = str(kstimezone.isUtc) | ||
| 182 | |||
| 183 | f = open(self.path("/etc/sysconfig/clock"), "w+") | ||
| 184 | f.write("ZONE=\"" + tz + "\"\n") | ||
| 185 | f.write("UTC=" + utc + "\n") | ||
| 186 | f.close() | ||
| 187 | tz_source = "/usr/share/zoneinfo/%s" % (tz) | ||
| 188 | tz_dest = "/etc/localtime" | ||
| 189 | try: | ||
| 190 | cpcmd = fs.find_binary_inchroot('cp', self.instroot) | ||
| 191 | if cpcmd: | ||
| 192 | self.call([cpcmd, "-f", tz_source, tz_dest]) | ||
| 193 | else: | ||
| 194 | cpcmd = fs.find_binary_path('cp') | ||
| 195 | subprocess.call([cpcmd, "-f", | ||
| 196 | self.path(tz_source), | ||
| 197 | self.path(tz_dest)]) | ||
| 198 | except (IOError, OSError), (errno, msg): | ||
| 199 | raise errors.KsError("Timezone setting error: %s" % msg) | ||
| 200 | |||
| 201 | class AuthConfig(KickstartConfig): | ||
| 202 | """A class to apply a kickstart authconfig configuration to a system.""" | ||
| 203 | @apply_wrapper | ||
| 204 | def apply(self, ksauthconfig): | ||
| 205 | auth = ksauthconfig.authconfig or "--useshadow --enablemd5" | ||
| 206 | args = ["/usr/share/authconfig/authconfig.py", "--update", "--nostart"] | ||
| 207 | self.call(args + auth.split()) | ||
| 208 | |||
| 209 | class FirewallConfig(KickstartConfig): | ||
| 210 | """A class to apply a kickstart firewall configuration to a system.""" | ||
| 211 | @apply_wrapper | ||
| 212 | def apply(self, ksfirewall): | ||
| 213 | # | ||
| 214 | # FIXME: should handle the rest of the options | ||
| 215 | # | ||
| 216 | if not os.path.exists(self.path("/usr/sbin/lokkit")): | ||
| 217 | return | ||
| 218 | if ksfirewall.enabled: | ||
| 219 | status = "--enabled" | ||
| 220 | else: | ||
| 221 | status = "--disabled" | ||
| 222 | |||
| 223 | self.call(["/usr/sbin/lokkit", | ||
| 224 | "-f", "--quiet", "--nostart", status]) | ||
| 225 | |||
| 226 | class RootPasswordConfig(KickstartConfig): | ||
| 227 | """A class to apply a kickstart root password configuration to a system.""" | ||
| 228 | def unset(self): | ||
| 229 | self.call(["/usr/bin/passwd", "-d", "root"]) | ||
| 230 | |||
| 231 | def set_encrypted(self, password): | ||
| 232 | self.call(["/usr/sbin/usermod", "-p", password, "root"]) | ||
| 233 | |||
| 234 | def set_unencrypted(self, password): | ||
| 235 | for p in ("/bin/echo", "/usr/sbin/chpasswd"): | ||
| 236 | if not os.path.exists("%s/%s" %(self.instroot, p)): | ||
| 237 | raise errors.KsError("Unable to set unencrypted password due " | ||
| 238 | "to lack of %s" % p) | ||
| 239 | |||
| 240 | p1 = subprocess.Popen(["/bin/echo", "root:%s" %password], | ||
| 241 | stdout = subprocess.PIPE, | ||
| 242 | preexec_fn = self.chroot) | ||
| 243 | p2 = subprocess.Popen(["/usr/sbin/chpasswd", "-m"], | ||
| 244 | stdin = p1.stdout, | ||
| 245 | stdout = subprocess.PIPE, | ||
| 246 | preexec_fn = self.chroot) | ||
| 247 | p2.communicate() | ||
| 248 | |||
| 249 | @apply_wrapper | ||
| 250 | def apply(self, ksrootpw): | ||
| 251 | if ksrootpw.isCrypted: | ||
| 252 | self.set_encrypted(ksrootpw.password) | ||
| 253 | elif ksrootpw.password != "": | ||
| 254 | self.set_unencrypted(ksrootpw.password) | ||
| 255 | else: | ||
| 256 | self.unset() | ||
| 257 | |||
| 258 | class UserConfig(KickstartConfig): | ||
| 259 | def set_empty_passwd(self, user): | ||
| 260 | self.call(["/usr/bin/passwd", "-d", user]) | ||
| 261 | |||
| 262 | def set_encrypted_passwd(self, user, password): | ||
| 263 | self.call(["/usr/sbin/usermod", "-p", "%s" % password, user]) | ||
| 264 | |||
| 265 | def set_unencrypted_passwd(self, user, password): | ||
| 266 | for p in ("/bin/echo", "/usr/sbin/chpasswd"): | ||
| 267 | if not os.path.exists("%s/%s" %(self.instroot, p)): | ||
| 268 | raise errors.KsError("Unable to set unencrypted password due " | ||
| 269 | "to lack of %s" % p) | ||
| 270 | |||
| 271 | p1 = subprocess.Popen(["/bin/echo", "%s:%s" %(user, password)], | ||
| 272 | stdout = subprocess.PIPE, | ||
| 273 | preexec_fn = self.chroot) | ||
| 274 | p2 = subprocess.Popen(["/usr/sbin/chpasswd", "-m"], | ||
| 275 | stdin = p1.stdout, | ||
| 276 | stdout = subprocess.PIPE, | ||
| 277 | preexec_fn = self.chroot) | ||
| 278 | p2.communicate() | ||
| 279 | |||
| 280 | def addUser(self, userconfig): | ||
| 281 | args = [ "/usr/sbin/useradd" ] | ||
| 282 | if userconfig.groups: | ||
| 283 | args += [ "--groups", string.join(userconfig.groups, ",") ] | ||
| 284 | if userconfig.name: | ||
| 285 | args += [ "-m"] | ||
| 286 | args += [ "-d", "/home/%s" % userconfig.name ] | ||
| 287 | args.append(userconfig.name) | ||
| 288 | try: | ||
| 289 | dev_null = os.open("/dev/null", os.O_WRONLY) | ||
| 290 | msger.debug('adding user with %s' % args) | ||
| 291 | subprocess.call(args, | ||
| 292 | stdout = dev_null, | ||
| 293 | stderr = dev_null, | ||
| 294 | preexec_fn = self.chroot) | ||
| 295 | os.close(dev_null) | ||
| 296 | except: | ||
| 297 | msger.warning('Cannot add user using "useradd"') | ||
| 298 | |||
| 299 | if userconfig.password not in (None, ""): | ||
| 300 | if userconfig.isCrypted: | ||
| 301 | self.set_encrypted_passwd(userconfig.name, | ||
| 302 | userconfig.password) | ||
| 303 | else: | ||
| 304 | self.set_unencrypted_passwd(userconfig.name, | ||
| 305 | userconfig.password) | ||
| 306 | else: | ||
| 307 | self.set_empty_passwd(userconfig.name) | ||
| 308 | else: | ||
| 309 | raise errors.KsError("Invalid kickstart command: %s" \ | ||
| 310 | % userconfig.__str__()) | ||
| 311 | |||
| 312 | @apply_wrapper | ||
| 313 | def apply(self, user): | ||
| 314 | for userconfig in user.userList: | ||
| 315 | self.addUser(userconfig) | ||
| 316 | |||
| 317 | class ServicesConfig(KickstartConfig): | ||
| 318 | """A class to apply a kickstart services configuration to a system.""" | ||
| 319 | @apply_wrapper | ||
| 320 | def apply(self, ksservices): | ||
| 321 | if not os.path.exists(self.path("/sbin/chkconfig")): | ||
| 322 | return | ||
| 323 | for s in ksservices.enabled: | ||
| 324 | self.call(["/sbin/chkconfig", s, "on"]) | ||
| 325 | for s in ksservices.disabled: | ||
| 326 | self.call(["/sbin/chkconfig", s, "off"]) | ||
| 327 | |||
| 328 | class XConfig(KickstartConfig): | ||
| 329 | """A class to apply a kickstart X configuration to a system.""" | ||
| 330 | @apply_wrapper | ||
| 331 | def apply(self, ksxconfig): | ||
| 332 | if ksxconfig.startX and os.path.exists(self.path("/etc/inittab")): | ||
| 333 | f = open(self.path("/etc/inittab"), "rw+") | ||
| 334 | buf = f.read() | ||
| 335 | buf = buf.replace("id:3:initdefault", "id:5:initdefault") | ||
| 336 | f.seek(0) | ||
| 337 | f.write(buf) | ||
| 338 | f.close() | ||
| 339 | if ksxconfig.defaultdesktop: | ||
| 340 | self._check_sysconfig() | ||
| 341 | f = open(self.path("/etc/sysconfig/desktop"), "w") | ||
| 342 | f.write("DESKTOP="+ksxconfig.defaultdesktop+"\n") | ||
| 343 | f.close() | ||
| 344 | |||
| 345 | class DesktopConfig(KickstartConfig): | ||
| 346 | """A class to apply a kickstart desktop configuration to a system.""" | ||
| 347 | @apply_wrapper | ||
| 348 | def apply(self, ksdesktop): | ||
| 349 | if ksdesktop.defaultdesktop: | ||
| 350 | self._check_sysconfig() | ||
| 351 | f = open(self.path("/etc/sysconfig/desktop"), "w") | ||
| 352 | f.write("DESKTOP="+ksdesktop.defaultdesktop+"\n") | ||
| 353 | f.close() | ||
| 354 | if os.path.exists(self.path("/etc/gdm/custom.conf")): | ||
| 355 | f = open(self.path("/etc/skel/.dmrc"), "w") | ||
| 356 | f.write("[Desktop]\n") | ||
| 357 | f.write("Session="+ksdesktop.defaultdesktop.lower()+"\n") | ||
| 358 | f.close() | ||
| 359 | if ksdesktop.session: | ||
| 360 | if os.path.exists(self.path("/etc/sysconfig/uxlaunch")): | ||
| 361 | f = open(self.path("/etc/sysconfig/uxlaunch"), "a+") | ||
| 362 | f.write("session="+ksdesktop.session.lower()+"\n") | ||
| 363 | f.close() | ||
| 364 | if ksdesktop.autologinuser: | ||
| 365 | self._check_sysconfig() | ||
| 366 | f = open(self.path("/etc/sysconfig/desktop"), "a+") | ||
| 367 | f.write("AUTOLOGIN_USER=" + ksdesktop.autologinuser + "\n") | ||
| 368 | f.close() | ||
| 369 | if os.path.exists(self.path("/etc/gdm/custom.conf")): | ||
| 370 | f = open(self.path("/etc/gdm/custom.conf"), "w") | ||
| 371 | f.write("[daemon]\n") | ||
| 372 | f.write("AutomaticLoginEnable=true\n") | ||
| 373 | f.write("AutomaticLogin=" + ksdesktop.autologinuser + "\n") | ||
| 374 | f.close() | ||
| 375 | |||
| 376 | class MoblinRepoConfig(KickstartConfig): | ||
| 377 | """A class to apply a kickstart desktop configuration to a system.""" | ||
| 378 | def __create_repo_section(self, repo, type, fd): | ||
| 379 | baseurl = None | ||
| 380 | mirrorlist = None | ||
| 381 | reposuffix = {"base":"", "debuginfo":"-debuginfo", "source":"-source"} | ||
| 382 | reponame = repo.name + reposuffix[type] | ||
| 383 | if type == "base": | ||
| 384 | if repo.baseurl: | ||
| 385 | baseurl = repo.baseurl | ||
| 386 | if repo.mirrorlist: | ||
| 387 | mirrorlist = repo.mirrorlist | ||
| 388 | |||
| 389 | elif type == "debuginfo": | ||
| 390 | if repo.baseurl: | ||
| 391 | if repo.baseurl.endswith("/"): | ||
| 392 | baseurl = os.path.dirname(os.path.dirname(repo.baseurl)) | ||
| 393 | else: | ||
| 394 | baseurl = os.path.dirname(repo.baseurl) | ||
| 395 | baseurl += "/debug" | ||
| 396 | |||
| 397 | if repo.mirrorlist: | ||
| 398 | variant = repo.mirrorlist[repo.mirrorlist.find("$"):] | ||
| 399 | mirrorlist = repo.mirrorlist[0:repo.mirrorlist.find("$")] | ||
| 400 | mirrorlist += "debug" + "-" + variant | ||
| 401 | |||
| 402 | elif type == "source": | ||
| 403 | if repo.baseurl: | ||
| 404 | if repo.baseurl.endswith("/"): | ||
| 405 | baseurl = os.path.dirname( | ||
| 406 | os.path.dirname( | ||
| 407 | os.path.dirname(repo.baseurl))) | ||
| 408 | else: | ||
| 409 | baseurl = os.path.dirname(os.path.dirname(repo.baseurl)) | ||
| 410 | baseurl += "/source" | ||
| 411 | |||
| 412 | if repo.mirrorlist: | ||
| 413 | variant = repo.mirrorlist[repo.mirrorlist.find("$"):] | ||
| 414 | mirrorlist = repo.mirrorlist[0:repo.mirrorlist.find("$")] | ||
| 415 | mirrorlist += "source" + "-" + variant | ||
| 416 | |||
| 417 | fd.write("[" + reponame + "]\n") | ||
| 418 | fd.write("name=" + reponame + "\n") | ||
| 419 | fd.write("failovermethod=priority\n") | ||
| 420 | if baseurl: | ||
| 421 | auth_url = re.compile(AUTH_URL_PTN) | ||
| 422 | m = auth_url.match(baseurl) | ||
| 423 | if m: | ||
| 424 | baseurl = "%s://%s" % (m.group('scheme'), m.group('url')) | ||
| 425 | fd.write("baseurl=" + baseurl + "\n") | ||
| 426 | if mirrorlist: | ||
| 427 | fd.write("mirrorlist=" + mirrorlist + "\n") | ||
| 428 | """ Skip saving proxy settings """ | ||
| 429 | #if repo.proxy: | ||
| 430 | # fd.write("proxy=" + repo.proxy + "\n") | ||
| 431 | #if repo.proxy_username: | ||
| 432 | # fd.write("proxy_username=" + repo.proxy_username + "\n") | ||
| 433 | #if repo.proxy_password: | ||
| 434 | # fd.write("proxy_password=" + repo.proxy_password + "\n") | ||
| 435 | if repo.gpgkey: | ||
| 436 | fd.write("gpgkey=" + repo.gpgkey + "\n") | ||
| 437 | fd.write("gpgcheck=1\n") | ||
| 438 | else: | ||
| 439 | fd.write("gpgcheck=0\n") | ||
| 440 | if type == "source" or type == "debuginfo" or repo.disable: | ||
| 441 | fd.write("enabled=0\n") | ||
| 442 | else: | ||
| 443 | fd.write("enabled=1\n") | ||
| 444 | fd.write("\n") | ||
| 445 | |||
| 446 | def __create_repo_file(self, repo, repodir): | ||
| 447 | fs.makedirs(self.path(repodir)) | ||
| 448 | f = open(self.path(repodir + "/" + repo.name + ".repo"), "w") | ||
| 449 | self.__create_repo_section(repo, "base", f) | ||
| 450 | if repo.debuginfo: | ||
| 451 | self.__create_repo_section(repo, "debuginfo", f) | ||
| 452 | if repo.source: | ||
| 453 | self.__create_repo_section(repo, "source", f) | ||
| 454 | f.close() | ||
| 455 | |||
| 456 | @apply_wrapper | ||
| 457 | def apply(self, ksrepo, repodata, repourl): | ||
| 458 | for repo in ksrepo.repoList: | ||
| 459 | if repo.name in repourl: | ||
| 460 | repo.baseurl = repourl[repo.name] | ||
| 461 | if repo.save: | ||
| 462 | #self.__create_repo_file(repo, "/etc/yum.repos.d") | ||
| 463 | self.__create_repo_file(repo, "/etc/zypp/repos.d") | ||
| 464 | """ Import repo gpg keys """ | ||
| 465 | if repodata: | ||
| 466 | for repo in repodata: | ||
| 467 | if repo['repokey']: | ||
| 468 | runner.quiet(['rpm', | ||
| 469 | "--root=%s" % self.instroot, | ||
| 470 | "--import", | ||
| 471 | repo['repokey']]) | ||
| 472 | |||
| 473 | class RPMMacroConfig(KickstartConfig): | ||
| 474 | """A class to apply the specified rpm macros to the filesystem""" | ||
| 475 | @apply_wrapper | ||
| 476 | def apply(self, ks): | ||
| 477 | if not ks: | ||
| 478 | return | ||
| 479 | if not os.path.exists(self.path("/etc/rpm")): | ||
| 480 | os.mkdir(self.path("/etc/rpm")) | ||
| 481 | f = open(self.path("/etc/rpm/macros.imgcreate"), "w+") | ||
| 482 | if exclude_docs(ks): | ||
| 483 | f.write("%_excludedocs 1\n") | ||
| 484 | f.write("%__file_context_path %{nil}\n") | ||
| 485 | if inst_langs(ks) != None: | ||
| 486 | f.write("%_install_langs ") | ||
| 487 | f.write(inst_langs(ks)) | ||
| 488 | f.write("\n") | ||
| 489 | f.close() | ||
| 490 | |||
| 491 | class NetworkConfig(KickstartConfig): | ||
| 492 | """A class to apply a kickstart network configuration to a system.""" | ||
| 493 | def write_ifcfg(self, network): | ||
| 494 | p = self.path("/etc/sysconfig/network-scripts/ifcfg-" + network.device) | ||
| 495 | |||
| 496 | f = file(p, "w+") | ||
| 497 | os.chmod(p, 0644) | ||
| 498 | |||
| 499 | f.write("DEVICE=%s\n" % network.device) | ||
| 500 | f.write("BOOTPROTO=%s\n" % network.bootProto) | ||
| 501 | |||
| 502 | if network.bootProto.lower() == "static": | ||
| 503 | if network.ip: | ||
| 504 | f.write("IPADDR=%s\n" % network.ip) | ||
| 505 | if network.netmask: | ||
| 506 | f.write("NETMASK=%s\n" % network.netmask) | ||
| 507 | |||
| 508 | if network.onboot: | ||
| 509 | f.write("ONBOOT=on\n") | ||
| 510 | else: | ||
| 511 | f.write("ONBOOT=off\n") | ||
| 512 | |||
| 513 | if network.essid: | ||
| 514 | f.write("ESSID=%s\n" % network.essid) | ||
| 515 | |||
| 516 | if network.ethtool: | ||
| 517 | if network.ethtool.find("autoneg") == -1: | ||
| 518 | network.ethtool = "autoneg off " + network.ethtool | ||
| 519 | f.write("ETHTOOL_OPTS=%s\n" % network.ethtool) | ||
| 520 | |||
| 521 | if network.bootProto.lower() == "dhcp": | ||
| 522 | if network.hostname: | ||
| 523 | f.write("DHCP_HOSTNAME=%s\n" % network.hostname) | ||
| 524 | if network.dhcpclass: | ||
| 525 | f.write("DHCP_CLASSID=%s\n" % network.dhcpclass) | ||
| 526 | |||
| 527 | if network.mtu: | ||
| 528 | f.write("MTU=%s\n" % network.mtu) | ||
| 529 | |||
| 530 | f.close() | ||
| 531 | |||
| 532 | def write_wepkey(self, network): | ||
| 533 | if not network.wepkey: | ||
| 534 | return | ||
| 535 | |||
| 536 | p = self.path("/etc/sysconfig/network-scripts/keys-" + network.device) | ||
| 537 | f = file(p, "w+") | ||
| 538 | os.chmod(p, 0600) | ||
| 539 | f.write("KEY=%s\n" % network.wepkey) | ||
| 540 | f.close() | ||
| 541 | |||
| 542 | def write_sysconfig(self, useipv6, hostname, gateway): | ||
| 543 | path = self.path("/etc/sysconfig/network") | ||
| 544 | f = file(path, "w+") | ||
| 545 | os.chmod(path, 0644) | ||
| 546 | |||
| 547 | f.write("NETWORKING=yes\n") | ||
| 548 | |||
| 549 | if useipv6: | ||
| 550 | f.write("NETWORKING_IPV6=yes\n") | ||
| 551 | else: | ||
| 552 | f.write("NETWORKING_IPV6=no\n") | ||
| 553 | |||
| 554 | if hostname: | ||
| 555 | f.write("HOSTNAME=%s\n" % hostname) | ||
| 556 | else: | ||
| 557 | f.write("HOSTNAME=localhost.localdomain\n") | ||
| 558 | |||
| 559 | if gateway: | ||
| 560 | f.write("GATEWAY=%s\n" % gateway) | ||
| 561 | |||
| 562 | f.close() | ||
| 563 | |||
| 564 | def write_hosts(self, hostname): | ||
| 565 | localline = "" | ||
| 566 | if hostname and hostname != "localhost.localdomain": | ||
| 567 | localline += hostname + " " | ||
| 568 | l = hostname.split(".") | ||
| 569 | if len(l) > 1: | ||
| 570 | localline += l[0] + " " | ||
| 571 | localline += "localhost.localdomain localhost" | ||
| 572 | |||
| 573 | path = self.path("/etc/hosts") | ||
| 574 | f = file(path, "w+") | ||
| 575 | os.chmod(path, 0644) | ||
| 576 | f.write("127.0.0.1\t\t%s\n" % localline) | ||
| 577 | f.write("::1\t\tlocalhost6.localdomain6 localhost6\n") | ||
| 578 | f.close() | ||
| 579 | |||
| 580 | def write_resolv(self, nodns, nameservers): | ||
| 581 | if nodns or not nameservers: | ||
| 582 | return | ||
| 583 | |||
| 584 | path = self.path("/etc/resolv.conf") | ||
| 585 | f = file(path, "w+") | ||
| 586 | os.chmod(path, 0644) | ||
| 587 | |||
| 588 | for ns in (nameservers): | ||
| 589 | if ns: | ||
| 590 | f.write("nameserver %s\n" % ns) | ||
| 591 | |||
| 592 | f.close() | ||
| 593 | |||
| 594 | @apply_wrapper | ||
| 595 | def apply(self, ksnet): | ||
| 596 | fs.makedirs(self.path("/etc/sysconfig/network-scripts")) | ||
| 597 | |||
| 598 | useipv6 = False | ||
| 599 | nodns = False | ||
| 600 | hostname = None | ||
| 601 | gateway = None | ||
| 602 | nameservers = None | ||
| 603 | |||
| 604 | for network in ksnet.network: | ||
| 605 | if not network.device: | ||
| 606 | raise errors.KsError("No --device specified with " | ||
| 607 | "network kickstart command") | ||
| 608 | |||
| 609 | if (network.onboot and network.bootProto.lower() != "dhcp" and | ||
| 610 | not (network.ip and network.netmask)): | ||
| 611 | raise errors.KsError("No IP address and/or netmask " | ||
| 612 | "specified with static " | ||
| 613 | "configuration for '%s'" % | ||
| 614 | network.device) | ||
| 615 | |||
| 616 | self.write_ifcfg(network) | ||
| 617 | self.write_wepkey(network) | ||
| 618 | |||
| 619 | if network.ipv6: | ||
| 620 | useipv6 = True | ||
| 621 | if network.nodns: | ||
| 622 | nodns = True | ||
| 623 | |||
| 624 | if network.hostname: | ||
| 625 | hostname = network.hostname | ||
| 626 | if network.gateway: | ||
| 627 | gateway = network.gateway | ||
| 628 | |||
| 629 | if network.nameserver: | ||
| 630 | nameservers = network.nameserver.split(",") | ||
| 631 | |||
| 632 | self.write_sysconfig(useipv6, hostname, gateway) | ||
| 633 | self.write_hosts(hostname) | ||
| 634 | self.write_resolv(nodns, nameservers) | ||
| 635 | |||
| 636 | def use_installerfw(ks, feature): | ||
| 637 | """ Check if the installer framework has to be used for a feature | ||
| 638 | "feature". """ | ||
| 639 | |||
| 640 | features = ks.handler.installerfw.features | ||
| 641 | if features: | ||
| 642 | if feature in features or "all" in features: | ||
| 643 | return True | ||
| 644 | return False | ||
| 645 | |||
| 646 | def get_image_size(ks, default = None): | 74 | def get_image_size(ks, default = None): |
| 647 | __size = 0 | 75 | __size = 0 |
| 648 | for p in ks.handler.partition.partitions: | 76 | for p in ks.handler.partition.partitions: |
| @@ -665,21 +93,6 @@ def get_image_fsopts(ks, default = None): | |||
| 665 | return p.fsopts | 93 | return p.fsopts |
| 666 | return default | 94 | return default |
| 667 | 95 | ||
| 668 | def get_modules(ks): | ||
| 669 | devices = [] | ||
| 670 | if isinstance(ks.handler.device, kscommands.device.FC3_Device): | ||
| 671 | devices.append(ks.handler.device) | ||
| 672 | else: | ||
| 673 | devices.extend(ks.handler.device.deviceList) | ||
| 674 | |||
| 675 | modules = [] | ||
| 676 | for device in devices: | ||
| 677 | if not device.moduleName: | ||
| 678 | continue | ||
| 679 | modules.extend(device.moduleName.split(":")) | ||
| 680 | |||
| 681 | return modules | ||
| 682 | |||
| 683 | def get_timeout(ks, default = None): | 96 | def get_timeout(ks, default = None): |
| 684 | if not hasattr(ks.handler.bootloader, "timeout"): | 97 | if not hasattr(ks.handler.bootloader, "timeout"): |
| 685 | return default | 98 | return default |
| @@ -708,181 +121,5 @@ def get_default_kernel(ks, default = None): | |||
| 708 | return default | 121 | return default |
| 709 | return ks.handler.bootloader.default | 122 | return ks.handler.bootloader.default |
| 710 | 123 | ||
| 711 | def get_repos(ks, repo_urls=None): | ||
| 712 | repos = {} | ||
| 713 | for repo in ks.handler.repo.repoList: | ||
| 714 | inc = [] | ||
| 715 | if hasattr(repo, "includepkgs"): | ||
| 716 | inc.extend(repo.includepkgs) | ||
| 717 | |||
| 718 | exc = [] | ||
| 719 | if hasattr(repo, "excludepkgs"): | ||
| 720 | exc.extend(repo.excludepkgs) | ||
| 721 | |||
| 722 | baseurl = repo.baseurl | ||
| 723 | mirrorlist = repo.mirrorlist | ||
| 724 | |||
| 725 | if repo_urls and repo.name in repo_urls: | ||
| 726 | baseurl = repo_urls[repo.name] | ||
| 727 | mirrorlist = None | ||
| 728 | |||
| 729 | if repos.has_key(repo.name): | ||
| 730 | msger.warning("Overriding already specified repo %s" %(repo.name,)) | ||
| 731 | |||
| 732 | proxy = None | ||
| 733 | if hasattr(repo, "proxy"): | ||
| 734 | proxy = repo.proxy | ||
| 735 | proxy_username = None | ||
| 736 | if hasattr(repo, "proxy_username"): | ||
| 737 | proxy_username = repo.proxy_username | ||
| 738 | proxy_password = None | ||
| 739 | if hasattr(repo, "proxy_password"): | ||
| 740 | proxy_password = repo.proxy_password | ||
| 741 | if hasattr(repo, "debuginfo"): | ||
| 742 | debuginfo = repo.debuginfo | ||
| 743 | if hasattr(repo, "source"): | ||
| 744 | source = repo.source | ||
| 745 | if hasattr(repo, "gpgkey"): | ||
| 746 | gpgkey = repo.gpgkey | ||
| 747 | if hasattr(repo, "disable"): | ||
| 748 | disable = repo.disable | ||
| 749 | ssl_verify = True | ||
| 750 | if hasattr(repo, "ssl_verify"): | ||
| 751 | ssl_verify = repo.ssl_verify == "yes" | ||
| 752 | nocache = False | ||
| 753 | if hasattr(repo, "nocache"): | ||
| 754 | nocache = repo.nocache | ||
| 755 | cost = None | ||
| 756 | if hasattr(repo, "cost"): | ||
| 757 | cost = repo.cost | ||
| 758 | priority = None | ||
| 759 | if hasattr(repo, "priority"): | ||
| 760 | priority = repo.priority | ||
| 761 | |||
| 762 | repos[repo.name] = (repo.name, baseurl, mirrorlist, inc, exc, | ||
| 763 | proxy, proxy_username, proxy_password, debuginfo, | ||
| 764 | source, gpgkey, disable, ssl_verify, nocache, | ||
| 765 | cost, priority) | ||
| 766 | |||
| 767 | return repos.values() | ||
| 768 | |||
| 769 | def convert_method_to_repo(ks): | ||
| 770 | try: | ||
| 771 | ks.handler.repo.methodToRepo() | ||
| 772 | except (AttributeError, kserrors.KickstartError): | ||
| 773 | pass | ||
| 774 | |||
| 775 | def get_attachment(ks, required=()): | ||
| 776 | return ks.handler.attachment.packageList + list(required) | ||
| 777 | |||
| 778 | def get_pre_packages(ks, required=()): | ||
| 779 | return ks.handler.prepackages.packageList + list(required) | ||
| 780 | |||
| 781 | def get_packages(ks, required=()): | ||
| 782 | return ks.handler.packages.packageList + list(required) | ||
| 783 | |||
| 784 | def get_groups(ks, required=()): | ||
| 785 | return ks.handler.packages.groupList + list(required) | ||
| 786 | |||
| 787 | def get_excluded(ks, required=()): | ||
| 788 | return ks.handler.packages.excludedList + list(required) | ||
| 789 | |||
| 790 | def get_partitions(ks): | 124 | def get_partitions(ks): |
| 791 | return ks.handler.partition.partitions | 125 | return ks.handler.partition.partitions |
| 792 | |||
| 793 | def ignore_missing(ks): | ||
| 794 | return ks.handler.packages.handleMissing == ksconstants.KS_MISSING_IGNORE | ||
| 795 | |||
| 796 | def exclude_docs(ks): | ||
| 797 | return ks.handler.packages.excludeDocs | ||
| 798 | |||
| 799 | def inst_langs(ks): | ||
| 800 | if hasattr(ks.handler.packages, "instLange"): | ||
| 801 | return ks.handler.packages.instLange | ||
| 802 | elif hasattr(ks.handler.packages, "instLangs"): | ||
| 803 | return ks.handler.packages.instLangs | ||
| 804 | return "" | ||
| 805 | |||
| 806 | def get_post_scripts(ks): | ||
| 807 | scripts = [] | ||
| 808 | for s in ks.handler.scripts: | ||
| 809 | if s.type != ksparser.KS_SCRIPT_POST: | ||
| 810 | continue | ||
| 811 | scripts.append(s) | ||
| 812 | return scripts | ||
| 813 | |||
| 814 | def add_repo(ks, repostr): | ||
| 815 | args = repostr.split() | ||
| 816 | repoobj = ks.handler.repo.parse(args[1:]) | ||
| 817 | if repoobj and repoobj not in ks.handler.repo.repoList: | ||
| 818 | ks.handler.repo.repoList.append(repoobj) | ||
| 819 | |||
| 820 | def remove_all_repos(ks): | ||
| 821 | while len(ks.handler.repo.repoList) != 0: | ||
| 822 | del ks.handler.repo.repoList[0] | ||
| 823 | |||
| 824 | def remove_duplicate_repos(ks): | ||
| 825 | i = 0 | ||
| 826 | j = i + 1 | ||
| 827 | while True: | ||
| 828 | if len(ks.handler.repo.repoList) < 2: | ||
| 829 | break | ||
| 830 | if i >= len(ks.handler.repo.repoList) - 1: | ||
| 831 | break | ||
| 832 | name = ks.handler.repo.repoList[i].name | ||
| 833 | baseurl = ks.handler.repo.repoList[i].baseurl | ||
| 834 | if j < len(ks.handler.repo.repoList): | ||
| 835 | if (ks.handler.repo.repoList[j].name == name or \ | ||
| 836 | ks.handler.repo.repoList[j].baseurl == baseurl): | ||
| 837 | del ks.handler.repo.repoList[j] | ||
| 838 | else: | ||
| 839 | j += 1 | ||
| 840 | if j >= len(ks.handler.repo.repoList): | ||
| 841 | i += 1 | ||
| 842 | j = i + 1 | ||
| 843 | else: | ||
| 844 | i += 1 | ||
| 845 | j = i + 1 | ||
| 846 | |||
| 847 | def resolve_groups(creatoropts, repometadata): | ||
| 848 | iszypp = False | ||
| 849 | if 'zypp' == creatoropts['pkgmgr']: | ||
| 850 | iszypp = True | ||
| 851 | ks = creatoropts['ks'] | ||
| 852 | |||
| 853 | for repo in repometadata: | ||
| 854 | """ Mustn't replace group with package list if repo is ready for the | ||
| 855 | corresponding package manager. | ||
| 856 | """ | ||
| 857 | |||
| 858 | if iszypp and repo["patterns"]: | ||
| 859 | continue | ||
| 860 | if not iszypp and repo["comps"]: | ||
| 861 | continue | ||
| 862 | |||
| 863 | # But we also must handle such cases, use zypp but repo only has comps, | ||
| 864 | # use yum but repo only has patterns, use zypp but use_comps is true, | ||
| 865 | # use yum but use_comps is false. | ||
| 866 | groupfile = None | ||
| 867 | if iszypp and repo["comps"]: | ||
| 868 | groupfile = repo["comps"] | ||
| 869 | get_pkglist_handler = misc.get_pkglist_in_comps | ||
| 870 | if not iszypp and repo["patterns"]: | ||
| 871 | groupfile = repo["patterns"] | ||
| 872 | get_pkglist_handler = misc.get_pkglist_in_patterns | ||
| 873 | |||
| 874 | if groupfile: | ||
| 875 | i = 0 | ||
| 876 | while True: | ||
| 877 | if i >= len(ks.handler.packages.groupList): | ||
| 878 | break | ||
| 879 | pkglist = get_pkglist_handler( | ||
| 880 | ks.handler.packages.groupList[i].name, | ||
| 881 | groupfile) | ||
| 882 | if pkglist: | ||
| 883 | del ks.handler.packages.groupList[i] | ||
| 884 | for pkg in pkglist: | ||
| 885 | if pkg not in ks.handler.packages.packageList: | ||
| 886 | ks.handler.packages.packageList.append(pkg) | ||
| 887 | else: | ||
| 888 | i = i + 1 | ||
