#!/bin/sh set -e #set -x ARCHS="i386 powerpc amd64" DISTS="etch lenny sid" SRCBASE=~/public_debian PUBBASE=~/public_websites/debian.jones.dk #PUBTOSRC=../../public_debian archsfrompaths() { find "$@" -type l -exec find '{}'/ -type f -name '*.deb' ';' \ | sed 's/^.*_\([a-z0-9-]\+\)\.deb$/\1/' \ | sort -u } distsfrompaths() { find "$@" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' } pathsfromsections() { case "$@" in all) sections_re="" ;; "") echo 1>&2 "ERROR: At least one section (or the magic \"all\") is needed." exit 1 ;; *) sections_re="\b\($(echo "$@" | sed 's/[[:space:]]\+/\\|/g')\)\b" ;; esac find $SRCBASE -type f -name HINTS -exec grep -q "^Sections:.*$sections_re" '{}' ';' -printf '%h\n' \ | sed "s,^$SRCBASE/,," } sectionsfrompaths() { case "$@" in all) fullpaths="$SRCBASE" ;; *) fullpaths= for path in "$@"; do # TODO: rewrite to support spaces in directory names fullpaths="$fullpaths $SRCBASE/$path" done ;; esac find $fullpaths -type f -name HINTS -exec cat '{}' ';' \ | grep '^Sections:' \ | sed 's/^Sections://; s/[[:space:]]\+/ /g; s/^ //; s/ $//' \ | tr ' ' '\n' \ | sort -u } genlist() { dist="$1" arch="$2" srcdir="$3" basedir="$4" case "$arch" in source) destdir="$basedir/source"; cmd="dpkg-scansources"; file="Sources"; ;; *) destdir="$basedir/binary-$arch"; cmd="dpkg-scanpackages"; file="Packages"; ;; esac mkdir -p "$destdir" ( cd "$srcdir" && $cmd $dist /dev/null pools/ ) > "$destdir/$file" gzip -c "$destdir/$file" > "$destdir/$file.gz" bzip2 -c "$destdir/$file" > "$destdir/$file.bz2" } genlistsfromsection() { section="$1" case "$section" in all) srcdir="$SRCBASE/sections" ;; "") echo 1>&2 "ERROR: At least one section (or the magic \"all\") is needed." exit 1 ;; *) srcdir="$SRCBASE/sections/$section" ;; esac dists="$(distsfrompaths "$srcdir")" archs="$(archsfrompaths "$srcdir")" for dist in $DISTS; do do_dist= for dist_found in $dists; do if [ "$dist_found" = "$dist" ]; then do_dist=1 continue fi done [ -n "$do_dist" ] || continue for arch in $ARCHS; do do_arch= for arch_found in $archs; do case $arch_found in $arch|all) do_arch=1 continue esac done [ -n "$do_arch" ] || continue echo genlist "$section" "$dist" "$arch" "$srcdir" "$PUBBASE/dists/$dist/$section" done echo genlist "$section" "$dist" "source" "$srcdir" "$PUBBASE/dists/$dist/$section" done } sections="$@" paths="$(pathsfromsections "$sections")" #echo $paths; exit 0 #sectionsfrompaths all; exit 0 for path in $paths; do package="$(basename "$path")" pool="$(echo $(dirname "$path") | sed 's,.*/pool-\([^/]\+\)/\?.*,\1,; s,-all$,,')" buildhost="$(echo $(dirname "$path") | sed 's,^\([^/]\+\)/pool-.*,\1,')" symlink_dir="$pool/$package" mkdir -p "$PUBBASE/pools/$symlink_dir" # ln -sf -T "../../../$PUBTOSRC/$path" "$PUBBASE/pools/$symlink_dir/$buildhost" ln -sf -T "$SRCBASE/$path" "$PUBBASE/pools/$symlink_dir/$buildhost" for section in $(sectionsfrompaths "$path"); do mkdir -p "$SRCBASE/sections/$section/$symlink_dir" ln -sf -T "../../../../$path" "$SRCBASE/sections/$section/$symlink_dir/$buildhost" done done for section in $sections; do genlistsfromsection $section done exit 0