Skip to content

Instantly share code, notes, and snippets.

@ssato
Last active December 18, 2015 09:09
Show Gist options
  • Save ssato/5759708 to your computer and use it in GitHub Desktop.
Save ssato/5759708 to your computer and use it in GitHub Desktop.
#! /bin/bash
set -e
set -x
conffile=$1
listfile=$2
## Example ~/.ssh/config:
#Host rhel-x86_64-server-5
# Hostname 192.168.155.151
# User root
# IdentityFile ~/.ssh/id_rsa_sync
#
target_host="rhel-x86_64-server-5"
target_repoid="rhel-x86_64-server-5"
host="yum-server.example.com"
http_root=/srv/www
test "x$conffile" = "x" || source $conffile
test "x$listfile" = "x" || rsync_eopts="--include-from=$listfile"
test -d $metadatadir || mkdir -p $metadatadir
test "x$target_repodir" = "x" && target_repodir=/var/cache/yum/$target_repoid/ || :
test "x$reposubdir" = "x" && reposubdir=yum/metadata_mirrors/$target_repoid || :
test "x$repodir" = "x" && repodir=$http_root/$reposubdir || :
test "x$metadatadir" = "x" && metadatadir=$repodir/repodata || :
test "x$repofile" = "x" && repofile=$repodir/${target_repoid}.repo || :
ssh $target_host "yum makecache"
scp $target_host:$target_repodir/{\*.xml.gz,\*.xml} $metadatadir/
#rsync -e ssh -vaz $rsync_eopts $target_host:$target_repodir/ $metadatadir/
chcon -R --reference $http_root $repodir
if test ! -f $repofile; then
cat << EOF > $repofile
[${target_repoid}]
name=Mirrored metadata only repo of $target_repoid on $host
baseurl=http://${host}/$reposubdir/
enabled=0
gpgcheck=0
EOF
fi
# vim:sw=4:ts=4:et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment