-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate the %pre-install and %post script
- Loading branch information
1 parent
32e24a4
commit 2956709
Showing
13 changed files
with
302 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# | ||
# Commond utilities for working with scripts | ||
# | ||
# Copyright (C) 2024 Red Hat, Inc. | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
# modify, copy, or redistribute it subject to the terms and conditions of | ||
# the GNU General Public License v.2, or (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY expressed or implied, including the implied warranties 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, write to the | ||
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the | ||
# source code or documentation are not subject to the GNU General Public | ||
# License and may only be used or replicated with the express permission of | ||
# Red Hat, Inc. | ||
# | ||
import os | ||
import tempfile | ||
from pyanaconda.core import util | ||
from pyanaconda.core.path import open_with_perm | ||
|
||
from pyanaconda.anaconda_loggers import get_module_logger | ||
log = get_module_logger(__name__) | ||
|
||
script_log = log.getChild("script") | ||
|
||
|
||
__all__ = ["run_script"] | ||
|
||
|
||
def run_script(script, chroot): | ||
""" Run the kickstart script | ||
This will write the script to a file named /tmp/ks-script- before | ||
execution. | ||
Output is logged by the program logger, the path specified by --log | ||
or to /tmp/ks-script-\\*.log | ||
# TODORV return | ||
@param chroot directory path to chroot into before execution | ||
""" | ||
if script.inChroot: | ||
scriptRoot = chroot | ||
else: | ||
scriptRoot = "/" | ||
|
||
(fd, path) = tempfile.mkstemp("", "ks-script-", scriptRoot + "/tmp") | ||
|
||
os.write(fd, script.script.encode("utf-8")) | ||
os.close(fd) | ||
os.chmod(path, 0o700) | ||
|
||
# Always log stdout/stderr from scripts. Using --log just lets you | ||
# pick where it goes. The script will also be logged to program.log | ||
# because of execWithRedirect. | ||
if script.logfile: | ||
if script.inChroot: | ||
messages = "%s/%s" % (scriptRoot, script.logfile) | ||
else: | ||
messages = script.logfile | ||
|
||
d = os.path.dirname(messages) | ||
if not os.path.exists(d): | ||
os.makedirs(d) | ||
else: | ||
# Always log outside the chroot, we copy those logs into the | ||
# chroot later. | ||
messages = "/tmp/%s.log" % os.path.basename(path) | ||
|
||
with open_with_perm(messages, "w", 0o600) as fp: | ||
rc = util.execWithRedirect(script.interp, ["/tmp/%s" % os.path.basename(path)], | ||
stdout=fp, | ||
root=scriptRoot) | ||
|
||
if rc != 0: | ||
script_log.error("Error code %s running the kickstart script at line %s", rc, script.lineno) | ||
|
||
return rc, messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# Copyright (C) 2024 Red Hat, Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published | ||
# by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pkgpyexecdir = $(pyexecdir)/py$(PACKAGE_NAME) | ||
scriptsdir = $(pkgpyexecdir)/modules/runtime/scripts | ||
dist_scripts_DATA = $(wildcard $(srcdir)/*.py) | ||
|
||
MAINTAINERCLEANFILES = Makefile.in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# Copyright (C) 2024 Red Hat, Inc. | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
# modify, copy, or redistribute it subject to the terms and conditions of | ||
# the GNU General Public License v.2, or (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY expressed or implied, including the implied warranties 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, write to the | ||
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the | ||
# source code or documentation are not subject to the GNU General Public | ||
# License and may only be used or replicated with the express permission of | ||
# Red Hat, Inc. | ||
# | ||
from pyanaconda.modules.runtime.scripts.scripts import ScriptsModule | ||
|
||
__all__ = ["ScriptsModule"] |
Oops, something went wrong.