diff --git a/spacewalk/certs-tools/Makefile.certs b/spacewalk/certs-tools/Makefile.certs index 65513d5ad06a..8cc42ee4ca1b 100644 --- a/spacewalk/certs-tools/Makefile.certs +++ b/spacewalk/certs-tools/Makefile.certs @@ -18,7 +18,7 @@ SUBDIR = certs FILES = __init__ rhn_ssl_tool sslToolCli sslToolConfig sslToolLib \ - timeLib rhn_bootstrap rhn_bootstrap_strings client_config_update \ + timeLib rhn_bootstrap rhn_bootstrap_strings \ mgr_ssl_cert_setup INSTALL_ROOT_FILES = gen-rpm.sh sign.sh update-ca-cert-trust.sh @@ -51,17 +51,9 @@ install :: $(SBINFILES) $(BINFILES) $(PYBINFILES) $(MANS) $(PREFIX)/$(MANDIR) $(INSTALL_BIN) $(f) $(PREFIX)$(BINDIR)/$(f) ; ) $(foreach f,$(PYBINFILES), \ $(INSTALL_BIN) $(f) $(PREFIX)$(BINDIR)/$(f)-$(PYTHONVERSION) ; ) - -install :: instClientScript @$(foreach f,$(INSTALL_ROOT_FILES), \ $(INSTALL_DATA) $(f) $(PREFIX)$(ROOT)/$(SUBDIR)/$(f) ; ) -# note: this file is in two places. One in the RPM and one in pub/bootstrap/ -instClientScript: $(PUB_BOOTSTRAP_DIR)/client_config_update.py - -$(PUB_BOOTSTRAP_DIR)/client_config_update.py : $(PREFIX)/$(PUB_BOOTSTRAP_DIR) client_config_update.py - install -m 0755 client_config_update.py $(PREFIX)/$@ - %.$(MANSECT) : %.sgml /usr/bin/docbook2man $< diff --git a/spacewalk/certs-tools/client_config_update.py b/spacewalk/certs-tools/client_config_update.py deleted file mode 100755 index bf8bebf2ede3..000000000000 --- a/spacewalk/certs-tools/client_config_update.py +++ /dev/null @@ -1,216 +0,0 @@ -#!/usr/bin/python -u -# -# Copyright (c) 2008--2013 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# -# key=value formatted "config file" mapping script -# -# NOT TO BE USED DIRECTLY -# This is called by a script generated by the rhn-bootstrap utility. -# -# Specifically engineered with the RHN Update Agent configuration files -# in mind though it is relatively generic in nature. -# -# Author: Todd Warner -# - -""" -Client configuration mapping script that writes to an SUSE Manager Update Agent-type -config file(s) - -I.e., maps a file with SUSE Manager Update Agent-like key=value pairs e.g., -serverURL=https://test-satellite.example.redhat.com/XMLRPC -enableProxy=0 -sslCACert=/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT - -And maps that to the client's configuration files. - -------------- -To map new settings to a file that uses the format key=value, where -key[comment]=value is a comment line you do this (e.g., mapping -key=value pairs to /etc/sysconfig/rhn/up2date): - - 1. edit a file (e.g., 'client-config-overrides.txt'), inputing new key=value pairs - to replace in config file (e.g., /etc/sysconfig/rhn/up2date). - Specifically: -serverURL=https://test-satellite.example.redhat.com/XMLRPC - - 2. ./client_config_update.py /etc/sysconfig/rhn/up2date client-config-overrides.txt - -That's all there is to it. - -If you are running an older RHN Update Agent, the rhn_register file can be -mapped as well: - - ./client_config_update.py /etc/sysconfig/rhn/rhn_register client-config-overrides.txt -""" - - -from __future__ import print_function -import os -import sys -import tempfile - -DEFAULT_CLIENT_CONFIG_OVERRIDES = 'client-config-overrides.txt' - -RHN_REGISTER = "/etc/sysconfig/rhn/rhn_register" -UP2DATE = "/etc/sysconfig/rhn/up2date" - - -def _parseConfigLine(line): - """parse a line from a config file. Format can be either "key=value\n" - or "whatever text\n" - - return either: - (key, value) - or - None - The '\n' is always stripped from the value. - """ - - kv = line.decode('utf8').split('=') - if len(kv) < 2: - # not a setting - return None - - if len(kv) > 2: - # '=' is part of the value, need to rejoin it. - kv = [kv[0], '='.join(kv[1:])] - - if kv[0].find('[comment]') > 0: - # comment; not a setting - return None - - # it's a setting, trim the '\n' and return the (key, value) pair. - kv[0] = kv[0].strip() - kv[1] = kv[1].strip() - return tuple(kv) - -def readConfigFile(configFile): - "read in config file, return dictionary of key/value pairs" - - fin = open(configFile, 'rb') - - d = {} - - for line in fin.readlines(): - kv = _parseConfigLine(line) - if kv: - d[kv[0]] = kv[1] - return d - - -def dumpConfigFile(configFile): - "print out dictionary of key/value pairs from configFile" - - import pprint - pprint.pprint(readConfigFile(configFile)) - - -def mapNewSettings(configFile, dnew): - fo = tempfile.TemporaryFile(prefix = '/tmp/client-config-overrides-', mode = 'r+b') - fin = open(configFile, 'rb') - - changedYN = 0 - - # write to temp file - for line in fin.readlines(): - kv = _parseConfigLine(line) - if not kv: - # not a setting, write the unaltered line - fo.write(line) - else: - # it's a setting, populate from the dictionary - if kv[0] in dnew: - if dnew[kv[0]] != kv[1]: - fo.write(('%s=%s\n' % (kv[0], dnew[kv[0]])).encode('utf8')) - changedYN = 1 - else: - fo.write(line) - # it's a setting but not being mapped - else: - fo.write(line) - fin.close() - - if changedYN: - # write from temp file to configFile - fout = open(configFile, 'wb') - fo.seek(0) - fout.write(fo.read()) - print('*', configFile, 'written') - - -def parseCommandline(): - """parse/process the commandline - - Commandline is dead simple for easiest portability. - """ - - # USAGE & HELP! - if '--usage' in sys.argv or '-h' in sys.argv or '--help' in sys.argv: - print("""\ -usage: python %s CONFIG_FILENAME NEW_MAPPINGS [options] -arguments: - CONFIG_FILENAME config file to alter - NEW_MAPPINGS file containing new settings that map onto the - config file -options: - -h, --help show this help message and exit - --usage show brief usage summary - -examples: - python %s %s %s - python %s %s %s -""" % (sys.argv[0], - sys.argv[0], RHN_REGISTER, DEFAULT_CLIENT_CONFIG_OVERRIDES, - sys.argv[0], UP2DATE, DEFAULT_CLIENT_CONFIG_OVERRIDES)) - - sys.exit(0) - - - if len(sys.argv) != 3: - msg = "ERROR: exactly two arguments are required, see --help" - raise TypeError(msg) - - configFilename = os.path.abspath(sys.argv[1]) - newMappings = os.path.abspath(sys.argv[2]) - - if not os.path.exists(configFilename): - msg = ("ERROR: filename to alter (1st argument), does not exist:\n" - " %s" - % configFilename) - raise IOError(msg) - - if not os.path.exists(newMappings): - msg = ("ERROR: filename that contains the mappings (2nd argument), " - "does not exist:\n" - " %s" % newMappings) - raise IOError(msg) - - return configFilename, newMappings - - -def main(): - "parse commandline, process config file key=value mappings" - - configFilename, newMappings = parseCommandline() - #dumpConfigFile(configFilename) - #mapNewSettings('test-up2date', readConfigFile(DEFAULT_CLIENT_CONFIG_OVERRIDES)) - - mapNewSettings(configFilename, readConfigFile(newMappings)) - -if __name__ == '__main__': - try: - sys.exit(main() or 0) - except Exception as err: - print(err) diff --git a/spacewalk/certs-tools/mgr-bootstrap.sgml b/spacewalk/certs-tools/mgr-bootstrap.sgml index 981ee85d66a7..17093f450488 100644 --- a/spacewalk/certs-tools/mgr-bootstrap.sgml +++ b/spacewalk/certs-tools/mgr-bootstrap.sgml @@ -185,7 +185,6 @@ Files /usr/bin/mgr-bootstrap - /usr/bin/client_config_update.py /usr/bin/client-config-overrides.txt diff --git a/spacewalk/certs-tools/rhn_bootstrap.py b/spacewalk/certs-tools/rhn_bootstrap.py index 3aaffcc2e19d..38819dc85399 100755 --- a/spacewalk/certs-tools/rhn_bootstrap.py +++ b/spacewalk/certs-tools/rhn_bootstrap.py @@ -39,7 +39,6 @@ ## local imports from uyuni.common import rhn_rpm from spacewalk.common.rhnConfig import CFG, initCFG -from .client_config_update import readConfigFile from .rhn_bootstrap_strings import \ getHeader, getGPGKeyImportSh, \ getCorpCACertSh, getRegistrationStackSh, \ @@ -83,6 +82,47 @@ errnoCANotFound = 16 errnoGPGNotFound = 17 +def _parseConfigLine(line): + """parse a line from a config file. Format can be either "key=value\n" + or "whatever text\n" + + return either: + (key, value) + or + None + The '\n' is always stripped from the value. + """ + + kv = line.decode('utf8').split('=') + if len(kv) < 2: + # not a setting + return None + + if len(kv) > 2: + # '=' is part of the value, need to rejoin it. + kv = [kv[0], '='.join(kv[1:])] + + if kv[0].find('[comment]') > 0: + # comment; not a setting + return None + + # it's a setting, trim the '\n' and return the (key, value) pair. + kv[0] = kv[0].strip() + kv[1] = kv[1].strip() + return tuple(kv) + +def readConfigFile(configFile): + "read in config file, return dictionary of key/value pairs" + + fin = open(configFile, 'rb') + + d = {} + + for line in fin.readlines(): + kv = _parseConfigLine(line) + if kv: + d[kv[0]] = kv[1] + return d # should come out of common code when we move this code out of # rhns-certs-tools @@ -498,8 +538,6 @@ def writeClientConfigOverrides(options): fout.write("""\ # RHN Client (rhn_register/up2date) config-overrides file v4.0 # -# To be used only in conjuction with client_config_update.py -# # This file was autogenerated. # # The simple rules: diff --git a/spacewalk/certs-tools/spacewalk-certs-tools.spec b/spacewalk/certs-tools/spacewalk-certs-tools.spec index fbb69106fb9c..ff9c2dd391fd 100644 --- a/spacewalk/certs-tools/spacewalk-certs-tools.spec +++ b/spacewalk/certs-tools/spacewalk-certs-tools.spec @@ -87,7 +87,7 @@ sed -i 's|etc/httpd/conf|etc/apache2|g' ssl-howto.txt %install install -d -m 755 $RPM_BUILD_ROOT/%{rhnroot}/certs -sed -i '1s|python\b|python3|' rhn-ssl-tool mgr-package-rpm-certificate-osimage rhn-bootstrap client_config_update.py +sed -i '1s|python\b|python3|' rhn-ssl-tool mgr-package-rpm-certificate-osimage rhn-bootstrap make -f Makefile.certs install PREFIX=$RPM_BUILD_ROOT ROOT=%{rhnroot} \ PYTHONPATH=%{python3_sitelib} PYTHONVERSION=%{python3_version} \ MANDIR=%{_mandir} PUB_BOOTSTRAP_DIR=%{pub_bootstrap_dir} @@ -126,7 +126,6 @@ ln -s spacewalk-ssh-push-init $RPM_BUILD_ROOT/%{_sbindir}/mgr-ssh-push-init %doc %{_mandir}/man1/mgr-*.1* %doc ssl-howto-simple.txt ssl-howto.txt %license LICENSE -%{pub_bootstrap_dir}/client_config_update.py* %dir %{rhnroot} %dir %{pub_dir} %dir %{pub_bootstrap_dir} diff --git a/spacewalk/certs-tools/spacewalk-ssh-push-init b/spacewalk/certs-tools/spacewalk-ssh-push-init index d95629abf93a..08e505a505fc 100755 --- a/spacewalk/certs-tools/spacewalk-ssh-push-init +++ b/spacewalk/certs-tools/spacewalk-ssh-push-init @@ -268,7 +268,7 @@ if [ "${USE_TUNNEL}" = "Y" ]; then exit_in_case_of_error echo "* Cleaning up temporary files" - ssh -i ${SSH_IDENTITY} ${OPTIONS} ${USER}@${CLIENT} "rm -fv enable.sh bootstrap.sh client-config-overrides-tunnel.txt client_config_update.py" + ssh -i ${SSH_IDENTITY} ${OPTIONS} ${USER}@${CLIENT} "rm -fv enable.sh bootstrap.sh client-config-overrides-tunnel.txt" cleanup_temp_files elif [ -n "${BOOTSTRAP}" ]; then # Simple registration with given bootstrap script @@ -278,5 +278,5 @@ elif [ -n "${BOOTSTRAP}" ]; then exit_in_case_of_error echo "* Cleaning up temporary files remotely" - ssh -i ${SSH_IDENTITY} ${OPTIONS} ${USER}@${CLIENT} "rm -fv bootstrap.sh client-config-overrides.txt client_config_update.py" + ssh -i ${SSH_IDENTITY} ${OPTIONS} ${USER}@${CLIENT} "rm -fv bootstrap.sh client-config-overrides.txt" fi