#!/bin/bash

INSTALL_DIR=install-dir
HTTP_ROOT=/var/www/html
USER_DIR=ocp129

ocp-vm-cleanup
sudo rm -rf /home/libvirt-openshift-images/jpoulin*
echo "Waiting for disk cleanup to register"
sleep 2s
ocp-vm-cleanup

virsh -c qemu+tcp:///system net-destroy jpoulin-ocp
virsh -c qemu+tcp:///system net-undefine jpoulin-ocp
virsh -c qemu+tcp:///system net-define net.xml
virsh -c qemu+tcp:///system net-autostart jpoulin-ocp
virsh -c qemu+tcp:///system net-start jpoulin-ocp

rm ~/go/src/github.com/openshift/installer/bin/openshift-install
oc adm release extract --registry-config "pull_secret" --command=openshift-install --to "/home/jpoulin/go/src/github.com/openshift/installer/bin/" $OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE

rm -rf "${INSTALL_DIR}"
mkdir -p "${INSTALL_DIR}"
cp *.yaml "${INSTALL_DIR}"
ocp-dev-install --dir "${INSTALL_DIR}" agent create pxe-files

sudo rm -rf "${HTTP_ROOT}/${USER_DIR}"
sudo mkdir -p "${HTTP_ROOT}/${USER_DIR}"
sudo cp -r "${INSTALL_DIR}/boot-artifacts" "${HTTP_ROOT}/${USER_DIR}" 
sudo chmod 755 "${HTTP_ROOT}/${USER_DIR}/boot-artifacts"
sudo restorecon -vr "${HTTP_ROOT}/${USER_DIR}"

bash control-0.sh
bash control-1.sh
bash control-2.sh
bash compute-0.sh
bash compute-1.sh

ocp-dev-install --dir "${INSTALL_DIR}" agent wait-for bootstrap-complete --log-level=debug
ocp-dev-install --dir "${INSTALL_DIR}" agent wait-for install-complete --log-level=debug
