#!/bin/nice sh
SRPMDIR="/var/ftp/pub/Linux/ALT/Sisyphus/files/SRPMS"
SPECPREFIX="/var/ftp/pub/Linux/ALT/people/mike/Sisyphus-SPECS"
TEMPSPECDIR="$SPECPREFIX/.updated"
TEMPDIR="$SPECPREFIX/.tmp"

rm -rf "$TEMPSPECDIR" "$TEMPDIR"
mkdir -p "$SPECPREFIX"
mkdir "$TEMPSPECDIR" "$TEMPDIR" || exit 1

cd "$TEMPDIR"
ls $SRPMDIR/ \
| fgrep .src.rpm \
| while read srpm; do
  srpm="$SRPMDIR/$srpm"
  rpm2cpio "$srpm" | cpio --quiet --extract *.spec \
  && spec="`rpmquery --qf='%{NAME}' -p "$srpm"`.spec" \
  && chmod 644 -- *.spec \
  && mv -f -- *.spec "$TEMPSPECDIR/$spec" \
  || echo "$srpm"
  rm -f -- *.spec
done

rsync -qa --delete-after "$TEMPSPECDIR/" "$SPECPREFIX/"
