#!/bin/bash
# 
# script for copying sound banks from sound blaster cd to localhost
# dan meszaros <dmeszar@suse.cz>

# source directory
SRC_DIR=$1

SOUNDFONTDIR="/usr/share/sfbank/creative"

# create target directory
mkdir -p $SOUNDFONTDIR 

# create list of unique sound font found on the whole cd
cd $SRC_DIR
for F in `find . -name '*.[sS][fF]2' -type f `
do 
    echo -e "${F##*/}\t$F"
done | \
sort | \
while read NAM FILE
do
    if [ "$NAM" != "$OLD" ]
    then
        cp -a $FILE $SOUNDFONTDIR
        OLD=$NAM
	echo "line"
    fi
done | wc -l 

cd $SOUNDFONTDIR

# find the largest file in $SOUNDFONTDIR
HIGHEST=`ls -S1 *.[sS][fF]2 | head -n1`

# is there any sound font except the default one?
if [ "$HIGHEST" != "default.sf2" ]
then
    # remove old link
    rm -f default.sf2

    #create link to the largest font file
    ln -s $HIGHEST default.sf2
fi

