#!/bin/bash

if test "${1:-}" = ""; then
    echo "MISSING ARG"
    exit 1
fi

# We override with system wide custom settings (if existing)
if test -f /etc/metwork.custom_profile; then
    # shellcheck disable=SC1091
    . /etc/metwork.custom_profile
fi

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if test "${METWORK_PROFILE_LOADED}" != "1" -a "${METWORK_PROFILE_LOADING}" != "1"; then
    if test -f "${CURRENT_DIR}/../share/profile"; then
        . "${CURRENT_DIR}/../share/profile"
    fi
fi

# We override with module wide custom settings (if existing)
if test -f ~/.metwork.custom_profile; then
    . ~/.metwork.custom_profile
fi

exec "$@"
