-
Notifications
You must be signed in to change notification settings - Fork 355
/
cli-process-env.sh
98 lines (77 loc) · 1.97 KB
/
cli-process-env.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
NETWORK="$1"
ENV_VALUE="$2"
FORCE_REWRITE="$3"
LOCAL_RUN="$4"
# Colors
Red="\033[0;31m" # Red
Default="\033[1;37m" # White
Green="\033[0;32m" # Green
Blue="\033[0;34m" # Blue
BBlue="\033[1;34m" # Bold Blue
if [ -z $NETWORK ]; then
NETWORK="goerli"
fi
if [ -z $ENV_VALUE ]; then
ENV_VALUE="dev"
fi
FILE=".env"
printf "\n${BBlue}Configuration:\n\n" "" "$NC"
printf "${Default} Environment:"
if [ "$ENV_VALUE" == "prod" ]; then
echo "${Red} Prod"
else
echo "${Green} $ENV_VALUE"
fi
echo "${Default} Ethereum network: ${Green}$NETWORK"
printf "${Default} Localhost:"
if [ -z $LOCAL_RUN ]; then
echo "${Green} nope"
else
echo "${Red} yes"
fi
printf "${Default} Generate .env anyway:"
if [ -n $FORCE_REWRITE ]; then
echo "${Red} yes"
else
echo "${Green} nope"
fi
printf "${BBlue}\nSearching for .env...\n\n"
printf "${Default} File status: "
if [ -e $FILE ]; then
echo "${Green}.env found"
else
echo "${Default} Configuring .env for $NETWORK ethereum network"
FORCE_REWRITE=1
fi
printf "\n${BBlue}Resolving...\n\n"
if [ -z $FORCE_REWRITE ]; then
printf "${Default} No changes made\n\n"
echo "${Red} Exiting..."
exit
else
printf "${Red} Overriding found .env\n\n"
fi
GIT_VERSION="\nAPP_GIT_VERSION=$(git tag -l | tail -n1)"
GIT_REVISION="APP_GIT_REVISION=$(git rev-parse --short HEAD)"
GIT_UPDATED_AT="APP_GIT_UPDATED_AT=\"$(git log -1 --format=%cd)\""
APP_ENV="APP_ENV=$ENV_VALUE\n"
rm -f ./.env &&
cp "environments/.env.$NETWORK" ".env" &&
echo "$GIT_VERSION" >>".env" &&
echo "$GIT_REVISION" >>".env" &&
echo "$APP_ENV" >>".env" &&
echo "$GIT_UPDATED_AT" >>".env"
printf "${BBlue}Defining host...\n\n"
if [ -z $LOCAL_RUN ]; then
echo "${Green} Remote host detected."
else
echo "${Red} Localhost detected:"
echo ""
echo "${Default} Sentry: ${Red}Disabled"
echo "${Default} GTM: ${Red}Disabled"
echo ""
echo "IS_LOCALHOST=1" >> ".env"
fi
echo ""
echo "${Green} ✅ Environment configured successfully!"