#!/bin/bash

# Script to place a single copy of each connector in /var/lib/cf-repo
# into the current directory, without duplicates or backups. Useful
# when you want to perform a static analysis across the connectors.

dest=`pwd`
cd /var/lib/cf-repo
for i in *; do
    if [ -L "$i" ]; then
        echo "ignoring '$i' directory (symlink)"
	continue
    fi

    (
        echo "copying from '$i'"
    	cd "$i"
	for j in *; do
	    if [[ "$j" == *.bak ]]; then
		echo "	skipping '$j' (is a backup)"	    
	    elif [ ! -L "$j" ]; then
		echo "	skipping '$j' (numbered version)"
	    elif [ -f "$dest/$j" ]; then
		echo "	skipping '$j' (already exists)"
	    else
		echo "	copying '$j'"
		cp "$j" "$dest"
	    fi
	done
    )
done
