-
Notifications
You must be signed in to change notification settings - Fork 1
/
dtcw
executable file
·406 lines (374 loc) · 12.9 KB
/
dtcw
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
#!/usr/bin/env bash
#here you can specify the URL of a theme to use with generateSite-task
#export DTC_SITETHEME=https://....zip
#here you can specify the location of additional templates
#export DTC_TEMPLATE1=https://....zip
#export DTC_TEMPLATE2=https://....zip
#...
MAIN_CONFIG_FILE=docToolchainConfig.groovy
# find official release versions on github:
# https://github.com/docToolchain/docToolchain/releases
# set VERSION to "latest" to get the unreleased latest version
VERSION=2.2.1
DISTRIBUTION_URL=https://github.com/docToolchain/docToolchain/releases/download/v${VERSION}/docToolchain-${VERSION}.zip
if [ -z "$DTC_PROJECT_BRANCH" ]; then
if [ -d .git ]; then
DTC_PROJECT_BRANCH=$(git branch --show-current)
else
DTC_PROJECT_BRANCH="-"
fi;
export DTC_PROJECT_BRANCH
fi
DTC_HEADLESS=${DTC_HEADLESS:="false"}
if [ -t 0 ]; then
# do nothing - we have a tty
echo ""
else
echo "Using headless mode since there is no (terminal) interaction possible"
DTC_HEADLESS=true
fi
export DTC_HEADLESS
DTC_OPTS="$DTC_OPTS -PmainConfigFile=$MAIN_CONFIG_FILE --warning-mode=none --no-daemon "
echo "dtcw - docToolchain wrapper V0.36"
echo "docToolchain V${VERSION}"
# check if CLI, docker or sdkman are installed
cli=false
docker=false
sdkman=false
homefolder=false
java=false
wsl=false
doJavaCheck=true
arch=`uname -m`
os=`uname -s`
if command -v doctoolchain &> /dev/null; then
echo "docToolchain as CLI available"
cli=true
fi
if command -v docker &> /dev/null; then
echo "docker available"
docker=true
fi
if command -v sdk &> /dev/null; then
echo "sdkman available"
sdkman=true
fi
if [ -d "$HOME/.doctoolchain/docToolchain-${VERSION}/." ]; then
echo "home folder exists"
homefolder=true
fi
if [ "$1" = "local" ] ; then
echo "force use of local install"
docker=false
cli=false
shift
fi
if [ "$1" = "docker" ] ; then
cli=false
homefolder=false
echo "force use of docker"
shift
fi
if [ "$1" = "sdk" ] ; then
cli=false
homefolder=false
docker=false
sdkman=true
echo "force use of sdkman"
shift
fi
if [ "$1" = "generateDeck" ]; then
if [ "$homefolder" = false ]; then
echo "generateDeck currently only works with a local installed docToolchain"
echo "please run './dtcw local install' to install it locally"
exit 1
else
if [ -d "$HOME/.doctoolchain/docToolchain-${VERSION}/resources/reveal.js/." ]; then
# reveal.js already installed
echo ""
else
echo "cloning reveal.js"
cd $HOME/.doctoolchain/docToolchain-${VERSION}/resources/.
./clone.sh
cd -
fi
fi
fi
# check for apple M1 silicon
if [ "$os" = "Darwin" ]; then
if [ "$arch" = "arm64" ]; then
echo "it seems that you try to run docToolchain on M1 silicon"
echo "please consider to switch to a x86 shell by executing"
echo "arch -x86_64 /bin/bash"
echo "in order to run docToolchain in x86 mode"
echo ""
fi
fi
if ! $DTC_HEADLESS ; then
if [ "$docker" = false ] ; then
# important for the docker file to find dependencies
DTC_OPTS="$DTC_OPTS '-Dgradle.user.home=$HOME/.doctoolchain/.gradle'"
fi
fi
if [ "$docker" = false ] ; then
# check for locally installed jdk
if [ -d "$HOME/.doctoolchain/jdk/." ]; then
echo "local java JDK found"
java=true
if [ -d "$HOME/.doctoolchain/jdk/Contents/." ]; then
javaHome="$HOME/.doctoolchain/jdk/Contents/Home"
else
javaHome="$HOME/.doctoolchain/jdk"
fi
echo "use $javaHome as JDK"
DTC_OPTS="$DTC_OPTS '-Dorg.gradle.java.home=$javaHome'"
if [ -z "${JAVA_HOME}" ]; then
#if JAVA_HOME is not set, export it
export JAVA_HOME=$javaHome
else
if command -v $JAVA_HOME/bin/java &> /dev/null; then
#java is installed and JAVA_HOME is ok
echo ""
else
#set JAVA_HOME to our own JDK
export JAVA_HOME=$javaHome
fi
fi
doJavaCheck=false
fi
fi
# check if we are running on WSL
if [[ $(grep -i 'microsoft' /proc/version) ]]; then
echo " "
echo "Bash is running on WSL"
echo "this might cause problems with plantUML"
echo "see https://doctoolchain.github.io/docToolchain/#wsl for more details"
echo " "
wsl=true
fi
# url toLocation
download ( ) {
url=$1
toLocation=$2
echo ">>> $1 $2"
#check that pre-requisites are met
if ! (command -v wget &> /dev/null); then
if ! (command -v curl &> /dev/null); then
echo "you need either wget or curl installed"
echo "please install it and re-run the command"
exit 1
fi
fi
if ! (command -v unzip &> /dev/null); then
echo "you need unzip installed"
echo "please install it and re-run the command"
exit 1
fi
if command -v curl &> /dev/null; then
curl -Lo $toLocation $url
else
wgetversion=$(wget --version && true | head -1 | sed -E 's/^.* 1.([0-9]+).*$/\1/')
if (( $wgetversion > 13 )); then
wget $url -O $toLocation
else
echo "you need curl or wget (version >= 1.14) installed"
echo "please install or update and re-run the command"
exit 1
fi
fi
}
java_help_and_die() {
echo "it might be that you have installed the needed version java in another shell from which you started dtcw"
echo "dtcw is running in bash and uses the PATH to find java"
echo ""
echo "to install a local java for docToolchain, you cann run"
echo "./dtcw getJava"
echo ""
echo "another way to install or update java is to install"
echo "sdkman and then java via sdkman"
echo "https://sdkman.io/install"
echo "$ curl -s "https://get.sdkman.io" | bash"
echo "$ sdk install java"
echo ""
echo "or you can download it from https://adoptium.net/"
echo ""
echo "make sure that your java version is between 8 and 14"
echo ""
echo "If you do not want to use a local java installtion, you can also use docToolchain as docker container."
echo "In that case, specify 'docker' as first parameter in your statement."
echo "example: ./dtcw docker generateSite"
exit 1
}
check_java() {
if command -v java &> /dev/null; then
java=true
if java -version 2>&1 >/dev/null | grep -q "Unable to locate a Java Runtime" ; then
##we are on a mac and the java command is only a shim
java=false
fi
fi
if [ "$java" = false ] ; then
echo "docToolchain depends on java, but the java command couldn't be found in this shell (bash)"
echo ""
java_help_and_die
fi
javaversion=$(java -version 2>&1 | awk -F '"' '/version/ {print $0}' | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
echo "Java Version $javaversion"
if (( $javaversion < 8 )); then
echo "your java version $javaversion is too old (<8): $(which java)"
echo "please update your java installation and try again"
echo ""
java_help_and_die
else
if (( $javaversion > 14 )); then
echo "your java version $javaversion is too new (>14): $(which java)"
echo "please update your java installation and try again"
echo ""
java_help_and_die
fi
fi
}
install_local() {
mkdir $HOME/.doctoolchain
download $DISTRIBUTION_URL $HOME/.doctoolchain/source.zip
unzip $HOME/.doctoolchain/source.zip -d $HOME/.doctoolchain/.
}
if [ "$VERSION" == "latest" ] || [ "$VERSION" == "latestdev" ] ; then
echo "force latest version with local install"
docker=false
cli=false
mkdir -p $HOME/.doctoolchain
# check if we have to clone or just pull
if [ -d "$HOME/.doctoolchain/docToolchain-${VERSION}/.git" ]; then
cd $HOME/.doctoolchain/docToolchain-$VERSION
git pull
cd -
else
if [ "$VERSION" == "latest" ] ; then
git clone https://github.com/docToolchain/docToolchain.git $HOME/.doctoolchain/docToolchain-$VERSION
else
git clone [email protected]:docToolchain/docToolchain.git $HOME/.doctoolchain/docToolchain-$VERSION
fi
fi
homefolder=true
fi
if [ "$1" == "getJava" ] ; then
version=11
implementation=hotspot
heapsize=normal
imagetype=jdk
releasetype=ga
case "$arch" in
x86_64 ) arch=x64 ;;
arm64 ) arch=aarch64 ;;
esac
if [[ $os == MINGW* ]] ; then
echo ""
echo "Error: MINGW64 is not supported"
echo "please use powershell or wsl"
exit 1
fi
case "$os" in
Linux ) os=linux ;;
Darwin ) os=mac ;;
Cygwin ) os=linux ;;
esac
echo "this script assumes that you have linux as operating system ($arch / $os)"
echo "it now tries to install Java for you"
mkdir $HOME/.doctoolchain/jdk
echo "downloading JDK Temurin 11 from adoptiom to $HOME/.doctoolchain/jdk.tar.gz"
download https://api.adoptium.net/v3/binary/latest/$version/$releasetype/$os/$arch/$imagetype/$implementation/$heapsize/eclipse?project=jdk $HOME/.doctoolchain/jdk/jdk.tar.gz
#wget -r -O $HOME/.doctoolchain/jdk/jdk.tar.gz https://api.adoptium.net/v3/binary/latest/$version/$releasetype/$os/$arch/$imagetype/$implementation/$heapsize/eclipse?project=jdk
echo "expanding JDK"
tar -zxf $HOME/.doctoolchain/jdk/jdk.tar.gz --strip 1 -C $HOME/.doctoolchain/jdk/.
shift
exit 1
fi
#if bakePreview is called, deactivate deamon
if [ "$1" = "bakePreview" ] ; then
DTC_OPTS="$DTC_OPTS -Dorg.gradle.daemon=false"
fi
if [[ $# -lt 1 ]]; then
echo '
Usage: ./dtcw [option...] [task...]
You can use the same options and tasks as in underlying gradle.
Use "./dtcw tasks --group doctoolchain" to see available tasks.
Use "local", "sdk" or "docker" as first argument to force the use of a local, sdkman or docker install.
Examples:
Download and install arc42 Template:
./dtcw downloadTemplate
Generate PDF:
./dtcw generatePDF
Generate HTML:
./dtcw generateHTML
Publish HTML to Confluence:
./dtcw publishToConfluence
get more documentation at https://doctoolchain.github.io
'
exit 1
fi
if [ "$cli" = true ] ; then
command="$(which doctoolchain) . $1 $2 $3 $4 $5 $6 $7 $8 $9 $DTC_OPTS"
echo "use cli install $(which doctoolchain)"
else
if [ "$homefolder" = true ] ; then
command="$HOME/.doctoolchain/docToolchain-${VERSION}/bin/doctoolchain . $1 $2 $3 $4 $5 $6 $7 $8 $9 $DTC_OPTS"
echo "use local homefolder install $HOME/.doctoolchain/"
else
if [ "$docker" = true ] ; then
if ! docker info >/dev/null 2>&1; then
echo "Docker does not seem to be running, run it first and retry"
echo "if you want to use a local installation of doctoolchain instead"
echo "use 'local' as first argument to force the installation and use of a local install."
exit 1
fi
docker_cmd=$(which docker)
echo $docker_cmd
if command -v cygpath &>/dev/null; then
pwd=$(cygpath -w $PWD)
else
pwd=$PWD
fi
command="'$docker_cmd' run -u $(id -u):$(id -g) --name doctoolchain${version} -e DTC_HEADLESS=1 -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=$DTC_PROJECT_BRANCH -p 8042:8042 --rm -i --entrypoint /bin/bash -v '${pwd}:/project' doctoolchain/doctoolchain:v${VERSION} -c \"doctoolchain . $1 $2 $3 $4 $5 $6 $7 $8 $9 $DTC_OPTS && exit\""
doJavaCheck=false
echo "use docker installation"
else
echo "docToolchain not installed."
if [ "$sdkman" = true ] ; then
echo "please use sdkman to install docToolchain"
echo "$ sdk install doctoolchain ${VERSION}-beta"
exit
else
echo "sdkman not found"
if [ "$DTC_HEADLESS" == true ] ; then
# just download
install_local
else
echo "Do you wish to install doctoolchain to $HOME/.doctoolchain?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "installing doctoolchain";
install_local
break
;;
No )
echo "you need docToolchain as CLI-Tool installed or docker."
echo "to install docToolchain as CLI-Tool, please install"
echo "sdkman and re-run this command."
echo "https://sdkman.io/install"
echo "$ curl -s "https://get.sdkman.io" | bash"
exit 1
;;
esac
done
fi
command="$HOME/.doctoolchain/docToolchain-${VERSION}/bin/doctoolchain . $1 $2 $3 $4 $5 $6 $7 $8 $9 $DTC_OPTS"
fi
fi
fi
fi
if [ "$doJavaCheck" = true ] ; then
check_java
fi
# echo "Command to invoke: $command"
exec bash -c "$command"