-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotenv
executable file
·80 lines (72 loc) · 1.76 KB
/
dotenv
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
#!/bin/bash -e
#
# Generate `.env` file with randomized secrets.
#######################################
# Create dotenv file for development.
#
# Globals:
# None
# Arguments:
# None
# Outputs:
# None
#######################################
create_env() {
if [ ! -f .env ]
then
touch .env
POSTGRES_DB=clairbuoyant
POSTGRES_PASSWORD=$(random_password)
POSTGRES_USER=$(username)
PYTHON_ENV=development
DATABASE_URL="postgresql+asyncpg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}"
echo "POSTGRES_DB=${POSTGRES_DB}" >> .env
echo "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}" >> .env
echo "POSTGRES_USER=${POSTGRES_USER}" >> .env
echo "DATABASE_URL=postgresql+asyncpg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}" >> .env
echo "PYTHON_ENV=${PYTHON_ENV}" >> .env
fi
}
#######################################
# Load contents of dotenv file to shell.
#
# Globals:
# None
# Arguments:
# None
# Outputs:
# None
#######################################
load_env() {
if [ -f .env ]; then
export $(echo $(cat .env | sed 's/#.*//g'| xargs) | envsubst)
fi
}
#######################################
# Generate randomized password
# for development environment.
#
# Globals:
# None
# Arguments:
# None
# Outputs:
# Writes random password to stdout
#######################################
random_password() {
LC_ALL=C < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c ${1:-20}; echo;
}
#######################################
# Get name of currently logged-in user.
#
# Globals:
# None
# Arguments:
# None
# Outputs:
# Writes name of user to stdout
#######################################
username() {
whoami
}
create_env