-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmakeMicrosite.sh
More file actions
executable file
·190 lines (169 loc) · 4.86 KB
/
makeMicrosite.sh
File metadata and controls
executable file
·190 lines (169 loc) · 4.86 KB
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
#!/bin/bash
set -ue
enable_cassandra_2=-1
enable_cassandra_3=-1
enable_jekyll=1
clean_workspace=0
publish=0
function help {
echo "how to use:"
echo "must be run from project home (same level as build.sbt file)."
echo "first time running will download cassandra binaries. This will require an internet connection"
echo "must use one of:"
echo " -0 -- only combine existing docs"
echo " -2 -- compile cassandra 2 docs"
echo " -3 -- compile cassandra 3 docs"
echo " -23 -- compile cassandra 2 and 3 docs"
echo " -h -- print out this message"
echo "may optionally include any of:"
echo " -x -- disable start up of jekyll at the end of the script"
echo " -c -- clean the workspace first"
echo " -p -- publish the microsite instead of starting jekyll"
exit 1
}
function in_right_location {
if [[ ! -f build.sbt || ! -n $(cat build.sbt | grep 'com.github.thurstonsand') ]]; then
echo "not in root project folder!"
echo
help
fi
}
function parse_inputs {
while getopts ":023xcph" opt; do
case $opt in
0)
enable_cassandra_2=0
enable_cassandra_3=0
;;
2)
enable_cassandra_2=1
;;
3)
enable_cassandra_3=1
;;
x)
enable_jekyll=0
;;
c)
clean_workspace=1
;;
p)
publish=1
enable_jekyll=0
;;
h)
help
;;
\?)
echo "Invalid option: -$OPTARG" >&2
help
;;
:)
echo "Option -$OPTARG requires an argument." >&2
help
;;
esac
done
if [[ $enable_cassandra_2 -ne -1 && $enable_cassandra_3 -eq -1 ]]; then
enable_cassandra_3=0
elif [[ $enable_cassandra_2 -eq -1 && $enable_cassandra_3 -ne -1 ]]; then
enable_cassandra_2=0
elif [[ $enable_cassandra_2 -eq -1 && $enable_cassandra_3 -eq -1 ]]; then
help
fi
}
function setup_cassandra {
version=$1
cassandra_path="cassandra-docs/cassandra-$version"
if [[ ! -d $cassandra_path ]]; then
wget -P cassandra-docs "http://archive.apache.org/dist/cassandra/$version/apache-cassandra-$version-bin.tar.gz"
tar -xzf "cassandra-docs/apache-cassandra-$version-bin.tar.gz" -C cassandra-docs
mv "cassandra-docs/apache-cassandra-$version" $cassandra_path
mkdir -p $cassandra_path/data
mkdir -p $cassandra_path/commitlog
echo "data_file_directories:" >> "$cassandra_path/conf/cassandra.yaml"
echo " - $PWD/$cassandra_path/data" >> "$cassandra_path/conf/cassandra.yaml"
echo "commitlog_directory: $PWD/$cassandra_path/commitlog" >> "$cassandra_path/conf/cassandra.yaml"
fi
}
function clear_cassandra {
rm -rf $cassandra_path/data/*
rm -rf $cassandra_path/commitlog/*
}
function wait_for_cassandra {
for i in $(seq 1 60); do
if $1/nodetool status 2>/dev/null | grep "^UN" >/dev/null; then
$1/nodetool setlogginglevel ERROR 2>/dev/null
echo "cassandra is running"
return 0
else
echo "waiting on cassandra..."
sleep 2
fi
done
echo "cassandra did not start successfully"
return -1
}
function run_cassandra {
local folder_ext=$1
local cassandra_version=""
if [[ "$folder_ext" -eq "21" ]]; then
cassandra_version="2.1.10.3"
else
cassandra_version="3.5.0"
fi
if ./$cassandra_path/bin/nodetool status 2>/dev/null | grep "^UN" >/dev/null; then
echo "cassandra is already running. you must stop that instance first"
exit 1
fi
echo "starting cassandra $version"
trap 'if [[ -n "$cass_pid" ]]; then kill $cass_pid; fi' INT TERM EXIT
./$cassandra_path/bin/cassandra -f >/dev/null &
cass_pid=$!
wait_for_cassandra "./$cassandra_path/bin"
if [[ clean_workspace -gt 0 ]]; then
echo "cleaning and compiling cassandra $folder_ext docs"
sbt -Dcassandra-driver.version=$cassandra_version "tut-cass$folder_ext/clean" "tut-cass$folder_ext/tut"
else
echo "compiling cassandra $folder_ext docs"
sbt -Dcassandra-driver.version=$cassandra_version "tut-cass$folder_ext/tut"
fi
kill $cass_pid
unset cass_pid
trap - INT TERM EXIT
rm -rf docs/root/src/main/tut/cass$folder_ext
cp -r "docs/cass$folder_ext/target/scala-2.12/resource_managed/main/jekyll/cass$folder_ext" docs/root/src/main/tut/
}
function compile_results {
echo "compiling docs"
sbt -Dmicrosite.baseurl="" "docs/clean" "docs/makeMicrosite"
}
function run_jekyll {
trap "rm -rf _site" INT TERM EXIT
jekyll serve -s docs/root/target/jekyll/
}
function publish_site {
echo "publishing docs"
sbt "docs/clean" "docs/publishMicrosite"
}
mkdir -p cassandra-docs
in_right_location
parse_inputs $@
if [[ enable_cassandra_2 -gt 0 ]]; then
setup_cassandra "2.1.20"
clear_cassandra
run_cassandra 21
fi
if [[ enable_cassandra_3 -gt 0 ]]; then
setup_cassandra "3.5"
clear_cassandra
run_cassandra 3
fi
if [[ publish -gt 0 ]]; then
publish_site
else
compile_results
if [[ enable_jekyll -gt 0 ]]; then
run_jekyll
fi
fi