-
Notifications
You must be signed in to change notification settings - Fork 0
/
.envrc
68 lines (58 loc) · 1.79 KB
/
.envrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
exit_with_error() {
printf "Error: %b\n" "$1"
if [ -f "$CHAIN_ID_FILE" ]; then
# Cleanup
rm -f "$CHAIN_ID_FILE"
fi
exit 1
}
# Load default settings
source .env.default
CHAIN_ID_FILE=".chain_id"
if [ ! -f "$CHAIN_ID_FILE" ]; then
echo "CHAIN_ID file (.chain_id) does not exist. Please enter the CHAIN_ID:"
read CHAIN_ID
echo "$CHAIN_ID" > "$CHAIN_ID_FILE"
fi
export CHAIN_ID=$(cat "$CHAIN_ID_FILE")
# Load the corresponding .env file
export CHAIN_ENV_FILE=".env.${CHAIN_ID}"
if [ -n "$ENVIRONMENT" ]; then
export CHAIN_ENV_FILE="${CHAIN_ENV_FILE}.${ENVIRONMENT}"
fi
if [ -f "$CHAIN_ENV_FILE" ]; then
# Export variables from the .env file
set -a
. "$CHAIN_ENV_FILE"
set +a
else
exit_with_error "The environment file $CHAIN_ENV_FILE does not exist.\n\
Please, use the .env.example file to define it.\n\
Then re-run direnv allow."
fi
export PRIVATE_ENV_FILE=".env"
if [ -f "$PRIVATE_ENV_FILE" ]; then
# Export private variables from the .env file
set -a
. "$PRIVATE_ENV_FILE"
set +a
else
exit_with_error "The environment file $PRIVATE_ENV_FILE does not exist.\n\
Please, use the .env.private.example file to define it.\n\
Then re-run direnv allow."
fi
if [ ! -n "$DEPLOYMENTS_DIR" ]; then
export DEPLOYMENTS_DIR="deployments/"
fi
export CHAIN_DEPLOYMENTS_FILE="$DEPLOYMENTS_DIR/$DEPLOYMENT_CONTEXT/contract_addresses.json"
if [ -f "$CHAIN_DEPLOYMENTS_FILE" ]; then
TEMP_CONTRACTS_FILE="$DEPLOYMENTS_DIR/$DEPLOYMENT_CONTEXT/$CHAIN_ENV_FILE.contracts"
jq -r 'to_entries | .[] | "\(.key)=\(.value)"' "$CHAIN_DEPLOYMENTS_FILE" > "$TEMP_CONTRACTS_FILE"
# Export deployments from the .env file
set -a
. "$TEMP_CONTRACTS_FILE"
set +a
rm "$TEMP_CONTRACTS_FILE"
TEMP_CONTRACTS_FILE=""
fi