forked from apache/nifi-minifi-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbstrp_functions.sh
executable file
·308 lines (275 loc) · 9.05 KB
/
bstrp_functions.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
script_directory="$(cd "$(dirname "$0")" && pwd)"
add_option(){
eval "$1=$2"
OPTIONS+=("$1")
CMAKE_OPTIONS_ENABLED+=("$1:$3")
CMAKE_OPTIONS_DISABLED+=("$1:$4")
}
add_enabled_option(){
eval "$1=$2"
OPTIONS+=("$1")
CMAKE_OPTIONS_DISABLED+=("$1:$3")
}
add_cmake_option(){
eval "$1=$2"
}
add_disabled_option(){
eval "$1=$2"
OPTIONS+=("$1")
CMAKE_OPTIONS_ENABLED+=("$1:$3")
if [ ! -z "$4" ]; then
CMAKE_MIN_VERSION+=("$1:$4")
fi
if [ ! -z "$5" ]; then
if [ "$5" = "true" ]; then
DEPLOY_LIMITS+=("$1")
fi
fi
}
add_dependency(){
DEPENDENCIES+=("$1:$2")
}
### parse the command line arguments
EnableAllFeatures(){
for option in "${OPTIONS[@]}" ; do
feature_status=${!option}
if [ "$feature_status" = "${FALSE}" ]; then
ToggleFeature $option
fi
# eval "$option=${TRUE}"
done
}
pause(){
read -p "Press [Enter] key to continue..." fackEnterKey
}
load_state(){
if [ -f ${script_directory}/bt_state ]; then
. ${script_directory}/bt_state
for option in "${OPTIONS[@]}" ; do
option_value="${!option}"
if [ "${option_value}" = "${FALSE}" ]; then
ALL_FEATURES_ENABLED=${FALSE}
fi
done
fi
}
echo_state_variable(){
VARIABLE_VALUE=${!1}
echo "$1=\"${VARIABLE_VALUE}\"" >> ${script_directory}/bt_state
}
save_state(){
echo "VERSION=1" > ${script_directory}/bt_state
echo_state_variable BUILD_IDENTIFIER
echo_state_variable BUILD_DIR
echo_state_variable TESTS_DISABLED
for option in "${OPTIONS[@]}" ; do
echo_state_variable $option
done
}
can_deploy(){
for option in "${DEPLOY_LIMITS[@]}" ; do
OPT=${option%%:*}
if [ "${OPT}" = "$1" ]; then
echo "false"
fi
done
echo "true"
}
ToggleFeature(){
VARIABLE_VALUE=${!1}
ALL_FEATURES_ENABLED="Disabled"
if [ $VARIABLE_VALUE = "Enabled" ]; then
eval "$1=${FALSE}"
else
for option in "${CMAKE_MIN_VERSION[@]}" ; do
OPT=${option%%:*}
if [ "$OPT" = "$1" ]; then
NEEDED_VER=${option#*:}
NEEDED_MAJOR=`echo $NEEDED_VER | cut -d. -f1`
NEEDED_MINOR=`echo $NEEDED_VER | cut -d. -f2`
NEEDED_REVISION=`echo $NEEDED_VERSION | cut -d. -f3`
if (( NEEDED_MAJOR > CMAKE_MAJOR )); then
return 1
fi
if (( NEEDED_MINOR > CMAKE_MINOR )); then
return 1
fi
if (( NEEDED_REVISION > CMAKE_REVISION )); then
return 1
fi
fi
done
CAN_ENABLE=$(verify_enable $1)
CAN_DEPLOY=$(can_deploy $1)
if [ "$CAN_ENABLE" = "true" ]; then
if [[ "$DEPLOY" = "true" && "$CAN_DEPLOY" = "true" ]] || [[ "$DEPLOY" = "false" ]]; then
eval "$1=${TRUE}"
fi
fi
fi
}
print_feature_status(){
feature="$1"
feature_status=${!1}
if [ "$feature_status" = "Enabled" ]; then
echo "Enabled"
else
for option in "${CMAKE_MIN_VERSION[@]}" ; do
OPT=${option%%:*}
if [ "${OPT}" = "$1" ]; then
NEEDED_VER=${option#*:}
NEEDED_MAJOR=`echo $NEEDED_VER | cut -d. -f1`
NEEDED_MINOR=`echo $NEEDED_VER | cut -d. -f2`
NEEDED_REVISION=`echo $NEEDED_VERSION | cut -d. -f3`
if (( NEEDED_MAJOR > CMAKE_MAJOR )); then
echo -e "${RED}Disabled*${NO_COLOR}"
return 1
fi
if (( NEEDED_MINOR > CMAKE_MINOR )); then
echo -e "${RED}Disabled*${NO_COLOR}"
return 1
fi
if (( NEEDED_REVISION > CMAKE_REVISION )); then
echo -e "${RED}Disabled*${NO_COLOR}"
return 1
fi
fi
done
CAN_ENABLE=$(verify_enable $1)
if [ "$CAN_ENABLE" = "true" ]; then
echo -e "${RED}Disabled${NO_COLOR}"
else
echo -e "${RED}Disabled*${NO_COLOR}"
fi
fi
}
show_main_menu() {
clear
echo "****************************************"
echo " MiNiFi C++ Main Menu."
echo "****************************************"
echo "A. Select MiNiFi C++ Features "
if [ "$ALL_FEATURES_ENABLED" = "${TRUE}" ]; then
echo " All features enabled ........$(print_feature_status ALL_FEATURES_ENABLED)"
fi
echo "B. Select Advanced Features "
echo "C. Continue with selected options "
echo -e "Q. Exit\r\n"
}
read_main_menu_options(){
local choice
read -p "Enter choice [ A-C ] " choice
choice=$(echo ${choice} | tr '[:upper:]' '[:lower:]')
case $choice in
a) MENU="features" ;;
b) MENU="advanced" ;;
c) FEATURES_SELECTED="true" ;;
q) exit 0;;
*) echo -e "${RED}Please enter a valid option...${NO_COLOR}" && sleep 1
esac
}
show_advanced_features_menu() {
clear
echo "****************************************"
echo " MiNiFi C++ Advanced Features."
echo "****************************************"
echo "A. Portable Build ..............$(print_feature_status PORTABLE_BUILD)"
echo "B. Build with Debug symbols ....$(print_feature_status DEBUG_SYMBOLS)"
echo "C. Build RocksDB from source ...$(print_feature_status BUILD_ROCKSDB)"
echo -e "R. Return to Main Menu\r\n"
}
read_advanced_menu_options(){
local choice
read -p "Enter choice [ A-C ] " choice
choice=$(echo ${choice} | tr '[:upper:]' '[:lower:]')
case $choice in
a) ToggleFeature PORTABLE_BUILD ;;
b) ToggleFeature DEBUG_SYMBOLS ;;
c) ToggleFeature BUILD_ROCKSDB ;;
r) MENU="main" ;;
*) echo -e "${RED}Please enter a valid option...${NO_COLOR}" && sleep 1
esac
}
show_supported_features() {
clear
echo "****************************************"
echo " Select MiNiFi C++ Features to toggle."
echo "****************************************"
echo "A. Persistent Repositories .....$(print_feature_status ROCKSDB_ENABLED)"
echo "B. Lib Curl Features ...........$(print_feature_status HTTP_CURL_ENABLED)"
echo "C. Lib Archive Features ........$(print_feature_status LIBARCHIVE_ENABLED)"
echo "D. Execute Script support ......$(print_feature_status EXECUTE_SCRIPT_ENABLED)"
echo "E. Expression Language support .$(print_feature_status EXPRESSION_LANGAUGE_ENABLED)"
echo "F. Kafka support ...............$(print_feature_status KAFKA_ENABLED)"
echo "G. PCAP support ................$(print_feature_status PCAP_ENABLED)"
echo "H. USB Camera support ..........$(print_feature_status USB_ENABLED)"
echo "I. GPS support .................$(print_feature_status GPS_ENABLED)"
echo "J. TensorFlow Support ..........$(print_feature_status TENSORFLOW_ENABLED)"
echo "K. Bustache Support ............$(print_feature_status BUSTACHE_ENABLED)"
echo "L. MQTT Support ................$(print_feature_status MQTT_ENABLED)"
echo "M. SQLite Support ..............$(print_feature_status SQLITE_ENABLED)"
echo "N. Python Support ..............$(print_feature_status PYTHON_ENABLED)"
echo "O. COAP Support ................$(print_feature_status COAP_ENABLED)"
echo "****************************************"
echo " Build Options."
echo "****************************************"
echo "1. Disable Tests ...............$(print_feature_status TESTS_DISABLED)"
echo "2. Enable all extensions"
echo "3. Enable JNI Support ..........$(print_feature_status JNI_ENABLED)"
echo "P. Continue with these options"
if [ "$GUIDED_INSTALL" = "${TRUE}" ]; then
echo "R. Return to Main Menu"
fi
echo "Q. Quit"
echo "* Extension cannot be installed due to"
echo -e " version of cmake or other software\r\n"
}
read_feature_options(){
local choice
read -p "Enter choice [ A - P or 1-3 ] " choice
choice=$(echo ${choice} | tr '[:upper:]' '[:lower:]')
case $choice in
a) ToggleFeature ROCKSDB_ENABLED ;;
b) ToggleFeature HTTP_CURL_ENABLED ;;
c) ToggleFeature LIBARCHIVE_ENABLED ;;
d) ToggleFeature EXECUTE_SCRIPT_ENABLED ;;
e) ToggleFeature EXPRESSION_LANGAUGE_ENABLED ;;
f) ToggleFeature KAFKA_ENABLED ;;
g) ToggleFeature PCAP_ENABLED ;;
h) ToggleFeature USB_ENABLED ;;
i) ToggleFeature GPS_ENABLED ;;
j) ToggleFeature TENSORFLOW_ENABLED ;;
k) ToggleFeature BUSTACHE_ENABLED ;;
l) ToggleFeature MQTT_ENABLED ;;
m) ToggleFeature SQLLITE_ENABLED ;;
n) ToggleFeature PYTHON_ENABLED ;;
o) ToggleFeature COAP_ENABLED ;;
1) ToggleFeature TESTS_DISABLED ;;
2) EnableAllFeatures ;;
3) ToggleFeature JNI_ENABLED;;
p) FEATURES_SELECTED="true" ;;
r) if [ "$GUIDED_INSTALL" = "${TRUE}" ]; then
MENU="main"
fi
;;
q) exit 0;;
*) echo -e "${RED}Please enter an option A-P or 1-3...${NO_COLOR}" && sleep 2
esac
}