#!/bin/bash script_file_path="$(realpath "${0}")" script_dir_path="$(dirname "${script_file_path}")" pushd "${script_dir_path}" >/dev/null || exit 1 # shellcheck disable=SC1091 source ./_libs/libbase.sh # shellcheck disable=SC1091 source ./kybus.conf function initKybus { StatusEcho "Cleaning up old Environment" rm -f .kybusenv >/dev/null } function parseKybusRole { metaKybus=$(cat "roles/${1}/meta/kybus.yml") KYBUS_BASE_IMAGE="download/$(echo "${metaKybus}" | grep "^image:" | cut -d " " -f 2-)" setKybusVariable "KYBUS_BASE_IMAGE" "${KYBUS_BASE_IMAGE}" return } function setKybusVariable { if [[ -z "${1}" || -z ${2} ]]; then WarningEcho "Variables not passed to setKybusVariable correctly" exit 1 fi # Create variable file if one does not exist if [[ ! -e .kybusenv ]]; then touch .kybusenv fi StatusEcho "Setting ${1}" # Set blank variable if it does not already exist grep "${1}" .kybusenv >/dev/null || echo "${1}=" >>.kybusenv # Set variable sed -i "s|${1}=.*|${1}=${2}|" .kybusenv >/dev/null return } function findCVE { StatusEcho "Attempting to find ${1}" ls "roles/${1}" &>/dev/null || failed=1 if (( failed == 1 )); then WarningEcho "CVE - ${1} not found" exit 1 fi return } function ArgParse { while (("${#}")); do case "${1}" in --cve | -c) shift findCVE "${1}" && setKybusVariable "KYBUS_SELECTED_CVE" "${1}" export KYBUS_SELECTED_CVE=${1} shift ;; --help | -h) shift WarningEcho "Not implemented" exit 0 ;; --list-roles) shift local roles roles=$(find roles/* -maxdepth 0 | sed 's|roles/||g') CyanEcho "Available Roles:" CyanEcho "${roles}" unset roles exit 0 ;; --destroy) terraform destroy -auto-approve exit 0 shift ;; *) shift ;; esac done return } #initKybus ArgParse "${@}" parseKybusRole "${KYBUS_SELECTED_CVE}" docker run --rm -v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock -v "$(pwd):/mnt" -v "${SSH_KEY_FILE}:/root/.ssh/key" --env-file kybus.conf --env-file .kybusenv kybus:latest ./init.sh KYBUS_ADDRESS=$(grep -A 1 addresses