generated from abmruman/docker-compose-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·56 lines (47 loc) · 1.19 KB
/
init.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
#!/bin/bash
#title : init.sh
#description : Initializes by creating `.env` and external NETWORK defined in `.env`
#author : abmruman
#usage : `./scripts/init.sh` OR `make init`
set -e
echo
# Create env from env.example if it doesn't exist
if [ -f ".env" ]
then
echo -e "env file exists"
else
echo -e "Copying env file"
cp env.example .env
fi
echo
eval $(egrep -m1 '^USERS_FILE=' .env | xargs)
AUTH_FILE="auth/$USERS_FILE"
# Create env from env.example if it doesn't exist
if [ -f "$AUTH_FILE" ]
then
echo -e "'$AUTH_FILE' file exists"
chmod 600 "$AUTH_FILE"
else
echo -e "Creating '$AUTH_FILE' file"
touch "$AUTH_FILE"
chmod 600 "$AUTH_FILE"
fi
echo
# Create network if necessary
eval $(egrep -m1 '^NETWORK=' .env | xargs)
eval $(egrep -m1 '^NETWORK_EXTERNAL=' .env | xargs)
echo -e "NETWORK: $NETWORK"
echo -e "NETWORK_EXTERNAL: $NETWORK_EXTERNAL"
echo
if [ ! -z "$NETWORK" ] && [ ! -z "$NETWORK_EXTERNAL" ]
then
if [ "$NETWORK_EXTERNAL" = "true" ]
then
docker network ls | grep "$NETWORK" || docker network create "$NETWORK"
else
echo -e "Skipping network creation, not external"
fi
else
echo -e "\nNETWORK not defined, creation not necessary\n"
fi
echo