#!/bin/sh
#
# $Id$
#
# Set up an OSGi-runner from a test harness directory bootstrapped with
#
#   osgi-runner-test-setup <path>
#

if test $# -ne 1
then
    echo "Usage: $0 <path>"
    echo "  <path> is the directory to be filled with etc et al for a test osgi-runner"
    exit 64
fi

dir=$1
absdir=$(cd $dir && pwd)

echo '***** '"Setting up osgi-runner test directory $absdir..."

if test ! -d $abdir
then
    echo "Error: $1 does not exists or is not a directory."
    exit 1
fi

cd $absdir

echo '***** '"Populating $absdir/etc"

(cd /usr/share/osgi-runner/test; tar cf - etc) | tar xvf -

echo '***** '"Creating $absdir/run.sh"

cat <<EOF > run.sh
#!/bin/sh
#
# Run osgi-runner-test in this directory.
#
dir=\$(dirname \$0)
/usr/bin/osgi-runner-test \$* \$dir
EOF

chmod 775 run.sh

echo '***** '"Consider correcting imported base bundles in"
echo '***** '"  $absdir/etc/adm.d/org.apache.felix.fileinstall-osgibundles.cfg"

echo '***** '"Password of user test/test is test123!"
echo '***** '"Password of user test/test01 is test123!01"
echo '***** '"Password of user test/test02 is test123!02"
echo '***** '"Password of user test/test03 is test123!03"
echo '***** '"Password of user test/test04 is test123!04"
echo '***** '"Password of user test/test05 is test123!05"
echo '***** '"Password of user test/test06 is test123!06"
echo '***** '"Password of user test/test07 is test123!07"
echo '***** '"Password of user test/test08 is test123!08"
echo '***** '"Password of user test/test09 is test123!09"


echo '***** '"If you use svn, consider to run the following:"
echo "  cd $absdir"
echo "  svn add run.sh"
echo "  svn add etc"
echo "  svn propset svn:ignore 'cache"
echo "log' ."
echo "  svn propset svn:ignore org.ops4j.pax.logging.cfg etc/adm.d"
echo "  svn propset svn:ignore authorized_keys etc/sshd.d"

echo '***** '"Finished setup up of osgi-runner test directory $absdir"
