コード例 #1
0
def update_net(options: Namespace) -> None:
    """ Copy packages and scripts from remote mirror into local repository """
    mirror = UniventionMirror()
    # update local repository if available
    urepo.assert_local_repository()
    # mirror.run calls "apt-mirror", which needs /etc/apt/mirror.conf, which is
    # only generated with repository/mirror=true
    if not configRegistry.is_true('repository/mirror', False):
        print(
            'Error: Mirroring for the local repository is disabled. Set the Univention Configuration Registry variable repository/mirror to yes.'
        )
        sys.exit(1)

    # create mirror_base and symbolic link "univention-repository" if missing
    destdir = os.path.join(
        configRegistry.get('repository/mirror/basepath',
                           '/var/lib/univention-repository'), 'mirror')
    makedirs(destdir)
    try:
        os.symlink('.', os.path.join(destdir, 'univention-repository'))
    except EnvironmentError as e:
        if e.errno != errno.EEXIST:
            raise

    if options.sync:
        # only update packages of current repositories
        mirror.run()
    elif options.errata_only:
        # trigger update to find new errata repositories
        handler_commit(['/etc/apt/mirror.list'])
        mirror.run()
    elif options.update_to:
        # trigger update to explicitly mirror until given versions
        handler_set(['repository/mirror/version/end=%s' % options.update_to])
        mirror = UniventionMirror()
        mirror.run()
    else:
        # mirror all future versions
        handler_commit(['/etc/apt/mirror.list'])
        nextupdate = mirror.release_update_available()
        mirror_run = False
        while nextupdate:
            handler_set(['repository/mirror/version/end=%s' % nextupdate])
            # UCR variable repository/mirror/version/end has change - reinit Mirror object
            mirror = UniventionMirror()
            mirror.run()
            mirror_run = True
            nextupdate = mirror.release_update_available(nextupdate)
        if not mirror_run:
            # sync only
            mirror.run()
コード例 #2
0
def main() -> None:
    options = parse_args()

    if options.silent:
        sys.stdout = open(devnull, 'w')

    with UpdaterLock():
        check_preconditions(options)

        current_ucs_version = "%(version/version)s-%(version/patchlevel)s" % configRegistry
        options.version = UCS_Version(current_ucs_version)

        prepare(options)

        # set repository server to local system
        ucr_set = [
            'repository/online/server=%(hostname)s.%(domainname)s' %
            configRegistry,
            'repository/mirror/version/start?%s' % current_ucs_version,
        ]
        # set last version contained in repository
        end = configRegistry.get('repository/mirror/version/end', '').strip()
        if not end or UCS_Version(end) < options.version:
            ucr_set.append('repository/mirror/version/end=%s' %
                           options.version)

        handler_set(ucr_set)

        # create symbolic link univention-repository
        try:
            symlink('.', join(options.base, 'mirror', 'univention-repository'))
        except EnvironmentError as ex:
            if ex.errno != errno.EEXIST:
                raise

        print('Starting mirror download. This can take a long time!')
        print(
            'Check /var/log/univention/repository.log for the current status')
        subprocess.call(['univention-repository-update', 'net'])
        handler_commit([
            '/etc/apt/sources.list.d/15_ucs-online-version.list',
            '/etc/apt/sources.list.d/20_ucs-online-component.list',
        ])

        print(
            dedent(r"""
            The local repository has been prepared. The repository can be updated using:

              univention-repository-update net

            The local host has been modified to use this local repository.  Other hosts
            must be re-configured by setting the Univention Configuration Registry (UCR)
            variable 'repository/online/server' to the FQDN of this host.

              ucr set repository/online/server="%(hostname)s.%(domainname)s"

            The setting is best set in a domain by defining UCR Policies, which
            set this variable on all hosts using this repository server. For example:

              udm policies/repositoryserver create \
                --position "cn=repository,cn=update,cn=policies,%(ldap/base)s" \
                --set name="%(hostname)s repository" \
                --set repositoryServer="%(hostname)s.%(domainname)s"
              udm container/dc modify \
                --dn "%(ldap/base)s" \
                --policy-reference "cn=%(hostname)s repository,cn=repository,cn=update,cn=policies,%(ldap/base)s"
            """ % configRegistry))

        if options.version.minor != 0 or options.version.patchlevel != 0:
            print(
                dedent("""
                An UCS repository must always start with minor version 0, for example
                with UCS {ver.major}. Please synchronize the repository
                by using the tool 'univention-repository-update'.
                """).format(ver=options.version))
コード例 #3
0
 def _update_conffiles(self):
     conffiles = self._get_conffiles()
     if conffiles:
         with catch_stdout(self.logger):
             handler_commit(conffiles)