From 3577ff8ddadcbbb496159acd895982ef714d1d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Iranzo=20G=C3=B3mez?= Date: Thu, 11 Nov 2021 11:43:56 +0100 Subject: [PATCH] Fix function name to be compatible with bash --- install.sh | 90 ++++++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 50 deletions(-) diff --git a/install.sh b/install.sh index 9e21c619ba..6483dfc42b 100755 --- a/install.sh +++ b/install.sh @@ -11,24 +11,22 @@ set -e -o pipefail CONFIG_ENV_ONLY=${CONFIG_ENV_ONLY:=false} # Only get the version number if installing a release version -[ $CONFIG_ENV_ONLY = false ] && \ - VERSION=$(curl -s https://api.github.com/repos/redhat-et/microshift/releases | grep tag_name | head -n 1 | cut -d '"' -f 4) +[ $CONFIG_ENV_ONLY = false ] && + VERSION=$(curl -s https://api.github.com/repos/redhat-et/microshift/releases | grep tag_name | head -n 1 | cut -d '"' -f 4) # Function to get Linux distribution get_distro() { - DISTRO=$(egrep '^(ID)=' /etc/os-release| sed 's/"//g' | cut -f2 -d"=") - if [[ $DISTRO != @(rhel|fedora|centos|ubuntu) ]] - then - echo "This Linux distro is not supported by the install script" - exit 1 + DISTRO=$(egrep '^(ID)=' /etc/os-release | sed 's/"//g' | cut -f2 -d"=") + if [[ $DISTRO != @(rhel|fedora|centos|ubuntu) ]]; then + echo "This Linux distro is not supported by the install script" + exit 1 fi } # Function to get system architecture get_arch() { ARCH=$(uname -m | sed "s/x86_64/amd64/" | sed "s/aarch64/arm64/") - if [[ $ARCH != @(amd64|arm64) ]] - then + if [[ $ARCH != @(amd64|arm64) ]]; then printf "arch %s unsupported" "$ARCH" >&2 exit 1 fi @@ -40,11 +38,11 @@ get_os_version() { } # Function to check system prerequisites -pre-check-installation(){ +pre_check_installation() { mem_threshold='1024' disk_threshold='2048' numCPU_threshold='2' - + numCPU=$(nproc --all) if [ $numCPU -lt $numCPU_threshold ]; then echo "Warning: Pre-Install check number of CPUs cores less than recommended number: $numCPU_threshold" @@ -53,16 +51,14 @@ pre-check-installation(){ fi mem_free=$(free -m | grep "Mem" | awk '{print $4+$6}') - if [ $mem_free -lt $mem_threshold ] - then + if [ $mem_free -lt $mem_threshold ]; then echo "Warning: Pre-Install check MEM usage less than recommended number: $mem_threshold" #uncomment this line to exit on error. By now informative only #exit 1 fi disk_free=$(df -m | grep /$ | grep -v -E '(tmp|boot)' | awk '{print $4}') - if [ $disk_free -lt $disk_threshold ] - then + if [ $disk_free -lt $disk_threshold ]; then echo "Warning: Pre-Install check DISK usage less than recommended number: $disk_threshold" #uncomment this line to exit on error. By now informative only #exit 1 @@ -75,17 +71,15 @@ register_subs() { REPO="rhocp-4.7-for-rhel-8-x86_64-rpms" # Check subscription status and register if not STATUS=$(sudo subscription-manager status | awk '/Overall Status/ { print $3 }') - if [[ $STATUS != "Current" ]] - then - sudo subscription-manager register --auto-attach < /dev/tty + if [[ $STATUS != "Current" ]]; then + sudo subscription-manager register --auto-attach /dev/null - echo "deb [signed-by=$KEYRINGS_DIR/libcontainers-crio-archive-keyring.gpg] http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$CRIOVERSION/$OS/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$CRIOVERSION.list > /dev/null + echo "deb [signed-by=$KEYRINGS_DIR/libcontainers-archive-keyring.gpg] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list >/dev/null + echo "deb [signed-by=$KEYRINGS_DIR/libcontainers-crio-archive-keyring.gpg] http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$CRIOVERSION/$OS/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$CRIOVERSION.list >/dev/null sudo mkdir -p $KEYRINGS_DIR curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | sudo gpg --dearmor -o $KEYRINGS_DIR/libcontainers-archive-keyring.gpg @@ -172,11 +165,10 @@ install_crio() { sudo apt-get update -y # Vagrant Ubuntu VMs don't provide containernetworking-plugins by default sudo apt-get install -y cri-o cri-o-runc cri-tools containernetworking-plugins - ;; + ;; esac } - # CRI-O config to match MicroShift networking values crio_conf() { sudo sh -c 'cat << EOF > /etc/cni/net.d/100-crio-bridge.conf @@ -199,10 +191,10 @@ crio_conf() { } } EOF' - - if [ "$DISTRO" == "rhel" ]; then - sudo sed -i 's|/usr/libexec/crio/conmon|/usr/bin/conmon|' /etc/crio/crio.conf - fi + + if [ "$DISTRO" == "rhel" ]; then + sudo sed -i 's|/usr/libexec/crio/conmon|/usr/bin/conmon|' /etc/crio/crio.conf + fi } # Start CRI-O @@ -226,14 +218,14 @@ get_microshift() { BIN_SHA="$(sha256sum microshift-linux-$ARCH | awk '{print $1}')" KNOWN_SHA="$(grep "microshift-linux-$ARCH" release.sha256 | awk '{print $1}')" - if [[ "$BIN_SHA" != "$KNOWN_SHA" ]]; then + if [[ "$BIN_SHA" != "$KNOWN_SHA" ]]; then echo "SHA256 checksum failed" && exit 1 fi sudo chmod +x microshift-linux-$ARCH sudo mv microshift-linux-$ARCH /usr/local/bin/microshift - cat << EOF | sudo tee /usr/lib/systemd/system/microshift.service + cat < $HOME/.kube/config + sudo KUBECONFIG=/var/lib/microshift/resources/kubeadmin/kubeconfig:$HOME/.kube/config.orig /usr/local/bin/kubectl config view --flatten >$HOME/.kube/config } -# validation checks for deployment -validation_check(){ +# validation checks for deployment +validation_check() { echo $HOSTNAME | grep -P '(?=^.{1,254}$)(^(?>(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)' && echo "Correct" - if [ $? != 0 ]; - then + if [ $? != 0 ]; then echo "======================================================================" echo "!!! WARNING !!!" echo "The hostname $HOSTNAME does not follow FQDN, which might cause problems while operating the cluster." @@ -288,7 +279,7 @@ validation_check(){ get_distro get_arch get_os_version -pre-check-installation +pre_check_installation if [ "$DISTRO" = "rhel" ]; then register_subs fi @@ -303,11 +294,10 @@ if [ "$DISTRO" != "ubuntu" ]; then build_selinux_policy fi -[ "$CONFIG_ENV_ONLY" = true ] && { echo "Env config complete" && exit 0 ; } +[ "$CONFIG_ENV_ONLY" = true ] && { echo "Env config complete" && exit 0; } get_microshift -until sudo test -f /var/lib/microshift/resources/kubeadmin/kubeconfig -do - sleep 2 +until sudo test -f /var/lib/microshift/resources/kubeadmin/kubeconfig; do + sleep 2 done prepare_kubeconfig