#!/bin/bash -e SCRIPT_URL="https://file.up9cloud.net/source-env-json.sh" if [ -z "$1" ]; then echo "Usage:" echo echo "set -- path/to/env.json" echo "source /dev/stdin <<<\"\$(curl -sSL $SCRIPT_URL)\"" exit 1 fi ENV_FILE="$1" # Check if the environment variable file exists and is readable. if [ ! -f "$ENV_FILE" ]; then echo "Error: Secrets JSON file not found at $ENV_FILE" >&2 exit 1 fi # Check if jq is installed. jq is required for this script. if ! command -v jq &> /dev/null then echo "Error: 'jq' is not installed. Please install it to run this script." >&2 exit 1 fi # Read the JSON file and iterate through its keys. # Export each key-value pair as an environment variable. # This approach works when the script is sourced, not subshelled. eval "$( jq -r 'to_entries[] | @sh "export \(.key)=\(.value)"' "$ENV_FILE" )"