Merge pull request #67 from clong/build_scripts_format

Fixing formatting and some shell anti-patterns
This commit is contained in:
Chris Long
2018-03-01 11:22:16 -08:00
committed by GitHub
11 changed files with 211 additions and 196 deletions

View File

@@ -63,6 +63,9 @@ jobs:
fi fi
done done
if [ "$MINUTES_PAST" -gt 120 ]; then if [ "$MINUTES_PAST" -gt 120 ]; then
export IP_ADDRESS=$(cat /tmp/ip_address);
scp -i ~/.ssh/id_rsa root@"$IP_ADDRESS":/opt/DetectionLab/Vagrant/vagrant.log .
cat vagrant.log
curl -X DELETE --header 'Accept: application/json' --header 'X-Auth-Token: '"$PACKET_API_TOKEN" 'https://api.packet.net/devices/'"$DEVICE_ID" curl -X DELETE --header 'Accept: application/json' --header 'X-Auth-Token: '"$PACKET_API_TOKEN" 'https://api.packet.net/devices/'"$DEVICE_ID"
exit 1 exit 1
fi fi
@@ -74,6 +77,9 @@ jobs:
export STATUS=$(cat /tmp/status) export STATUS=$(cat /tmp/status)
echo $STATUS echo $STATUS
if [ "$STATUS" != "success" ]; then if [ "$STATUS" != "success" ]; then
export IP_ADDRESS=$(cat /tmp/ip_address);
scp -i ~/.ssh/id_rsa root@"$IP_ADDRESS":/opt/DetectionLab/Vagrant/vagrant.log .
cat vagrant.log
curl -X DELETE --header 'Accept: application/json' --header 'X-Auth-Token: '"$PACKET_API_TOKEN" 'https://api.packet.net/devices/'"$DEVICE_ID" curl -X DELETE --header 'Accept: application/json' --header 'X-Auth-Token: '"$PACKET_API_TOKEN" 'https://api.packet.net/devices/'"$DEVICE_ID"
exit 1 exit 1
fi fi

View File

@@ -2,6 +2,8 @@ if ($env:PACKER_BUILDER_TYPE -And $($env:PACKER_BUILDER_TYPE).startsWith("hyperv
Write-Host Skip debloat steps in Hyper-V build. Write-Host Skip debloat steps in Hyper-V build.
} else { } else {
Write-Host Downloading debloat zip Write-Host Downloading debloat zip
# GitHub requires TLS 1.2 as of 2/1/2018
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url="https://github.com/StefanScherer/Debloat-Windows-10/archive/master.zip" $url="https://github.com/StefanScherer/Debloat-Windows-10/archive/master.zip"
(New-Object System.Net.WebClient).DownloadFile($url, "$env:TEMP\debloat.zip") (New-Object System.Net.WebClient).DownloadFile($url, "$env:TEMP\debloat.zip")
Expand-Archive -Path $env:TEMP\debloat.zip -DestinationPath $env:TEMP -Force Expand-Archive -Path $env:TEMP\debloat.zip -DestinationPath $env:TEMP -Force

View File

@@ -41,8 +41,8 @@ else
# Get Splunk.com into the DNS cache. Sometimes resolution randomly fails during wget below # Get Splunk.com into the DNS cache. Sometimes resolution randomly fails during wget below
dig @8.8.8.8 splunk.com dig @8.8.8.8 splunk.com
# Download Splunk # Download Splunk
wget --progress=bar:force -O splunk-7.0.1-2b5b15c4ee89-linux-2.6-amd64.deb 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=7.0.1&product=splunk&filename=splunk-7.0.1-2b5b15c4ee89-linux-2.6-amd64.deb&wget=true' wget --progress=bar:force -O splunk-7.0.2-03bbabbd5c0f-linux-2.6-amd64.deb 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=7.0.2&product=splunk&filename=splunk-7.0.2-03bbabbd5c0f-linux-2.6-amd64.deb&wget=true'
dpkg -i splunk-7.0.1-2b5b15c4ee89-linux-2.6-amd64.deb dpkg -i splunk-7.0.2-03bbabbd5c0f-linux-2.6-amd64.deb
/opt/splunk/bin/splunk start --accept-license /opt/splunk/bin/splunk start --accept-license
/opt/splunk/bin/splunk add index wineventlog -auth 'admin:changeme' /opt/splunk/bin/splunk add index wineventlog -auth 'admin:changeme'
/opt/splunk/bin/splunk add index osquery -auth 'admin:changeme' /opt/splunk/bin/splunk add index osquery -auth 'admin:changeme'

View File

@@ -3,5 +3,7 @@ Write-Host "Downloading and unzipping the Palantir osquery Repo from Github..."
$osqueryRepoPath = 'C:\Users\vagrant\AppData\Local\Temp\osquery-Master.zip' $osqueryRepoPath = 'C:\Users\vagrant\AppData\Local\Temp\osquery-Master.zip'
# GitHub requires TLS 1.2 as of 2/1/2018
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri "https://github.com/palantir/osquery-configuration/archive/master.zip" -OutFile $osqueryRepoPath Invoke-WebRequest -Uri "https://github.com/palantir/osquery-configuration/archive/master.zip" -OutFile $osqueryRepoPath
Expand-Archive -path "$osqueryRepoPath" -destinationpath 'c:\Users\vagrant\AppData\Local\Temp' -Force Expand-Archive -path "$osqueryRepoPath" -destinationpath 'c:\Users\vagrant\AppData\Local\Temp' -Force

View File

@@ -1,7 +1,13 @@
# Purpose: Downloads and unzips a copy of the Palantir WEF Github Repo. This includes WEF subscriptions and custom WEF channels. # Purpose: Downloads and unzips a copy of the Palantir WEF Github Repo. This includes WEF subscriptions and custom WEF channels.
# GitHub requires TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Write-Host "Downloading and unzipping the Palantir Windows Event Forwarding Repo from Github..." Write-Host "Downloading and unzipping the Palantir Windows Event Forwarding Repo from Github..."
$wefRepoPath = 'C:\Users\vagrant\AppData\Local\Temp\wef-Master.zip' $wefRepoPath = 'C:\Users\vagrant\AppData\Local\Temp\wef-Master.zip'
# GitHub requires TLS 1.2 as of 2/1/2018
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri "https://github.com/palantir/windows-event-forwarding/archive/master.zip" -OutFile $wefRepoPath Invoke-WebRequest -Uri "https://github.com/palantir/windows-event-forwarding/archive/master.zip" -OutFile $wefRepoPath
Expand-Archive -path "$wefRepoPath" -destinationpath 'c:\Users\vagrant\AppData\Local\Temp' -Force Expand-Archive -path "$wefRepoPath" -destinationpath 'c:\Users\vagrant\AppData\Local\Temp' -Force

View File

@@ -14,6 +14,8 @@ If (-not (Test-Path "C:\Program Files\cagent\cagent.exe")) {
Write-Host "Downloading Caldera Agent (cagent.exe)" Write-Host "Downloading Caldera Agent (cagent.exe)"
$cagentPath = "C:\Program Files\cagent\cagent.exe" $cagentPath = "C:\Program Files\cagent\cagent.exe"
$cagentConfPath = "C:\Program Files\cagent\conf.yml" $cagentConfPath = "C:\Program Files\cagent\conf.yml"
# GitHub requires TLS 1.2 as of 2/1/2018
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(New-Object System.Net.WebClient).DownloadFile('https://github.com/mitre/caldera-agent/releases/download/v0.1.0/cagent.exe', $cagentPath) (New-Object System.Net.WebClient).DownloadFile('https://github.com/mitre/caldera-agent/releases/download/v0.1.0/cagent.exe', $cagentPath)
# Ignore SSL warning for conf file download # Ignore SSL warning for conf file download
# https://stackoverflow.com/questions/34331206/ignore-ssl-warning-with-powershell-downloadstring # https://stackoverflow.com/questions/34331206/ignore-ssl-warning-with-powershell-downloadstring

View File

@@ -27,6 +27,8 @@ If ($env:computername -eq "WIN10") {
# Purpose: Downloads and unzips a copy of the latest Mimikatz trunk # Purpose: Downloads and unzips a copy of the latest Mimikatz trunk
Write-Host "Determining latest release of Mimikatz..." Write-Host "Determining latest release of Mimikatz..."
# GitHub requires TLS 1.2 as of 2/27
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$tag = (Invoke-WebRequest "https://api.github.com/repos/gentilkiwi/mimikatz/releases" -UseBasicParsing | ConvertFrom-Json)[0].tag_name $tag = (Invoke-WebRequest "https://api.github.com/repos/gentilkiwi/mimikatz/releases" -UseBasicParsing | ConvertFrom-Json)[0].tag_name
$mimikatzDownloadUrl = "https://github.com/gentilkiwi/mimikatz/releases/download/$tag/mimikatz_trunk.zip" $mimikatzDownloadUrl = "https://github.com/gentilkiwi/mimikatz/releases/download/$tag/mimikatz_trunk.zip"
$mimikatzRepoPath = 'C:\Users\vagrant\AppData\Local\Temp\mimikatz_trunk.zip' $mimikatzRepoPath = 'C:\Users\vagrant\AppData\Local\Temp\mimikatz_trunk.zip'

176
build.sh
View File

@@ -16,30 +16,27 @@ print_usage() {
check_packer_and_vagrant() { check_packer_and_vagrant() {
# Check for existence of Vagrant in PATH # Check for existence of Vagrant in PATH
which vagrant > /dev/null if ! which vagrant >/dev/null; then
if [ "$?" -ne 0 ]; then (echo >&2 "Vagrant was not found in your PATH.")
(>&2 echo "Vagrant was not found in your PATH.") (echo >&2 "Please correct this before continuing. Quitting.")
(>&2 echo "Please correct this before continuing. Quitting.")
exit 1 exit 1
fi fi
# Ensure Vagrant >= 2.0.0 # Ensure Vagrant >= 2.0.0
if [ "$(vagrant --version | grep -o "[0-9]" | head -1)" -lt 2 ]; then if [ "$(vagrant --version | grep -o "[0-9]" | head -1)" -lt 2 ]; then
(>&2 echo "WARNING: It is highly recommended to use Vagrant 2.0.0 or above before continuing") (echo >&2 "WARNING: It is highly recommended to use Vagrant 2.0.0 or above before continuing")
fi fi
# Check for existence of Packer in PATH # Check for existence of Packer in PATH
which packer > /dev/null if ! which packer >/dev/null; then
if [ "$?" -ne 0 ]; then (echo >&2 "Packer was not found in your PATH.")
(>&2 echo "Packer was not found in your PATH.") (echo >&2 "Please correct this before continuing. Quitting.")
(>&2 echo "Please correct this before continuing. Quitting.") (echo >&2 "Hint: sudo cp ./packer /usr/local/bin/packer; sudo chmod +x /usr/local/bin/packer")
(>&2 echo "Hint: sudo cp ./packer /usr/local/bin/packer; sudo chmod +x /usr/local/bin/packer")
exit 1 exit 1
fi fi
} }
# Returns 0 if not installed or 1 if installed # Returns 0 if not installed or 1 if installed
check_virtualbox_installed() { check_virtualbox_installed() {
which VBoxManage > /dev/null if which VBoxManage >/dev/null; then
if [ "$?" -eq 0 ]; then
echo "1" echo "1"
else else
echo "0" echo "0"
@@ -48,19 +45,23 @@ check_virtualbox_installed() {
# Returns 0 if not installed or 1 if installed # Returns 0 if not installed or 1 if installed
check_vmware_fusion_installed() { check_vmware_fusion_installed() {
echo "$(ls /Applications | grep -ci 'VMware Fusion.app')" if [ -e "/Applications/VMware Fusion.app" ]; then
echo "1"
else
echo "0"
fi
} }
# Returns 0 if not installed or 1 if installed # Returns 0 if not installed or 1 if installed
check_vmware_vagrant_plugin_installed() { check_vmware_vagrant_plugin_installed() {
VAGRANT_VMWARE_PLUGIN_PRESENT=$(vagrant plugin list | grep -c 'vagrant-vmware-fusion') VAGRANT_VMWARE_PLUGIN_PRESENT="$(vagrant plugin list | grep -c 'vagrant-vmware-fusion')"
if [ $VAGRANT_VMWARE_PLUGIN_PRESENT -eq 0 ]; then if [ "$VAGRANT_VMWARE_PLUGIN_PRESENT" -eq 0 ]; then
(>&2 echo "VMWare Fusion is installed, but the Vagrant plugin is not.") (echo >&2 "VMWare Fusion is installed, but the Vagrant plugin is not.")
(>&2 echo "Visit https://www.vagrantup.com/vmware/index.html#buy-now for more information on how to purchase and install it") (echo >&2 "Visit https://www.vagrantup.com/vmware/index.html#buy-now for more information on how to purchase and install it")
(>&2 echo "VMWare Fusion will not be listed as a provider until the Vagrant plugin has been installed.") (echo >&2 "VMWare Fusion will not be listed as a provider until the Vagrant plugin has been installed.")
echo "0" echo "0"
else else
echo $VAGRANT_VMWARE_PLUGIN_PRESENT echo "$VAGRANT_VMWARE_PLUGIN_PRESENT"
fi fi
} }
@@ -69,7 +70,7 @@ list_providers() {
VBOX_PRESENT=0 VBOX_PRESENT=0
VMWARE_FUSION_PRESENT=0 VMWARE_FUSION_PRESENT=0
if [ $(uname) == "Darwin" ]; then if [ "$(uname)" == "Darwin" ]; then
# Detect Providers on OSX # Detect Providers on OSX
VBOX_PRESENT=$(check_virtualbox_installed) VBOX_PRESENT=$(check_virtualbox_installed)
VMWARE_FUSION_PRESENT=$(check_vmware_fusion_installed) VMWARE_FUSION_PRESENT=$(check_vmware_fusion_installed)
@@ -79,28 +80,25 @@ list_providers() {
VBOX_PRESENT=$(check_virtualbox_installed) VBOX_PRESENT=$(check_virtualbox_installed)
fi fi
(>&2 echo "Available Providers:") (echo >&2 "Available Providers:")
if [ "$VBOX_PRESENT" == "1" ]; then if [ "$VBOX_PRESENT" == "1" ]; then
(>&2 echo "virtualbox";) (echo >&2 "virtualbox")
fi fi
if [[ $VMWARE_FUSION_PRESENT -eq 1 ]] && [[ $VAGRANT_VMWARE_PLUGIN_PRESENT -eq 1 ]] if [[ $VMWARE_FUSION_PRESENT -eq 1 ]] && [[ $VAGRANT_VMWARE_PLUGIN_PRESENT -eq 1 ]]; then
then (echo >&2 "vmware_fusion")
(>&2 echo "vmware_fusion";)
fi fi
if [[ $VBOX_PRESENT -eq 0 ]] && [[ $VMWARE_FUSION_PRESENT -eq 0 ]] if [[ $VBOX_PRESENT -eq 0 ]] && [[ $VMWARE_FUSION_PRESENT -eq 0 ]]; then
then (echo >&2 "You need to install a provider such as VirtualBox or VMware Fusion to continue.")
(>&2 echo "You need to install a provider such as VirtualBox or VMware Fusion to continue.")
exit 1 exit 1
fi fi
(>&2 echo -e "\nWhich provider would you like to use?") (echo >&2 -e "\\nWhich provider would you like to use?")
read PROVIDER read -r PROVIDER
# Sanity check # Sanity check
if [[ "$PROVIDER" != "virtualbox" ]] && [[ "$PROVIDER" != "vmware_fusion" ]] if [[ "$PROVIDER" != "virtualbox" ]] && [[ "$PROVIDER" != "vmware_fusion" ]]; then
then (echo >&2 "Please choose a valid provider. \"$PROVIDER\" is not a valid option")
(>&2 echo "Please choose a valid provider. \"$PROVIDER\" is not a valid option")
exit 1 exit 1
fi fi
echo $PROVIDER echo "$PROVIDER"
} }
# A series of checks to identify potential issues before starting the build # A series of checks to identify potential issues before starting the build
@@ -108,43 +106,42 @@ preflight_checks() {
DL_DIR="$1" DL_DIR="$1"
# Check to see if curl is in PATH # Check to see if curl is in PATH
which curl > /dev/null if ! which curl >/dev/null; then
if [ "$?" -ne 0 ]; then (echo >&2 "Please install curl and make sure it is in your PATH.")
(>&2 echo "Please install curl and make sure it is in your PATH.")
exit 1 exit 1
fi fi
# Check to see if boxes exist already # Check to see if boxes exist already
BOXES_BUILT=$(ls -al "$DL_DIR"/Boxes/*.box 2> /dev/null | wc -l) BOXES_BUILT=$(find "$DL_DIR"/Boxes -name "*.box" | wc -l)
if [ $BOXES_BUILT -gt 0 ]; then if [ "$BOXES_BUILT" -gt 0 ]; then
(>&2 echo "You appear to have already built at least one box using Packer. This script does not support pre-built boxes. Please either delete the existing boxes or follow the build steps in the README to continue.") (echo >&2 "You appear to have already built at least one box using Packer. This script does not support pre-built boxes. Please either delete the existing boxes or follow the build steps in the README to continue.")
exit 1 exit 1
fi fi
# Check to see if any Vagrant instances exist already # Check to see if any Vagrant instances exist already
cd "$DL_DIR"/Vagrant/ cd "$DL_DIR"/Vagrant/
VAGRANT_BUILT=$(vagrant status | grep -c 'not created') # Vagrant status has the potential to return a non-zero error code, so we work around it with "|| true"
if [ $VAGRANT_BUILT -ne 4 ]; then VAGRANT_BUILT=$(vagrant status | grep -c 'not created') || true
(>&2 echo "You appear to have already created at least one Vagrant instance. This script does not support already created instances. Please either destroy the existing instances or follow the build steps in the README to continue.") if [ "$VAGRANT_BUILT" -ne 4 ]; then
(echo >&2 "You appear to have already created at least one Vagrant instance. This script does not support pre-created instances. Please either destroy the existing instances or follow the build steps in the README to continue.")
exit 1 exit 1
fi fi
# Check available disk space. Recommend 80GB free, warn if less. # Check available disk space. Recommend 80GB free, warn if less.
FREE_DISK_SPACE=$(df -m $HOME | tr -s ' ' | grep '/' | cut -d ' ' -f 4) FREE_DISK_SPACE=$(df -m "$HOME" | tr -s ' ' | grep '/' | cut -d ' ' -f 4)
if [ $FREE_DISK_SPACE -lt 80000 ]; then if [ "$FREE_DISK_SPACE" -lt 80000 ]; then
(>&2 echo -e "Warning: You appear to have less than 80GB of HDD space free on your primary partition. If you are using a separate parition, you may ignore this warning.\n") (echo >&2 -e "Warning: You appear to have less than 80GB of HDD space free on your primary partition. If you are using a separate parition, you may ignore this warning.\\n")
(>&2 df -m $HOME) (df >&2 -m "$HOME")
(>&2 echo "") (echo >&2 "")
fi fi
# Check Packer version against known bad # Check Packer version against known bad
if [ "$(packer --version)" == '1.1.2' ]; then if [ "$(packer --version)" == '1.1.2' ]; then
(>&2 echo "Packer 1.1.2 is not supported. Please upgrade to a newer version and see https://github.com/hashicorp/packer/issues/5622 for more information.") (echo >&2 "Packer 1.1.2 is not supported. Please upgrade to a newer version and see https://github.com/hashicorp/packer/issues/5622 for more information.")
exit 1 exit 1
fi fi
# Ensure the vagrant-reload plugin is installed # Ensure the vagrant-reload plugin is installed
VAGRANT_RELOAD_PLUGIN_INSTALLED=$(vagrant plugin list | grep -c 'vagrant-reload') VAGRANT_RELOAD_PLUGIN_INSTALLED=$(vagrant plugin list | grep -c 'vagrant-reload')
if [ "$VAGRANT_RELOAD_PLUGIN_INSTALLED" != "1" ]; then if [ "$VAGRANT_RELOAD_PLUGIN_INSTALLED" != "1" ]; then
(>&2 echo "The vagrant-reload plugin is required and not currently installed. This script will attempt to install it now.") (echo >&2 "The vagrant-reload plugin is required and not currently installed. This script will attempt to install it now.")
$(which vagrant) plugin install "vagrant-reload" if ! $(which vagrant) plugin install "vagrant-reload"; then
if [ "$?" -ne 0 ]; then (echo >&2 "Unable to install the vagrant-reload plugin. Please try to do so manually and re-run this script.")
(>&2 echo "Unable to install the vagrant-reload plugin. Please try to do so manually and re-run this script.")
exit 1 exit 1
fi fi
fi fi
@@ -159,11 +156,10 @@ packer_build_box() {
PROVIDER="vmware" PROVIDER="vmware"
fi fi
cd "$DL_DIR/Packer" cd "$DL_DIR/Packer"
(>&2 echo "Using Packer to build the $BOX Box. This can take 90-180 minutes depending on bandwidth and hardware.") (echo >&2 "Using Packer to build the $BOX Box. This can take 90-180 minutes depending on bandwidth and hardware.")
$(which packer) build --only="$PROVIDER-iso" $BOX.json if ! $(which packer) build --only="$PROVIDER-iso" "$BOX".json; then
if [ "$?" -ne 0 ]; then (echo >&2 "Something went wrong while attempting to build the $BOX box.")
(>&2 echo "Something went wrong while attempting to build the $BOX box.") (echo >&2 "To file an issue, please visit https://github.com/clong/DetectionLab/issues/")
(>&2 echo "To file an issue, please visit https://github.com/clong/DetectionLab/issues/")
fi fi
} }
@@ -178,12 +174,12 @@ move_boxes() {
mv "$DL_DIR"/Packer/*.box "$DL_DIR"/Boxes mv "$DL_DIR"/Packer/*.box "$DL_DIR"/Boxes
# Ensure Windows 10 box exists # Ensure Windows 10 box exists
if [ ! -f "$DL_DIR"/Boxes/windows_10_"$PROVIDER".box ]; then if [ ! -f "$DL_DIR"/Boxes/windows_10_"$PROVIDER".box ]; then
(>&2 echo "Windows 10 box is missing from the Boxes directory. Qutting.") (echo >&2 "Windows 10 box is missing from the Boxes directory. Qutting.")
exit 1 exit 1
fi fi
# Ensure Windows 2016 box exists # Ensure Windows 2016 box exists
if [ ! -f "$DL_DIR"/Boxes/windows_2016_"$PROVIDER".box ]; then if [ ! -f "$DL_DIR"/Boxes/windows_2016_"$PROVIDER".box ]; then
(>&2 echo "Windows 2016 box is missing from the Boxes directory. Qutting.") (echo >&2 "Windows 2016 box is missing from the Boxes directory. Qutting.")
exit 1 exit 1
fi fi
} }
@@ -193,9 +189,9 @@ vagrant_up_host() {
PROVIDER="$1" PROVIDER="$1"
HOST="$2" HOST="$2"
DL_DIR="$3" DL_DIR="$3"
(>&2 echo "Attempting to bring up the $HOST host using Vagrant") (echo >&2 "Attempting to bring up the $HOST host using Vagrant")
cd "$DL_DIR"/Vagrant cd "$DL_DIR"/Vagrant
$(which vagrant) up $HOST --provider="$PROVIDER" 1>&2 $(which vagrant) up "$HOST" --provider="$PROVIDER" 1>&2
echo "$?" echo "$?"
} }
@@ -205,7 +201,7 @@ vagrant_reload_host() {
DL_DIR="$2" DL_DIR="$2"
cd "$DL_DIR"/Vagrant cd "$DL_DIR"/Vagrant
# Attempt to reload the host if the vagrant up command didn't exit cleanly # Attempt to reload the host if the vagrant up command didn't exit cleanly
$(which vagrant) reload $HOST --provision 1>&2 $(which vagrant) reload "$HOST" --provision 1>&2
echo "$?" echo "$?"
} }
@@ -221,22 +217,21 @@ post_build_checks() {
# Associative arrays are only supported in bash 4 and up # Associative arrays are only supported in bash 4 and up
if [ "$BASH_MAJOR_VERSION" -ge 4 ]; then if [ "$BASH_MAJOR_VERSION" -ge 4 ]; then
declare -A SERVICES declare -A SERVICES
SERVICES=( ["caldera"]="$CALDERA_CHECK" ["splunk"]="$SPLUNK_CHECK" ["fleet"]="$FLEET_CHECK") SERVICES=(["caldera"]="$CALDERA_CHECK" ["splunk"]="$SPLUNK_CHECK" ["fleet"]="$FLEET_CHECK")
for SERVICE in "${!SERVICES[@]}" for SERVICE in "${!SERVICES[@]}"; do
do
if [ "${SERVICES[$SERVICE]}" -lt 1 ]; then if [ "${SERVICES[$SERVICE]}" -lt 1 ]; then
(>&2 echo "Warning: $SERVICE failed post-build tests and may not be functioning correctly.") (echo >&2 "Warning: $SERVICE failed post-build tests and may not be functioning correctly.")
fi fi
done done
else else
if [ "$CALDERA_CHECK" -lt 1 ]; then if [ "$CALDERA_CHECK" -lt 1 ]; then
(>&2 echo "Warning: Caldera failed post-build tests and may not be functioning correctly.") (echo >&2 "Warning: Caldera failed post-build tests and may not be functioning correctly.")
fi fi
if [ "$SPLUNK_CHECK" -lt 1 ]; then if [ "$SPLUNK_CHECK" -lt 1 ]; then
(>&2 echo "Warning: Splunk failed post-build tests and may not be functioning correctly.") (echo >&2 "Warning: Splunk failed post-build tests and may not be functioning correctly.")
fi fi
if [ "$FLEET_CHECK" -lt 1 ]; then if [ "$FLEET_CHECK" -lt 1 ]; then
(>&2 echo "Warning: Fleet failed post-build tests and may not be functioning correctly.") (echo >&2 "Warning: Fleet failed post-build tests and may not be functioning correctly.")
fi fi
fi fi
} }
@@ -244,7 +239,7 @@ post_build_checks() {
main() { main() {
# Get location of build.sh # Get location of build.sh
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within # https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
DL_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROVIDER="" PROVIDER=""
LAB_HOSTS=("logger" "dc" "wef" "win10") LAB_HOSTS=("logger" "dc" "wef" "win10")
# If no argument was supplied, list available providers # If no argument was supplied, list available providers
@@ -261,22 +256,22 @@ main() {
# TODO: Check to make sure they actually have their provider installed # TODO: Check to make sure they actually have their provider installed
case "$1" in case "$1" in
virtualbox) virtualbox)
PROVIDER="$1" PROVIDER="$1"
;; ;;
vmware_fusion) vmware_fusion)
PROVIDER="$1" PROVIDER="$1"
;; ;;
*) *)
echo "\"$1\" is not a valid provider. Listing available providers:" echo "\"$1\" is not a valid provider. Listing available providers:"
PROVIDER=$(list_providers) PROVIDER=$(list_providers)
;; ;;
esac esac
fi fi
preflight_checks $DL_DIR preflight_checks "$DL_DIR"
packer_build_box $PROVIDER "windows_2016" $DL_DIR packer_build_box "$PROVIDER" "windows_2016" "$DL_DIR"
packer_build_box $PROVIDER "windows_10" $DL_DIR packer_build_box "$PROVIDER" "windows_10" "$DL_DIR"
move_boxes $PROVIDER $DL_DIR move_boxes "$PROVIDER" "$DL_DIR"
# Change provider back to original selection if using vmware_fusion # Change provider back to original selection if using vmware_fusion
if [ "$PROVIDER" == "vmware" ]; then if [ "$PROVIDER" == "vmware" ]; then
@@ -284,19 +279,18 @@ main() {
fi fi
# Vagrant up each box and attempt to reload one time if it fails # Vagrant up each box and attempt to reload one time if it fails
for VAGRANT_HOST in "${LAB_HOSTS[@]}" for VAGRANT_HOST in "${LAB_HOSTS[@]}"; do
do RET=$(vagrant_up_host "$PROVIDER" "$VAGRANT_HOST" "$DL_DIR")
RET=$(vagrant_up_host $PROVIDER $VAGRANT_HOST $DL_DIR)
if [ "$RET" -eq 0 ]; then if [ "$RET" -eq 0 ]; then
(>&2 echo "Good news! $VAGRANT_HOST was built successfully!") (echo >&2 "Good news! $VAGRANT_HOST was built successfully!")
fi fi
# Attempt to recover if the intial "vagrant up" fails # Attempt to recover if the intial "vagrant up" fails
if [ "$RET" -ne 0 ]; then if [ "$RET" -ne 0 ]; then
(>&2 echo "Something went wrong while attempting to build the $VAGRANT_HOST box.") (echo >&2 "Something went wrong while attempting to build the $VAGRANT_HOST box.")
(>&2 echo "Attempting to reload and reprovision the host...") (echo >&2 "Attempting to reload and reprovision the host...")
RETRY_STATUS=$(vagrant_reload_host $VAGRANT_HOST $DL_DIR) RETRY_STATUS=$(vagrant_reload_host "$VAGRANT_HOST" "$DL_DIR")
if [ "$RETRY_STATUS" -ne 0 ]; then if [ "$RETRY_STATUS" -ne 0 ]; then
(>&2 echo "Failed to bring up $VAGRANT_HOST after a reload. Exiting.") (echo >&2 "Failed to bring up $VAGRANT_HOST after a reload. Exiting.")
exit 1 exit 1
fi fi
fi fi
@@ -305,5 +299,5 @@ main() {
post_build_checks post_build_checks
} }
main $@ main "$@"
exit 0 exit 0

View File

@@ -16,22 +16,20 @@ print_usage() {
check_vagrant() { check_vagrant() {
# Check for existence of Vagrant in PATH # Check for existence of Vagrant in PATH
which vagrant > /dev/null if ! which vagrant >/dev/null; then
if [ "$?" -ne 0 ]; then (echo >&2 "Vagrant was not found in your PATH.")
(>&2 echo "Vagrant was not found in your PATH.") (echo >&2 "Please correct this before continuing. Quitting.")
(>&2 echo "Please correct this before continuing. Quitting.")
exit 1 exit 1
fi fi
# Ensure Vagrant >= 2.0.0 # Ensure Vagrant >= 2.0.0
if [ "$(vagrant --version | grep -o "[0-9]" | head -1)" -lt 2 ]; then if [ "$(vagrant --version | grep -o "[0-9]" | head -1)" -lt 2 ]; then
(>&2 echo "WARNING: It is highly recommended to use Vagrant 2.0.0 or above before continuing") (echo >&2 "WARNING: It is highly recommended to use Vagrant 2.0.0 or above before continuing")
fi fi
} }
# Returns 0 if not installed or 1 if installed # Returns 0 if not installed or 1 if installed
check_virtualbox_installed() { check_virtualbox_installed() {
which VBoxManage > /dev/null if ! which VBoxManage >/dev/null; then
if [ "$?" -eq 0 ]; then
echo "1" echo "1"
else else
echo "0" echo "0"
@@ -40,19 +38,23 @@ check_virtualbox_installed() {
# Returns 0 if not installed or 1 if installed # Returns 0 if not installed or 1 if installed
check_vmware_fusion_installed() { check_vmware_fusion_installed() {
echo "$(ls /Applications | grep -ci 'VMware Fusion.app')" if [ -e "/Applications/VMware Fusion.app" ]; then
echo "1"
else
echo "0"
fi
} }
# Returns 0 if not installed or 1 if installed # Returns 0 if not installed or 1 if installed
check_vmware_vagrant_plugin_installed() { check_vmware_vagrant_plugin_installed() {
VAGRANT_VMWARE_PLUGIN_PRESENT=$(vagrant plugin list | grep -c 'vagrant-vmware-fusion') VAGRANT_VMWARE_PLUGIN_PRESENT="$(vagrant plugin list | grep -c 'vagrant-vmware-fusion')"
if [ $VAGRANT_VMWARE_PLUGIN_PRESENT -eq 0 ]; then if [ "$VAGRANT_VMWARE_PLUGIN_PRESENT" -eq 0 ]; then
(>&2 echo "VMWare Fusion is installed, but the Vagrant plugin is not.") (echo >&2 "VMWare Fusion is installed, but the Vagrant plugin is not.")
(>&2 echo "Visit https://www.vagrantup.com/vmware/index.html#buy-now for more information on how to purchase and install it") (echo >&2 "Visit https://www.vagrantup.com/vmware/index.html#buy-now for more information on how to purchase and install it")
(>&2 echo "VMWare Fusion will not be listed as a provider until the Vagrant plugin has been installed.") (echo >&2 "VMWare Fusion will not be listed as a provider until the Vagrant plugin has been installed.")
echo "0" echo "0"
else else
echo $VAGRANT_VMWARE_PLUGIN_PRESENT echo "$VAGRANT_VMWARE_PLUGIN_PRESENT"
fi fi
} }
@@ -61,7 +63,7 @@ list_providers() {
VBOX_PRESENT=0 VBOX_PRESENT=0
VMWARE_FUSION_PRESENT=0 VMWARE_FUSION_PRESENT=0
if [ $(uname) == "Darwin" ]; then if [ "$(uname)" == "Darwin" ]; then
# Detect Providers on OSX # Detect Providers on OSX
VBOX_PRESENT=$(check_virtualbox_installed) VBOX_PRESENT=$(check_virtualbox_installed)
VMWARE_FUSION_PRESENT=$(check_vmware_fusion_installed) VMWARE_FUSION_PRESENT=$(check_vmware_fusion_installed)
@@ -71,72 +73,69 @@ list_providers() {
VBOX_PRESENT=$(check_virtualbox_installed) VBOX_PRESENT=$(check_virtualbox_installed)
fi fi
(>&2 echo "Available Providers:") (echo >&2 "Available Providers:")
if [ "$VBOX_PRESENT" == "1" ]; then if [ "$VBOX_PRESENT" == "1" ]; then
(>&2 echo "virtualbox";) (echo >&2 "virtualbox")
fi fi
if [[ $VMWARE_FUSION_PRESENT -eq 1 ]] && [[ $VAGRANT_VMWARE_PLUGIN_PRESENT -eq 1 ]] if [[ $VMWARE_FUSION_PRESENT -eq 1 ]] && [[ $VAGRANT_VMWARE_PLUGIN_PRESENT -eq 1 ]]; then
then (echo >&2 "vmware_fusion")
(>&2 echo "vmware_fusion";)
fi fi
if [[ $VBOX_PRESENT -eq 0 ]] && [[ $VMWARE_FUSION_PRESENT -eq 0 ]] if [[ $VBOX_PRESENT -eq 0 ]] && [[ $VMWARE_FUSION_PRESENT -eq 0 ]]; then
then (echo >&2 "You need to install a provider such as VirtualBox or VMware Fusion to continue.")
(>&2 echo "You need to install a provider such as VirtualBox or VMware Fusion to continue.")
exit 1 exit 1
fi fi
(>&2 echo -e "\nWhich provider would you like to use?") (echo >&2 -e "\\nWhich provider would you like to use?")
read PROVIDER read -r PROVIDER
# Sanity check # Sanity check
if [[ "$PROVIDER" != "virtualbox" ]] && [[ "$PROVIDER" != "vmware_fusion" ]] if [[ "$PROVIDER" != "virtualbox" ]] && [[ "$PROVIDER" != "vmware_fusion" ]]; then
then (echo >&2 "Please choose a valid provider. \"$PROVIDER\" is not a valid option")
(>&2 echo "Please choose a valid provider. \"$PROVIDER\" is not a valid option")
exit 1 exit 1
fi fi
echo $PROVIDER echo "$PROVIDER"
} }
# A series of checks to identify potential issues before starting the build # A series of checks to identify potential issues before starting the build
preflight_checks() { preflight_checks() {
DL_DIR="$1" DL_DIR="$1"
DOWNLOAD_BOXES=1
# Check to see if curl is in PATH # Check to see if curl is in PATH
which curl > /dev/null if ! which curl >/dev/null; then
if [ "$?" -ne 0 ]; then (echo >&2 "Please install curl and make sure it is in your PATH.")
(>&2 echo "Please install curl and make sure it is in your PATH.")
exit 1 exit 1
fi fi
# Check to see if wget is in PATH # Check to see if wget is in PATH
which wget > /dev/null if ! which wget >/dev/null; then
if [ "$?" -ne 0 ]; then (echo >&2 "Please install curl and make sure it is in your PATH.")
(>&2 echo "Please install curl and make sure it is in your PATH.")
exit 1 exit 1
fi fi
# Check to see if boxes exist already # Check to see if boxes exist already
BOXES_BUILT=$(ls -al "$DL_DIR"/Boxes/*.box 2> /dev/null | wc -l) BOXES_BUILT=$(find "$DL_DIR"/Boxes -name "*.box" | wc -l)
if [ $BOXES_BUILT -gt 0 ]; then if [ "$BOXES_BUILT" -gt 0 ]; then
(>&2 echo "WARNING: You seem to have boxes present in the Boxes/ directory already. If you would like fresh boxes downloaded, please remove all files from the Boxes/ directory and re-run this script.") (echo >&2 "WARNING: You seem to have boxes present in the Boxes directory already. If you would like fresh boxes downloaded, please remove all files from the Boxes directory and re-run this script.")
DOWNLOAD_BOXES=0
fi fi
# Check to see if any Vagrant instances exist already # Check to see if any Vagrant instances exist already
cd "$DL_DIR"/Vagrant/ cd "$DL_DIR"/Vagrant/
VAGRANT_BUILT=$(vagrant status | grep -c 'not created') # Vagrant status has the potential to return a non-zero error code, so we work around it with "|| true"
if [ $VAGRANT_BUILT -ne 4 ]; then VAGRANT_BUILT=$(vagrant status | grep -c 'not created') || true
(>&2 echo "You appear to have already created at least one Vagrant instance. This script does not support already created instances. Please either destroy the existing instances or follow the build steps in the README to continue.") if [ "$VAGRANT_BUILT" -ne 4 ]; then
(echo >&2 "You appear to have already created at least one Vagrant instance. This script does not support pre-created instances. Please either destroy the existing instances or follow the build steps in the README to continue.")
exit 1 exit 1
fi fi
# Check available disk space. Recommend 80GB free, warn if less. # Check available disk space. Recommend 80GB free, warn if less.
FREE_DISK_SPACE=$(df -m $HOME | tr -s ' ' | grep '/' | cut -d ' ' -f 4) FREE_DISK_SPACE=$(df -m "$HOME" | tr -s ' ' | grep '/' | cut -d ' ' -f 4)
if [ $FREE_DISK_SPACE -lt 80000 ]; then if [ "$FREE_DISK_SPACE" -lt 80000 ]; then
(>&2 echo -e "Warning: You appear to have less than 80GB of HDD space free on your primary partition. If you are using a separate parition, you may ignore this warning.\n") (echo >&2 -e "Warning: You appear to have less than 80GB of HDD space free on your primary partition. If you are using a separate parition, you may ignore this warning.\\n")
(>&2 df -m $HOME) (df >&2 -m "$HOME")
(>&2 echo "") (echo >&2 "")
fi fi
# Ensure the vagrant-reload plugin is installed # Ensure the vagrant-reload plugin is installed
VAGRANT_RELOAD_PLUGIN_INSTALLED=$(vagrant plugin list | grep -c 'vagrant-reload') VAGRANT_RELOAD_PLUGIN_INSTALLED=$(vagrant plugin list | grep -c 'vagrant-reload')
if [ "$VAGRANT_RELOAD_PLUGIN_INSTALLED" != "1" ]; then if [ "$VAGRANT_RELOAD_PLUGIN_INSTALLED" != "1" ]; then
(>&2 echo "The vagrant-reload plugin is required and not currently installed. This script will attempt to install it now.") (echo >&2 "The vagrant-reload plugin is required and not currently installed. This script will attempt to install it now.")
$(which vagrant) plugin install "vagrant-reload" if ! $(which vagrant) plugin install "vagrant-reload"; then
if [ "$?" -ne 0 ]; then (echo >&2 "Unable to install the vagrant-reload plugin. Please try to do so manually and re-run this script.")
(>&2 echo "Unable to install the vagrant-reload plugin. Please try to do so manually and re-run this script.")
exit 1 exit 1
fi fi
fi fi
@@ -162,30 +161,30 @@ download_boxes() {
# Ensure Windows 10 box exists # Ensure Windows 10 box exists
if [ ! -f "$DL_DIR"/Boxes/windows_10_"$PROVIDER".box ]; then if [ ! -f "$DL_DIR"/Boxes/windows_10_"$PROVIDER".box ]; then
(>&2 echo "Windows 10 box is missing from the Boxes directory. Qutting.") (echo >&2 "Windows 10 box is missing from the Boxes directory. Qutting.")
exit 1 exit 1
fi fi
# Ensure Windows 2016 box exists # Ensure Windows 2016 box exists
if [ ! -f "$DL_DIR"/Boxes/windows_2016_"$PROVIDER".box ]; then if [ ! -f "$DL_DIR"/Boxes/windows_2016_"$PROVIDER".box ]; then
(>&2 echo "Windows 2016 box is missing from the Boxes directory. Qutting.") (echo >&2 "Windows 2016 box is missing from the Boxes directory. Qutting.")
exit 1 exit 1
fi fi
# Verify hashes of VirtualBox boxes # Verify hashes of VirtualBox boxes
if [ "$PROVIDER" == "virtualbox" ]; then if [ "$PROVIDER" == "virtualbox" ]; then
if [ "$(md5sum windows_10_"$PROVIDER".box | cut -d ' ' -f 1)" != "30b06e30b36b02ccf1dc5c04017654aa" ]; then if [ "$(md5sum windows_10_"$PROVIDER".box | cut -d ' ' -f 1)" != "30b06e30b36b02ccf1dc5c04017654aa" ]; then
(>&2 echo "Hash mismatch on windows_10_virtualbox.box") (echo >&2 "Hash mismatch on windows_10_virtualbox.box")
fi fi
if [ "$(md5sum windows_2016_"$PROVIDER".box | cut -d ' ' -f 1)" != "614f984c82b51471b5bb753940b59d38" ]; then if [ "$(md5sum windows_2016_"$PROVIDER".box | cut -d ' ' -f 1)" != "614f984c82b51471b5bb753940b59d38" ]; then
(>&2 echo "Hash mismatch on windows_2016_virtualbox.box") (echo >&2 "Hash mismatch on windows_2016_virtualbox.box")
fi fi
# Verify hashes of VMware boxes # Verify hashes of VMware boxes
elif [ "$PROVIDER" == "vmware" ]; then elif [ "$PROVIDER" == "vmware" ]; then
if [ "$(md5 windows_10_"$PROVIDER".box | cut -d ' ' -f 1)" != "174ad0f0fd2089ff74a880c6dadac74c" ]; then if [ "$(md5 windows_10_"$PROVIDER".box | cut -d ' ' -f 1)" != "174ad0f0fd2089ff74a880c6dadac74c" ]; then
(>&2 echo "Hash mismatch on windows_10_vmware.box") (echo >&2 "Hash mismatch on windows_10_vmware.box")
exit 1 exit 1
fi fi
if [ "$(md5 windows_2016_"$PROVIDER".box | cut -d ' ' -f 1)" != "1511b9dc942c69c2cc5a8dc471fa8865" ]; then if [ "$(md5 windows_2016_"$PROVIDER".box | cut -d ' ' -f 1)" != "1511b9dc942c69c2cc5a8dc471fa8865" ]; then
(>&2 echo "Hash mismatch on windows_2016_vmware.box") (echo >&2 "Hash mismatch on windows_2016_vmware.box")
exit 1 exit 1
fi fi
# Reset PROVIDER variable # Reset PROVIDER variable
@@ -198,9 +197,9 @@ vagrant_up_host() {
PROVIDER="$1" PROVIDER="$1"
HOST="$2" HOST="$2"
DL_DIR="$3" DL_DIR="$3"
(>&2 echo "Attempting to bring up the $HOST host using Vagrant") (echo >&2 "Attempting to bring up the $HOST host using Vagrant")
cd "$DL_DIR"/Vagrant cd "$DL_DIR"/Vagrant
$(which vagrant) up $HOST --provider="$PROVIDER" 1>&2 $(which vagrant) up "$HOST" --provider="$PROVIDER" 1>&2
echo "$?" echo "$?"
} }
@@ -210,7 +209,7 @@ vagrant_reload_host() {
DL_DIR="$2" DL_DIR="$2"
cd "$DL_DIR"/Vagrant cd "$DL_DIR"/Vagrant
# Attempt to reload the host if the vagrant up command didn't exit cleanly # Attempt to reload the host if the vagrant up command didn't exit cleanly
$(which vagrant) reload $HOST --provision 1>&2 $(which vagrant) reload "$HOST" --provision 1>&2
echo "$?" echo "$?"
} }
@@ -226,22 +225,21 @@ post_build_checks() {
# Associative arrays are only supported in bash 4 and up # Associative arrays are only supported in bash 4 and up
if [ "$BASH_MAJOR_VERSION" -ge 4 ]; then if [ "$BASH_MAJOR_VERSION" -ge 4 ]; then
declare -A SERVICES declare -A SERVICES
SERVICES=( ["caldera"]="$CALDERA_CHECK" ["splunk"]="$SPLUNK_CHECK" ["fleet"]="$FLEET_CHECK") SERVICES=(["caldera"]="$CALDERA_CHECK" ["splunk"]="$SPLUNK_CHECK" ["fleet"]="$FLEET_CHECK")
for SERVICE in "${!SERVICES[@]}" for SERVICE in "${!SERVICES[@]}"; do
do
if [ "${SERVICES[$SERVICE]}" -lt 1 ]; then if [ "${SERVICES[$SERVICE]}" -lt 1 ]; then
(>&2 echo "Warning: $SERVICE failed post-build tests and may not be functioning correctly.") (echo >&2 "Warning: $SERVICE failed post-build tests and may not be functioning correctly.")
fi fi
done done
else else
if [ "$CALDERA_CHECK" -lt 1 ]; then if [ "$CALDERA_CHECK" -lt 1 ]; then
(>&2 echo "Warning: Caldera failed post-build tests and may not be functioning correctly.") (echo >&2 "Warning: Caldera failed post-build tests and may not be functioning correctly.")
fi fi
if [ "$SPLUNK_CHECK" -lt 1 ]; then if [ "$SPLUNK_CHECK" -lt 1 ]; then
(>&2 echo "Warning: Splunk failed post-build tests and may not be functioning correctly.") (echo >&2 "Warning: Splunk failed post-build tests and may not be functioning correctly.")
fi fi
if [ "$FLEET_CHECK" -lt 1 ]; then if [ "$FLEET_CHECK" -lt 1 ]; then
(>&2 echo "Warning: Fleet failed post-build tests and may not be functioning correctly.") (echo >&2 "Warning: Fleet failed post-build tests and may not be functioning correctly.")
fi fi
fi fi
} }
@@ -249,7 +247,7 @@ post_build_checks() {
main() { main() {
# Get location of build_vagrant_only.sh # Get location of build_vagrant_only.sh
# https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within # https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
DL_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROVIDER="" PROVIDER=""
LAB_HOSTS=("logger" "dc" "wef" "win10") LAB_HOSTS=("logger" "dc" "wef" "win10")
# If no argument was supplied, list available providers # If no argument was supplied, list available providers
@@ -266,36 +264,39 @@ main() {
# TODO: Check to make sure they actually have their provider installed # TODO: Check to make sure they actually have their provider installed
case "$1" in case "$1" in
virtualbox) virtualbox)
PROVIDER="$1" PROVIDER="$1"
;; ;;
vmware_fusion) vmware_fusion)
PROVIDER="$1" PROVIDER="$1"
;; ;;
*) *)
echo "\"$1\" is not a valid provider. Listing available providers:" echo "\"$1\" is not a valid provider. Listing available providers:"
PROVIDER=$(list_providers) PROVIDER=$(list_providers)
;; ;;
esac esac
fi fi
check_vagrant check_vagrant
preflight_checks $DL_DIR preflight_checks "$DL_DIR"
download_boxes $DL_DIR $PROVIDER if [ "$DOWNLOAD_BOXES" -eq 0 ]; then
(echo >&2 "Skipping box downloads since .box files are already present in the Boxes/ directory.")
else
download_boxes "$DL_DIR" "$PROVIDER"
fi
# Vagrant up each box and attempt to reload one time if it fails # Vagrant up each box and attempt to reload one time if it fails
for VAGRANT_HOST in "${LAB_HOSTS[@]}" for VAGRANT_HOST in "${LAB_HOSTS[@]}"; do
do RET=$(vagrant_up_host "$PROVIDER" "$VAGRANT_HOST" "$DL_DIR")
RET=$(vagrant_up_host $PROVIDER $VAGRANT_HOST $DL_DIR)
if [ "$RET" -eq 0 ]; then if [ "$RET" -eq 0 ]; then
(>&2 echo "Good news! $VAGRANT_HOST was built successfully!") (echo >&2 "Good news! $VAGRANT_HOST was built successfully!")
fi fi
# Attempt to recover if the intial "vagrant up" fails # Attempt to recover if the intial "vagrant up" fails
if [ "$RET" -ne 0 ]; then if [ "$RET" -ne 0 ]; then
(>&2 echo "Something went wrong while attempting to build the $VAGRANT_HOST box.") (echo >&2 "Something went wrong while attempting to build the $VAGRANT_HOST box.")
(>&2 echo "Attempting to reload and reprovision the host...") (echo >&2 "Attempting to reload and reprovision the host...")
RETRY_STATUS=$(vagrant_reload_host $VAGRANT_HOST $DL_DIR) RETRY_STATUS=$(vagrant_reload_host "$VAGRANT_HOST" "$DL_DIR")
if [ "$RETRY_STATUS" -ne 0 ]; then if [ "$RETRY_STATUS" -ne 0 ]; then
(>&2 echo "Failed to bring up $VAGRANT_HOST after a reload. Exiting.") (echo >&2 "Failed to bring up $VAGRANT_HOST after a reload. Exiting.")
exit 1 exit 1
fi fi
fi fi
@@ -304,5 +305,5 @@ main() {
post_build_checks post_build_checks
} }
main $@ main "$@"
exit 0 exit 0

View File

@@ -7,11 +7,11 @@
# the text "building". Once the test is completed, the text will be replaced # the text "building". Once the test is completed, the text will be replaced
# with "success" or "failed". # with "success" or "failed".
# Install Virtualbox 5.1 # Install Virtualbox 5.2
echo "deb http://download.virtualbox.org/virtualbox/debian xenial contrib" >> /etc/apt/sources.list echo "deb http://download.virtualbox.org/virtualbox/debian xenial contrib" >> /etc/apt/sources.list
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
apt-get update apt-get update
apt-get install -y virtualbox-5.1 build-essential unzip git ufw apache2 apt-get install -y linux-headers-"$(uname -r)" virtualbox-5.2 build-essential unzip git ufw apache2
echo "building" > /var/www/html/index.html echo "building" > /var/www/html/index.html
@@ -23,14 +23,14 @@ ufw --force enable
# Install Vagrant # Install Vagrant
mkdir /opt/vagrant mkdir /opt/vagrant
cd /opt/vagrant cd /opt/vagrant || exit 1
wget https://releases.hashicorp.com/vagrant/2.0.1/vagrant_2.0.1_x86_64.deb wget https://releases.hashicorp.com/vagrant/2.0.2/vagrant_2.0.2_x86_64.deb
dpkg -i vagrant_2.0.1_x86_64.deb dpkg -i vagrant_2.0.2_x86_64.deb
vagrant plugin install vagrant-reload vagrant plugin install vagrant-reload
# Install Packer # Install Packer
mkdir /opt/packer mkdir /opt/packer
cd /opt/packer cd /opt/packer || exit 1
wget https://releases.hashicorp.com/packer/1.1.3/packer_1.1.3_linux_amd64.zip wget https://releases.hashicorp.com/packer/1.1.3/packer_1.1.3_linux_amd64.zip
unzip packer_1.1.3_linux_amd64.zip unzip packer_1.1.3_linux_amd64.zip
cp packer /usr/local/bin/packer cp packer /usr/local/bin/packer
@@ -41,14 +41,14 @@ for file in $(ls *.json); do
done done
# Make the Vagrant instances headless # Make the Vagrant instances headless
cd /opt/DetectionLab/Vagrant cd /opt/DetectionLab/Vagrant || exit 1
sed -i 's/vb.gui = true/vb.gui = false/g' Vagrantfile sed -i 's/vb.gui = true/vb.gui = false/g' Vagrantfile
# Ensure the script is executable # Ensure the script is executable
chmod +x /opt/DetectionLab/build.sh chmod +x /opt/DetectionLab/build.sh
cd /opt/DetectionLab cd /opt/DetectionLab || exit 1
# Start the build in a tmux session # Start the build in a tmux session
sn=tmuxsession sn=tmuxsession
tmux new-session -s "$sn" -d tmux new-session -s "$sn" -d
tmux send-keys -t "$sn:0" './build.sh virtualbox && echo "success" > /var/www/html/index.html || echo "failed" > /var/www/html/index.html' Enter tmux send-keys -t "$sn:0" './build.sh virtualbox | tee -a /opt/DetectionLab/Vagrant/vagrant.log && echo "success" > /var/www/html/index.html || echo "failed" > /var/www/html/index.html' Enter

View File

@@ -7,11 +7,11 @@
# the text "building". Once the test is completed, the text will be replaced # the text "building". Once the test is completed, the text will be replaced
# with "success" or "failed". # with "success" or "failed".
# Install Virtualbox 5.1 # Install Virtualbox 5.2
echo "deb http://download.virtualbox.org/virtualbox/debian xenial contrib" >> /etc/apt/sources.list echo "deb http://download.virtualbox.org/virtualbox/debian xenial contrib" >> /etc/apt/sources.list
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
apt-get update apt-get update
apt-get install -y virtualbox-5.1 build-essential unzip git ufw apache2 apt-get install -y linux-headers-"$(uname -r)" virtualbox-5.2 build-essential unzip git ufw apache2
echo "building" > /var/www/html/index.html echo "building" > /var/www/html/index.html
@@ -23,20 +23,20 @@ ufw --force enable
# Install Vagrant # Install Vagrant
mkdir /opt/vagrant mkdir /opt/vagrant
cd /opt/vagrant cd /opt/vagrant || exit 1
wget https://releases.hashicorp.com/vagrant/2.0.1/vagrant_2.0.1_x86_64.deb wget https://releases.hashicorp.com/vagrant/2.0.2/vagrant_2.0.2_x86_64.deb
dpkg -i vagrant_2.0.1_x86_64.deb dpkg -i vagrant_2.0.2_x86_64.deb
vagrant plugin install vagrant-reload vagrant plugin install vagrant-reload
# Make the Vagrant instances headless # Make the Vagrant instances headless
cd /opt/DetectionLab/Vagrant cd /opt/DetectionLab/Vagrant || exit 1
sed -i 's/vb.gui = true/vb.gui = false/g' Vagrantfile sed -i 's/vb.gui = true/vb.gui = false/g' Vagrantfile
# Ensure the script is executable # Ensure the script is executable
chmod +x /opt/DetectionLab/build_vagrant_only.sh chmod +x /opt/DetectionLab/build_vagrant_only.sh
cd /opt/DetectionLab cd /opt/DetectionLab || exit 1
# Start the build in a tmux session # Start the build in a tmux session
sn=tmuxsession sn=tmuxsession
tmux new-session -s "$sn" -d tmux new-session -s "$sn" -d
tmux send-keys -t "$sn:0" './build_vagrant_only.sh virtualbox && echo "success" > /var/www/html/index.html || echo "failed" > /var/www/html/index.html' Enter tmux send-keys -t "$sn:0" './build_vagrant_only.sh virtualbox | tee -a /opt/DetectionLab/Vagrant/vagrant.log && echo "success" > /var/www/html/index.html || echo "failed" > /var/www/html/index.html' Enter