#!/usr/bin/env bash

set -e

if [ "$#" -ne 1 ]; then
    echo >&2 "ERROR: You need to pass a dependencies list file as an argument to cpk-pip3-install."
    exit 1
fi

PACKAGES_LIST=$1
PACKAGES=$(awk -F: '/^[^#]/ { print $1 }' $PACKAGES_LIST | uniq)
HAS_PACKAGES=$(echo $PACKAGES | sed '/^\s*#/d;/^\s*$/d' | wc -l)

if [ $HAS_PACKAGES -eq 1 ]; then
    echo "Installing packages via PIP3..."
    pip3 install -r ${PACKAGES_LIST}
else
    echo "No packages to install via PIP3."
fi
