#!/bin/bash

# Download the Microsoft Install (MSI) file for a given version of Puppet
# agent (if necessary) and install it on a Windows VM

set -eou pipefail

source utils.sh

# Download MSI file if it doesn't exist in the current directory.
msi_file="puppet-agent-$PUPPET_AGENT_VERSION-x64.msi"

echo "Checking for file $msi_file in current directory"
if [ ! -f $msi_file ]; then

    echo "File $msi_file is not found"
    major_version="$(semver_major_version $PUPPET_AGENT_VERSION)"

    echo "Extracted major version of $major_version"
    msi_download="https://downloads.puppetlabs.com/windows/puppet$major_version/$msi_file"

    echo "Downloading $msi_download"
    wget $msi_download
fi

echo "Installing Puppet Agent version $PUPPET_AGENT_VERSION in Windows VM"
vagrant powershell -e -c "/vagrant/install_puppet_agent.ps1 $msi_file"

#!/bin/bash

# Download the Microsoft Install (MSI) file for a given version of Puppet
# agent (if necessary) and install it on a Windows VM

set -eou pipefail

source utils.sh

base_snapshot_name="base-install"

# Download MSI file if it doesn't exist in the current directory.
msi_file="puppet-agent-$PUPPET_AGENT_VERSION-x64.msi"

echo "Checking for file $msi_file in current directory"
if [ ! -f $msi_file ]; then

    echo "File $msi_file is not found"
    major_version="$(semver_major_version $PUPPET_AGENT_VERSION)"

    echo "Extracted major version of $major_version"
    msi_download="https://downloads.puppetlabs.com/windows/puppet$major_version/$msi_file"

    echo "Downloading $msi_download"
    wget $msi_download
fi

echo "Restoring base-install snapshot..."
vagrant snapshot restore "$base_snapshot_name"

echo "Installing Puppet Agent version $PUPPET_AGENT_VERSION in Windows VM"
vagrant powershell -e -c "/vagrant/install_puppet_agent.ps1 $msi_file"

Make agent installation in E2E vagrant test use a snapshot source
Make agent installation in E2E vagrant test use a snapshot source

We don't want to keep installing/reinstalling the agent on a dirty VM so
this change ensures that we always install the agent on a clean VM.
