Skip to content

Instantly share code, notes, and snippets.

@Richard-Barrett
Last active November 2, 2022 08:43
Show Gist options
  • Save Richard-Barrett/3d4e39ba5ce67d5512ed5b4e98bccd2d to your computer and use it in GitHub Desktop.
Save Richard-Barrett/3d4e39ba5ce67d5512ed5b4e98bccd2d to your computer and use it in GitHub Desktop.
Download the MKE Client Bundle Automatically
#!/bin/bash
# =============================================
# Created by: Richard Barrett
# Date Created: 02/27/2020
# Purpose: Auto Client Bundle Download in CWD
# Company: Mirantis
# =============================================
# Documentation:
# ========================================================================================
# https://docs.mirantis.com/docker-enterprise/v3.1/dockeree-products/mke/user-access.html
# ========================================================================================
#set -e
# keep track of the last executed command
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# echo an error message before exiting
trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT
# System Variables
# ================
DATE="$(date +'%Y%-m%d')"
AUTHTOKEN=$(curl -sk -d '{"username":"$USERNAME","password":"$PASSWORD"}' ${REQUEST_URL}/auth/login | jq -r .auth_token)
KUBECTL_PRESENT=$(kubctl version)
OS_VERSION=$(cat /etc/os-release)
# Grab Token
# =====================
echo "Would you like to collect kubernetes cluster information (yes/no)?
read ANS
echo "What is your MKE/UCP username?"
read USERNAME
echo "What is your MKE/UCP password?"
read PASSWORD
echo "What is the MKE/UCP IP Address?"
read MKE_IP
while true; do
read -p "Create Client Bundle Inside of Current Working Directory (yes/no)?" yn
case $yn in
[Yy]* ) echo "==================================="; \
echo " Collecting Bundle..."; \
echo "==================================="; \
# Get MKE Client Bundle and Create Bundle in Working Directory as hostname_bundle_date
# Make Bundle Directory
mkdir $(pwd)/$hostname_bundle_$DATE;
cd $(pwd)/$hostname_bundle_$DATE;
AUTHTOKEN=$(curl -sk -d '{"username":"$USERNAME","password":"$PASSWORD"}' https://$MKE_IP/auth/login | jq -r .auth_token);
curl -k -H "Authorization: Bearer $AUTHTOKEN" https://$MKE_IP/api/clientbundle -o bundle.zip;
unzip bundle.zip;
eval "$(<env.sh)";
echo "Confirming Docker MKE Containers are Running...";
docker ps -af state=running;
echo "=========================================================="; \
echo " Downloaded Bundle in $(pwd)..."; \
echo "=========================================================="; \
break;; \
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment