#!/usr/bin/env bash
set -e # this will stop the installation process if there is an error on any of the commands
DIRECTORY_TO_CHECK="/Applications/Microsoft Excel.app" # this has to be a folder (.app extensions are folders)
FILE_TO_DOWNLOAD="https://s3.amazonaws.com/files.addigy.com/file.pkg" # this is the url to download the file from
DOWNLOAD_LOCAL_PATH="/tmp/file.pkg" # this is the local path in the machine to download the file to

if [ -d "${DIRECTORY_TO_CHECK}" ]; then
    echo "Microsoft Excel is already installed"
else
    echo "Installing office..."

    # In the following line we are going to download the file using Addigy's Lan-Cache. This service will
    # ensure that only one device per network downloads this file and shares it with its peers.
    /Library/Addigy/go-utils cache-client download "${FILE_TO_DOWNLOAD}" "${DOWNLOAD_LOCAL_PATH}"

    # Here we run the PKG file to install the software. Keep in mind that this command only works for PKG files.
    # If the file you are downloading is not a pkg file then you need to run a different command to install it.
    /usr/sbin/installer -pkg ${DOWNLOAD_LOCAL_PATH} -target /
fi