#!/bin/bash

# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

SCRIPTPATH="$(cd "$(dirname "$0")" || exit; pwd -P)"
ROOTDIR="$(dirname "${SCRIPTPATH}")"
# shellcheck source=tests/e2e/local/common_linux.sh
source "${ROOTDIR}/common_linux.sh"

check_apt_get

install_curl

install_docker

function check_and_install_golang() {
	sudo apt-get install -y golang
}

function check_and_install_kind() {
	echo "Checking KinD is installed..."
	if ! kind --help > /dev/null; then
		if ! (GO111MODULE="on" go get sigs.k8s.io/kind@v0.3.0); then
			echo "Looks like KinD installation failed."
			echo "Please install it manually then run this script again."
			exit 1
		fi
	fi
}

check_and_install_golang
check_and_install_kind

echo "Everything installed for you and ready to go."
