11#! /usr/bin/env bash
2- # Prerequisites installation script for Grounds Development Infrastructure
3- # Automatically installs missing dependencies for local Kubernetes development
42
53set -euo pipefail
64
7- # Colors and emojis for fancy console output
8- readonly RED=' \033[0;31m'
9- readonly GREEN=' \033[0;32m'
10- readonly YELLOW=' \033[1;33m'
11- readonly BLUE=' \033[0;34m'
12- readonly PURPLE=' \033[0;35m'
13- readonly CYAN=' \033[0;36m'
14- readonly WHITE=' \033[1;37m'
15- readonly NC=' \033[0m' # No Color
16-
17- # Logging functions
18- log_info () {
19- echo -e " ${BLUE} ℹ️ $1 ${NC} "
20- }
21-
22- log_success () {
23- echo -e " ${GREEN} ✅ $1 ${NC} "
24- }
25-
26- log_warning () {
27- echo -e " ${YELLOW} ⚠️ $1 ${NC} "
28- }
29-
30- log_error () {
31- echo -e " ${RED} ❌ $1 ${NC} "
32- }
33-
34- log_step () {
35- echo -e " ${PURPLE} 🚀 $1 ${NC} "
36- }
5+ here=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
6+ source " ${here} /common.sh"
377
388# Check if command exists
399command_exists () {
40- command -v " $1 " > /dev/null 2>&1
10+ if command -v " $1 " > /dev/null 2>&1 ; then
11+ echo 0
12+ else
13+ echo 1
14+ fi
4115}
4216
4317# Detect OS
4418detect_os () {
4519 if [[ " ${OSTYPE} " == " linux-gnu" * ]]; then
4620 local has_apt has_yum has_pacman
47- command_exists apt-get
48- has_apt=$?
49- command_exists yum
50- has_yum=$?
51- command_exists pacman
52- has_pacman=$?
21+ has_apt=$( command_exists apt-get)
22+ has_yum=$( command_exists yum)
23+ has_pacman=$( command_exists pacman)
5324
5425 if [[ " ${has_apt} " -eq 0 ]]; then
5526 echo " ubuntu"
@@ -77,8 +48,7 @@ install_docker() {
7748 case " ${os} " in
7849 " ubuntu" )
7950 local docker_exists
80- command_exists docker
81- docker_exists=$?
51+ docker_exists=$( command_exists docker)
8252 if [[ " ${docker_exists} " -ne 0 ]]; then
8353 curl -fsSL https://get.docker.com | sh
8454 sudo usermod -aG docker " ${USER} "
@@ -89,8 +59,7 @@ install_docker() {
8959 ;;
9060 " macos" )
9161 local docker_exists
92- command_exists docker
93- docker_exists=$?
62+ docker_exists=$( command_exists docker)
9463 if [[ " ${docker_exists} " -ne 0 ]]; then
9564 log_warning " Please install Docker Desktop for macOS from https://www.docker.com/products/docker-desktop"
9665 log_info " Or install via Homebrew: brew install --cask docker"
@@ -107,8 +76,7 @@ install_docker() {
10776# Install k3d
10877install_k3d () {
10978 local k3d_exists
110- command_exists k3d
111- k3d_exists=$?
79+ k3d_exists=$( command_exists k3d)
11280 if [[ " ${k3d_exists} " -ne 0 ]]; then
11381 log_info " Installing k3d..."
11482 curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
@@ -121,8 +89,7 @@ install_k3d() {
12189# Install kubectl
12290install_kubectl () {
12391 local kubectl_exists
124- command_exists kubectl
125- kubectl_exists=$?
92+ kubectl_exists=$( command_exists kubectl)
12693 if [[ " ${kubectl_exists} " -ne 0 ]]; then
12794 log_info " Installing kubectl..."
12895 local kubectl_version=$( curl -L -s https://dl.k8s.io/release/stable.txt)
@@ -138,8 +105,7 @@ install_kubectl() {
138105# Install Helm
139106install_helm () {
140107 local helm_exists
141- command_exists helm
142- helm_exists=$?
108+ helm_exists=$( command_exists helm)
143109 if [[ " ${helm_exists} " -ne 0 ]]; then
144110 log_info " Installing Helm..."
145111 curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
@@ -152,13 +118,15 @@ install_helm() {
152118# Install Helmfile
153119install_helmfile () {
154120 local helmfile_exists
155- command_exists helmfile
156- helmfile_exists=$?
121+ helmfile_exists=$( command_exists helmfile)
157122 if [[ " ${helmfile_exists} " -ne 0 ]]; then
158123 log_info " Installing Helmfile..."
159- local helmfile_version=" v0.156.0"
160- curl -L " https://github.com/helmfile/helmfile/releases/download/${helmfile_version} /helmfile_${helmfile_version# v} _linux_amd64.tar.gz" | tar xz
161- sudo mv helmfile /usr/local/bin/
124+ local helmfile_version=" v1.2.3"
125+ local tmp_dir
126+ tmp_dir=" $( mktemp -d) "
127+ curl -L " https://github.com/helmfile/helmfile/releases/download/${helmfile_version} /helmfile_${helmfile_version# v} _linux_amd64.tar.gz" | tar -xz -C " ${tmp_dir} "
128+ sudo mv " ${tmp_dir} /helmfile" /usr/local/bin/
129+ rm -rf " ${tmp_dir} "
162130 log_success " Helmfile installed"
163131 else
164132 log_success " Helmfile already installed"
@@ -197,18 +165,12 @@ check_prereqs() {
197165 local missing=()
198166 local docker_exists k3d_exists kubectl_exists helm_exists helmfile_exists devspace_exists
199167
200- command_exists docker
201- docker_exists=$?
202- command_exists k3d
203- k3d_exists=$?
204- command_exists kubectl
205- kubectl_exists=$?
206- command_exists helm
207- helm_exists=$?
208- command_exists helmfile
209- helmfile_exists=$?
210- command_exists devspace
211- devspace_exists=$?
168+ docker_exists=$( command_exists docker)
169+ k3d_exists=$( command_exists k3d)
170+ kubectl_exists=$( command_exists kubectl)
171+ helm_exists=$( command_exists helm)
172+ helmfile_exists=$( command_exists helmfile)
173+ devspace_exists=$( command_exists devspace)
212174
213175 if [[ " ${docker_exists} " -ne 0 ]]; then
214176 missing+=(" docker" )
0 commit comments