forked from docToolchain/docToolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtcw
executable file
·230 lines (208 loc) · 7.15 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
#!/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
#...
DTC_HEADLESS=true
MAIN_CONFIG_FILE=docToolchainConfig.groovy
VERSION=2.0.3
DISTRIBUTION_URL=https://github.com/docToolchain/docToolchain/releases/download/v${VERSION}/docToolchain-${VERSION}.zip
export DTC_PROJECT_BRANCH=$(git branch --show-current)
DTC_OPTS="$DTC_OPTS -PmainConfigFile=$MAIN_CONFIG_FILE --warning-mode=none --no-daemon"
echo "dtcw - docToolchain wrapper V0.22"
echo "docToolchain V${VERSION}"
# check if CLI, docker or sdkman are installed
cli=false
docker=false
sdkman=false
homefolder=false
java=false
wsl=false
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
java_help_and_die() {
echo "one 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 "make sure that your java version is between 8 and 14"
exit 1
}
install_local() {
#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
mkdir $HOME/.doctoolchain
wgetversion=$(wget --version | head -1 | sed -E 's/^.* 1.([0-9.]+) .*$/\1/')
echo $DISTRIBUTION_URL
if command -v curl &> /dev/null; then
curl -Lo $HOME/.doctoolchain/source.zip $DISTRIBUTION_URL
else
if (( $wgetversion > 13 )); then
wget $DISTRIBUTION_URL -O $HOME/.doctoolchain/source.zip
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
unzip $HOME/.doctoolchain/source.zip -d $HOME/.doctoolchain/.
command="$HOME/.doctoolchain/docToolchain-${VERSION}/bin/doctoolchain . $1 $2 $3 $4 $5 $6 $7 $8 $9 $DTC_OPTS"
}
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 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 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 [ "$docker" = false ] ; then
if [ "$java" = false ] ; then
echo "docToolchain depends on java, but the java command couldn't be found"
java_help_and_die
fi
javaversion=$(java -version 2>&1 | 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"
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"
java_help_and_die
fi
fi
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"
exit 1
fi
docker_cmd=$(which docker)
echo $docker_cmd
command="$docker_cmd run -u $(id -u):$(id -g) --name doctoolchain${version} -e DTC_HEADLESS=1 -e DTC_SITETHEME -p 8042:8042 --rm -it --entrypoint /bin/bash -v ${PWD}:/project rdmueller/doctoolchain:v${VERSION} -c \"doctoolchain . $1 $2 $3 $4 $5 $6 $7 $8 $9 $DTC_OPTS && exit\""
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
fi
fi
fi
fi
bash -cl "$command"