FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
secureCodeBox/bin/install.sh at v2.9 · secureCodeBox/secureCodeBox · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
secureCodeBox
/
secureCodeBox
Public
Notifications
You must be signed in to change notification settings
Fork
183
Star
985
Code
Issues
62
Pull requests
3
Discussions
Actions
Projects
Security and quality
1
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
secureCodeBox
/
bin
/
install.sh
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
302 lines (254 loc) · 8.63 KB
Breadcrumbs
secureCodeBox
/
bin
/
install.sh
Copy path
File metadata and controls
executable file
·
302 lines (254 loc) · 8.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!
/usr/bin/env bash
#
SPDX-FileCopyrightText: 2020 iteratec GmbH
#
#
SPDX-License-Identifier: Apache-2.0
#
Official installation script for the secureCodeBox
#
#
Creates namespace, securecodebox-system, and installs the operator.
#
Then installs all possible resources (scanners, demo-apps, hooks).
#
#
There exist different modes:
#
Call without parameters to install interactively
#
Call with --all to install all available resources automatically
#
Call with --scanners / --demo-apps / --hooks to only install the wanted resources
#
Call with --help for usage information
#
#
For more information see https://docs.securecodebox.io/
set
-euo pipefail
shopt
-s extglob
USAGE=
"
Usage:
$(
basename
"
$0
"
)
[--all] [--scanners] [--hooks] [--demo-apps] [--help|-h]
"
COLOR_HIGHLIGHT=
"
\e[35m
"
COLOR_OK=
"
\e[32m
"
COLOR_ERROR=
"
\e[31m
"
COLOR_RESET=
"
\e[0m
"
#
@see: http://wiki.bash-hackers.org/syntax/shellvars
[
-z
"
${SCRIPT_DIRECTORY
:-
}
"
] \
&&
SCRIPT_DIRECTORY=
"
$(
cd
"
$(
dirname
"
${BASH_SOURCE[0]}
"
)
"
>
/dev/null
&&
pwd
)
"
BASE_DIR=
$(
dirname
"
${SCRIPT_DIRECTORY}
"
)
INSTALL_INTERACTIVE=
'
'
INSTALL_SCANNERS=
'
'
INSTALL_DEMO_APPS=
'
'
INSTALL_HOOKS=
'
'
function
print()
{
if
[[
$#
==
0 ]]
;
then
echo
elif
[[
$#
==
1 ]]
;
then
local
message=
"
${1}
"
echo
"
${message}
"
elif
[[
$#
==
2 ]]
;
then
local
color=
"
${1}
"
local
message=
"
${2}
"
echo
-e
"
${color}${message}${COLOR_RESET}
"
fi
}
function
printHelp()
{
local
help
help=
$(
cat
<<
-
EOT
$USAGE
The installation is interactive if no arguments are provided.
Options
--all Install scanners, demo-apps and hooks
--scanners Install scanners
--demo-apps Install demo-apps
--hooks Install hooks
-h|--help Show help
Examples:
install.sh --all Installs the operator in namespace: securecodebox-system and
all resources in namespace: default
install.sh --hooks --scanners Installs only operator, scanners and hooks
EOT
)
print
"
$help
"
}
function
exitIfKubectlIsNotInstalled()
{
print
print
"
Checking kubectl...
"
local
kube
kube=
$(
kubectl cluster-info
)
||
true
if
[[
$kube
==
*
"
running
"
*
]]
;
then
print
"
$COLOR_OK
"
"
Kubectl is there!
"
else
print
"
$COLOR_ERROR
"
"
Kubectl not found or not working, quitting...
"
exit
1
fi
}
function
exitIfHelmIsNotInstalled()
{
print
print
"
Checking helm...
"
local
helm
helm=
$(
helm version
)
||
true
if
[[
$helm
==
*
"
Version
"
*
]]
;
then
print
"
$COLOR_OK
"
"
Helm is there!
"
else
print
"
$COLOR_ERROR
"
"
Helm not found or not working, quitting...
"
exit
1
fi
}
#
Create namespace securecodebox-system and install Operator there in one step,
#
because the namespace is not used otherwise
function
createNamespaceAndInstallOperator()
{
print
print
"
Creating namespace securecodebox-system
"
kubectl create namespace securecodebox-system
||
print
"
Namespace already exists...
"
print
"
Installing the operator in the securecodebox-system namespace
"
if
[[
$(
helm -n securecodebox-system upgrade --install securecodebox-operator
"
$BASE_DIR
"
/operator/
)
]]
;
then
print
"
$COLOR_OK
"
"
Successfully installed the operator!
"
else
print
"
$COLOR_ERROR
"
"
Operator installation failed, cancelling...
"
&&
exit
1
fi
}
#
installResources() installs all the available helm Charts found in the subdirectories for the given directory
#
@$1 - resource_directory: Directory where the subdirectories with Chart.yamls are located
#
@$2 - namespace: Namespace where the resources should be installed
#
@$3 - unattended: If the installation is interactive or unattended
function
installResources()
{
local
resource_directory=
"
$1
"
local
namespace=
"
$2
"
local
unattended=
"
$3
"
local
resources=()
for
path
in
"
$resource_directory
"
/
*
;
do
[
-d
"
${path}
"
]
||
continue
#
skip if not a directory
local
directory
directory=
"
$(
basename
"
${path}
"
)
"
#
Check if directory contains Chart.yaml File:
if
[[
-f
"
${resource_directory}
/
${directory}
/Chart.yaml
"
]]
;
then
resources+=(
"
${directory}
"
)
fi
done
if
[[
$unattended
==
True ]]
;
then
for
resource
in
"
${resources[@]}
"
;
do
local
resource_name=
"
${resource
//
+([_])
/
-}
"
#
Necessary because ssh_scan is called ssh-scan
helm upgrade --install -n
"
$namespace
"
"
$resource_name
"
"
$resource_directory
"
/
"
$resource
"
/ \
||
print
"
$COLOR_ERROR
"
"
Installation of '
$resource
' failed
"
done
else
for
resource
in
"
${resources[@]}
"
;
do
print
"
Do you want to install
$resource
? [y/N]
"
local
line
read
-r line
if
[[
$line
==
*
[Yy] ]]
;
then
local
resource_name=
"
${resource
//
+([_])
/
-}
"
helm upgrade --install -n
"
$namespace
"
"
$resource_name
"
"
$resource_directory
"
/
"
$resource
"
/ \
||
print
"
$COLOR_ERROR
"
"
Installation of '
$resource
' failed
"
fi
done
fi
print
print
"
$COLOR_OK
"
"
Completed to install '
$resource_directory
'!
"
}
function
welcomeToInteractiveInstall()
{
print
"
$COLOR_HIGHLIGHT
"
"
Welcome to the secureCodeBox!
"
print
"
This interactive installation script will guide you through all the relevant installation steps in order to have you ready to scan.
"
print
"
Start? [y/N]
"
read
-r LINE
if
[[
$LINE
==
*
[Yy] ]]
;
then
print
"
Starting!
"
else
exit
fi
}
function
interactiveInstall()
{
print
print
"
Starting to install scanners...
"
installResources
"
$BASE_DIR
/scanners
"
"
default
"
False
print
print
"
Starting to install demo-apps...
"
print
"
Do you want to install the demo apps in a separate namespace? Otherwise they will be installed into the [default] namespace [y/N]
"
read
-r line
NAMESPACE=
"
default
"
if
[[
$line
==
*
[Yy] ]]
;
then
print
"
Please provide a name for the namespace:
"
read
-r NAMESPACE
kubectl create namespace
"
$NAMESPACE
"
||
print
"
Namespace already exists or could not be created..
"
fi
installResources
"
$BASE_DIR
/demo-apps
"
"
$NAMESPACE
"
False
print
print
"
Starting to install hooks...
"
installResources
"
$BASE_DIR
/hooks
"
"
default
"
False
print
print
"
$COLOR_OK
"
"
Information about your cluster:
"
kubectl get namespaces
print
kubectl get scantypes
print
kubectl get pods
print
print
"
$COLOR_OK
"
"
Finished installation successfully!
"
}
function
unattendedInstall()
{
if
[[
-n
"
${INSTALL_SCANNERS}
"
]]
;
then
print
"
Starting to install scanners...
"
installResources
"
$BASE_DIR
/scanners
"
"
default
"
True
fi
if
[[
-n
"
${INSTALL_DEMO_APPS}
"
]]
;
then
print
"
Starting to install demo-apps...
"
installResources
"
$BASE_DIR
/demo-apps
"
"
default
"
True
fi
if
[[
-n
"
${INSTALL_HOOKS}
"
]]
;
then
print
"
Starting to install hooks...
"
installResources
"
$BASE_DIR
/hooks
"
"
default
"
True
fi
print
"
$COLOR_OK
"
"
Finished installation successfully!
"
}
function
parseArguments()
{
if
[[
$#
==
0 ]]
;
then
INSTALL_INTERACTIVE=true
return
fi
while
((
"
$#
"
))
;
do
case
"
$1
"
in
--scanners)
INSTALL_SCANNERS=
'
true
'
shift
#
Pop current argument from array
;;
--demo-apps)
INSTALL_DEMO_APPS=
'
true
'
shift
;;
--hooks)
INSTALL_HOOKS=
'
true
'
shift
;;
--all)
INSTALL_SCANNERS=
'
true
'
INSTALL_DEMO_APPS=
'
true
'
INSTALL_HOOKS=
'
true
'
shift
;;
-h|--help)
printHelp
exit
;;
--
*
)
#
unsupported flags
print
"
Error: Unsupported flag
$1
"
>&2
print
"
$USAGE
"
exit
1
;;
*
)
#
preserve positional arguments
shift
;;
esac
done
}
#
Main Script:
parseArguments
"
$@
"
print
"
$COLOR_HIGHLIGHT
"
"
"
print
"
$COLOR_HIGHLIGHT
"
"
_____ _ ____
"
print
"
$COLOR_HIGHLIGHT
"
"
/ ____| | | | _ \
"
print
"
$COLOR_HIGHLIGHT
"
"
___ ___ ___ _ _ _ __ ___| | ___ __| | ___| |_) | _____ __
"
print
"
$COLOR_HIGHLIGHT
"
"
/ __|/ _ \/ __| | | | '__/ _ \ | / _ \ / _ |/ _ \ _ < / _ \ \/ /
"
print
"
$COLOR_HIGHLIGHT
"
"
\__ \ __/ (__| |_| | | | __/ |___| (_) | (_| | __/ |_) | (_) > <
"
print
"
$COLOR_HIGHLIGHT
"
"
|___/\___|\___|\__,_|_| \___|\_____\___/ \__,_|\___|____/ \___/_/\_\
"
print
"
$COLOR_HIGHLIGHT
"
"
"
parseArguments
"
$@
"
if
[[
-n
"
${INSTALL_INTERACTIVE}
"
]]
;
then
welcomeToInteractiveInstall
fi
exitIfKubectlIsNotInstalled
exitIfHelmIsNotInstalled
createNamespaceAndInstallOperator
if
[[
-n
"
${INSTALL_INTERACTIVE}
"
]]
;
then
interactiveInstall
else
unattendedInstall
fi
Back
|
FazBrowse Home
|
New Git URL