This repository has been archived by the owner on May 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
install.sh
executable file
·209 lines (182 loc) · 5.77 KB
/
install.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
#!/bin/bash
#
# The main goal is to download and install :
# - the Java EE 7 app server
# - the asciidoctor module
# - the asciidoctor-backends data
# - the ad-editor app
###########
debug=true
APP_SERVER_HOME=""
applicationServer="wildfly-8.0.0.Final"
appVersion="0.1.0-alpha3"
appName="ad-editor"
function usage {
echo "usage : install.sh -s {server} -v {version}"
echo "OPTIONS :"
echo " -X : debug mode to shwo process steps"
echo " -s {server} : Java EE 7 server name (default: wildfly)"
echo " -v {version} : ad-editor version (default: last release)"
echo "ex : install.sh -s wildfly -v 0.1.0-alpha3"
}
while getopts s:v:X opt; do
case $opt in
s) server="$OPTARG" ;;
v) version="$OPTARG" ;;
X) debug=true ;;
esac;
done
#
#if mode debug is true
function log {
if [ $# -eq 1 ] && [ $debug = true ]; then
echo "[INFO] $1";
fi
}
#
#Check that all required params are present
function checkParams {
if [ -z "$server" ]; then
log "No server name specified (-s), Wildfly used by default"
else
log "TODO handle TomEE and other app server..."
#TODO : handle TomEE
#applicationServer==$server
fi
if [ -z "$version" ]; then
log "No version specified (-v), $appVersion used by default"
else
appVersion=$version
fi
app=$appName"-"$appVersion
appWAR=$app".war"
#github release
releaseVersion="v"$appVersion
log "Installation for ... App Server : $applicationServer, Application : $app "
}
#check if a server is already started on 8080
function checkPortAlreadyUsed {
STATUS=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8080)
if [ $STATUS -eq 200 ]; then
log "Is there a server already started on 8080 ? Please stop it and relaunch this script."
exit 0;
else
log " $STATUS, OK (no app server started on 8080)"
fi
}
#
# Download and install the target Java EE 7 app server
function checkJavaEE7AppServer {
isAppServerInstalled=false
# determine if WildFly is installed
if [ "x$JBOSS_HOME" = "x" ]; then
log "No JBOSS_HOME defined"
#check if JBOSS_HOME is a WildFly version
elif [ ! -f "$JBOSS_HOME/bin/init.d/wildfly.conf" ]; then
log "JBOSS installed is not a WildFly version"
#ok
else
isAppServerInstalled=true
APP_SERVER_HOME=$JBOSS_HOME
fi
# install WildFly if is not present
if [ "$isAppServerInstalled" = false ]; then
if [ ! -f "$applicationServer.tar.gz" ]; then
log "No targz archive found, download the server..."
curl -O http://download.jboss.org/wildfly/8.0.0.Final/$applicationServer.tar.gz
else
#clean an older wildfly version
if [ -d "$applicationServer" ]; then
log "Delete an older unpacked version"
rm -rf $applicationServer
fi
fi
tar xzf $applicationServer.tar.gz
APP_SERVER_HOME=$(pwd)"/$applicationServer"
export JBOSS_HOME="$APP_SERVER_HOME"
fi
log "App Server HOME : $APP_SERVER_HOME"
}
#
# AsciidoctorJ + JRuby + asciidoctor-backends
function createAsciidoctorModule {
#check if this module already exist
if [ -d "$APP_SERVER_HOME/modules/org/asciidoctor/main" ]; then
log "Asciidoctor module is already installed in the App Server"
else
#if it doesn't exist, check if the dependencies are present in the local m2 repo
jrubyInRepoLocal=$HOME"/.m2/repository/org/jruby/jruby-complete/1.7.4/jruby-complete-1.7.4.jar"
jrubyInRepoDistant="http://search.maven.org/remotecontent?filepath=org/jruby/jruby-complete/1.7.4/jruby-complete-1.7.4.jar"
asciidoctorJInRepoLocal=$HOME"/.m2/repository/org/asciidoctor/asciidoctor-java-integration/0.1.4/asciidoctor-java-integration-0.1.4.jar"
asciidoctorJInRepoDistant="http://search.maven.org/remotecontent?filepath=org/asciidoctor/asciidoctor-java-integration/0.1.4/asciidoctor-java-integration-0.1.4.jar"
if [ ! -d "./org/asciidoctor/main" ]; then
mkdir "org" && cd "org" && mkdir "asciidoctor" && cd "asciidoctor" && mkdir "main" && cd "main"
if [ ! -f "$jrubyInRepoLocal" ]; then
log "Download JRuby $jrubyInRepoLocal..."
curl -O $jrubyInRepoDistant
else
log "Copy JRuby from local repo"
cp $jrubyInRepoLocal .
fi
if [ ! -f "$asciidoctorJInRepoLocal" ]; then
log "Download AsciidoctorJ ..."
curl -O $asciidoctorJInRepoDistant
else
log "Copy AsciidoctorJ from local repo"
cp $asciidoctorJInRepoLocal .
fi
log "Download module.xml"
curl -O https://raw.github.com/mgreau/when-websocket-met-asciidoctor/$releaseVersion/module/org/asciidoctor/main/module.xml
cd ../../..
else
log "Asciidoctor module is ready to install"
fi
log "Install asciidoctor module"
cp -r org $APP_SERVER_HOME/modules
fi
}
#
#
function installApp {
log "Downloading and install app...$releaseVersion $appWAR"
curl -OL https://github.com/mgreau/when-websocket-met-asciidoctor/releases/download/$releaseVersion/$appWAR
mv $appWAR $APP_SERVER_HOME/standalone/deployments
log "App deployed"
}
#
#
function cleanAndStatus {
log "cleaning..."
rm -rf "org"
}
function launchApp {
log "Launch the app..."
$APP_SERVER_HOME/bin/standalone.sh &
url="http://localhost:8080/$app"
while true
do
if [ -f $APP_SERVER_HOME/standalone/log/server.log ]
then
cat $APP_SERVER_HOME/standalone/log/server.log | grep "started in" 2>/dev/null
if [ $? = 0 ]
then
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
xdg-open $url
else
open $url
fi
exit
fi
fi
done
log "Have fun with $app : $url"
}
echo "--------- INSTALLING Real-time Collaborative editor for AsciiDoc -------"
checkParams
checkPortAlreadyUsed
checkJavaEE7AppServer
createAsciidoctorModule
installApp
cleanAndStatus
launchApp