55# Creates namespace, securecodebox-system, and installs the operator.
66# Then installs all possible resources (scanners, demo-apps, hooks).
77#
8- # There exist two modes:
8+ # There exist different modes:
99# Call without parameters to install interactively
1010# Call with --all to install all available resources automatically
1111# Call with --scanners / --demo-apps / --hooks to only install the wanted resources
1212# Call with --help for usage information
1313#
1414# For more information see https://docs.securecodebox.io/
1515
16- set -eu
16+ set -euo pipefail
1717shopt -s extglob
1818
19+ USAGE=" Usage: $( basename " $0 " ) [--all] [--scanners] [--hooks] [--demo-apps] [--help|-h]"
20+
1921COLOR_HIGHLIGHT=" \e[35m"
2022COLOR_OK=" \e[32m"
2123COLOR_ERROR=" \e[31m"
@@ -27,6 +29,11 @@ COLOR_RESET="\e[0m"
2729
2830BASE_DIR=$( dirname " ${SCRIPT_DIRECTORY} " )
2931
32+ INSTALL_INTERACTIVE=' '
33+ INSTALL_SCANNERS=' '
34+ INSTALL_DEMO_APPS=' '
35+ INSTALL_HOOKS=' '
36+
3037function print() {
3138 if [[ $# == 0 ]]; then
3239 echo
@@ -40,36 +47,32 @@ function print() {
4047 fi
4148}
4249
43- function usage() {
44- local usage
45- usage=" Usage: $( basename " $0 " ) [--all] [--scanners] [--hooks] [--demo-apps] [--help]"
50+ function printHelp() {
4651 local help
4752 help=$( cat << - EOT
48- The installation is interactive if no arguments are provided.
49-
50- Options:
51- --all Install scanners, demo-apps and hooks
52- --scanners Install scanners
53- --demo-apps Install demo-apps
54- --hooks Install hooks
55- -h|--help Show help
56-
57- Examples:
58- install.sh --all
59- Installs the operator in namespace: securecodebox-system and
60- all resources in namespace: default
61-
62- install.sh --hooks --scanners
63- Installs only operator, scanners and hooks
53+ $USAGE
54+ The installation is interactive if no arguments are provided.
55+
56+ Options
57+
58+ --all Install scanners, demo-apps and hooks
59+ --scanners Install scanners
60+ --demo-apps Install demo-apps
61+ --hooks Install hooks
62+ -h|--help Show help
63+
64+ Examples:
65+
66+ install.sh --all Installs the operator in namespace: securecodebox-system and
67+ all resources in namespace: default
68+
69+ install.sh --hooks --scanners Installs only operator, scanners and hooks
6470EOT
6571 )
66- print " SecureCodeBox Install Script"
67- print " $usage "
68- print
6972 print " $help "
7073}
7174
72- function checkKubectl () {
75+ function exitIfKubectlIsNotInstalled () {
7376 print
7477 print " Checking kubectl..."
7578 local kube
@@ -83,7 +86,7 @@ function checkKubectl() {
8386 fi
8487}
8588
86- function checkHelm () {
89+ function exitIfHelmIsNotInstalled () {
8790 print
8891 print " Checking helm..."
8992 local helm
@@ -97,6 +100,8 @@ function checkHelm() {
97100 fi
98101}
99102
103+ # Create namespace securecodebox-system and install Operator there in one step,
104+ # because the namespace is not used otherwise
100105function createNamespaceAndInstallOperator() {
101106 print
102107 print " Creating namespace securecodebox-system"
@@ -111,6 +116,10 @@ function createNamespaceAndInstallOperator() {
111116 fi
112117}
113118
119+ # installResources() installs all the available helm Charts found in the subdirectories for the given directory
120+ # @$1 - resource_directory: Directory where the subdirectories with Chart.yamls are located
121+ # @$2 - namespace: Namespace where the resources should be installed
122+ # @$3 - unattended: If the installation is interactive or unattended
114123function installResources() {
115124 local resource_directory=" $1 "
116125 local namespace=" $2 "
@@ -121,7 +130,10 @@ function installResources() {
121130 [ -d " ${path} " ] || continue # skip if not a directory
122131 local directory
123132 directory=" $( basename " ${path} " ) "
124- resources+=(" ${directory} " )
133+ # Check if directory contains Chart.yaml File:
134+ if [[ -f " ${resource_directory} /${directory} /Chart.yaml" ]]; then
135+ resources+=(" ${directory} " )
136+ fi
125137 done
126138
127139 if [[ $unattended == True ]]; then
@@ -149,7 +161,7 @@ function installResources() {
149161 print " $COLOR_OK " " Completed to install '$resource_directory '!"
150162}
151163
152- function interactiveInstall () {
164+ function welcomeToInteractiveInstall () {
153165 print " $COLOR_HIGHLIGHT " " Welcome to the secureCodeBox!"
154166 print " This interactive installation script will guide you through all the relevant installation steps in order to have you ready to scan."
155167 print " Start? [y/N]"
@@ -161,11 +173,9 @@ function interactiveInstall() {
161173 else
162174 exit
163175 fi
176+ }
164177
165- checkKubectl
166- checkHelm
167- createNamespaceAndInstallOperator
168-
178+ function interactiveInstall() {
169179 print
170180 print " Starting to install scanners..."
171181 installResources " $BASE_DIR /scanners" " default" False
@@ -200,25 +210,17 @@ function interactiveInstall() {
200210}
201211
202212function unattendedInstall() {
203- checkKubectl
204- checkHelm
205- createNamespaceAndInstallOperator
206-
207- local install_scanners=$1
208- local install_demo_apps=$2
209- local install_hooks=$3
210-
211- if [[ $install_scanners == true ]]; then
213+ if [[ -n " ${INSTALL_SCANNERS} " ]]; then
212214 print " Starting to install scanners..."
213215 installResources " $BASE_DIR /scanners" " default" True
214216 fi
215217
216- if [[ $install_demo_apps == true ]]; then
218+ if [[ -n " ${INSTALL_DEMO_APPS} " ]]; then
217219 print " Starting to install demo-apps..."
218220 installResources " $BASE_DIR /demo-apps" " default" True
219221 fi
220222
221- if [[ $install_hooks == true ]]; then
223+ if [[ -n " ${INSTALL_HOOKS} " ]]; then
222224 print " Starting to install hooks..."
223225 installResources " $BASE_DIR /hooks" " default" True
224226 fi
@@ -227,48 +229,50 @@ function unattendedInstall() {
227229}
228230
229231function parseArguments() {
230- local install_scanners=false
231- local install_demo_apps=false
232- local install_hooks=false
232+ if [[ $# == 0 ]]; then
233+ INSTALL_INTERACTIVE=true
234+ return
235+ fi
233236
234237 while (( "$# " )) ; do
235238 case " $1 " in
236239 --scanners)
237- install_scanners= true
240+ INSTALL_SCANNERS= ' true'
238241 shift # Pop current argument from array
239242 ;;
240243 --demo-apps)
241- install_demo_apps= true
244+ INSTALL_DEMO_APPS= ' true'
242245 shift
243246 ;;
244247 --hooks)
245- install_hooks= true
248+ INSTALL_HOOKS= ' true'
246249 shift
247250 ;;
248251 --all)
249- install_scanners= true
250- install_demo_apps= true
251- install_hooks= true
252+ INSTALL_SCANNERS= ' true'
253+ INSTALL_DEMO_APPS= ' true'
254+ INSTALL_HOOKS= ' true'
252255 shift
253256 ;;
254257 -h|--help)
255- usage
258+ printHelp
256259 exit
257260 ;;
258261 --* ) # unsupported flags
259- echo " Error: Unsupported flag $1 " >&2
260- usage
262+ print " Error: Unsupported flag $1 " >&2
263+ print " $USAGE "
261264 exit 1
262265 ;;
263266 * ) # preserve positional arguments
264267 shift
265268 ;;
266269 esac
267270 done
268-
269- unattendedInstall $install_scanners $install_demo_apps $install_hooks
270271}
271272
273+ # Main Script:
274+ parseArguments " $@ "
275+
272276print " $COLOR_HIGHLIGHT " " "
273277print " $COLOR_HIGHLIGHT " " _____ _ ____ "
274278print " $COLOR_HIGHLIGHT " " / ____| | | | _ \ "
@@ -278,8 +282,17 @@ print "$COLOR_HIGHLIGHT" " \__ \ __/ (__| |_| | | | __/ |___| (_) | (_| | __/
278282print " $COLOR_HIGHLIGHT " " |___/\___|\___|\__,_|_| \___|\_____\___/ \__,_|\___|____/ \___/_/\_\ "
279283print " $COLOR_HIGHLIGHT " " "
280284
281- if [[ $# == 0 ]]; then
285+ parseArguments " $@ "
286+ if [[ -n " ${INSTALL_INTERACTIVE} " ]]; then
287+ welcomeToInteractiveInstall
288+ fi
289+
290+ exitIfKubectlIsNotInstalled
291+ exitIfHelmIsNotInstalled
292+ createNamespaceAndInstallOperator
293+
294+ if [[ -n " ${INSTALL_INTERACTIVE} " ]]; then
282295 interactiveInstall
283296 else
284- parseArguments " $@ "
297+ unattendedInstall
285298fi
0 commit comments