-
Notifications
You must be signed in to change notification settings - Fork 38
/
application.sh
executable file
·142 lines (123 loc) · 4.09 KB
/
application.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Copyright (C) 2003-2017, e-Evolution Consultants S.A. , http://www.e-evolution.com
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Email: victor.perez@e-evolution.com, http://www.e-evolution.com , http://github.com/e-Evolution
#!/usr/bin/env bash
BASE_DIR=$(cd "$(dirname "$0")"; pwd)
if [ -z "$1" ];
then
echo "ADempiere instance name, should use application.sh <instance name> up -d "
exit 1
fi
# load environment variables
. .env
export COMPOSE_PROJECT_NAME=$1;
echo "Instance $COMPOSE_PROJECT_NAME"
. ./$COMPOSE_PROJECT_NAME/.env
if [ -z "$ADEMPIERE_WEB_PORT" ];
then
echo "ADempiere HTTP port not setting"
exit 1
fi
if [ -z "$ADEMPIERE_SSL_PORT" ];
then
echo "ADempiere HTTPS port not setting"
exit 1
fi
if [ -z "$ADEMPIERE_DB_INIT" ];
then
echo "Initialize Database not setting"
exit 1
fi
if [ -z "$ADEMPIERE_VERSION" ];
then
echo "ADempiere version not setting"
exit 1
fi
export ADEMPIERE_WEB_PORT;
export ADEMPIERE_SSL_PORT;
export ADEMPIERE_DB_INIT;
echo "ADempiere HTTP port: $ADEMPIERE_WEB_PORT"
echo "ADempiere HTTPS port: $ADEMPIERE_SSL_PORT"
echo "Initialize Database $ADEMPIERE_DB_INIT"
if [ "$(docker network inspect -f '{{.Name}}' custom)" != "custom" ];
then
echo "Create custom network"
docker network create -d bridge custom
fi
RUNNING=$(docker inspect --format="{{.State.Running}}" postgres${PG_VERSION//.}_db_1 2> /dev/null)
if [ $? -eq 1 ]; then
echo "Dababase container does not exist."
echo "Create Database container"
docker-compose \
-f "$BASE_DIR/database.yml" \
-f "$BASE_DIR/database.volume.yml" \
-p postgres${PG_VERSION} \
up -d
fi
if [ "$RUNNING" == "false" ];
then
echo "CRITICAL - postgres${PG_VERSION//.}_db_1 is not running."
echo "Starting Database"
docker-compose \
-f "$BASE_DIR/database.yml" \
-f "$BASE_DIR/database.volume.yml" \
-p postgres${PG_VERSION} \
start
fi
if [ "$RUNNING" == "true" ];
then
docker-compose \
-f "$BASE_DIR/database.yml" \
-f "$BASE_DIR/database.volume.yml" \
-p postgres${PG_VERSION} \
config
fi
export DB_CONTAINER_ID=$(docker inspect --format="{{.Id}}" postgres${PG_VERSION//.}_db_1)
# Define Adempiere path and binary
export ADEMPIERE_DB_SERVER=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $DB_CONTAINER_ID)
echo "Database Host: $ADEMPIERE_DB_SERVER"
ADEMPIERE_PATH="./$COMPOSE_PROJECT_NAME"
ADEMPIERE_BINARY=Adempiere_${ADEMPIERE_VERSION//.}"LTS.tar.gz"
export ADEMPIERE_BINARY;
export ADEMPIERE_DB_SERVER;
URL="https://github.com/adempiere/adempiere/releases/download/"$ADEMPIERE_VERSION"/"$ADEMPIERE_BINARY
if [ -d "$ADEMPIERE_PATH" ]
then
if [ -f "$ADEMPIERE_PATH/$ADEMPIERE_BINARY" ]
then
echo "Installed based on ADempiere $ADEMPIERE_VERSION"
else
echo "Adempiere Path $ADEMPIERE_PATH"
echo "Adempiere Version $ADEMPIERE_VERSION"
echo "Adempiere Binary $ADEMPIERE_PATH/$ADEMPIERE_BINARY"
echo "Download from $URL"
curl -L $URL > "$ADEMPIERE_PATH/$ADEMPIERE_BINARY"
if [ -f "$ADEMPIERE_PATH/$ADEMPIERE_BINARY" ]
then
echo "Adempiere Binary download successful"
else
"Adempiere Binary not download"
exit
fi
fi
# Execute docker-compose
echo
docker-compose \
-f "$BASE_DIR/adempiere.yml" \
-p "$COMPOSE_PROJECT_NAME" \
$2 \
$3 \
$4 \
$5
else
echo "Project directory not found for : $COMPOSE_PROJECT_NAME "
fi