Skip to content

Instantly share code, notes, and snippets.

@brianredbeard
Last active January 30, 2024 06:23
Show Gist options
  • Star 32 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save brianredbeard/7034245 to your computer and use it in GitHub Desktop.
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.
#!/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 <brian@dead-city.org>
# 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
@brianredbeard
Copy link
Author

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