1
+ #! /bin/bash
2
+ # ###############################################################################
3
+ # Build spring boot with starter script
4
+ # Usage:
5
+ # bash build.sh [/path/to/installation/dir]
6
+ # ###############################################################################
7
+
8
+ # ###############################################################################
9
+ # Define default values for variables
10
+ # ###############################################################################
11
+ # no defaults yet!
12
+
13
+ # ###############################################################################
14
+ # START DECLARATION FUNCTIONS
15
+ # ###############################################################################
16
+
17
+ # ###############################################################################
18
+ function usage {
19
+ # ###############################################################################
20
+ echo " Script for creating indexing-service."
21
+ echo " USAGE:"
22
+ echo " $0 [/path/to/installation/dir]"
23
+ echo " IMPORTANT: Please enter an empty or new directory as installation directory."
24
+ exit 1
25
+ }
26
+
27
+ # ###############################################################################
28
+ function checkParameters {
29
+ # ###############################################################################
30
+ # Check no of parameters.
31
+ if [ " $# " -ne 1 ]; then
32
+ echo " Illegal number of parameters!"
33
+ usage
34
+ fi
35
+
36
+ # Check if argument is given
37
+ if [ -z " $1 " ]; then
38
+ echo " Please provide a directory where to install."
39
+ usage
40
+ exit 1
41
+ fi
42
+
43
+ # Check for invalid flags
44
+ if [ " ${1: 0: 1} " = " -" ]; then
45
+ usage
46
+ fi
47
+
48
+ INSTALLATION_DIRECTORY=$1
49
+
50
+ # Check if directory exists
51
+ if [ ! -d " $INSTALLATION_DIRECTORY " ]; then
52
+ # Create directory if it doesn't exists.
53
+ mkdir -p " $INSTALLATION_DIRECTORY "
54
+ if [ $? -ne 0 ]; then
55
+ echo " Error creating directory '$INSTALLATION_DIRECTORY '!"
56
+ echo " Please make sure that you have the correct access permissions for the specified directory."
57
+ exit 1
58
+ fi
59
+ fi
60
+ # Check if directory is empty
61
+ if [ ! -z " $( ls -A " $INSTALLATION_DIRECTORY " ) " ]; then
62
+ echo " Directory '$INSTALLATION_DIRECTORY ' is not empty!"
63
+ echo " Please enter an empty or a new directory!"
64
+ exit 1
65
+ fi
66
+ # Convert variable of installation directory to an absolute path
67
+ cd " $INSTALLATION_DIRECTORY "
68
+ INSTALLATION_DIRECTORY=` pwd`
69
+ cd " $ACTUAL_DIR "
70
+ }
71
+
72
+ # ###############################################################################
73
+ function printInfo {
74
+ # ###############################################################################
75
+ echo " ---------------------------------------------------------------------------"
76
+ echo $*
77
+ echo " ---------------------------------------------------------------------------"
78
+ }
79
+
80
+ # ###############################################################################
81
+ # END DECLARATION FUNCTIONS / START OF SCRIPT
82
+ # ###############################################################################
83
+
84
+ # ###############################################################################
85
+ # Test for commands used in this script
86
+ # ###############################################################################
87
+ testForCommands=" chmod cp dirname find java javac mkdir"
88
+
89
+ for command in $testForCommands
90
+ do
91
+ type $command >> /dev/null
92
+ if [ $? -ne 0 ]; then
93
+ echo " Error: command '$command ' is not installed!"
94
+ exit 1
95
+ fi
96
+ done
97
+
98
+ # ###############################################################################
99
+ # Determine directory of script.
100
+ # ###############################################################################
101
+ ACTUAL_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) "
102
+
103
+ # ###############################################################################
104
+ # Check parameters
105
+ # ###############################################################################
106
+ checkParameters $*
107
+
108
+ # ###############################################################################
109
+ # Determine repo name
110
+ # ###############################################################################
111
+ REPO_NAME=` ./gradlew -q printProjectName`
112
+ # Use only last line
113
+ REPO_NAME=${REPO_NAME##* $' \n ' }
114
+
115
+ printInfo " Build microservice of $REPO_NAME at '$INSTALLATION_DIRECTORY '"
116
+
117
+
118
+ # ###############################################################################
119
+ # Build service
120
+ # ###############################################################################
121
+
122
+ echo Build service...
123
+ ./gradlew -Prelease clean build
124
+
125
+
126
+ echo " Copy configuration to '$INSTALLATION_DIRECTORY '..."
127
+ find . -name application-default.properties -exec cp ' {}' " $INSTALLATION_DIRECTORY " /application.properties \;
128
+
129
+ echo " Copy jar file to '$INSTALLATION_DIRECTORY '..."
130
+ find . -name " $REPO_NAME *.jar" -exec cp ' {}' " $INSTALLATION_DIRECTORY " \;
131
+
132
+ echo " Create config directory"
133
+ mkdir " $INSTALLATION_DIRECTORY " /config
134
+
135
+ echo " Create lib directory"
136
+ mkdir " $INSTALLATION_DIRECTORY " /lib
137
+
138
+ # ##############################################################################
139
+ # Create run script
140
+ # ###############################################################################
141
+ printInfo " Create run script ..."
142
+
143
+ cd " $INSTALLATION_DIRECTORY "
144
+
145
+ # Determine name of jar file.
146
+ jarFile=(` ls $REPO_NAME * .jar` )
147
+
148
+ echo " #!/bin/bash" > run.sh
149
+ echo " ################################################################################" >> run.sh
150
+ echo " # Run microservice '$REPO_NAME '" >> run.sh
151
+ echo " # /" >> run.sh
152
+ echo " # |- application.properties - Default configuration for microservice" >> run.sh
153
+ echo " # |- '$REPO_NAME '*.jar" - Microservice >> run.sh
154
+ echo " # |- run.sh - Start script " >> run.sh
155
+ echo " # |- lib/ - Directory for plugins (if supported)" >> run.sh
156
+ echo " # |- config/ " >> run.sh
157
+ echo " # |- application.properties - Overwrites default configuration (optional)" >> run.sh
158
+ echo " ################################################################################" >> run.sh
159
+ echo " " >> run.sh
160
+ echo " ################################################################################" >> run.sh
161
+ echo " # Define jar file" >> run.sh
162
+ echo " ################################################################################" >> run.sh
163
+ echo jarFile=$jarFile >> run.sh
164
+ echo " " >> run.sh
165
+ echo " ################################################################################" >> run.sh
166
+ echo " # Determine directory of script." >> run.sh
167
+ echo " ################################################################################" >> run.sh
168
+ echo ' ACTUAL_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"' >> run.sh
169
+ echo ' cd "$ACTUAL_DIR"' >> run.sh
170
+ echo " " >> run.sh
171
+ echo " ################################################################################" >> run.sh
172
+ echo " # Start micro service" >> run.sh
173
+ echo " ################################################################################" >> run.sh
174
+ echo ' java -cp ".:$jarFile" -Dloader.path="file://$ACTUAL_DIR/$jarFile,./lib/,." -jar $jarFile' >> run.sh
175
+
176
+ # make script executable
177
+ chmod 755 run.sh
178
+
179
+ echo .
180
+ printInfo " Now you can start the service by calling '$INSTALLATION_DIRECTORY /run.sh'"
0 commit comments