From 3bc27774a9834aee09ee7d17f32029b92825bf14 Mon Sep 17 00:00:00 2001 From: Grant Date: Mon, 19 Aug 2024 07:48:02 -0500 Subject: [PATCH 1/6] add ERROR_CODE --- resources/scripts/quick_start.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/resources/scripts/quick_start.sh b/resources/scripts/quick_start.sh index 7d473848c..f9b623b90 100755 --- a/resources/scripts/quick_start.sh +++ b/resources/scripts/quick_start.sh @@ -1,6 +1,7 @@ #!/bin/bash set -euo pipefail +ERROR_CODE=0 is_cygwin_etal() { uname -s | grep -qE "CYGWIN|MINGW|MSYS" @@ -10,7 +11,7 @@ is_wsl() { } if is_cygwin_etal || is_wsl; then echo "Quick start does not support Windows" - exit 1 + ERROR_CODE=1 fi @@ -76,7 +77,7 @@ if [ -n "$docker_path" ]; then else print_partial_message " 💥 Could not find " "docker" ". Please follow this link to install Docker Engine..." "$BOLD" print_message "" " https://docs.docker.com/engine/install/" "$BOLD" - exit 127 + ERROR_CODE=127 fi current_user=$(whoami) @@ -94,7 +95,7 @@ if [ -n "$helm_path" ]; then else print_partial_message " 💥 Could not find " "helm" ". Please follow this link to install it..." "$BOLD" print_message "" " https://helm.sh/docs/intro/install/" "$BOLD" - exit 127 + ERROR_CODE=127 fi just_path=$(command -v just || true) @@ -103,6 +104,7 @@ if [ -n "$just_path" ]; then else print_partial_message " 💥 Could not find " "just" ". Please follow this link to install it..." "$BOLD" print_message "" " https://github.com/casey/just?tab=readme-ov-file#pre-built-binaries" "$BOLD" + ERROR_CODE=127 fi python_path=$(command -v python3 || true) @@ -133,4 +135,7 @@ if [ -n "$bpf_status" ]; then else print_partial_message " 💥 Could not find " "BPF" ". Please figure out how to enable Berkeley Packet Filters in your kernel." "$BOLD" exit 1 +if [ $ERROR_CODE -ne 0 ]; then + print_message "" "There were errors in the setup process. Please fix them and try again." "$BOLD" + exit $ERROR_CODE fi From f4121ee97d934180084afbb2ab9e1363d27424da Mon Sep 17 00:00:00 2001 From: Grant Date: Mon, 19 Aug 2024 08:21:04 -0500 Subject: [PATCH 2/6] update title --- resources/scripts/quick_start.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/scripts/quick_start.sh b/resources/scripts/quick_start.sh index f9b623b90..241dc3775 100755 --- a/resources/scripts/quick_start.sh +++ b/resources/scripts/quick_start.sh @@ -46,9 +46,9 @@ print_partial_message() { } print_message "" "" "" -print_message "" " ╭───────────────────────────────────╮" "" -print_message "" " │ Welcome to the Warnet Quickstart │" "" -print_message "" " ╰───────────────────────────────────╯" "" +print_message "" " ╭───────────────────────────╮" "" +print_message "" " │ Welcome to Warnet Setup │" "" +print_message "" " ╰───────────────────────────╯" "" print_message "" "" "" print_message "" " Let's find out if your system has what it takes to run Warnet..." "" print_message "" "" "" From 9ea8442de1f4280f7810433e32c36b2e08ba58a3 Mon Sep 17 00:00:00 2001 From: Grant Date: Mon, 19 Aug 2024 08:22:15 -0500 Subject: [PATCH 3/6] prompt user for minikube/docker-desktop choice --- resources/scripts/quick_start.sh | 35 +++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/resources/scripts/quick_start.sh b/resources/scripts/quick_start.sh index 241dc3775..fcaefa199 100755 --- a/resources/scripts/quick_start.sh +++ b/resources/scripts/quick_start.sh @@ -45,6 +45,13 @@ print_partial_message() { echo -e "${color}${pre_message}${format}${formatted_part}${RESET}${color}${post_message}${RESET}" } +prompt_user() { + local prompt="$1" + tput bold # Make the prompt bold + echo "$prompt" + tput sgr0 # Reset formatting +} + print_message "" "" "" print_message "" " ╭───────────────────────────╮" "" print_message "" " │ Welcome to Warnet Setup │" "" @@ -53,24 +60,24 @@ print_message "" "" "" print_message "" " Let's find out if your system has what it takes to run Warnet..." "" print_message "" "" "" -minikube_path=$(command -v minikube || true) -if [ -n "$minikube_path" ]; then - print_partial_message " ⭐️ Found " "minikube" ": $minikube_path " "$BOLD" -else - print_partial_message " 💥 Could not find " "minikube" ". Please follow this link to install it..." "$BOLD" - print_message "" " https://minikube.sigs.k8s.io/docs/start/" "$BOLD" - exit 127 +prompt_user "Use [1] minikube (Default) or [2] docker-desktop? Enter 1 or 2: " +read -r choice + +if [[ "$choice" == "1" || -z "$choice" ]]; then + choice=1 +elif ! [[ "$choice" == "2" ]]; then + echo " Please enter 1 for minikube or 2 for docker-desktop." + exit 1 fi -kubectl_path=$(command -v kubectl || true) -if [ -n "$kubectl_path" ]; then - print_partial_message " ⭐️ Found " "kubectl" ": $kubectl_path " "$BOLD" -else - print_partial_message " 💥 Could not find " "kubectl" ". Please follow this link to install it..." "$BOLD" - print_message "" " https://kubernetes.io/docs/tasks/tools/" "$BOLD" - exit 127 +if [[ "$choice" == "1" || -z "$choice" ]]; then + approach="minikube" +elif [[ "$choice" == "2" ]]; then + approach="docker-desktop" fi +print_partial_message " ⭐️ You chose " ""$approach"" "." "$BOLD" + docker_path=$(command -v docker || true) if [ -n "$docker_path" ]; then print_partial_message " ⭐️ Found " "docker" ": $docker_path" "$BOLD" From 557cfe8c12b0d8206f65c83cbf2475955adc2293 Mon Sep 17 00:00:00 2001 From: Grant Date: Mon, 19 Aug 2024 08:23:16 -0500 Subject: [PATCH 4/6] check for docker as needed --- resources/scripts/quick_start.sh | 62 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/resources/scripts/quick_start.sh b/resources/scripts/quick_start.sh index fcaefa199..cf2eb8679 100755 --- a/resources/scripts/quick_start.sh +++ b/resources/scripts/quick_start.sh @@ -88,8 +88,38 @@ else fi current_user=$(whoami) -if id -nG "$current_user" | grep -qw "docker"; then - print_partial_message " ⭐️ Found " "$current_user" " in the docker group" "$BOLD" +if [ -n "$docker_path" ]; then + current_context=$(docker context show) + if id -nG "$current_user" | grep -qw "docker"; then + print_partial_message " ⭐️ Found " "$current_user" " in the docker group" "$BOLD" + elif [ "$current_context" == "rootless" ]; then + print_message " " "⭐️ Docker is set to rootless" "$BOLD" + elif [[ "$(uname)" == "Darwin" ]]; then + print_message " " "⭐️ Found Docker on Darwin" "$BOLD" + else + print_partial_message " 💥 Could not find " "$current_user" " in the docker group. Please add it like this..." "$BOLD" + print_message "" " sudo usermod -aG docker $current_user && newgrp docker" "$BOLD" + ERROR_CODE=1 + fi + + if docker info >/dev/null 2>&1; then + print_partial_message " ⭐️" " Docker" " is running" "$BOLD" + else + print_message " " "💥 Docker is not running. Please start docker." "$BOLD" + ERROR_CODE=1 + fi + + if [[ "$approach" == "docker-desktop" && -n "$docker_path" ]]; then + if docker context ls | grep -q "docker-desktop"; then + print_message " ⭐️ Found " "Docker Desktop" "$BOLD" + else + print_partial_message " 💥 Could not find " "docker-desktop" ". Please follow this link to install it..." "$BOLD" + print_message "" " https://www.docker.com/products/docker-desktop/" "$BOLD" + ERROR_CODE=127 + fi + fi +fi + else print_partial_message " 💥 Could not find " "$current_user" " in the docker group. Please add it like this..." "$BOLD" print_message "" " sudo usermod -aG docker $current_user && newgrp docker" "$BOLD" @@ -114,34 +144,6 @@ else ERROR_CODE=127 fi -python_path=$(command -v python3 || true) -if [ -n "$python_path" ]; then - print_partial_message " ⭐️ Found " "python3" ": $python_path " "$BOLD" -else - print_partial_message " 💥 Could not find " "python3" ". Please follow this link to install it (or use your package manager)..." "$BOLD" - print_message "" " https://www.python.org/downloads/" "$BOLD" - exit 127 -fi - -if [ -n "$VIRTUAL_ENV" ]; then - print_partial_message " ⭐️ Running in virtual environment: " "$VIRTUAL_ENV" "$BOLD" -else - print_partial_message " 💥 Not running in a virtual environment. " "Please activate a venv before proceeding." "$BOLD" - exit 127 -fi - -bpf_status=$(grep CONFIG_BPF /boot/config-"$(uname -r)" || true) -if [ -n "$bpf_status" ]; then - config_bpf=$(echo "$bpf_status" | grep CONFIG_BPF=y) - if [ "$config_bpf" = "CONFIG_BPF=y" ]; then - print_partial_message " ⭐️ Found " "BPF" ": Berkeley Packet Filters appear enabled" "$BOLD" - else - print_partial_message " 💥 Could not find " "BPF" ". Please figure out how to enable Berkeley Packet Filters in your kernel." "$BOLD" - exit 1 - fi -else - print_partial_message " 💥 Could not find " "BPF" ". Please figure out how to enable Berkeley Packet Filters in your kernel." "$BOLD" - exit 1 if [ $ERROR_CODE -ne 0 ]; then print_message "" "There were errors in the setup process. Please fix them and try again." "$BOLD" exit $ERROR_CODE From 1184d9fe98670a015762f5244e07d5979a4ff565 Mon Sep 17 00:00:00 2001 From: Grant Date: Mon, 19 Aug 2024 08:27:38 -0500 Subject: [PATCH 5/6] update kubectl check --- resources/scripts/quick_start.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/resources/scripts/quick_start.sh b/resources/scripts/quick_start.sh index cf2eb8679..25d774529 100755 --- a/resources/scripts/quick_start.sh +++ b/resources/scripts/quick_start.sh @@ -120,10 +120,14 @@ if [ -n "$docker_path" ]; then fi fi + +kubectl_path=$(command -v kubectl || true) +if [ -n "$kubectl_path" ]; then + print_partial_message " ⭐️ Found " "kubectl" ": $kubectl_path " "$BOLD" else - print_partial_message " 💥 Could not find " "$current_user" " in the docker group. Please add it like this..." "$BOLD" - print_message "" " sudo usermod -aG docker $current_user && newgrp docker" "$BOLD" - exit 1 + print_partial_message " 💥 Could not find " "kubectl" ". Please follow this link to install it..." "$BOLD" + print_message "" " https://kubernetes.io/docs/tasks/tools/" "$BOLD" + ERROR_CODE=127 fi helm_path=$(command -v helm || true) From 2896a656a481d4dbf8684da911e44b8031a7f287 Mon Sep 17 00:00:00 2001 From: Grant Date: Mon, 19 Aug 2024 08:27:58 -0500 Subject: [PATCH 6/6] check minikube as appropriate --- resources/scripts/quick_start.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/resources/scripts/quick_start.sh b/resources/scripts/quick_start.sh index 25d774529..0249b0f8b 100755 --- a/resources/scripts/quick_start.sh +++ b/resources/scripts/quick_start.sh @@ -120,6 +120,20 @@ if [ -n "$docker_path" ]; then fi fi +if [[ "$approach" == "minikube" ]]; then + minikube_path=$(command -v minikube || true) + if [[ "$(uname)" == "Darwin" ]] && command -v minikube &> /dev/null && [[ "$(minikube version --short)" == "v1.33.1" ]]; then + print_partial_message " 💥 Could not find " "minikube version > 1.33.1" ". Please upgrade..." "$BOLD" + print_message "" " https://minikube.sigs.k8s.io/docs/start/" "$BOLD" + ERROR_CODE=127 + elif [ -n "$minikube_path" ]; then + print_partial_message " ⭐️ Found " "minikube" ": $minikube_path " "$BOLD" + else + print_partial_message " 💥 Could not find " "minikube" ". Please follow this link to install it..." "$BOLD" + print_message "" " https://minikube.sigs.k8s.io/docs/start/" "$BOLD" + ERROR_CODE=127 + fi +fi kubectl_path=$(command -v kubectl || true) if [ -n "$kubectl_path" ]; then