-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsanityCheckEnv.sh
More file actions
executable file
·42 lines (33 loc) · 1012 Bytes
/
sanityCheckEnv.sh
File metadata and controls
executable file
·42 lines (33 loc) · 1012 Bytes
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
#! /usr/bin/env bash
R_VAR='^(# +)?[A-Z0-9_]+='
RED='\033[0;31m'
GREEN='\033[0;32m'
PLAIN='\033[0m'
getVars () {
local envFile=$1
# Get raw var, inc possible comment and trailing equal sign
raw=$(grep -oE "$R_VAR" "$envFile")
# Uncomment
uncommented=$(sed 's/# *//' <(echo "$raw"))
# Un-equals
plain=$(sed 's/=//' <(echo "$uncommented"))
# Sort and remove duplicates
tidy=$(sort <(echo "$plain") | uniq)
echo -n "$tidy"
}
# Get all vars, commented or not
TEAM_VARS=$(getVars .env.example)
YOUR_VARS=$(getVars .env)
if diff -q <(echo "$TEAM_VARS") <(echo "$YOUR_VARS") > /dev/null; then
exit 0
fi
echo "[sanityCheckEnv.sh] found potential env spook! A happy engineer fixes this delta ASAP."
echo
echo "[sanityCheckEnv.sh] variables only in your .env:"
echo -en "$RED"
comm -13 <(echo "$TEAM_VARS") <(echo "$YOUR_VARS")
echo -e "$PLAIN"
echo "[sanityCheckEnv.sh] variables only in .env.example:"
echo -en "$GREEN"
comm -23 <(echo "$TEAM_VARS") <(echo "$YOUR_VARS")
echo -en "$PLAIN"