Skip to content

Instantly share code, notes, and snippets.

@casjay
Created April 19, 2023 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save casjay/b05dbf020083163e8a437a70dbcd83da to your computer and use it in GitHub Desktop.
Save casjay/b05dbf020083163e8a437a70dbcd83da to your computer and use it in GitHub Desktop.
setup_kubero
#!/usr/bin/env bash
# shellcheck shell=bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202304181752-git
# @@Author : Jason Hempstead
# @@Contact : jason@casjaysdev.com
# @@License : WTFPL
# @@ReadME : setup_kubero --help
# @@Copyright : Copyright: (c) 2023 Jason Hempstead, Casjays Developments
# @@Created : Tuesday, Apr 18, 2023 17:52 EDT
# @@File : setup_kubero
# @@Description :
# @@Changelog : New script
# @@TODO : Better documentation
# @@Other :
# @@Resource :
# @@Terminal App : no
# @@sudo/root : no
# @@Template : shell/sh
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HOME="${USER_HOME:-$HOME}"
USER="${SUDO_USER:-$USER}"
RUN_USER="${SUDO_USER:-$USER}"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ "$USER" = "root" ] || [ "$(id -u)" = 0 ] || { echo "Please run this script as root" && exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__curl() { curl -q -LSsf "$1" -o "$2" || return 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Define variables
work_dir="/tmp/setup"
out_dir="/tmp/kubero"
system_arch="$(uname -m | tr '[:upper:]' '[:lower:]')"
case "$system_arch" in
x86_64)
kind="https://kind.sigs.k8s.io/dl/v0.18.0/kind-linux-amd64"
kubero="https://github.com/kubero-dev/kubero-cli/releases/download/v1.9.0/kubero-cli_Linux_x86_64.tar.gz"
kubectl="https://dl.k8s.io/release/$(curl -q -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
;;
aarch64 | arm64)
kind="https://kind.sigs.k8s.io/dl/v0.18.0/kind-linux-arm64"
kubero="https://github.com/kubero-dev/kubero-cli/releases/download/v1.9.0/kubero-cli_Linux_arm64.tar.gz"
kubectl="https://dl.k8s.io/release/$(curl -q -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl"
;;
esac
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ -d "$out_dir" ] || mkdir -p "$out_dir"
[ -d "$work_dir" ] || mkdir -p "$work_dir"
cd "$work_dir" || exit
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Main application
echo "Downloading kind from $kind"
__curl "$kind" "$out_dir/kind"
[ -f "$out_dir/kind" ] && chmod +x "$out_dir/kind" && mv -f "$out_dir/kind" "/usr/local/bin/kind" || { echo "Failed to install kind" && exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo "Downloading kubectl from $kubectl"
__curl "$kubectl" "$out_dir/kubectl"
[ -f "$out_dir/kubectl" ] && chmod +x "$out_dir/kubectl" && mv -f "$out_dir/kubectl" "/usr/local/bin/kubectl" || { echo "Failed to install kubectl" && exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo "Downloading kubero from $kubero"
__curl "$kubero" "/tmp/kubero.tar.gz"
echo "Extracting /tmp/kubero.tar.gz"
tar xf "/tmp/kubero.tar.gz" && mv -f "$work_dir/kubero" "$out_dir/kubero"
[ -f "$out_dir/kubero" ] && chmod +x "$out_dir/kubero" && mv -f "$out_dir/kubero" "/usr/local/bin/kubero" || { echo "Failed to install kubero" && exit 1; }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -z "$(command -v docker 2>/dev/null)" ]; then
echo "Downloading docker install script"
__curl "https://get.docker.com" "/tmp/docker.sh"
[ -f "/tmp/docker.sh" ] && sh "/tmp/docker.sh" >/dev/null 2>&1 || { echo "Failed to install docker" && exit 1; }
fi
systemctl enable --now docker >/dev/null 2>&1
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
read -r -p -n1 'Install using kubero? [y/n] '
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$REPLY" = y ]; then
kubero install
else
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__curl "https://raw.githubusercontent.com/kubero-dev/kubero/main/kind.yaml" "/tmp/kind.yaml"
kind create cluster --config "/tmp/kind.yaml"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
kubectl create -f https://raw.githubusercontent.com/operator-framework/operator-lifecycle-manager/master/deploy/upstream/quickstart/crds.yaml
kubectl create -f https://raw.githubusercontent.com/operator-framework/operator-lifecycle-manager/master/deploy/upstream/quickstart/olm.yaml
kubectl create -f https://operatorhub.io/install/kubero-operator.yaml
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
kubectl create secret generic kubero-secrets \
--from-literal=KUBERO_WEBHOOK_SECRET=$(openssl rand -hex 20) \
--from-literal=KUBERO_SESSION_KEY=$(openssl rand -hex 20) \
--from-literal=GITHUB_PERSONAL_ACCESS_TOKEN=$GITHUB_TOKEN \
-n kubero
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
kubero install -c kubero-ui
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
kubectl apply -f https://raw.githubusercontent.com/kubero-dev/kubero-operator/main/config/samples/application_v1alpha1_kubero.yaml -n kubero
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# ex: ts=2 sw=2 et filetype=sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment