self.registerSection(TracebackScriptSection(self.handler, dataObj=Script))
self.registerSection(RunScriptSection(self.handler, dataObj=Script))
self.registerSection(PostUmountScriptSection(self.handler, dataObj=Script))
+ self.registerSection(RunScriptOutBootstrapSection(self.handler, dataObj=Script))
self.registerSection(PackageSection(self.handler))
self.registerSection(TpkPackageSection(self.handler))
raise KickstartError("%runscript and %post-umount " \
"can not be defined together")
+class RunScriptOutBootstrapSection(ScriptSection):
+ sectionOpen = "%runscript_out_bootstrap"
+
+ def _resetScript(self):
+ ScriptSection._resetScript(self)
+ self._script["type"] = KS_SCRIPT_RUN_OUT_BOOTSTRAP
+
class PackageSection(Section):
sectionOpen = "%packages"
import re
import shutil
import subprocess
+import tempfile
import ctypes
-from mic import bootstrap, msger
+from mic import bootstrap, msger, kickstart
from mic.conf import configmgr
from mic.utils import errors, proxy
from mic.utils.fs_related import find_binary_path, makedirs
return True
return (os.stat("/").st_ino != 2)
+# Provide '%runscript_out_bootstrap' section for kickstart, and runscript_out_bootstrap can
+# be run on local PC after image created. The default interpreter is /bin/sh,
+# use '--interpreter' to specify interpreter ('%runscript_out_bootstrap --interpreter=/bin/bash')
+def run_scripts_out_bootstrap(ks, rundir, env=None):
+ if kickstart.get_out_bootstarp_scripts(ks)==[]:
+ return
+
+ msger.info("Running scripts out bootstrap ...")
+ for s in kickstart.get_out_bootstarp_scripts(ks):
+ (fd, path) = tempfile.mkstemp(prefix = "ks-runscript-out-bootstrap-")
+ s.script = s.script.replace("\r", "")
+ os.write(fd, s.script)
+ if s.interp == '/bin/sh' or s.interp == '/bin/bash':
+ os.write(fd, '\n')
+ os.write(fd, 'exit 0\n')
+ os.close(fd)
+ os.chmod(path, 0o700)
+
+ oldoutdir = os.getcwd()
+ if os.path.exists(rundir):
+ os.chdir(rundir)
+ try:
+ try:
+ p = subprocess.Popen([s.interp, path],
+ env = env,
+ stdout = subprocess.PIPE,
+ stderr = subprocess.STDOUT)
+ while p.poll() == None:
+ msger.info(p.stdout.readline().strip())
+ if p.returncode != 0:
+ raise errors.CreatorError("Failed to execute script out bootstrap "
+ "with '%s'" % (s.interp))
+ except OSError as msg:
+ raise errors.CreatorError("Failed to execute script out bootstrap "
+ "with '%s' : %s" % (s.interp, msg))
+ finally:
+ os.chdir(oldoutdir)
+ os.unlink(path)
+
def bootstrap_mic(argv=None):
def mychroot():
os.chroot(rootdir)
value,tb = sys.exc_info()[1:]
raise errors.CreatorError((value,tb))
else:
+ if not ret:
+ run_scripts_out_bootstrap(cropts['ks'], cropts['outdir'])
sys.exit(ret)
finally:
bsenv.cleanup()
dest='interactive', default=True,
help='interactive output')
parent_parser.add_argument('--run_script', action='store', dest='run_script',
- default=None, help='Run script on local PC after image created')
+ default=None, help='Run script on mic bootstrap after image created')
parent_parser.add_argument('--tpk_install', action='store', dest='tpk_install',
default=None, help='Copy tpk file to /usr/apps/.preload-tpk')
parent_parser.add_argument('--rpm-debug', action='store_true', dest='rpm_debug', help='Set debug mode for rpm install')