+if [ "$DEBUG" == "yes" ]; then
+ rm()
+ {
+ echo "RM: $@" >&2
+ }
+ mv()
+ {
+ echo "MV: $@" >&2
+ }
+ cd()
+ {
+ command cd $1
+ echo "CD: $1" >&2
+ }
+fi
+
+# Return a list of packages that differ only by version than the one given
+# Args: $1 - the package we're intersted in (in N-V-R format)
+# Note1: we assume we're in .metadata dir
+# Note2: the list returned is newline, not space, separated
+# Note3: sets $glob_basename to basename (without V-R) if anybody need's it
+glob_packages()
+{
+ # Get just the name without the version tag
+ basename=`echo $1|sed -e 's,-[^-]*-[^-]*$,,'`
+ # Find packages beginning with that name
+ allfiles=`echo $basename*`
+ if [ "$allfiles" == "$basename*" ]; then
+ # No files found
+ return
+ fi
+ allfiles=`echo "$allfiles"|sed -e 's, ,\n,g' -e 's,.src.rpm.info,,g'`
+ # Filter out files that just begin with basename, but ain't other
+ # versions of that package
+ allfiles=`echo "$allfiles"|grep "$basename-[^-]*-[^-]*$"`
+ echo "$allfiles"
+}
+
+# Generate a list of older packages
+# Args: $1 - ftp tree
+# $2 - packages we're interested in
+find_older_pkgs()
+{
+ cd "$FTP_DIR/$1/SRPMS/.metadata/"
+ list=""
+ for file in $2; do
+ # "Glob" for other files
+ allfiles=`glob_packages $file`
+ # Get just the name without the version tag (we need it)
+ basename=`echo $file|sed -e 's,-[^-]*-[^-]*$,,'`
+ # Get only versions
+ allfiles=`echo "$allfiles"|sed -e "s,^$basename-,,"`
+ # Sort (note - this ain't perfect sorting)
+ allfiles=`echo "$allfiles"|sort -n`
+ # Readd names
+ allfiles=`echo "$allfiles"|sed -e "s,^,$basename-,"`
+ # Grep packages < current package
+ allfiles=`echo "$allfiles"|grep -B 999 "$file"|grep -v "^$file$"`
+ # Add to the list
+ allfiles=`echo $allfiles`
+ list="$list $allfiles"
+ done
+ echo $list
+}
+
+# Generate a list of all packages
+# Args: $1 - ftp tree
+# $2 - packages we're interested in
+find_all_pkgs()
+{
+ cd "$FTP_DIR/$1/SRPMS/.metadata/"
+ list=""
+ for file in $2; do
+ # "Glob" for other files
+ allfiles=`glob_packages $file`
+ # Add to the list
+ allfiles=`echo $allfiles`
+ list="$list $allfiles"
+ done
+ echo $list
+}
+
+# Remove packages in given tree
+# Args: $1 - ftp tree
+# $2 - list of packages (info files) to remove
+remove_pkgs() {
+ cd "$FTP_DIR/$1/SRPMS/.metadata/"
+ for srcfile in $2; do
+ # Remove all files connected to the old src.rpm
+ # (+ the src.rpm itself)
+ for i in `grep '^file:' $srcfile.src.rpm.info`; do
+ arch=`echo $i|cut -d: -f 2`
+ file=`echo $i|cut -d: -f 3`
+ rm "$FTP_DIR/$1/$arch/RPMS/$file"
+ done
+ # And finally remove the .info file
+ rm $srcfile.src.rpm.info
+ done
+}
+