Created
January 29, 2021 16:11
-
-
Save dcode/9aef8806b4f382d90cf1d2eb91675565 to your computer and use it in GitHub Desktop.
Quick dirty script to maintain local repo mirrors. Serve up with httpd, nginx, or whatever
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
# 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 |
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 | |
# 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