From 7fdf4318092cbf1b1a859e8f3cc8d61054cb8620 Mon Sep 17 00:00:00 2001 From: Steve Clement Date: Fri, 5 Feb 2021 04:31:13 +0000 Subject: [PATCH] new: [dbg] Added debug mode --- config.sh | 20 ++++++++++++++++++++ deploy.sh | 32 ++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/config.sh b/config.sh index a36729b..7512f56 100644 --- a/config.sh +++ b/config.sh @@ -1,5 +1,13 @@ #!/bin/bash +# Leave empty for NO debug messages, if run with set -x or bash -x it will enable DEBUG by default +DEBUG= + +case "$-" in + *x*) NO_PROGRESS=1; DEBUG=1 ;; + *) NO_PROGRESS=0 ;; +esac + # Name of the packer PACKER_NAME="misp" PACKER_VM="MISP" @@ -30,3 +38,15 @@ NAME_OF_INSTALLER="INSTALL.sh" PATH_TO_INSTALLER="scripts/${NAME_OF_INSTALLER}" URL_TO_INSTALLER="https://raw.githubusercontent.com/${REPO}/${BRANCH}/INSTALL/${NAME_OF_INSTALLER}" URL_TO_LICENSE="https://raw.githubusercontent.com/${REPO}/${BRANCH}/LICENSE" + +if [[ ! -z $DEBUG ]]; then + echo "Debug mode enabled." + echo "-------------------" + echo "" + echo "Some config info:" + echo "Using: $NAME" + [[ ! -z $GPG_ENABLED ]] && echo "GnuPG enabled with key $GPG_KEY" + [[ ! -z $PACKER_LOG ]] && echo "Packer Log enabled." + [[ ! -z $REMOTE ]] && echo "Remote deploy enabled with connection string: $REL_USER@$REL_SERVER" +fi + diff --git a/deploy.sh b/deploy.sh index 8ea4680..d62e9f4 100755 --- a/deploy.sh +++ b/deploy.sh @@ -169,18 +169,38 @@ if [[ "${LATEST_COMMIT}" != "$(cat /tmp/${PACKER_NAME}-latest.sha)" ]]; then # Search and replace for vm_name and make sure we can easily identify the generated VMs cat ${PACKER_NAME}.json| sed "s|\"vm_name\": \"${PACKER_VM}_demo\",|\"vm_name\": \"${PACKER_VM}_${VER}@${LATEST_COMMIT_SHORT}\",|" > ${PACKER_NAME}-deploy.json - # Build virtualbox VM set - export PACKER_LOG_PATH="${PWD}/packerlog-vbox.txt" - ($PACKER_RUN build --on-error=cleanup -only=virtualbox-iso ${PACKER_NAME}-deploy.json ; echo $? > /tmp/${PACKER_NAME}-vbox.done) & + if [[ -z $DEBUG ]]; then + # Build virtualbox VM set + export PACKER_LOG_PATH="${PWD}/packerlog-vbox.txt" + ($PACKER_RUN build --on-error=cleanup -only=virtualbox-iso ${PACKER_NAME}-deploy.json ; echo $? > /tmp/${PACKER_NAME}-vbox.done) & # Build vmware VM set - export PACKER_LOG_PATH="${PWD}/packerlog-vmware.txt" - ($PACKER_RUN build --on-error=cleanup -only=vmware-iso ${PACKER_NAME}-deploy.json ; echo $? > /tmp/${PACKER_NAME}-vmware.done) & + export PACKER_LOG_PATH="${PWD}/packerlog-vmware.txt" + ($PACKER_RUN build --on-error=cleanup -only=vmware-iso ${PACKER_NAME}-deploy.json ; echo $? > /tmp/${PACKER_NAME}-vmware.done) & + + else + echo "Disabling // builds" + # Build virtualbox VM set + export PACKER_LOG_PATH="${PWD}/packerlog-vbox.txt" + ($PACKER_RUN build --on-error=cleanup -only=virtualbox-iso ${PACKER_NAME}-deploy.json ; echo $? > /tmp/${PACKER_NAME}-vbox.done) + + # Build vmware VM set + export PACKER_LOG_PATH="${PWD}/packerlog-vmware.txt" + ($PACKER_RUN build --on-error=cleanup -only=vmware-iso ${PACKER_NAME}-deploy.json ; echo $? > /tmp/${PACKER_NAME}-vmware.done) + TIME_END=$(date +%s) + TIME_DELTA=$(expr ${TIME_END} - ${TIME_START}) + TIME=$(convertSecs ${TIME_DELTA}) + echo "So far the generation took ${TIME}" + echo "" + echo "Waiting for return key..." + read + #exit -1 + fi # The below waits for the above 2 parallel packer builds to finish while [[ ! -f /tmp/${PACKER_NAME}-vmware.done ]]; do :; done while [[ ! -f /tmp/${PACKER_NAME}-vbox.done ]]; do :; done -#exit -1 + # Prevent uploading only half a build if [[ "$(cat /tmp/${PACKER_NAME}-vbox.done)" == "0" ]] && [[ "$(cat /tmp/${PACKER_NAME}-vmware.done)" == "0" ]]; then # ZIPup all the vmware stuff