Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick dirty script to maintain local repo mirrors. Serve up with httpd, nginx, or whatever
# Add this file to /etc/yum.repos.d/local-mirrors.repo
# Change the IP below accordingly
[mirror-base]
name=Base mirror
baseurl=http://192.168.100.10/base
enabled=1
cost=500
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[mirror-extras]
name=Extras mirror
baseurl=http://192.168.100.10/extras
enabled=1
cost=500
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[mirror-updates]
name=Updates mirror
baseurl=http://192.168.100.10/updates
enabled=1
cost=500
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[mirror-epel]
name=EPEL mirror
baseurl=http://192.168.100.10/epel
enabled=1
cost=500
gpgcheck=1
# I had to manually copy this file to `/var/www/html/epel/RPM-GPG-KEY-EPEL-7`
gpgkey=http://192.168.100.10/epel/RPM-GPG-KEY-EPEL-7
#!/bin/bash
# Place this in /etc/cron.daily/sync-repos and chmod 0755
set -euo pipefail
# These repos must be added to your local system by name. Add more if you need them to this list.
repolist=(base updates extras epel)
for repo in "${repolist[@]}"; do
echo "Syncing repo: ${repo}"
reposync --download-metadata --delete --gpgcheck -l --download_path=/var/www/html --downloadcomps --download-metadata --newest-only --repoid "${repo}"
echo "Finished syncing '${repo}'. Generating metadata"
cd "/var/www/html/${repo}"
COMPS=""
if [ -f comps.xml ]; then
COMPS="--groupfile=./comps.xml"
fi
createrepo --verbose ${COMPS} "$(pwd)"
echo
echo "Syncing repo ${repo} complete."
done
# Ensure selinux context is valid for serving from http
restorecon -rv /var/www/html/
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment