Last active
April 2, 2019 05:59
-
-
Save myst3k/c3866ae65ccd203a93c7b702ecdd7ebc to your computer and use it in GitHub Desktop.
oracle linux local yum repo setup on OL7
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
## Updated courtesy of (https://oracle-base.com/articles/linux/create-a-local-yum-repository-for-oracle-linux-7) | |
yum -y install yum-utils createrepo_c httpd | |
systemctl enable --now httpd | |
cp /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle /var/www/html/ | |
mkdir -p /u01/repo/{OracleLinux,logs,scripts,cache} | |
touch /u01/repo/scripts/repo_sync.sh | |
chmod u+x /u01/repo/scripts/repo_sync.sh | |
## Runs at 1am | |
echo "0 1 * * * /u01/repo/scripts/repo_sync.sh > /dev/null 2>&1" >> /etc/crontab | |
/u01/repo/scripts/repo_sync.sh | |
~~~~~~~~~~~ | |
#!/usr/bin/env bash | |
#set -o xtrace | |
set -o nounset | |
set -o errexit | |
IFS="$(printf '\n\t')" | |
LOG_FILE=/u01/repo/logs/repo_sync_$(date +%Y.%m.%d).log | |
CACHE=/u01/repo/cache | |
REPOSYNC=/usr/bin/reposync | |
REPOSYNC_FLAGS="--newest-only --download-metadata" | |
CREATEREPO=/usr/bin/createrepo_c | |
if find /u01/repo/logs/repo_sync* -mtime +5 -delete; >> $LOG_FILE 2>&1 | |
then | |
echo 'Cleaned up old log files...' >> $LOG_FILE 2>&1 | |
else | |
echo 'No old log files found...' >> $LOG_FILE 2>&1 | |
fi | |
declare -a arr=() | |
arr+=("ol7_latest") | |
arr+=("ol7_u5_base") | |
arr+=("ol7_u6_base") | |
arr+=("ol7_UEKR4") | |
arr+=("ol7_UEKR5") | |
arr+=("ol7_addons") | |
arr+=("ol7_optional_latest") | |
arr+=("ol7_developer_EPEL") | |
echo "Syncing Repositories..." >> $LOG_FILE 2>&1 | |
for i in "${arr[@]}" | |
do | |
echo "RUNNING: $REPOSYNC $REPOSYNC_FLAGS --repoid=$i -p /u01/repo/OracleLinux" >> $LOG_FILE 2>&1 | |
$REPOSYNC --newest-only --download-metadata --repoid=$i -p /u01/repo/OracleLinux >> $LOG_FILE 2>&1 | |
done | |
echo "Creating Repositories..." >> $LOG_FILE 2>&1 | |
for i in "${arr[@]}" | |
do | |
## Check if .repodata is left over from previous run and remove it | |
WORKINGDIR=/u01/repo/OracleLinux/$i/getPackage/.repodata/ | |
if [ -d "$WORKINGDIR" ]; then | |
echo "Removing directory $WORKINGDIR..." >> $LOG_FILE 2>&1 | |
rm -rf $WORKINGDIR | |
fi | |
## Do not generate groupfile if repo does not contain any groups | |
GROUPFILE=/u01/repo/OracleLinux/$i/comps.xml | |
if [ -f $GROUPFILE ]; then | |
echo "RUNNING: $CREATEREPO --simple-md-filenames --update --cachedir $CACHE --groupfile=$GROUPFILE /u01/repo/OracleLinux/$i/getPackage/" >> $LOG_FILE 2>&1 | |
$CREATEREPO --simple-md-filenames --update --cachedir $CACHE --groupfile=$GROUPFILE /u01/repo/OracleLinux/$i/getPackage/ >> $LOG_FILE 2>&1 | |
else | |
echo "RUNNING: $CREATEREPO --simple-md-filenames --update --cachedir $CACHE /u01/repo/OracleLinux/$i/getPackage/" >> $LOG_FILE 2>&1 | |
$CREATEREPO --simple-md-filenames --update --cachedir $CACHE /u01/repo/OracleLinux/$i/getPackage/ >> $LOG_FILE 2>&1 | |
fi | |
done | |
echo "Updating links..." >> $LOG_FILE 2>&1 | |
for i in "${arr[@]}" | |
do | |
LINK=/var/www/html/repo/OracleLinux/$i/x86_64 | |
if [ ! -e "$LINK" ]; then | |
mkdir -p /var/www/html/repo/OracleLinux/$i | |
ln -sf /u01/repo/OracleLinux/$i/getPackage/ /var/www/html/repo/OracleLinux/$i/x86_64 | |
fi | |
done | |
echo "Done!!" >> $LOG_FILE 2>&1 | |
~~~~~~~~~~~ | |
Run /u01/repo/scripts/repo_sync.sh manually to download everything the first time, it will take a while | |
Add a new arr entry for a new repository to mirror |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment