#!/bin/bash

if [ "$#" -ne 3 ]
then
	echo "This script requires 3 arguments (IPs)"
	exit
fi

export M2_HOME=/qa/tools/opt/maven-3.3.9/
export PATH=$M2_HOME/bin:$PATH
cp /qa/fuseqe-shared/fuse/jboss-fuse-karaf-6.3.0.redhat-432.zip .
unzip jboss-fuse-karaf-6.3.0.redhat-432.zip
git clone https://gitlab.cee.redhat.com/jboss-fuse-qe/jbossqe-fuse.git
cd jbossqe-fuse
git checkout 6.3.x
cd fuse-tests/fabric-related-tests/blank-project/
mvn clean install
cd ~
cd jboss-fuse-6.3.0.redhat-432
sed -i '32s/#//' etc/users.properties
sed -i '87s/#//' fabric/import/fabric/profiles/karaf.profile/org.ops4j.pax.logging.properties
sed -i '88s/#//' fabric/import/fabric/profiles/karaf.profile/org.ops4j.pax.logging.properties
sed -i '89s/#//' fabric/import/fabric/profiles/karaf.profile/org.ops4j.pax.logging.properties
sed -i '90s/#//' fabric/import/fabric/profiles/karaf.profile/org.ops4j.pax.logging.properties
sed -i '91s/#//' fabric/import/fabric/profiles/karaf.profile/org.ops4j.pax.logging.properties
mv fabric/import/fabric/profiles/karaf.profile/org.ops4j.pax.logging.properties fabric/import/fabric/profiles/default.profile/
bin/start
sleep 20
bin/client "fabric:create --resolver localip --global-resolver localip"
sleep 20
bin/client "fabric:profile-create --parent default --parent feature-cxf --parent feature-camel --parent mq-client complex-create"
sleep 1
bin/client "fabric:profile-edit -f camel-jetty -f camel-jdbc -f camel-amq -f camel-jms -f fabric-cxf -f camel-jaxb -f camel-stream complex-create"
sleep 1
bin/client "fabric:profile-edit -f activemq-camel -f camel-cxf -f fabric-cxf-registry -f spring-jdbc -f camel-jetty -f jetty complex-create"
sleep 1
bin/client "fabric:profile-edit -b mvn:org.jboss.fuse.qa.test/useless-artifact/1.0 complex-create"
sleep 1
bin/client "mq-create --port openwire=11111 testbroker"
sleep 1
bin/client "profile-create --parent mq-broker-default.testbroker override"
sleep 1
bin/client "profile-edit --pid io.fabric8.mq.fabric.server-testbroker/openwire-port=11112 override"
sleep 1
bin/client "fabric:container-create-ssh --user hudson --password redhat --host $1 ssh1-offline"
sleep 1
bin/client "fabric:container-create-ssh --profile feature-camel --profile complex-create --user hudson --password redhat --host $2 ssh2-offline"
sleep 1
bin/client "fabric:container-create-child root offline-root-child-test"
sleep 1
bin/client "fabric:container-create-child --profile complex-create ssh1-offline child-ssh-offline1"
sleep 1
bin/client "fabric:container-create-child --profile complex-create ssh2-offline child-ssh-offline2"
sleep 1
bin/client "fabric:container-create-ssh --profile override --user hudson --password redhat --host $3 offline-broker"

