Last active
January 30, 2024 06:23
-
-
Save brianredbeard/7034245 to your computer and use it in GitHub Desktop.
Reposync - A better tool than mrepo. Use this to sync down all channels a RHEL system is subscribed to and turn them into locally exposed yum repositories.
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
#!/bin/bash | |
# This tool can be used to sync down Red Hat based packages from RHN using only Red Hat shipped tools | |
# Brian "Red Beard" Harrington <[email protected]> | |
# Copyright 2013 | |
# | |
# To satisfy the pre-reqs for this script install the following two rpms: | |
# yum-utils | |
# createrepo_c (in RHEL 8 createrepo and createrepo_c have been combined) | |
# See https://github.com/rpm-software-management/createrepo_c#differences-in-behavior-between-createrepo_c-and-createrepo | |
# Additional Notes: | |
# - The command `reposync` is handled by a DNF plugin of the same name in | |
# RHEL 8. This plugin does not provide a flag for control of GPG key | |
# checking and so must be handled via DNF config files or `--setopt` | |
# - For old CentOS content (e.g. CentOS 6) one must target vault.centos.org | |
# - `repoview` was deprecated in RHEL8 due to python-KID not being maintained | |
# - This tool does nothing special in relation to Modularity nor does it | |
# perform any optimized file handling (e.g. hard linking of content). | |
# - For more information read the "RPM-Based Distributions" section of this | |
# blog entry https://www.percona.com/blog/2020/01/02/how-to-create-your-own-repositories-for-packages/ | |
# | |
set -eu -o pipefail | |
RS_DOWNLOAD_DIR="${RS_DOWNLOAD_DIR:-/var/www/html/RHN}" | |
RS_LOG="${RS_LOG:-True}" | |
RS_LOG_PATH="${RS_LOG_PATH:-/var/log/reposync.log}" | |
function logger() { | |
echo "$(date):$(printf ' %q' "$@")" >> "${RS_LOG_PATH}" | |
"$@" 2>> "${RS_LOG_PATH}" | |
} | |
RS_LOG_CMD="" | |
if [ "${RS_LOG}" == "True" ]; then | |
RS_LOG_CMD="logger" | |
fi | |
# Perform synchronization of content | |
${RS_LOG_CMD} /usr/bin/reposync -m --download-metadata -p ${RS_DOWNLOAD_DIR}/ | |
# Process all RPMs in directory structure, generating repodata. | |
for dirname in `find ${RS_DOWNLOAD_DIR} -maxdepth 1 -mindepth 1 -type d`; do | |
echo $dirname: | tee -a /var/log/reposync.log | |
COMPS="" | |
# Check to see if comps.xml exists if so use it for group information | |
if [ -f "${dirname}/comps.xml" ]; then | |
${RS_LOG_CMD} cp ${dirname}/comps.xml ${dirname}/Packages/ | |
# Assign this to the comps path for use if comps.xml exists | |
COMPS="-g '${dirname}/Packages/comps.xml'" | |
fi | |
${RS_LOG_CMD} createrepo --update -p --workers 2 ${COMPS} ${dirname} | |
updateinfo=$(ls -1t ${dirname}/*-updateinfo.xml.gz 2>/dev/null | head -1 ) | |
if [[ -f $updateinfo && $? -eq 0 ]]; then | |
${RS_LOG_CMD} echo "Updating errata information for ${dirname}" | |
${RS_LOG_CMD} \cp $updateinfo ${dirname}/updateinfo.xml.gz | |
${RS_LOG_CMD} gunzip -df ${dirname}/updateinfo.xml.gz | |
${RS_LOG_CMD} modifyrepo ${dirname}/updateinfo.xml ${dirname}/repodata/ | |
else | |
${RS_LOG_CMD} echo "No errata information to be processed for ${dirname}" | |
fi | |
done | |
#vim: ts=4 sw=4 expandtab |
Is there a way when using this script to say "exclude" certain packages?
Can anyone have an example config to reposync rhel6/7 from a rhel7 machine?
@bp85 More recently I've been running this via a container (normally i use systemd-nspawn, but docker should work too) to get things done.
Makes me realize there should also be a variant of this for container content.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@admin-pro reposync could use specified yum.conf and multi-repo file. you could store rhel5/6/7 repo in one yum.repo.d forlder. then use reposync, and another question you need resolve is the server cloud visit rhel5/6/7 official repository at same time. give you a hint. look the repo file.