Skip to content

Commit

Permalink
Merge pull request #73 from unicef/fix/install-macos-when-missing-dep…
Browse files Browse the repository at this point in the history
…endencies

Fix: install macos when missing dependencies
  • Loading branch information
merlos authored Mar 14, 2024
2 parents 95b6af0 + 3559af6 commit faf7a75
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 3 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/install-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
143 changes: 140 additions & 3 deletions installer/install-magasin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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?"
Expand Down Expand Up @@ -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:"
Expand All @@ -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:"
Expand All @@ -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
Expand Down

0 comments on commit faf7a75

Please sign in to comment.