Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # The script assumes $CWD=='$DOCROOT/pub' as basis for links.
- # Prep the environment with:
- # $DOCROOT/pub/kickstart -> /var/satellite/rhn/kickstart
- # $DOCROOT/pub/channels -> /var/cache/rhn/repodata
- #
- # 'ks-' denotes kickstart (aka static) repository
- #
- # Example REPO file:
- #
- #[ks-rhel-x86_64-server-5.9]
- #name=RHEL5.9 - Server (x86_64)
- #baseurl=file:///var/satellite/rhn/kickstart/ks-rhel-x86_64-server-5-5.9/Server/
- # http://<satellite>/ks/dist/ks-rhel-x86_64-server-5-5.9/Server/
- # http://<satellite>/pub/kickstart/ks-rhel-x86_64-server-5-5.9/Server/
- #enabled=0
- #gpgkey=http://<satellite>/pub/RPM-GPG-KEY-redhat-release
- #
- #[rhel-x86_64-server-6]
- #name=RHEL6.x - Server (x86_64)
- #baseurl=file:///var/cache/rhn/repodata/rhel-x86_64-server-6/
- # http://<satellite>/pub/channels/rhel-x86_64-server-6/
- #enabled=0
- #gpgkey=http://<satellite>/pub/RPM-GPG-KEY-redhat-release
- # where Satellite keeps imported RPMs
- : ${SATDIR:=/var/satellite/redhat}
- # must be fully-qualified path
- : ${REPOFILE:=/var/www/html/pub/satellite.repo}
- # 'getPackage' path is hardcoded into repo metadata like so:
- # http://<satellite>/ks/dist/<channel>/.../getPackage/<rpm>
- PKGDIR=getPackage
- pkg_cache=/tmp/create-links.dat
- if [ -f $pkg_cache ]; then
- test $pkg_cache -nt `ls -td /var/cache/rhn/reposync/* | head -1` || \
- rm $pkg_cache
- else
- rm -f $pkg_cache 2>/dev/null
- fi
- # scan once to create list
- echo "creating package cache ..."
- test -s $pkg_cache || {
- t=`mktemp`
- trap "/bin/rm $t 2>/dev/null" INT KILL TERM EXIT
- find $SATDIR -type f > $t
- mv $t $pkg_cache
- }
- declare -A repos
- eval repos=(`awk '/^\[.*\]$/ { printf "%s=", $0; } /^baseurl=file:/ { sub(/.+:\/\//, "", $0); print $0; }' $REPOFILE`)
- for ch in ${!repos[@]}; do
- chp=${repos[$ch]}
- echo "processing '$ch' ..."
- if [ "${chp:0:1}" != "/" ]; then
- echo " ERROR: couldn't parse file-based 'baseurl'"
- continue
- fi
- if [ ! -d $chp -o ! -s $chp/repomd.xml ]; then
- echo " ERROR: baseurl path '$chp' is not invalid"
- continue
- fi
- ( cd $chp
- [ -e .CREATE_SKIP -o -e .CREATE_DONE ] && continue
- if [ ! -d repodata ]; then
- echo " INFO: creating missing 'repodata' directory"
- ln -s . repodata
- fi
- if [ ! -d $PKGDIR ]; then
- echo " INFO: creating package target directory '$PKGDIR'"
- mkdir $PKGDIR
- fi
- for rpm in `repoquery -c $REPOFILE --tempcache --repoid=$ch \
- --qf='%{name}-%{version}-%{release}.%{arch}.rpm' \
- --all --show-dupes 2>/dev/null`; do
- link=`grep -m 1 "${rpm}$" $pkg_cache`
- if [ -z "$link" ]; then # was 'reposync' run?
- echo " ERROR: package '$rpm' not found in repository"
- continue
- fi
- if [ -e "$PKGDIR/$rpm" ]; then
- if [ ! -h "$PKGDIR/$rpm" ]; then
- # remove non-symlink (eg. dedup populated repository)
- echo " WARN: removing non-symlink '$rpm'"
- rm -f $PKGDIR/$rpm
- elif ! stat -L $PKGDIR/$rpm &>/dev/null ; then
- echo " WARN: removing broken symlink '$rpm'"
- rm -f $PKGDIR/$rpm
- fi
- fi
- if [ ! -e "$PKGDIR/$rpm" ]; then
- ln -s "$link" "$PKGDIR/$rpm" || \
- echo " ERROR: create link to '$rpm' failed"
- fi
- done
- [ "ks-" = "${ch:0:3}" ] && touch .CREATE_DONE
- )
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement