From cd8d6350663b496739d018b378883bcbe526c56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Flendrich?= Date: Thu, 10 Oct 2019 10:38:39 +0200 Subject: [PATCH 1/6] shellcheck: fix errors, unwrap the version_lt logic --- cleanup.sh | 2 +- lib/footloose.sh | 2 ++ lib/functions.sh | 31 +++++++++++++++++-------------- lib/ignite.sh | 2 ++ lib/jk.sh | 2 ++ lib/wksctl.sh | 2 ++ setup.sh | 19 ++++++++++++------- 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/cleanup.sh b/cleanup.sh index 962f21b2..86097000 100755 --- a/cleanup.sh +++ b/cleanup.sh @@ -13,7 +13,7 @@ fi set -euo pipefail log() { - echo "•" $* + echo "•" "$@" } config_backend() { diff --git a/lib/footloose.sh b/lib/footloose.sh index 4446bc44..66c954e8 100644 --- a/lib/footloose.sh +++ b/lib/footloose.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + footloose_help() { echo "firekube requires footloose to spawn VMs that will be used as Kubernetes nodes." echo "" diff --git a/lib/functions.sh b/lib/functions.sh index 069f0b0f..060847c6 100644 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + log() { echo "•" "$@" } @@ -105,22 +107,21 @@ version_lt() { local b b="$(clean_version "${2}")" - VERSION_MAJOR="${a%.*.*}" - REST="${a%.*}" VERSION_MINOR="${REST#*.}" - VERSION_PATCH="${a#*.*.}" + A_MAJOR="${a%.*.*}" + REST="${a%.*}" A_MINOR="${REST#*.}" + A_PATCH="${a#*.*.}" - MIN_VERSION_MAJOR="${b%.*.*}" - REST="${b%.*}" MIN_VERSION_MINOR="${REST#*.}" - MIN_VERSION_PATCH="${b#*.*.}" + B_MAJOR="${b%.*.*}" + REST="${b%.*}" B_MINOR="${REST#*.}" + B_PATCH="${b#*.*.}" - if [ \( "${VERSION_MAJOR}" -lt "${MIN_VERSION_MAJOR}" \) -o \ - \( "${VERSION_MAJOR}" -eq "${MIN_VERSION_MAJOR}" -a \ - \( "${VERSION_MINOR}" -lt "${MIN_VERSION_MINOR}" -o \ - \( "${VERSION_MINOR}" -eq "${MIN_VERSION_MINOR}" -a \ - \( "${VERSION_PATCH}" -lt "${MIN_VERSION_PATCH}" \) \) \) \) ] ; then - return 0 - fi - return 1 + [ "${A_MAJOR}" -lt "${B_MAJOR}" ] && return 0 + [ "${A_MAJOR}" -gt "${B_MAJOR}" ] && return 1 + + [ "${A_MINOR}" -lt "${B_MINOR}" ] && return 0 + [ "${A_MINOR}" -gt "${B_MINOR}" ] && return 1 + + [ "${A_PATCH}" -lt "${B_PATCH}" ] } download() { @@ -169,10 +170,12 @@ check_version() { } git_ssh_url() { + # shellcheck disable=SC2001 echo "${1}" | sed -e 's#^https://github.com/#git@github.com:#' } git_http_url() { + # shellcheck disable=SC2001 echo "${1}" | sed -e 's#^git@github.com:#https://github.com/#' } diff --git a/lib/ignite.sh b/lib/ignite.sh index be5b8cd3..8da355a1 100644 --- a/lib/ignite.sh +++ b/lib/ignite.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + ignite_help() { echo "firekube with the ignite backend requires ignite to spawn VMs that will be used as Kubernetes nodes." echo "" diff --git a/lib/jk.sh b/lib/jk.sh index 4853d144..4cb0fd46 100644 --- a/lib/jk.sh +++ b/lib/jk.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + jk_help() { echo "firekube needs jk to generate configuration manifests." echo "" diff --git a/lib/wksctl.sh b/lib/wksctl.sh index 086af8d6..b4363c9b 100644 --- a/lib/wksctl.sh +++ b/lib/wksctl.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + wksctl_help() { echo "firekube needs wksctl to install Kubernetes." echo "" diff --git a/setup.sh b/setup.sh index e515583d..8b14c9d9 100755 --- a/setup.sh +++ b/setup.sh @@ -3,12 +3,17 @@ unset CDPATH SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd "${SCRIPT_DIR}" || exit 1 -. ${SCRIPT_DIR}/lib/functions.sh - -. ${SCRIPT_DIR}/lib/footloose.sh -. ${SCRIPT_DIR}/lib/ignite.sh -. ${SCRIPT_DIR}/lib/jk.sh -. ${SCRIPT_DIR}/lib/wksctl.sh +# shellcheck source=lib/functions.sh +. "${SCRIPT_DIR}/lib/functions.sh" + +# shellcheck source=lib/footloose.sh +. "${SCRIPT_DIR}/lib/footloose.sh" +# shellcheck source=lib/ignite.sh +. "${SCRIPT_DIR}/lib/ignite.sh" +# shellcheck source=lib/jk.sh +. "${SCRIPT_DIR}/lib/jk.sh" +# shellcheck source=lib/wksctl.sh +. "${SCRIPT_DIR}/lib/wksctl.sh" # user-overrideable via ENV if command -v sudo >/dev/null 2>&1; then @@ -163,5 +168,5 @@ git diff-index --quiet HEAD || git commit -m "Initial cluster configuration" git push "${git_remote}" HEAD log "Installing Kubernetes cluster" -wksctl apply --git-url="$(git_http_url "$(git_remote_fetchurl "${git_remote}")")" --git-branch="$(git_current_branch)" ${git_deploy_key} +wksctl apply --git-url="$(git_http_url "$(git_remote_fetchurl "${git_remote}")")" --git-branch="$(git_current_branch)" "${git_deploy_key}" wksctl kubeconfig From 3f38d46c6784fb54f24d5927689781e139d956c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Flendrich?= Date: Fri, 11 Oct 2019 02:03:00 +0200 Subject: [PATCH 2/6] lib/footloose.sh: replace shebang with 'shellcheck shell=bash' As per review comment Co-Authored-By: leigh capili --- lib/footloose.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/footloose.sh b/lib/footloose.sh index 66c954e8..181a04c7 100644 --- a/lib/footloose.sh +++ b/lib/footloose.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash footloose_help() { echo "firekube requires footloose to spawn VMs that will be used as Kubernetes nodes." From 148c4f1b245986aa78fc3063e8afefbb78e3c636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Flendrich?= Date: Fri, 11 Oct 2019 01:54:31 +0200 Subject: [PATCH 3/6] setup.sh: simplify imports --- setup.sh | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/setup.sh b/setup.sh index 8b14c9d9..eda6c962 100755 --- a/setup.sh +++ b/setup.sh @@ -3,17 +3,12 @@ unset CDPATH SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd "${SCRIPT_DIR}" || exit 1 -# shellcheck source=lib/functions.sh -. "${SCRIPT_DIR}/lib/functions.sh" - -# shellcheck source=lib/footloose.sh -. "${SCRIPT_DIR}/lib/footloose.sh" -# shellcheck source=lib/ignite.sh -. "${SCRIPT_DIR}/lib/ignite.sh" -# shellcheck source=lib/jk.sh -. "${SCRIPT_DIR}/lib/jk.sh" -# shellcheck source=lib/wksctl.sh -. "${SCRIPT_DIR}/lib/wksctl.sh" +. lib/functions.sh + +. lib/footloose.sh +. lib/ignite.sh +. lib/jk.sh +. lib/wksctl.sh # user-overrideable via ENV if command -v sudo >/dev/null 2>&1; then From 063a1917c3bfd1e287fd012aa67afb78f91be4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Flendrich?= Date: Fri, 11 Oct 2019 02:01:49 +0200 Subject: [PATCH 4/6] setup.sh: fix wksctl apply flag handling --- setup.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/setup.sh b/setup.sh index eda6c962..d5d9e567 100755 --- a/setup.sh +++ b/setup.sh @@ -86,7 +86,7 @@ while test $# -gt 0; do ;; --git-deploy-key) shift - git_deploy_key="--git-deploy-key ${1}" + git_deploy_key="--git-deploy-key=${1}" log "Using git deploy key: ${1}" ;; -h|--help) @@ -163,5 +163,10 @@ git diff-index --quiet HEAD || git commit -m "Initial cluster configuration" git push "${git_remote}" HEAD log "Installing Kubernetes cluster" -wksctl apply --git-url="$(git_http_url "$(git_remote_fetchurl "${git_remote}")")" --git-branch="$(git_current_branch)" "${git_deploy_key}" +apply_args=( + "--git-url=$(git_http_url "$(git_remote_fetchurl "${git_remote}")")" + "--git-branch=$(git_current_branch)" +) +[ "${git_deploy_key}" ] && apply_args+=("${git_deploy_key}") +wksctl apply "${apply_args[@]}" wksctl kubeconfig From 7c26f5e488f0f30c681feb2be92df28d486ddd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Flendrich?= Date: Fri, 11 Oct 2019 02:06:01 +0200 Subject: [PATCH 5/6] cleanup.sh: import "log" instead of redefining --- cleanup.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cleanup.sh b/cleanup.sh index 86097000..73b2af93 100755 --- a/cleanup.sh +++ b/cleanup.sh @@ -3,6 +3,8 @@ unset CDPATH SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd "${SCRIPT_DIR}" || exit 1 +. lib/functions.sh + # user-overrideable via ENV if command -v sudo >/dev/null 2>&1; then sudo="${sudo:-"sudo"}" @@ -12,10 +14,6 @@ fi set -euo pipefail -log() { - echo "•" "$@" -} - config_backend() { sed -n -e 's/^backend: *\(.*\)/\1/p' config.yaml } From 9d949eb8fef2a676b50a6f38d2a7120a95052936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Flendrich?= Date: Fri, 11 Oct 2019 02:09:46 +0200 Subject: [PATCH 6/6] lib/*.sh: replace shebang with "shellcheck shell=bash" --- lib/functions.sh | 2 +- lib/ignite.sh | 2 +- lib/jk.sh | 2 +- lib/wksctl.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/functions.sh b/lib/functions.sh index 060847c6..1b1cd5da 100644 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash log() { echo "•" "$@" diff --git a/lib/ignite.sh b/lib/ignite.sh index 8da355a1..4bd4a2a6 100644 --- a/lib/ignite.sh +++ b/lib/ignite.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash ignite_help() { echo "firekube with the ignite backend requires ignite to spawn VMs that will be used as Kubernetes nodes." diff --git a/lib/jk.sh b/lib/jk.sh index 4cb0fd46..6ce3e44d 100644 --- a/lib/jk.sh +++ b/lib/jk.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash jk_help() { echo "firekube needs jk to generate configuration manifests." diff --git a/lib/wksctl.sh b/lib/wksctl.sh index b4363c9b..bdb0ff28 100644 --- a/lib/wksctl.sh +++ b/lib/wksctl.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash wksctl_help() { echo "firekube needs wksctl to install Kubernetes."