-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.sh
363 lines (333 loc) · 9.65 KB
/
runner.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/bin/bash
VERSION=1.0.4
TEMP_DIR="/tmp"
SOURCE_DIR=~/source
APP_DIR=~/app
INSTALLER_DIR=${APP_DIR}/installer
HYBRIS_DIR=${APP_DIR}/hybris
LAST_CHECK_FILE=~/.runner.update.check
RECIPE_FILE=~/.runner.recipe
# Check for Updates if more than 7 days
if [ ! -f ${LAST_CHECK_FILE} ]; then
check_for_updates;
else
old_timestamp=`cat ${LAST_CHECK_FILE} `;
new_timestamp=$(date +%s)
if [ $((${new_timestamp} - ${old_timestamp} > 604800)) ]; then
check_for_updates;
fi
fi
# Load current storefront recipe
current_recipe=Unknown
if [ -f ${RECIPE_FILE} ]; then
current_recipe=`cat ${RECIPE_FILE}`
fi
function show_menu(){
NORMAL=`echo "\033[m"`
MENU=`echo "\033[36m"` #Blue
NUMBER=`echo "\033[33m"` #yellow
FGRED=`echo "\033[41m"`
RED_TEXT=`echo "\033[31m"`
ENTER_LINE=`echo "\033[33m"`
echo -e "${MENU}************************************************${NORMAL}"
echo -e "${MENU}** Current Storefront Recipe: ${current_recipe}"
echo -e "${MENU}************************************************${NORMAL}"
echo -e "${MENU}**${NUMBER} 1)${MENU} Start hybris server"
echo -e "${MENU}**${NUMBER} 2)${MENU} Stop hybris server"
echo -e "${MENU}**${NUMBER} 3)${MENU} Change Storefront Recipe (reload from zip)"
echo -e ""
echo -e "*********** Spartacus Storefront ****************"
echo -e "${MENU}**${NUMBER} 4)${MENU} Start Spartacus (requires internet connection)"
echo -e "${MENU}**${NUMBER} 5)${MENU} Stop Spartacus"
echo -e ""
echo -e "*********** Less Common Options ****************"
echo -e "${MENU}**${NUMBER} 6)${MENU} Initialize hybris"
echo -e "${MENU}**${NUMBER} 7)${MENU} Rebuild hybris (ant clean all)"
echo -e "${MENU}**${NUMBER} 8)${MENU} Tail console log"
echo -e "${MENU}**${NUMBER} 9)${MENU} Reinstall Spartacus (latest dev version)"
echo -e "${MENU}**${NUMBER} 10)${MENU} Self update this program"
echo -e "${MENU}************************************************${NORMAL}"
echo -e "${ENTER_LINE}Please enter a menu option and enter or ${RED_TEXT}enter to exit. ${NORMAL}"
read opt
}
function error_message() {
COLOR='\033[01;31m' # bold red
RESET='\033[00;00m' # normal white
MESSAGE=${@:-"${RESET}Error: No message passed"}
echo -e "${COLOR}${MESSAGE}${RESET}"
}
function pause(){
read -p "$*"
}
function init_hybris() {
cd ${HYBRIS_DIR}/bin/platform;
. ./setantenv.sh
ant initialize;
if [ $? -eq 0 ]; then
echo "Initialization successful. Press enter to continue."
pause;
else
error_message "Initialization failed. Check the error messages above. Press enter to continue."
pause;
fi
}
function init_hybris_with_warning() {
error_message "Warning: Initialize will delete all your current data. Are you sure you want to continue? (y/n)"
read option;
if [[ $option = 'y' ]]; then
init_hybris;
fi
}
function check_for_updates() {
wget -O /tmp/runner.sh -q --timeout=5 --tries=1 --no-check-certificate https://raw.githubusercontent.com/bradyemerson/hybris_vm/master/runner.sh
if [ $? -eq 0 ]; then
old_version=`grep -P '^VERSION=([\d\.]+)$' ~/runner.sh | grep -oP '([\d\.]+)$'`
new_version=`grep -P '^VERSION=([\d\.]+)$' /tmp/runner.sh | grep -oP '([\d\.]+)$'`
if [ $old_version != $new_version ]; then
echo "Updating to new version: ${new_version}";
rm ~/runner.sh;
cp /tmp/runner.sh ~/runner.sh;
chmod 775 ~/runner.sh;
echo "New version applied. Please restart to complete upgrade. Press enter to exit.";
pause;
exit;
elif [ $1 ]; then
echo "You already have the latest version";
fi
rm /tmp/runner.sh;
echo $(date +%s) > ${LAST_CHECK_FILE}
else
error_message "Error downloading latest version. Please check internet connection and try again later."
fi
}
function change_recipe() {
clear;
echo "Available recipes:";
for dir in `ls -D ${INSTALLER_DIR}/recipes`; do
echo "$dir "
done
echo
echo "Enter 'info' to see description of recipes. Enter the name of new recipe name or leave blank to cancel: ";
read recipe;
if [[ $recipe = 'info' ]]; then
echo "Loading recipes...";
${INSTALLER_DIR}/install.sh -l > ${TEMP_DIR}/recipes.out
zenity --width=800 --height=600 --title "Available Recipes" --text-info --filename="${TEMP_DIR}/recipes.out" 2> /dev/null
rm ${TEMP_DIR}/recipes.out
change_recipe;
elif [[ $recipe != "" ]]; then
${INSTALLER_DIR}/install.sh -r ${recipe} setup
if [ -e "${SOURCE_DIR}/hybrislicence.jar" ] ; then
cp ${SOURCE_DIR}/hybrislicence.jar ${HYBRIS_DIR}/config/licence;
fi
if [ $? -eq 0 ]; then
echo $recipe > ${RECIPE_FILE}
current_recipe=$recipe
echo
echo -e "Change recipe to ${recipe} was successful. Do you want to initialize to load new sample data? (y/n)";
read choice;
if [[ $choice = "y" ]]; then
init_hybris;
fi
else
echo
error_message "Build failed. Check the error messages above. Press enter to continue."
pause;
fi
fi
clear;
}
function load_spartacus() {
if [ -d "${APP_DIR}/spartacus" ] ; then
echo "Clearing previous Spartacus installation."
rm -rf ${APP_DIR}/spartacus;
fi
git -c http.sslVerify=false clone https://github.com/SAP/cloud-commerce-spartacus-storefront.git ${APP_DIR}/spartacus;
if [ $? -eq 0 ]; then
init_spartacus;
else
error_message "Unable to download Spartacus. Are you connected to the internet?"
pause;
fi
}
function init_spartacus() {
cd ${APP_DIR}/spartacus;
yarn;
if [ $? -eq 0 ]; then
echo "Spartacus successful installed."
else
error_message "Could not install Spartacus dependencies. See error message above. Do you want to try again? (Y/n)"
read option;
if [[ $option = 'y' || $option = 'Y' || $option = '' ]]; then
init_spartacus;
fi
fi
}
function start_spartacus() {
pid=`pgrep "ng serve"`
if [ $pid > 0 ] ; then
echo "Looks like Spartacus is already running. Try accessing at http://localhost:4200/."
echo "Press enter to continue."
pause;
return;
fi
if [ ! -d "${APP_DIR}/spartacus" ] ; then
load_spartacus;
fi
cd ${APP_DIR}/spartacus;
yarn run start &> /dev/null &
if [ $? -eq 0 ]; then
echo "Spartacus server is starting -- please wait approximently 90 seconds."
echo "Checking if Spartacus is available..."
sleep 90s
wget_output=$(wget --spider --no-check-certificate http://localhost:4200/ 2>&1)
wget_exit_code=$?
echo
if [ $wget_exit_code -ne 0 ]; then
error_message "The server has not responded. There may have been an issue during startup.";
pause;
else
echo "Spartacus is ready! You can access it in the web browser at http://localhost:4200/. Press enter to continue."
pause;
fi
else
error_message "Could not start Spartacus server. See error message above."
pause;
fi
}
function stop_spartacus() {
pid=`pgrep "ng serve"`
if [ $pid > 0 ] ; then
kill $pid;
echo "Spartacus server stopped. Press enter to continue."
pause;
else
echo "It doesn't look like the Spartacus server is running."
echo "Press enter to continue."
pause;
fi
}
clear
echo "************************************************"
echo "*** Version: ${VERSION} ***"
echo "************************************************"
echo
show_menu
while [ opt != '' ]
do
if [[ $opt = "" ]]; then
exit;
else
case $opt in
1) clear;
cd ${HYBRIS_DIR}/bin/platform;
./hybrisserver.sh start;
if [ $? -eq 0 ]; then
echo
echo "hybris server has started, but it will take a couple more minutes before you can access it in the web browser."
echo "Checking if hybris is available..."
wget_output=$(wget --spider --tries 4 --no-check-certificate https://localhost:9002/ 2>&1)
wget_exit_code=$?
echo
if [ $wget_exit_code -ne 0 ]; then
error_message "The server has not responded. There may have been an issue during startup. Use option 7 to check the logs.";
pause;
else
echo "hybris is ready! Press enter to continue."
pause
fi
else
error_message "Could not start hybris server. Is it already running?"
pause;
fi
clear
show_menu
;;
2) clear;
cd ${HYBRIS_DIR}/bin/platform;
./hybrisserver.sh stop;
echo "Press enter to continue"
pause;
clear;
show_menu;
;;
3) clear;
if [ -e "${SOURCE_DIR}/hybris.tar.lzma" ] ; then
error_message "Warning: This will clear and rebuild hybris from zip. Are you sure you want to continue? (y/n)"
read option;
if [[ $option = 'y' ]]; then
echo "Clearing previous installation"
rm -rf ${APP_DIR}/hybris ${APP_DIR}/installer;
cd ${APP_DIR};
echo "Starting unzip";
tar --lzma -xvf ${SOURCE_DIR}/hybris.tar.lzma 1>/dev/null
if [ -e "${SOURCE_DIR}/custom.properties" ] ; then
cp ${SOURCE_DIR}/custom.properties ${INSTALLER_DIR}/customconfig;
fi
echo "Unzip Complete. Check above for error messages. Press enter to continue."
pause;
change_recipe;
fi
else
error_message "Operation Unavailable. Please upgrade to latest VM."
pause;
fi
clear;
show_menu;
;;
4) clear;
start_spartacus;
clear;
show_menu;
;;
5) clear;
stop_spartacus;
clear;
show_menu;
;;
6) clear;
init_hybris_with_warning;
clear;
show_menu;
;;
7) clear;
cd ${HYBRIS_DIR}/bin/platform;
. ./setantenv.sh
ant clean all;
if [ $? -eq 0 ]; then
echo "Build successful. Press enter to continue."
pause;
else
error_message "Build failed. Check the error messages above. Press enter to continue."
pause;
fi
clear;
show_menu;
;;
8) clear;
cd ${HYBRIS_DIR}/log/tomcat;
file=`ls -t console* | head -n1`
qterminal -e "tail --lines=200 -f ${file}"
show_menu;
;;
9) clear;
load_spartacus;
clear;
show_menu;
;;
10) clear;
echo "Checking for latest version"
check_for_updates true;
show_menu;
;;
x)exit;
;;
\n)exit;
;;
*)clear;
echo "Pick an option from the menu";
show_menu;
;;
esac
fi
done