diff --git a/bin/install.sh b/bin/install.sh index 06060f5e12..adb969e6f9 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -37,6 +37,11 @@ INSTALL_INTERACTIVE='' INSTALL_SCANNERS='' INSTALL_DEMO_TARGETS='' INSTALL_HOOKS='' +INSTALL_NAMESPACED='' + +SCB_SYSTEM_NAMESPACE='securecodebox-system' +SCB_DEMO_NAMESPACE='demo-targets' +SCB_NAMESPACE='default' function print() { if [[ $# == 0 ]]; then @@ -59,11 +64,11 @@ The installation is interactive if no arguments are provided. Options - --all Install scanners, demo-targets and hooks - --scanners Install scanners - --demo-targets Install demo-targets - --hooks Install hooks - -h|--help Show help + --all Install scanners, demo-targets and hooks + --scanners Install scanners (namespace: default) + --demo-targets Install demo-targets (namespace: default) + --hooks Install hooks (namespace: default) + -h|--help Show help Examples: @@ -104,19 +109,19 @@ function exitIfHelmIsNotInstalled() { fi } -# Create namespace securecodebox-system and install Operator there in one step, +# 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 "Creating namespace $SCB_SYSTEM_NAMESPACE..." + kubectl create namespace $SCB_SYSTEM_NAMESPACE || print "Namespace '$SCB_SYSTEM_NAMESPACE' already exists!" - print "Installing the operator in the securecodebox-system namespace" + print "Installing the operator in the '$SCB_SYSTEM_NAMESPACE' namespace" - if [[ $(helm -n securecodebox-system upgrade --install securecodebox-operator "$BASE_DIR"/operator/) ]]; then - print "$COLOR_OK" "Successfully installed the operator!" + if [[ $(helm -n "$SCB_SYSTEM_NAMESPACE" upgrade --install securecodebox-operator "$BASE_DIR/operator/") ]]; then + print "$COLOR_OK" "Successfully installed the operator in namespace '$SCB_SYSTEM_NAMESPACE'!" else - print "$COLOR_ERROR" "Operator installation failed, cancelling..." && exit 1 + print "$COLOR_ERROR" "Operator installation failed in namespace '$SCB_SYSTEM_NAMESPACE', cancelling installation!" && exit 1 fi } @@ -178,26 +183,37 @@ function welcomeToInteractiveInstall() { } function interactiveInstall() { - print - print "Starting to install scanners..." - installResources "$BASE_DIR/scanners" "default" False - print print "Starting to install demo-targets..." - print "Do you want to install the demo targets in a separate namespace? Otherwise they will be installed into the [default] namespace [y/N]" + 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.. " + kubectl create namespace "$NAMESPACE" || print "Namespace '$NAMESPACE' already exists or could not be created!" fi installResources "$BASE_DIR/demo-targets" "$NAMESPACE" False + print + print "Starting to install 'scanners' and 'hooks'..." + print "Do you want to install the secureCodeBox 'scanners' and 'hooks' 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 '$NAMESPACE' already exists or could not be created!" + fi + print print "Starting to install hooks..." - installResources "$BASE_DIR/hooks" "default" False + installResources "$BASE_DIR/hooks" "$NAMESPACE" "" + + print + print "Starting to install scanners..." + installResources "$BASE_DIR/scanners" "$NAMESPACE" "" print print "$COLOR_OK" "Information about your cluster:" @@ -212,19 +228,22 @@ function interactiveInstall() { } function unattendedInstall() { - if [[ -n "${INSTALL_SCANNERS}" ]]; then - print "Starting to install scanners..." - installResources "$BASE_DIR/scanners" "default" True + if [[ -n "${INSTALL_DEMO_APPS}" ]]; then + print "Starting to install 'demo-targets' into namespace '$SCB_DEMO_NAMESPACE' ..." + kubectl create namespace "$SCB_DEMO_NAMESPACE" || print "Namespace '$SCB_DEMO_NAMESPACE' already exists or could not be created!" + installResources "$BASE_DIR/demo-targets" "$SCB_DEMO_NAMESPACE" "true" fi - if [[ -n "${INSTALL_DEMO_TARGETS}" ]]; then - print "Starting to install demo-targets..." - installResources "$BASE_DIR/demo-targets" "default" True + if [[ -n "${INSTALL_SCANNERS}" ]]; then + print "Starting to install 'scanners' into namespace '$SCB_NAMESPACE' ..." + kubectl create namespace "$SCB_NAMESPACE" || print "Namespace '$SCB_NAMESPACE' already exists or could not be created!" + installResources "$BASE_DIR/scanners" "$SCB_NAMESPACE" "true" fi if [[ -n "${INSTALL_HOOKS}" ]]; then - print "Starting to install hooks..." - installResources "$BASE_DIR/hooks" "default" True + print "Starting to install 'hooks' into namespace '$SCB_NAMESPACE' ..." + kubectl create namespace "$SCB_NAMESPACE" || print "Namespace '$SCB_NAMESPACE' already exists or could not be created!" + installResources "$BASE_DIR/hooks" "$SCB_NAMESPACE" "true" fi print "$COLOR_OK" "Finished installation successfully!" diff --git a/bin/uninstall.sh b/bin/uninstall.sh index f78d42d682..a36bea40fe 100755 --- a/bin/uninstall.sh +++ b/bin/uninstall.sh @@ -19,8 +19,13 @@ shopt -s extglob BASE_DIR=$(dirname "${SCRIPT_DIRECTORY}") +SCB_SYSTEM_NAMESPACE='securecodebox-system' +SCB_DEMO_NAMESPACE='demo-targets' +SCB_NAMESPACE='default' + function uninstallResources() { local resource_directory="$1" + local namespace="$2" local resources=() for path in "$resource_directory"/*; do @@ -31,14 +36,14 @@ function uninstallResources() { done for resource in "${resources[@]}"; do - helm uninstall "$resource" || true + helm uninstall "$resource_name" -n "$namespace" || true done } -helm -n securecodebox-system uninstall securecodebox-operator || true +helm -n "$SCB_SYSTEM_NAMESPACE" uninstall securecodebox-operator || true -uninstallResources "$BASE_DIR/scanners" -uninstallResources "$BASE_DIR/demo-targets" -uninstallResources "$BASE_DIR/hooks" +uninstallResources "$BASE_DIR/demo-targets" "$SCB_DEMO_NAMESPACE" +uninstallResources "$BASE_DIR/scanners" "$SCB_NAMESPACE" +uninstallResources "$BASE_DIR/hooks" "$SCB_NAMESPACE" -kubectl delete namespaces securecodebox-system || true +kubectl delete namespaces "$SCB_SYSTEM_NAMESPACE" || true