Skip to content

Instantly share code, notes, and snippets.

@tdeheurles
Created March 12, 2016 08:35
Show Gist options
  • Save tdeheurles/4d7ab5332033214ff196 to your computer and use it in GitHub Desktop.
Save tdeheurles/4d7ab5332033214ff196 to your computer and use it in GitHub Desktop.
kmachine bootstrap for windows -- replace docker-toolbox start.sh
#!/bin/bash
if [[ $1 == TEST ]];then
rm -rf "/C/Users/$(whoami)/.kube"
fi
trap '[ "$?" -eq 0 ] || read -p "Looks like something went wrong... Press any key to continue..."' EXIT
# ENVIRONMENTS
KMACHINE_PATH="/C/Users/$(whoami)/.kube/bin"
VM="dev"
KMACHINE="./kmachine.exe"
BLUE='\033[1;34m'
GREEN='\033[0;32m'
NC='\033[0m'
# FUNCTIONS
docker () {
MSYS_NO_PATHCONV=1 docker.exe "$@"
}
hive_install() {
curl -L -O https://github.com/tdeheurles/hive/releases/download/latest/hive
chmod 755 hive
}
kmachine_install() {
INSTALL_PATH="$1"
KMACHINE_FOLDER="kmachine_windows-amd64"
KMACHINE_VERSION="v1.2.0-alpha.8"
ARCHIVE="${KMACHINE_FOLDER}".tar.gz
if [[ ! -e ${KMACHINE_FOLDER} ]];then
echo " "
echo "no kmachine in PATH, downloading in the current path"
echo "===================================================="
echo " "
curl -L -O https://github.com/skippbox/kmachine/releases/download/${KMACHINE_VERSION}/${ARCHIVE}
tar -xzf ${ARCHIVE}
rm ${ARCHIVE}
mkdir -p ${INSTALL_PATH}
mv ${KMACHINE_FOLDER}/* ${INSTALL_PATH}/
rm -rf ${KMACHINE_FOLDER}
if [[ ! -e ${INSTALL_PATH}/kmachine.exe ]];then
echo " "
echo "Attempt to download/extract kmachine has failed, Aborting ..."
echo "============================================================="
echo " "
exit 1
fi
fi
}
# SCRIPT
mkdir -p ${KMACHINE_PATH}
cd ${KMACHINE_PATH}
# CONTROL KMACHINE INSTALLATION
if [[ ! -f ${KMACHINE} ]];then
kmachine_install ${KMACHINE_PATH}
fi
# CONTROL VIRTUALBOX INSTALLATION
if [ ! -z "$VBOX_MSI_INSTALL_PATH" ]; then
VBOXMANAGE="${VBOX_MSI_INSTALL_PATH}VBoxManage.exe"
else
VBOXMANAGE="${VBOX_INSTALL_PATH}VBoxManage.exe"
fi
if [ ! -f "${VBOXMANAGE}" ]; then
echo "VirtualBox is not installed. Please re-run the Toolbox Installer and try again."
exit 1
fi
"${VBOXMANAGE}" list vms | grep \""${VM}"\" &> /dev/null
VM_EXISTS_CODE=$?
set -e
# CONTROL KMACHINE
if [ $VM_EXISTS_CODE -eq 1 ]; then
"${KMACHINE}" rm -f "${VM}" &> /dev/null || :
rm -rf ~/.kube/machine/machines/"${VM}"
"${KMACHINE}" create -d virtualbox "${VM}"
fi
VM_STATUS="$(${KMACHINE} status ${VM} 2>&1)"
if [ "${VM_STATUS}" != "Running" ]; then
"${KMACHINE}" start "${VM}"
yes | "${KMACHINE}" regenerate-certs "${VM}"
fi
# GET ENVIRONMENT
# eval "$(${KMACHINE} env --shell=bash ${VM})"
echo -e "${BLUE}docker${NC} is configured to use the ${GREEN}${VM}${NC} machine with IP ${GREEN}$(${KMACHINE} ip ${VM})${NC}"
echo "For help getting started, check out the docs at https://docs.docker.com"
echo
cd
# SAVE SOME ENV AND MOVE TO HOME
export -f docker
export -f hive_install
export PATH="${PATH}:${KMACHINE_PATH}"
exec "${BASH}" --login -i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment