forked from appserver-io/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-mac.sh
executable file
·289 lines (244 loc) · 6.72 KB
/
setup-mac.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
#!/bin/bash
#title :setup-mac.sh
#description :This script configures appserver components
#author :Marcus Döllerer
#date :20170919
#usage :bash setup-mac.sh
#####################
### Configuration ###
#####################
# Directory to which the selected repositories will be cloned
WORKSPACE_DIR="$HOME/workspace/appserver-sdk"
# Path to the sdk
# Please change if you run the script from a different directory
SCRIPT_DIR=`pwd`
# The build version of the runtime which will be installed
APPSERVER_RUNTIME_VERSION="1.1.7-109_x86_64"
# vendor/name:branch of the appserver repository
APPSERVER_REPOSITORY="appserver-io/appserver:1.1"
# Array of components to configure (vendor/name:branch)
# Just comment out or remove entries you don't need
COMPONENTS=(
'appserver-io/authenticator'
'appserver-io/build'
'appserver-io/collections'
'appserver-io/concurrency'
'appserver-io/configuration'
'appserver-io/description'
'appserver-io/dnsserver'
'appserver-io/doppelgaenger'
'appserver-io/fastcgi'
'appserver-io/http'
'appserver-io/lang:3.0'
'appserver-io/logger'
'appserver-io/messaging'
'appserver-io/microcron'
'appserver-io/properties'
'appserver-io/pthreads-polyfill'
'appserver-io/rmi'
'appserver-io/robo-tasks'
'appserver-io/routlt'
'appserver-io/routlt-project'
'appserver-io/server'
'appserver-io/single-app'
'appserver-io/storage'
'appserver-io/webserver'
'appserver-io-psr/application'
'appserver-io-psr/auth'
'appserver-io-psr/context'
'appserver-io-psr/deployment'
'appserver-io-psr/di'
'appserver-io-psr/epb'
'appserver-io-psr/http-message'
'appserver-io-psr/mop'
'appserver-io-psr/naming'
'appserver-io-psr/pms'
'appserver-io-psr/security'
'appserver-io-psr/servlet'
'appserver-io-psr/socket'
)
############################
### Function Definitions ###
############################
function clone {
componentBranch=$(getComponentBranch $1)
component=$(removeBranchVersion $1)
if ! git clone https://github.com/$component.git "$2/"
then
return
fi
if [[ ! "$componentBranch" = "" ]]
then
cd "$2"
git checkout -b $componentBranch origin/$componentBranch
fi
}
function linkComponent {
removeComponent $1 $2
component=$1
pre1="appserver-io/"
pre2="appserver-io-psr/"
if [[ "$component" =~ ^"$pre1" ]]
then
cd "$WORKSPACE_DIR/appserver/vendor/appserver-io/"
ln -s ../../../$2/
else
if [[ "$component" =~ ^"$pre2" ]]
then
cd "$WORKSPACE_DIR/appserver/vendor/appserver-io-psr/"
ln -s ../../../$2/
fi
fi
}
function removeComponent {
component=$1
pre1="appserver-io/"
pre2="appserver-io-psr/"
if [[ "$component" =~ ^"$pre1" ]]
then
VENDOR="appserver-io"
else
if [[ "$component" =~ ^"$pre2" ]]
then
VENDOR="appserver-io-psr"
fi
fi
if [[ -d "$WORKSPACE_DIR/appserver/vendor/$VENDOR/$2" ]]
then
rm -rf "$WORKSPACE_DIR/appserver/vendor/$VENDOR/$2"
fi
}
function removeBranchVersion {
componentBranch=$(getComponentBranch $1)
suffix=":$componentBranch"
result=${1%$suffix}
echo "$result"
}
function getComponentShort {
component=$1
pre1="appserver-io/"
pre2="appserver-io-psr/"
if [[ "$component" =~ ^"$pre1" ]]
then
result=${component#$pre1}
else
if [[ "$component" =~ ^"$pre2" ]]
then
result=${component#$pre2}
fi
fi
result=$(removeBranchVersion $result)
echo "$result"
}
function getComponentBranch {
result=`cut -d ":" -f 2 <<< "$1"`
if [[ "$result" = "$1" ]]
then
result=""
fi
echo "$result"
}
function installRuntime {
cd "$WORKSPACE_DIR/appserver/var/tmp"
curl -O http://builds.appserver.io/mac/appserver-runtime_$APPSERVER_RUNTIME_VERSION.tar.gz
tar xfz appserver-runtime_$APPSERVER_RUNTIME_VERSION.tar.gz
cp -R -f "$WORKSPACE_DIR/appserver/var/tmp/appserver/"* "$WORKSPACE_DIR/appserver"
rm appserver-runtime_$APPSERVER_RUNTIME_VERSION.tar.gz
rm -rf appserver/
echo "$APPSERVER_RUNTIME_VERSION" > "$WORKSPACE_DIR/appserver/var/tmp/runtime_version.properties"
}
########################
### Initialize setup ###
########################
if [[ $1 == "--workspace-dir"* ]]
then
if [[ $1 = "--workspace-dir" ]] && [[ ! $2 = "" ]]
then
WORKSPACE_DIR=$2
else
pre="--workspace-dir="
WORKSPACE_DIR=${1#$pre}
fi
fi
WORKSPACE_DIR="${WORKSPACE_DIR/#\~/$HOME}"
echo ""
echo ' ____ _____ ____ ________ ______ _____ _____(_)___ '
echo ' / __ `/ __ \/ __ \/ ___/ _ \/ ___/ | / / _ \/ ___/ / __ \ '
echo ' / /_/ / /_/ / /_/ (__ ) __/ / | |/ / __/ / / / /_/ / '
echo ' \__,_/ .___/ .___/____/\___/_/ |___/\___/_(_)/_/\____/ '
echo ' /_/ /_/ '
echo ""
echo ""
echo "This script will set up appserver-io/appserver and selected"
echo "components as git repositories in the defined workspace."
echo ""
echo "Don't forget to have a look at the configuration segment of this script"
echo "and verify that WORKSPACE_DIR and COMPONENTS are set correctly"
echo ""
echo "Please make sure that you don't have any unsaved changes in"
echo ""
echo " '$WORKSPACE_DIR'"
echo ""
echo "Shall we begin? (Press ENTER to continue, any other key to abort)"
read -s -n 1 begin
if [ ! "${#begin}" -eq 0 ]
then
exit
fi
echo ""
echo "The following repositories will be cloned:"
echo "$APPSERVER_REPOSITORY"
for full in "${COMPONENTS[@]}"
do
echo $full
done
echo ""
echo "Continue? (Press ENTER to continue, any other key to abort)"
read -s -n 1 continue1
if [ ! "${#continue1}" -eq 0 ]
then
echo "Aborting ..."
exit
fi
clone $APPSERVER_REPOSITORY "$WORKSPACE_DIR/appserver"
cd "$WORKSPACE_DIR/appserver"
git checkout -b 1.1 origin/1.1
composer install
for full in "${COMPONENTS[@]}"
do
cd "$WORKSPACE_DIR"
componentFQDN=$(removeBranchVersion $full)
componentShort=$(getComponentShort $full)
clone $full "$WORKSPACE_DIR/$componentShort"
linkComponent $componentFQDN $componentShort
done
installRuntime
echo "Creating symlink to /opt/appserver"
if [[ -L /opt/appserver ]]
then
sudo rm /opt/appserver
else
if [[ -d /opt/appserver ]]
then
echo "[ERROR] Directory '/opt/appserver/' already exists but has to be removed in order to continue"
echo "Please make sure you do not have any important files in '/opt/appserver/'"
echo ""
echo "Continue? (Press ENTER to continue, any other key to abort)"
read -s -n 1 continue2
if [ ! "${#continue1}" -eq 0 ]
then
echo "Aborting ..."
exit
fi
sudo rm -rf /opt/appserver
fi
fi
sudo ln -s "$WORKSPACE_DIR/appserver/" /opt
cp -R "$SCRIPT_DIR/sbin/"* "$WORKSPACE_DIR/appserver/sbin/"
cp -R "$SCRIPT_DIR/bin/"* "$WORKSPACE_DIR/appserver/bin/"
USER=`whoami`
sed -i '' -e "s/<param name=\"user\" type=\"string\">_www/<param name=\"user\" type=\"string\">$USER/g" "$WORKSPACE_DIR/appserver/etc/appserver/appserver.xml"
echo ""
echo "Setup complete. The configured repositories are accessable under '$WORKSPACE_DIR'."
echo "You may now start the appserver with '/opt/appserver/sbin/appserverctl start'"
echo ""