Repository: unicef/magasin (language: python)

Issue:
Installer does not work when missing dependencies using curl piping
In the installer, when it is run through curl piping and there are dependencies missing (which is almost always as mag is usually not installed), the installation fails when it reaches the point in which it asks the user if he wants to install the dependencies.

The reason for this is that the shell launched with curl piping is not interactive. 

Solution:
 Detect if the shell is interactive, if so => allow the question otherwise automatically install the dependencies. 






Discussion / hints:

Fix patch:
diff --git a/installer/install-magasin.sh b/installer/install-magasin.sh
index 5567eb8..6966d63 100755
--- a/installer/install-magasin.sh
+++ b/installer/install-magasin.sh
@@ -6,6 +6,10 @@
 # the functionality of all tools once installed.
 
 
+# If curl piping is used the name of the script is set to the name of the shell (f.i zsh or bash)
+# We replace the script_name variable with this value when zsh or bash 
+# It should be the name of the file containing the script.
+DEFAULT_SCRIPT_NAME='install-magasin.sh'
 
 # Magasin base url
 BASE_URL=http://unicef.github.io/magasin
@@ -150,6 +154,121 @@ function usage {
 
 script_name=$(basename "$0")
 
+# When curl piping the name is set to the name of the shell, so we setup a default name.
+if [[ "$script_name" == "zsh" || "$script_name" == "bash" ]]; then
+    script_name=$DEFAULT_SCRIPT_NAME
+fi
+
+
+while getopts ":f:u:r:yichd" opt; do
+  case $opt in
+    y)
+      AUTO_INSTALL=true
+      ;;
+    c)
+      ONLY_CHECK=true
+      ;;
+    i) 
+      ONLY_LOCAL_INSTALL=true
+      ;;
+    d)
+      DEBUG=true
+      ;;
+    u) 
+      CUSTOM_HELM_REPO=true
+      MAGASIN_HELM_REPO=$OPTARG
+      ;;
+    f)
+      # Check if the folder exists.
+      if [ -d $OPTARG ]; then
+          echo_debug "Values folder exists $OPTARG" 
+          VALUES_FOLDER=$OPTARG
+      fi
+      ;;
+  esac
+done
+
+# Function to display warning messages.
+# Prepends two !! in orangish color.
+echo_warning() {
+    printf "\033[38;5;208m[ W ]\033[0m %s\n" "$@" 
+}
+
+# Function to display error messages in red. Prepends ERROR
+echo_error() {
+    printf "\033[31mERROR:\033[0m %s\n" "$@"
+}
+
+# Exit displaying how to debug
+exit_error() {
+  local code=$1
+  echo_error "$code" 
+  echo_error "You may get more information about the issue by running the script including the debug option (-d):"
+  echo_error "       $script_name -d "
+  echo ""
+  exit $code
+}
+
+echo_magasin() {
+
+echo ""
+echo " Welcome to the world of tomorrow            "
+printf "\033[31m"
+printf "                            ▄          \n"             
+printf "                           ███        \n"
+printf "                            ▀         \033[0m\n"
+echo   " ▐█▙█▖ ▟██▖ ▟█▟▌ ▟██▖▗▟██▖ ██  ▐▙██▖   "
+echo   " ▐▌█▐▌ ▘▄▟▌▐▛ ▜▌ ▘▄▟▌▐▙▄▖▘  █  ▐▛ ▐▌   "
+echo   " ▐▌█▐▌▗█▀▜▌▐▌ ▐▌▗█▀▜▌ ▀▀█▖  █  ▐▌ ▐▌   "
+echo   " ▐▌█▐▌▐▙▄█▌▝█▄█▌▐▙▄█▌▐▄▄▟▌▗▄█▄▖▐▌ ▐▌   "
+echo   " ▝▘▀▝▘ ▀▀▝▘ ▞▀▐▌ ▀▀▝▘ ▀▀▀ ▝▀▀▀▘▝▘ ▝▘   "
+echo   "            ▜█▛▘                       "
+echo   ""  
+
+}
+
+function usage {
+  echo "Usage: $1 [-y] [-c] [-i] [-r realm_prefix-realm_postfix (magasin)] [-f values_folder (./)] [-d] [-h]"
+  echo ""
+  echo "This script checks dependencies and installs magasin components"
+  echo "Each component is installed within its own namespace."  
+  echo ""
+  echo "Options:"
+  echo "  -y  Skip prompting questions during installation"
+  echo "  -c  Only check if all pre-requisites are installed in the local machine."
+  echo "  -i  Only install all pre-requisites in the local machine. Does not install magasin in Kubernetes"
+  echo "  -r  Realm prefix and suffix (default: magasin). Prefix and suffix are separated by '-'." 
+  echo "        If more than one '-', the last one will be used as separator." 
+  echo "        The realm 'magasin-new-dev' will set 'magasin-new' as prefix and 'dev' as suffix."
+  echo "  -f  Folder with custom values.yaml files (default: ./)."
+  echo "        Files within the folder shall have the same name as the component. Example:"  
+  echo "        drill.yaml, dagster.yaml, superset.yaml, daskhub.yaml"
+  echo "  -u  URL/path to the magasin's helm repository (default: https://unicef.github.io/magasin/)"
+  echo "      "
+  echo "  -d  Enable debug mode (displays all commands run)."
+  echo "  -h  Display this help message and exit."
+  echo " "
+  echo "Examples:"
+  echo "   - Only check if all requirements are installed"
+  echo "       $1 -c "
+  echo "   - Setup the realm 'test'. Will use test-<component> as namespaces"
+  echo "       $1 -r test"
+  echo "   - Enable debug mode, skip being promted, and setup the realm 'magasin-dev'" 
+  echo "     (which results in magasin-<component>-dev as namespaces)"
+  echo "       $1 -d -y -r magasin-dev"
+  exit 0
+}
+
+script_name=$(basename "$0")
+
+# Check if the script name is zsh or bash and replace it with the default name (install_magasin.sh)
+if [[ "$script_name" == "zsh" || "$script_name" == "bash" ]]; then
+  script_name="install_magasin.sh"
+fi
+
+# If script name is zsh or bash replace is with default name (install_magasin.sh)
+
+
 while getopts ":f:u:r:yichd" opt; do
   case $opt in
     y)
@@ -253,6 +372,15 @@ echo "-----------"
 # Initialize report variables
 declare -A install_status
 
+
+if [[ $- == *i* ]]; then
+    echo_info "Interactive shell"
+else
+    echo_warning "Non-Interactive shell detected. Setting automatic install of dependencies..."
+    AUTO_INSTALL=true
+fi
+
+
 # if a command does not exist this variable is set to true
 command_missing=false
 
@@ -306,7 +434,6 @@ if [[ $PLATFORM == $LINUX ]]; then
   check_linux_requirements_status
   
   # Only debian / apt-get systems supported
-  
   if [ "${install_status["apt-get"]}" = "not installed" ]; then
     echo ""
     echo_error "apt-get is not installed. Are you in a Debian like system?"
@@ -469,6 +596,7 @@ not_working=false
 
 echo ""
 echo_info "Verifying commands are working..."
+# Verify kubeclt 
 if ! kubectl &> /dev/null; then
   echo_error "The kubectl command ($(command -v "kubectl")) is not working properly."
   echo_error "Installation documentation:"
@@ -490,7 +618,7 @@ else
   echo_success "helm is working"
 fi
 
-# Verify helm functionality
+# Verify mc functionality
 if ! mc --version &> /dev/null; then
   echo_error "The mc command ($(command -v "mc")) is not working properly."
   echo_error "Installation documentation:"
@@ -501,8 +629,17 @@ else
   echo_success "mc is working"
 fi
 
+if ! mag --version &> /dev/null; then
+  echo_error "The mag command ($(command -v "mag")) is not working properly."
+  echo_error "Installation documentation:"
+  echo_error "          https://min.io/docs/minio/linux/reference/minio-mc.html#install-mc"
+  not_working=true
+
+else 
+  echo_success "mc is working"
+fi
 
-if [ "$not_working" = true ]; then
+if [[ "$not_working" == true ]]; then
   echo_error "Some of the commands are not working."
   exit_error 10
 fi 


Test patch:
diff --git a/.github/workflows/install-tests.yml b/.github/workflows/install-tests.yml
index 3c3629a..6a67327 100644
--- a/.github/workflows/install-tests.yml
+++ b/.github/workflows/install-tests.yml
@@ -175,3 +175,17 @@ jobs:
           cd installer
           zsh ./install-magasin.sh -c
           zsh ./uninstall-magasin.sh -c
+
+      # Test uninstall 
+      - name: Prepare next test, uninstall helm dependency 
+        run: |
+            brew uninstall helm
+          
+      # Test install with curl 
+      - name: Test install using curl piping
+        run: |
+          cd installer
+          python -m http.server 8080 &
+          curl -sSL http://localhost:8080/install-magasin.sh | zsh -s - -i 
+
+