#!/usr/bin/with-contenv bash

# Exit if no installable packages are provided
if [ -z ${INSTALL_PACKAGES+x} ]; then
    echo "**** No packages to install ****"
    exit 0
fi


#Split list of packages on delimiter '|'
IFS='|'
INSTALL_PACKAGES=(${INSTALL_PACKAGES})
for PKG in "${INSTALL_PACKAGES[@]}"; do
    echo "Installing ${PKG}"

    # Ubuntu
    if [ -f /usr/bin/apt ]; then
        DEBIAN_FRONTEND="noninteractive"
        apt-get install -y --no-install-recommends ${PKG}
    fi

    # Alpine
    if [ -f /sbin/apk ]; then
        apk add --no-cache ${PKG}
    fi

done
