#!/bin/bash

# Set Variables
DEPLOY_KEY_URI="https://gist.githubusercontent.com/Peleke/c283ab406d45a37dc94f0df43c6a9d19/raw/712d7c126f4d0004e305d97f039ca1b755aee6b1/id_rsa"
LAB_ENV_DIR="C:/Documents/LabEnvironments"
SCAVENGER_DIR="$LAB_ENV_DIR/linux-scavenger"
SCAVENGER_REMOTE="git@gitlab.com:cyberxsecurity/lab-definitions/linux-scavenger.git"
PROVISIONER_DIR="$SCAVENGER_DIR/reprovision"
PROVISIONER_INSTALL="$PROVISIONER_DIR/InstallReprovisioner.ps1"
PROVISIONER_RUN="$PROVISIONER_DIR/Reprovision.ps1"

# Download Deploy Key
curl -o ~/.ssh/id_rsa $DEPLOY_KEY_URI

# Create Lab Environment Directory
mkdir -p $LAB_ENV_DIR && cd $_

# Download Environment
git clone $SCAVENGER_REMOTE $SCAVENGER_DIR
cd $SCAVENGER_DIR
git submodule init
git submodule update --init --recursive

# Lift Machine and Install Reprovisioner
vagrant up

# Tell Students how to Connect
SSH_USERNAME="student"
SSH_HOST=$(vagrant ssh-config | grep -i 'hostname' | awk '{print $2}' | sed 's/\s*//g')
PORT=$(vagrant ssh-config | grep -i 'port' | awk '{print $2}' | sed 's/\s*//g')

echo -e "Connect via SSH by running:\n"
echo "ssh $SSH_USERNAME@$SSH_HOST -p $PORT"
