-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
203 lines (182 loc) · 4.21 KB
/
setup.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
usage() {
msg=$(cat <<EOF
LDSHE docker services setup script
Usage: setup [OPTION]
OPTION
-b rebuild the docker images
-h help
-i clean install
-u fetch up-to-date LDSHE sources from repo, install the application libraries and recompile the assets
EOF
)
echo "$msg"
}
argsCheck() {
while getopts ":hibu" opt; do
case "$opt" in
"h")
usage
exit 0;
;;
"i")
cleanInstall
exit 0;
;;
"b")
stop
buildImg
start
exit 0;
;;
"u")
update
exit 0;
;;
"?")
echo "Unknown option $OPTARG"
usage
exit 0;
;;
":")
echo "No argument value for option $OPTARG"
usage
exit 0;
;;
*)
echo "Unknown error while processing options"
exit 0;
;;
esac
done
if [ $OPTIND -eq 1 ]; then
cleanInstall
fi
shift $(($OPTIND - 1))
}
cloneRepo() {
echo
echo "Cloning LDSHE repo..."
echo
if [ -d "src" ]; then
rm -rf src
fi
mkdir src
pushd src
git init
git remote add -f origin https://github.com/ldshe/ldshe.git
git checkout master
popd
}
pullRepo() {
echo
echo "Fetching source codes..."
echo
pushd src
git fetch origin master
git reset --hard origin/master
git checkout master
popd
}
rmInstallIdx() {
rm -f src/install/index.php
}
updateConf() {
if [ -f "src/api/.env" ]; then
appKey=`sed -n -e "/APP_KEY/ s/.*\= *//p" "src/api/.env"`
fi
copyConf
if [ ! -z "$appKey" ]; then
sed -i -E "s/(APP_KEY=)(.+)/\1$appKey/" "src/api/.env"
fi
}
copyConf() {
yes | cp config/app/.env.api src/api/.env
yes | cp config/app/.env.echo src/echo/.env
yes | cp config/app/.env.ldsv2 src/ldsv2/.env
yes | cp config/app/.env.users src/users/.env
}
buildImg() {
echo
echo "Building docker images..."
echo
docker build -t ldshe-php:1.0 php
docker-compose build --build-arg uid=$(id -u) app
docker-compose build cron
}
initDB() {
echo
echo "Creating database & tables..."
echo
docker-compose up -d mysql
while ! docker-compose exec mysql mysqladmin -uroot -hmysql ping --silent &> /dev/null ; do
echo "Waiting for database connection..."
sleep 2
done
echo "Executing SQL statements..."
docker-compose run --rm \
-v `pwd`/sql/init.sql:/root/init.sql:ro \
-v `pwd`/sql/seeds.sql:/root/seeds.sql:ro \
-v `pwd`/src/install/install/includes/sql.sql:/root/userspice.sql:ro \
mysql \
bash -c \
"mysql -uroot -hmysql < /root/init.sql &&\
mysql -uroot -hmysql ldshev2 < /root/userspice.sql &&\
mysql -uroot -hmysql ldshev2 < /root/seeds.sql"
}
installLib() {
echo
echo "Installing application libraries and recompile the assets..."
echo
docker-compose run --rm app bash -c \
"composer install -d ./api &&\
npm install --prefix ./echo &&\
composer install -d ./ldsv2 &&\
npm install --prefix ./ldsv2 &&\
npm run dev --prefix ./ldsv2 &&\
composer install -d ./users &&\
php api/artisan migrate"
}
start() {
echo
echo "Starting docker services..."
echo
docker-compose up -d
}
stop() {
echo
echo "Stopping docker services..."
echo
docker-compose stop
}
cleanInstall() {
read -p "You are going to clean install the LDSHE docker services. Continue (Y/N)? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
:
else
exit 0;
fi
stop
cloneRepo
rmInstallIdx
copyConf
buildImg
initDB
installLib
start
echo
echo "Docker services for LDSHE are now up and ready!"
echo
}
update() {
updateConf
pullRepo
rmInstallIdx
installLib
echo
echo "LDSHE application is updated!"
echo
}
argsCheck "$@"