#!/bin/bash
#
# Ubuntu installer for Kubernetes
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.


args=("$@")

usage() {
    echo "This is the standard Ubuntu installer for Kubernetes that supports your "
    echo "workstation, VMware, Openstack, AWS, Azure, Google, and Oracle cloud. "
    echo ""
    echo "Deploy a K8s instance with 'kubernetes install'"
}

case ${args[0]} in
    *help)
        usage
        exit 0
        ;;
    *version)
        echo "1.0.0"
        exit 0
        ;;
    install)
        PS3='Please choose an installation option: '
        options=("microk8s" "Canonical Distribution of Kubernetes" "Quit")
        select opt in "${options[@]}"
        do
            case $opt in
                "Canonical Distribution of Kubernetes")
                    echo "Fetching components..."
                    sudo snap install conjure-up --classic
                    conjure-up canonical-kubernetes
                    break
                    ;;
                "microk8s")
                    echo "Fetching components..."
                    sudo snap install conjure-up --classic
                    conjure-up microk8s
                    break
                    ;;
                "Quit")
                    echo "Exiting..."
                    break
                    ;;
                *)
                    echo "Invalid option"
                    ;;
            esac
        done
        exit 0
        ;;
    *)
        echo "Missing arguments: <install|help>"
        exit 1
        ;;
esac
