From ce1d818e401e640dea188926ab66b7113d0c067f Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 10 Apr 2010 02:33:02 +0200 Subject: initial commit --- createlinks | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 createlinks (limited to 'createlinks') diff --git a/createlinks b/createlinks new file mode 100755 index 0000000..bfcefae --- /dev/null +++ b/createlinks @@ -0,0 +1,69 @@ +#!/bin/bash + +home="$(dirname "${0}")" +target="${home}/repo" +repos=('core' 'extra' 'community') +arches=('i686' 'x86_64') +lock='/tmp/mirrorsync.lck' +tmp="$(mktemp -d)" + +[ -f "${lock}" ] && exit 1 +touch "${lock}" + +renice +10 -p $$ > /dev/null + +getpkgname() { + local tmp + + tmp=${1##*/} + echo ${tmp%-*.pkg.tar.*} +} + + +for repo in ${repos[@]}; do + for arch in ${arches[@]}; do + # ( + repodir=${repo}/os/${arch} + cached=false + + # extract old file archive + if [ -f ${target}/${repodir}/${repo}.links.tar.gz ]; then + mkdir -p ${tmp}/cache/${repodir} + bsdtar -xf ${target}/${repodir}/${repo}.links.tar.gz -C ${tmp}/cache/${repodir} + cached=true + fi + + # create file lists + for pkg in $(find $target/$repodir -type f -name '*.pkg.tar.*'); do + pkgname=$(getpkgname $pkg) + tmppkgdir=${tmp}/tmp/${repodir}/${pkgname} + mkdir -p $tmppkgdir + if [ -f "${tmp}/cache/${repodir}/${pkgname}/links" ]; then + # reuse the cached file + mv ${tmp}/cache/${repodir}/${pkgname}/links ${tmppkgdir}/links + else + echo "$repo/$arch: $pkgname" + mkdir -p ${tmppkgdir}/pkg + bsdtar -xof $pkg -C ${tmppkgdir}/pkg --include={opt,{,usr/}{lib,{s,}bin}}'/*' 2>/dev/null + for f in $(find ${tmppkgdir}/pkg -type f); do + readelf -d "$f" 2> /dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p' + done | sort -u > ${tmppkgdir}/links + rm -rf ${tmppkgdir}/pkg + cached=false + fi + done + + # create new file archive + if ! $cached; then + # at least one package has changed, so let's rebuild the archive + pkgdir=${target}/${repodir} + mkdir -p $pkgdir + bsdtar --exclude=*.tar.* -czf ${pkgdir}/${repo}.links.tar.gz -C ${tmp}/tmp/${repodir} . + fi + # )& + done +#wait +done + +rm -rf ${tmp} +rm -f "${lock}" -- cgit v1.2.3-24-g4f1b