Skip to content

Commit

Permalink
Add kickstart %pre-install section support
Browse files Browse the repository at this point in the history
The %pre-install section will run scripts after all the filesystems have
been setup and mounted on /mnt/sysimage, but before any packages have
been installed.
  • Loading branch information
bcl committed Apr 21, 2015
1 parent 38b6fa5 commit 8851c9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion anaconda.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Source0: %{name}-%{version}.tar.bz2
# Also update in AM_GNU_GETTEXT_VERSION in configure.ac
%define gettextver 0.18.3
%define intltoolver 0.31.2-3
%define pykickstartver 2.5
%define pykickstartver 2.6
%define yumver 3.4.3-91
%define dnfver 0.6.4
%define partedver 1.8.1
Expand Down
9 changes: 6 additions & 3 deletions pyanaconda/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from pyanaconda.i18n import _
from pyanaconda.threads import threadMgr
from pyanaconda.ui.lib.entropy import wait_for_entropy
from pyanaconda.kickstart import runPostScripts, runPreInstallScripts
import logging
import blivet
log = logging.getLogger("anaconda")
Expand All @@ -55,8 +56,6 @@ def _writeKS(ksdata):
iutil.eintr_retry_call(os.chmod, path, 0o600)

def doConfiguration(storage, payload, ksdata, instClass):
from pyanaconda.kickstart import runPostScripts

willWriteNetwork = not flags.flags.imageInstall and not flags.flags.dirInstall
willRunRealmd = ksdata.realm.discovered

Expand Down Expand Up @@ -150,7 +149,7 @@ def doInstall(storage, payload, ksdata, instClass):
# Update every 10% of packages installed. We don't know how many packages
# we are installing until it's too late (see realmd later on) so this is
# the best we can do.
steps += 10
steps += 11

# pre setup phase, post install
steps += 2
Expand Down Expand Up @@ -199,6 +198,10 @@ def doInstall(storage, payload, ksdata, instClass):
if not write_storage_late and not flags.flags.dirInstall:
storage.write()

# Run %pre-install scripts with the filesystem mounted and no packages
with progress_report(_("Running pre-installation scripts")):
runPreInstallScripts(ksdata.scripts)

# Do packaging.

# Discover information about realms to join,
Expand Down
16 changes: 14 additions & 2 deletions pyanaconda/kickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@
from pyanaconda.pwpolicy import F22_PwPolicy, F22_PwPolicyData

from pykickstart.constants import CLEARPART_TYPE_NONE, FIRSTBOOT_SKIP, FIRSTBOOT_RECONFIG, KS_SCRIPT_POST, KS_SCRIPT_PRE, \
KS_SCRIPT_TRACEBACK, SELINUX_DISABLED, SELINUX_ENFORCING, SELINUX_PERMISSIVE
KS_SCRIPT_TRACEBACK, KS_SCRIPT_PREINSTALL, SELINUX_DISABLED, SELINUX_ENFORCING, SELINUX_PERMISSIVE
from pykickstart.base import BaseHandler
from pykickstart.errors import formatErrorMsg, KickstartError, KickstartValueError
from pykickstart.parser import KickstartParser
from pykickstart.parser import Script as KSScript
from pykickstart.sections import Section
from pykickstart.sections import NullSection, PackageSection, PostScriptSection, PreScriptSection, TracebackScriptSection
from pykickstart.sections import NullSection, PackageSection, PostScriptSection, PreScriptSection, PreInstallScriptSection, TracebackScriptSection
from pykickstart.version import returnClassForVersion

import logging
Expand Down Expand Up @@ -2010,6 +2010,7 @@ def handleCommand(self, lineno, args):

def setupSections(self):
self.registerSection(PreScriptSection(self.handler, dataObj=AnacondaKSScript))
self.registerSection(NullSection(self.handler, sectionOpen="%pre-install"))
self.registerSection(NullSection(self.handler, sectionOpen="%post"))
self.registerSection(NullSection(self.handler, sectionOpen="%traceback"))
self.registerSection(NullSection(self.handler, sectionOpen="%packages"))
Expand All @@ -2031,6 +2032,7 @@ def handleCommand(self, lineno, args):

def setupSections(self):
self.registerSection(PreScriptSection(self.handler, dataObj=self.scriptClass))
self.registerSection(PreInstallScriptSection(self.handler, dataObj=self.scriptClass))
self.registerSection(PostScriptSection(self.handler, dataObj=self.scriptClass))
self.registerSection(TracebackScriptSection(self.handler, dataObj=self.scriptClass))
self.registerSection(PackageSection(self.handler))
Expand Down Expand Up @@ -2121,6 +2123,16 @@ def runPreScripts(scripts):

log.info("All kickstart %%pre script(s) have been run")

def runPreInstallScripts(scripts):
preInstallScripts = [s for s in scripts if s.type == KS_SCRIPT_PREINSTALL]

if len(preInstallScripts) == 0:
return

log.info("Running kickstart %%pre-install script(s)")
map(lambda s: s.run("/"), preInstallScripts)
log.info("All kickstart %%pre-install script(s) have been run")

def runTracebackScripts(scripts):
log.info("Running kickstart %%traceback script(s)")
for script in filter(lambda s: s.type == KS_SCRIPT_TRACEBACK, scripts):
Expand Down

0 comments on commit 8851c9e

Please sign in to comment.