#!/bin/bash -l : ${KUBASH_DIR:=$HOME/.kubash} : ${KUBASH_BIN:=$KUBASH_DIR/bin} : ${GOPATH:=$HOME/.go} PIP_INSTALL_PKGS="netaddr ceph-deploy" if [[ "$1" == '-y' ]]; then echo 'using YES' YES='-y' YES_ARCH='--noconfirm' else YES=' ' YES_ARCH=' ' fi set -ex check_shell () { THIS_SHELL=$(echo $SHELL| rev | cut -d'/' -f 1 | rev) if [[ "$THIS_SHELL" == "zsh" ]]; then . $HOME/.zshrc elif [[ "$THIS_SHELL" == "bash" ]]; then . $HOME/.bashrc else echo 'unsupported shell' exit 1 fi } squawk () { # This function simplifies error reporting and verbosity # call it by preceding your message with a verbosity level # e.g. `squawk 13 "This is a squawk"` # if the current verbosity level is greater than or equal # the number given then this function will echo out your message # and pad it with # to let you now how verbose that message was squawk_lvl=$1 shift squawk=$1 shift squawk_opt=$@ if [[ "$VERBOSITY" -ge "$squawk_lvl" ]] ; then count_squawk=0 while [[ "$count_squawk" -lt "$squawk_lvl" ]]; do echo -n "#" count_squawk=`expr $count_squawk + 1` done echo " $squawk" fi } # Check if a command exists check_cmd () { if ! type "$1" > /dev/null; then echo "$1 was not found in your path!" echo "To proceed please install $1 to your path and try again!" exit 1 fi } # Check if a command exists, and if not install it check_install () { if ! type "$1" > /dev/null; then squawk 10 "Installing $1" cd ~/.kubash make $1 else squawk 10 "$1 is already installed" fi } flight_checks () { # Let's display everything on stderr. exec 1>&2 UNAME=$(uname) if [ "$UNAME" = "CYGWIN_NT-10.0" ] ; then PLATFORM="os.cygwin.x86_64" echo "WARNING: Cygwin is not supported at this time!" exit 1 fi if [ "$UNAME" == "Linux" ] ; then if [[ $VERBOSITY -gt '1' ]]; then squawk 10 " $UNAME is a Supported OS" fi elif [ "$UNAME" == "Darwin" -o "$UNAME" == "FreeBSD" ] ; then if [[ $VERBOSITY -gt '1' ]]; then echo " $UNAME is not a Supported OS" exit 1 fi elif [ "$UNAME" ">" "MINGW" -a "$UNAME" "<" "MINGX" ] ; then if [[ $VERBOSITY -gt '1' ]]; then echo " $UNAME is not a Supported OS" exit 1 fi else echo " $UNAME is not a Supported OS" echo "Sorry, this OS is not supported yet via this installer." exit 1 fi if [ "$UNAME" = "Linux" ] ; then ### Linux ### LINUX_ARCH=$(uname -m) if [ "${LINUX_ARCH}" = "x86_64" ] ; then PLATFORM="os.linux.x86_64" else echo "Unusable architecture: ${LINUX_ARCH}" echo "Kubash only supports x86_64 for now on Linux." exit 1 fi fi # make reqs if [ "$PLATFORM" = "os.linux.x86_64" ] ; then squawk 10 "Installing on Linux" fi } upgrade_go () { GOTMP=$(mktemp -d) cd $GOTMP wget https://go.dev/dl/go1.19.2.linux-amd64.tar.gz sudo rm -rf /usr/local/go sudo tar -C /usr/local -xzf go1.19.2.linux-amd64.tar.gz } main () { . /etc/os-release cat /etc/os-release WHOAMI=$(whoami) if [[ "$WHOAMI" = "root" ]]; then PSEUDO='' else check_cmd sudo PSEUDO='sudo' fi if [[ "$NAME" = 'Debian GNU/Linux' || $NAME = 'Ubuntu' ]]; then if [[ "$CIRCLE_STAGE" == "acceptance-test" ]]; then DEB_PKG_GET='sudo jq git build-essential golang unzip curl wget parallel ansible rlwrap rsync nmap python3-pip virtinst qemu-kvm net-tools dnsutils' elif [[ "$UBUNTU_CODENAME" == "xenial" ]]; then DEB_PKG_GET='sudo jq git build-essential golang unzip curl wget parallel ansible rlwrap rsync nmap python-pip virtinst qemu-kvm libvirt-daemon-system net-tools dnsutils' elif [[ "$UBUNTU_CODENAME" == "bionic" ]]; then DEB_PKG_GET='sudo jq git build-essential golang unzip curl wget parallel ansible rlwrap rsync nmap python3-pip virtinst qemu-kvm libvirt-clients libvirt-daemon-system net-tools dnsutils' upgrade_go elif [[ "$UBUNTU_CODENAME" == "focal" ]]; then DEB_PKG_GET='sudo jq git build-essential golang unzip curl wget parallel ansible rlwrap rsync nmap python3-pip virtinst qemu-kvm libvirt-daemon-system net-tools dnsutils' elif [[ "$UBUNTU_CODENAME" == "jammy" ]]; then DEB_PKG_GET='sudo jq git build-essential golang unzip curl wget parallel ansible rlwrap rsync nmap python3-pip virtinst qemu-kvm libvirt-daemon-system net-tools dnsutils' else echo 'OS not detected! bailing out. you are on your own.' exit 1 fi if type "apt-get" &> /dev/null; then check_cmd apt-get $PSEUDO apt-get update $PSEUDO apt-get $YES install $DEB_PKG_GET fi elif [[ "$NAME" = 'CentOS Linux' ]]; then YUM_PKG_GET='sudo jq @development python3-pip golang unzip curl wget parallel ansible rlwrap rsync nmap net-tools qemu-kvm qemu-img virt-manager libvirt libvirt-python3 libvirt-client virt-install virt-viewer bridge-utils' if type "yum" &> /dev/null; then check_cmd yum $PSEUDO yum $YES update $PSEUDO yum install $YES epel-release $PSEUDO yum $YES update $PSEUDO yum install $YES $YUM_PKG_GET fi elif [[ "$NAME" = 'Arch Linux' ]]; then check_cmd pacman ARCH_PKG_GET='sudo awk nettle gettext jq git make go unzip curl wget parallel ansible rlwrap python-pip openbsd-netcat rsync nmap net-tools openssh' #echo "$PSEUDO pacman -Sy" #$PSEUDO pacman -Sy #$PSEUDO pacman -Su $YES_ARCH $PSEUDO pacman -Syu $YES_ARCH $ARCH_PKG_GET # if type "powerpill" &> /dev/null; then # check_cmd powerpill # #echo "$PSEUDO powerpill -S $YES_ARCH $ARCH_PKG_GET" # #$PSEUDO powerpill -S $YES_ARCH $ARCH_PKG_GET # $PSEUDO pacman -S $YES_ARCH $ARCH_PKG_GET # elif type "pacman" &> /dev/null; then # echo "$PSEUDO pacman -Sy $YES_ARCH $ARCH_PKG_GET" # fi fi check_cmd git check_cmd ssh check_cmd ansible check_cmd curl check_cmd unzip check_cmd uname check_cmd go if [[ -x /usr/bin/pip3 ]]; then echo 'Setting PIP=/usr/bin/pip3' PIP=/usr/bin/pip3 elif [[ -x $(which pip3) ]]; then echo 'Setting PIP=pip3' PIP=pip3 else echo 'Cannot find pip3 Setting PIP=pip' PIP=pip fi check_cmd $PIP check_cmd make check_cmd parallel check_cmd 'grep' check_cmd 'sed' flight_checks if [[ "$CIRCLECI" == true ]]; then echo 'in CircleCI skipping git clone' elif [ ! -d $KUBASH_DIR ]; then git clone https://github.com/kubash/kubash.git $KUBASH_DIR else echo "KUBASH_DIR=$KUBASH_DIR found" echo 'using found kubash directory' cd $KUBASH_DIR pwd git log -n1|cat fi export PATH=$HOME/.kubash/bin:$PATH $KUBASH_DIR/scripts/dotfiles check_shell cd $KUBASH_DIR if [[ "$CI_BUILD_REF_SLUG" == "fulltest" ]]; then THISGITLAB_EXISTS=$(git remote|grep thisgitlab|wc -l) if [[ "$THISGITLAB_EXISTS" == "0" ]]; then git remote add -f thisgitlab https://gitlab.com/kubash/kubash.git else echo 'no need to add remote' fi git fetch --all git checkout fulltest fi echo 'Updating submodules in the kubash directory' git submodule update --init --recursive echo 'ensure openebs is installed' make submodules/openebs if [[ "$CIRCLE_STAGE" == "acceptance-test" ]]; then echo 'circleci acceptance-test so nvm is installed!' else echo 'ensure nvm is installed' make nvm export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion nvm install --lts nvm use --default --lts nvm alias default node fi check_cmd npm echo 'ensure jinja2 is installed' cd $KUBASH_DIR $PIP install --user --upgrade jinja2-cli #cat $HOME/.bashrc . $HOME/.bashrc #echo $PATH #check_install jinja2 cd $KUBASH_DIR make yaml2json #echo 'ensure ct is installed' cd $KUBASH_DIR make ct #check_install ct #make ct check_install helm check_install oc # These need to exist in .kubash/bin/ cd $KUBASH_DIR make cfssl cd $KUBASH_DIR make packer cd $KUBASH_DIR # coreOS is deprecated #make coreos_key cd $KUBASH_DIR make kubectl cd $KUBASH_DIR check_install crictl # onessl is deprecated and is being removed #check_install onessl $PIP install --user --upgrade $PIP_INSTALL_PKGS if [ -w /usr/local/bin ] ; then touch /usr/local/bin/test_file_01 rm /usr/local/bin/test_file_01 echo '/usr/local/bin is writeable by the current user' else echo '/usr/local/bin is not writeable by the current user' echo 'Please ensure the current user can write to /usr/local/bin' #exit 1 fi echo 'logout and log back in, or source your RC files' } time main "$@" echo 'bootstrap complete' exit 0