Skip to content

Instantly share code, notes, and snippets.

@gtirloni
Created July 18, 2018 18:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtirloni/8089e51d1c7a23157521b03126835277 to your computer and use it in GitHub Desktop.
Save gtirloni/8089e51d1c7a23157521b03126835277 to your computer and use it in GitHub Desktop.
CentOS/Fedora mirror
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o xtrace
LOCKFILE="${PWD}/$(basename "$0").lock"
LOCKFD=99
_lock() { flock -"$1" "$LOCKFD"; }
_no_more_locking() { _lock u; _lock xn && rm -f "$LOCKFILE"; }
_prepare_locking() { eval "exec $LOCKFD>\"$LOCKFILE\""; trap _no_more_locking EXIT; }
exlock_now() { _lock xn; } # obtain an exclusive lock immediately or fail
exlock() { _lock x; } # obtain an exclusive lock
shlock() { _lock s; } # obtain a shared lock
unlock() { _lock u; } # drop a lock
# Obtain lock or fail
_prepare_locking
exlock_now || exit 1
#
# Fedora
#
BASEDIR="${HOME}/public_html/fedora"
MIRROR="mirrors.rit.edu"
RSYNC_OPTS=(-avuH --no-motd --delete-after --delete-excluded --exclude source --exclude SRPMS --exclude debug --exclude ppc --exclude ppc64 --exclude ppc64le --exclude i386 --exclude s390 --exclude s390x --exclude sparc --exclude sparc64 --exclude aarch64 --exclude armhfp --exclude arm)
rsync "${RSYNC_OPTS[@]}" "rsync://${MIRROR}/fedora/releases/27/" "${BASEDIR}/releases/27"
rsync "${RSYNC_OPTS[@]}" "rsync://${MIRROR}/fedora/releases/28/" "${BASEDIR}/releases/28"
rsync "${RSYNC_OPTS[@]}" "rsync://${MIRROR}/fedora/updates/27/" "${BASEDIR}/updates/27"
rsync "${RSYNC_OPTS[@]}" "rsync://${MIRROR}/fedora/updates/28/" "${BASEDIR}/updates/28"
#
# EPEL
#
BASEDIR="${HOME}/public_html/epel"
MIRROR="mirrors.rit.edu"
RSYNC_OPTS=(-avuH --no-motd --delete-after --delete-excluded --exclude debug --exclude .~tmp~)
rsync "${RSYNC_OPTS[@]}" "rsync://${MIRROR}/epel/7/x86_64/" "${BASEDIR}/7/x86_64"
#
# CentOS
#
BASEDIR="${HOME}/public_html/centos"
MIRROR="mirrors.rit.edu"
RSYNC_OPTS=(-avuH --no-motd --delete-after --delete-excluded --exclude .~tmp~ --exclude debug)
#rsync "${RSYNC_OPTS[@]}" "rsync://${MIRROR}/centos/7.4.1708/os/x86_64/" "${BASEDIR}/7.4.1708/os/x86_64"
#rsync "${RSYNC_OPTS[@]}" "rsync://${MIRROR}/centos/7.4.1708/updates/x86_64/" "${BASEDIR}/7.4.1708/updates/x86_64"
#rsync "${RSYNC_OPTS[@]}" "rsync://${MIRROR}/centos/7.4.1708/extras/x86_64/" "${BASEDIR}/7.4.1708/extras/x86_64"
rsync "${RSYNC_OPTS[@]}" "rsync://${MIRROR}/centos/7.5.1804/os/x86_64/" "${BASEDIR}/7.5.1804/os/x86_64"
rsync "${RSYNC_OPTS[@]}" "rsync://${MIRROR}/centos/7.5.1804/updates/x86_64/" "${BASEDIR}/7.5.1804/updates/x86_64"
rsync "${RSYNC_OPTS[@]}" "rsync://${MIRROR}/centos/7.5.1804/extras/x86_64/" "${BASEDIR}/7.5.1804/extras/x86_64"
echo "=> Updating MirrorManager"
/usr/bin/report_mirror
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment