FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Refactoring main function · secureCodeBox/secureCodeBox@0c113af · GitHub

Commit 0c113af

Browse files
authored andcommitted
Refactoring main function
The main part of the script is now easier to read and avoids duplicated code in the interactive/unattended Install functions. This required to use global variables for which resources should be installed. Signed-off-by: Sebastian Franz <sebastian.franz@iteratec.com>
1 parent 6adff91 commit 0c113af

1 file changed

Lines changed: 33 additions & 30 deletions

File tree

‎bin/install.sh‎

100644100755
Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ COLOR_RESET="\e[0m"
2727

2828
BASE_DIR=$(dirname "${SCRIPT_DIRECTORY}")
2929

30+
INSTALL_INTERACTIVE=''
31+
INSTALL_SCANNERS=''
32+
INSTALL_DEMO_APPS=''
33+
INSTALL_HOOKS=''
34+
3035
function print() {
3136
if [[ $# == 0 ]]; then
3237
echo
@@ -154,7 +159,7 @@ function installResources() {
154159
print "$COLOR_OK" "Completed to install '$resource_directory'!"
155160
}
156161

157-
function interactiveInstall() {
162+
function welcomeToInteractiveInstall() {
158163
print "$COLOR_HIGHLIGHT" "Welcome to the secureCodeBox!"
159164
print "This interactive installation script will guide you through all the relevant installation steps in order to have you ready to scan."
160165
print "Start? [y/N]"
@@ -166,11 +171,9 @@ function interactiveInstall() {
166171
else
167172
exit
168173
fi
174+
}
169175

170-
exitIfKubectlIsNotInstalled
171-
exitIfHelmIsNotInstalled
172-
createNamespaceAndInstallOperator
173-
176+
function interactiveInstall() {
174177
print
175178
print "Starting to install scanners..."
176179
installResources "$BASE_DIR/scanners" "default" False
@@ -205,25 +208,17 @@ function interactiveInstall() {
205208
}
206209

207210
function unattendedInstall() {
208-
exitIfKubectlIsNotInstalled
209-
exitIfHelmIsNotInstalled
210-
createNamespaceAndInstallOperator
211-
212-
local install_scanners=$1
213-
local install_demo_apps=$2
214-
local install_hooks=$3
215-
216-
if [[ $install_scanners == true ]]; then
211+
if [[ -n "${INSTALL_SCANNERS}" ]]; then
217212
print "Starting to install scanners..."
218213
installResources "$BASE_DIR/scanners" "default" True
219214
fi
220215

221-
if [[ $install_demo_apps == true ]]; then
216+
if [[ -n "${INSTALL_DEMO_APPS}" ]]; then
222217
print "Starting to install demo-apps..."
223218
installResources "$BASE_DIR/demo-apps" "default" True
224219
fi
225220

226-
if [[ $install_hooks == true ]]; then
221+
if [[ -n "${INSTALL_HOOKS}" ]]; then
227222
print "Starting to install hooks..."
228223
installResources "$BASE_DIR/hooks" "default" True
229224
fi
@@ -232,36 +227,37 @@ function unattendedInstall() {
232227
}
233228

234229
function parseArguments() {
235-
local install_scanners=false
236-
local install_demo_apps=false
237-
local install_hooks=false
230+
if [[ $# == 0 ]]; then
231+
INSTALL_INTERACTIVE=true
232+
return
233+
fi
238234

239235
while (( "$#" )); do
240236
case "$1" in
241237
--scanners)
242-
install_scanners=true
238+
INSTALL_SCANNERS='true'
243239
shift # Pop current argument from array
244240
;;
245241
--demo-apps)
246-
install_demo_apps=true
242+
INSTALL_DEMO_APPS='true'
247243
shift
248244
;;
249245
--hooks)
250-
install_hooks=true
246+
INSTALL_HOOKS='true'
251247
shift
252248
;;
253249
--all)
254-
install_scanners=true
255-
install_demo_apps=true
256-
install_hooks=true
250+
INSTALL_SCANNERS='true'
251+
INSTALL_DEMO_APPS='true'
252+
INSTALL_HOOKS='true'
257253
shift
258254
;;
259255
-h|--help)
260256
usage
261257
exit
262258
;;
263259
--*) # unsupported flags
264-
echo "Error: Unsupported flag $1" >&2
260+
print "Error: Unsupported flag $1" >&2
265261
usage
266262
exit 1
267263
;;
@@ -270,8 +266,6 @@ function parseArguments() {
270266
;;
271267
esac
272268
done
273-
274-
unattendedInstall $install_scanners $install_demo_apps $install_hooks
275269
}
276270

277271
print "$COLOR_HIGHLIGHT" " "
@@ -284,8 +278,17 @@ print "$COLOR_HIGHLIGHT" " |___/\___|\___|\__,_|_| \___|\_____\___/ \__,_|\___|
284278
print "$COLOR_HIGHLIGHT" " "
285279

286280

287-
if [[ $# == 0 ]]; then
281+
parseArguments "$@"
282+
if [[ -n "${INSTALL_INTERACTIVE}" ]]; then
283+
welcomeToInteractiveInstall
284+
fi
285+
286+
exitIfKubectlIsNotInstalled
287+
exitIfHelmIsNotInstalled
288+
createNamespaceAndInstallOperator
289+
290+
if [[ -n "${INSTALL_INTERACTIVE}" ]]; then
288291
interactiveInstall
289292
else
290-
parseArguments "$@"
293+
unattendedInstall
291294
fi

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL