diff --git a/branches/ucs-3.1/ucs/base/univention-debmirror/77univention-debmirror.inst b/branches/ucs-3.1/ucs/base/univention-debmirror/77univention-debmirror.inst index 17455d1..91f0306 100755 --- a/branches/ucs-3.1/ucs/base/univention-debmirror/77univention-debmirror.inst +++ b/branches/ucs-3.1/ucs/base/univention-debmirror/77univention-debmirror.inst @@ -36,11 +36,11 @@ joinscript_init eval "$(univention-config-registry shell hostname domainname)" . /usr/share/univention-lib/all.sh +FQDN="$hostname.$domainname" if is_ucr_true "local/repository" then REPO="univention-repository.$domainname" - FQDN="$hostname.$domainname" # Is there already another repository server? target="$(LC_ALL=C host -t CNAME "$REPO" | sed -ne 's|.* is an alias for \(.*\)\.$|\1|p')" if [ -z "$target" ]; then diff --git a/branches/ucs-3.1/ucs/base/univention-updater/debian/rules b/branches/ucs-3.1/ucs/base/univention-updater/debian/rules index e38d1ac..1139551 100755 --- a/branches/ucs-3.1/ucs/base/univention-updater/debian/rules +++ b/branches/ucs-3.1/ucs/base/univention-updater/debian/rules @@ -71,7 +71,6 @@ override_dh_fixperms: dh_fixperms chmod 755 debian/univention-updater/usr/lib/univention-directory-policy/univention-policy-set-repository-server chmod 755 debian/univention-updater/usr/lib/univention-directory-policy/univention-policy-maintenance - chmod 755 debian/univention-updater/usr/lib/univention-directory-policy/univention-policy-set-repository-server chmod 755 debian/univention-updater/usr/share/univention-updater/enable-apache2-umc chmod 755 debian/univention-updater/usr/share/univention-updater/disable-apache2-umc chmod 755 debian/univention-updater/usr/share/univention-updater/univention-updater-check diff --git a/branches/ucs-3.1/ucs/base/univention-updater/debian/univention-updater.postinst b/branches/ucs-3.1/ucs/base/univention-updater/debian/univention-updater.postinst index 287e491..da112a2 100644 --- a/branches/ucs-3.1/ucs/base/univention-updater/debian/univention-updater.postinst +++ b/branches/ucs-3.1/ucs/base/univention-updater/debian/univention-updater.postinst @@ -145,7 +145,7 @@ fi # the UCR debhelper section will be added before the pysupport section, # so we added the pysupport section manually if which update-python-modules >/dev/null 2>&1; then - update-python-modules univention-updater.public + update-python-modules univention-updater.public fi #DEBHELPER# @@ -159,11 +159,8 @@ fi test -x /etc/init.d/univention-directory-listener && /etc/init.d/univention-directory-listener restart # set the repository server -eval "$(univention-config-registry shell hostname domainname update/server)" -if [ -n "$update_server" -a "$update_server" != "http://download.univention.de" ]; then - update_server=`echo "$update_server" | LC_ALL=C sed -e 's|^[A-Za-z][0-9A-Za-z+.-]*://\([^/]*\).*|\1|'` # - univention-config-registry set repository/online/server?"$update_server" -elif host univention-repository.$domainname > /dev/null 2>&1; then +eval "$(univention-config-registry shell hostname domainname)" +if host "univention-repository.$domainname" > /dev/null 2>&1; then univention-config-registry set repository/online/server?"univention-repository.$domainname" else # univention-config-registry set repository/online/server?"testing.univention.de" diff --git a/branches/ucs-3.1/ucs/base/univention-updater/univention-directory-policy/univention-policy-set-repository-server b/branches/ucs-3.1/ucs/base/univention-updater/univention-directory-policy/univention-policy-set-repository-server index 681286d..3932b27 100644 --- a/branches/ucs-3.1/ucs/base/univention-updater/univention-directory-policy/univention-policy-set-repository-server +++ b/branches/ucs-3.1/ucs/base/univention-updater/univention-directory-policy/univention-policy-set-repository-server @@ -2,7 +2,9 @@ # -*- coding: utf-8 -*- # # Univention Updater -# read the repository server +""" +Read the repository server from LDAP policy. +""" # # Copyright 2004-2012 Univention GmbH # @@ -32,68 +34,81 @@ # . import os -import sys, subprocess -import univention.config_registry +import sys +import subprocess +from univention.config_registry import ConfigRegistry, handler_set -configRegistry = univention.config_registry.ConfigRegistry() -configRegistry.load() -ldap_hostdn = configRegistry.get('ldap/hostdn') - -def exit(result, message = None): - script = os.path.basename(sys.argv[0]) +def terminate(result, message=None): + """ + Exit with result and optional message. + """ if message: - print '%s: %s' % (script, message) + script = os.path.basename(sys.argv[0]) + print >> sys.stderr, '%s: %s' % (script, message) sys.exit(result) -def query_policy(update): - server = None - p1 = subprocess.Popen(['univention_policy_result', '-D', ldap_hostdn, '-y', '/etc/machine.secret', '-s', ldap_hostdn], stdout=subprocess.PIPE) - result = p1.communicate()[0] - if p1.returncode != 0: - exit(result, "FAIL: failed to execute `univention_policy_result'") +def query_policy(ldap_hostdn): + """ + Retrive policy result for host. + """ + cmd = ( + 'univention_policy_result', + '-D', ldap_hostdn, + '-y', '/etc/machine.secret', + '-s', ldap_hostdn + ) + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) + stdout, _stderr = proc.communicate() + + if proc.returncode != 0: + terminate(stdout, "FAIL: failed to execute `univention_policy_result'") - for line in result.split('\n'): - line = line.strip() - if line.startswith('univentionRepositoryServer='): - server = line.split('=', 1)[1].split('"',2)[1] - elif line.startswith('univentionUpdateVersion='): - update = line.split('=', 1)[1].split('"',2)[1] - if server and server.startswith('http://'): - server = server.replace('http://', '', 1) + server = update = None + for line in stdout.splitlines(): + key, value = line.split('=', 1) + if key == 'univentionRepositoryServer': + server = value[1:-1] + if server.startswith('http://'): + server = server[len('http://'):] + elif key == 'univentionUpdateVersion': + update = value[1:-1] return (server, update) + def main(): - restore_server = None - online_server = configRegistry.get( 'repository/online/server') - mirror_server = configRegistry.get( 'repository/mirror/server') - local_repo = configRegistry.is_true( 'local/repository') - fqdn = '%s.%s' % (configRegistry['hostname'], configRegistry['domainname']) - update = '%s-%s' % (configRegistry['version/version'], configRegistry['version/patchlevel']) - # ldap_host_dn, old_server, local_server, local_repo, fqdn, update = query_baseconfig() + """ + Retrieve repository servr from LDAP policy. + """ + ucr = ConfigRegistry() + ucr.load() - ucr_variables = [] + ldap_hostdn = ucr.get('ldap/hostdn') if not ldap_hostdn: # can't query policy without host-dn - exit(0) + return - new_server, update = query_policy(update) - # without a local repository - if not local_repo: - if not new_server or new_server == online_server: - # no new server specified - exit(0) - else: - ucr_variables.append( 'repository/online/server=%s' % new_server ) - else: + new_server, _update = query_policy(ldap_hostdn) + if not _update: + _update = '%(version/version)s-%(version/patchlevel)s' % ucr + + changes = [] + if ucr.is_true('local/repository'): # on a repository server - if not new_server: - ucr_variables.append( 'repository/online/server?%s' % fqdn ) - elif new_server != mirror_server: - ucr_variables.append( 'repository/mirror/server=%s' % new_server ) + if new_server and new_server != ucr.get('repository/mirror/server'): + changes.append('repository/mirror/server=%s' % new_server) + elif not new_server: + fqdn = '%(hostname)s.%(domainname)s' % ucr + changes.append('repository/online/server?%s' % fqdn) + else: + # without a local repository + if new_server and new_server != ucr.get('repository/online/server'): + changes.append('repository/online/server=%s' % new_server) + + if changes: + handler_set(changes) - univention.config_registry.handler_set( ucr_variables ) if __name__ == '__main__': main()