Adds option to also set per project env values

This commit is contained in:
Llewellyn van der Merwe 2022-08-04 18:29:31 +02:00
parent 4054508729
commit aa282bff5d
Signed by: Llewellyn
GPG Key ID: A9201372263741E7

View File

@ -23,9 +23,15 @@ command -v jq >/dev/null 2>&1 || {
# main function ˘Ô≈ôﺣ # main function ˘Ô≈ôﺣ
function main() { function main() {
# get the package details # check if we have project overides for the environment variables
# shellcheck disable=SC2015 # shellcheck disable=SC2015
[ -f "$VDM_PACKAGE_CONF_FILE" ] && getPackageDetails || { [ -f "$VDM_PACKAGE_CONF_FILE" ] && getProjectEnvironment || {
echo >&2 "[error] We require config file with correct packaging details for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not found in/at $VDM_PACKAGE_CONF_FILE. Aborting."
clearMainEnv
exit 1
}
# get the package details
getPackageDetails || {
echo >&2 "[error] We require config file with correct packaging details for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not found in/at $VDM_PACKAGE_CONF_FILE. Aborting." echo >&2 "[error] We require config file with correct packaging details for $PROGRAM_NAME v${PROGRAM_V} to work, but it's not found in/at $VDM_PACKAGE_CONF_FILE. Aborting."
clearMainEnv clearMainEnv
exit 1 exit 1
@ -78,10 +84,6 @@ function main() {
# set the package details # set the package details
function getPackageDetails() { function getPackageDetails() {
# load the config data
VDM_CONFIG_DATA=$(cat "$VDM_PACKAGE_CONF_FILE")
# make sure we have package details
if [[ "${VDM_CONFIG_DATA}" =~ '"package"' ]] && [[ "${VDM_CONFIG_DATA}" =~ '"files"' ]]; then
# little information of progress # little information of progress
_echo "[info] Loading the Package Details..." _echo "[info] Loading the Package Details..."
# make configuration globally available # make configuration globally available
@ -117,13 +119,8 @@ function getPackageDetails() {
getConfigValue 'VDM_UPDATE_SERVER' '.package.update_servers' || has_error=true getConfigValue 'VDM_UPDATE_SERVER' '.package.update_servers' || has_error=true
# check if we have some errors already # check if we have some errors already
$has_error && return 13 $has_error && return 13
# success # success
return 0 return 0
else
# failed
return 17
fi
} }
# set the target repository details # set the target repository details
@ -1079,6 +1076,32 @@ function runUninstall() {
fi fi
} }
# check if we have project overides for the environment variables
function getProjectEnvironment() {
# load the config data
VDM_CONFIG_DATA=$(cat "$VDM_PACKAGE_CONF_FILE")
# make sure we have package details
if [[ "${VDM_CONFIG_DATA}" =~ '"package"' ]] && [[ "${VDM_CONFIG_DATA}" =~ '"files"' ]]; then
# little information of progress
_echo "[info] Loading the environment variables..."
# make configuration globally available
export VDM_CONFIG_DATA
# get package code_name
getConfigValue 'VDM_CODE_NAME' '.package.code_name'
# the tmp path to the env of this project
tmp_path="/home/$USER/.config/${PROGRAM_CODE}/.${VDM_CODE_NAME}"
# shellcheck disable=SC1090
[ -f "${tmp_path}" ] && source "${tmp_path}"
# clear this tmp out
unset tmp_path
# success
return 0
else
# failed
return 17
fi
}
# update the script with the latest version # update the script with the latest version
function runUpdate() { function runUpdate() {
# remove the current version # remove the current version
@ -1194,7 +1217,7 @@ tmp_path="/home/$USER/.config/${PROGRAM_CODE}/.env"
# if path not set try $PWD path # if path not set try $PWD path
[ -f "$tmp_path" ] || tmp_path="$PWD/.env" [ -f "$tmp_path" ] || tmp_path="$PWD/.env"
VDM_ENV_FILE_PATH="${VDM_ENV_FILE_PATH:-$tmp_path}" VDM_ENV_FILE_PATH="${VDM_ENV_FILE_PATH:-$tmp_path}"
# car this tmp out # clear this tmp out
unset tmp_path unset tmp_path
# check if we have options # check if we have options