Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

shellcheck: fix errors, unwrap the version_lt logic #68

Merged
merged 6 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"}"
Expand All @@ -12,10 +14,6 @@ fi

set -euo pipefail

log() {
echo "" $*
}

config_backend() {
sed -n -e 's/^backend: *\(.*\)/\1/p' config.yaml
}
Expand Down
2 changes: 2 additions & 0 deletions lib/footloose.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# shellcheck shell=bash

footloose_help() {
echo "firekube requires footloose to spawn VMs that will be used as Kubernetes nodes."
echo ""
Expand Down
31 changes: 17 additions & 14 deletions lib/functions.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# shellcheck shell=bash

log() {
echo "•" "$@"
}
Expand Down Expand Up @@ -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}" ]
mflendrich marked this conversation as resolved.
Show resolved Hide resolved
}

download() {
Expand Down Expand Up @@ -169,10 +170,12 @@ check_version() {
}

git_ssh_url() {
# shellcheck disable=SC2001
echo "${1}" | sed -e 's#^https://github.com/#[email protected]:#'
}

git_http_url() {
# shellcheck disable=SC2001
echo "${1}" | sed -e 's#^[email protected]:#https://github.com/#'
mflendrich marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
2 changes: 2 additions & 0 deletions lib/ignite.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# shellcheck shell=bash

ignite_help() {
echo "firekube with the ignite backend requires ignite to spawn VMs that will be used as Kubernetes nodes."
echo ""
Expand Down
2 changes: 2 additions & 0 deletions lib/jk.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# shellcheck shell=bash

jk_help() {
echo "firekube needs jk to generate configuration manifests."
echo ""
Expand Down
2 changes: 2 additions & 0 deletions lib/wksctl.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# shellcheck shell=bash

wksctl_help() {
echo "firekube needs wksctl to install Kubernetes."
echo ""
Expand Down
19 changes: 12 additions & 7 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ unset CDPATH
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${SCRIPT_DIR}" || exit 1

. ${SCRIPT_DIR}/lib/functions.sh
. lib/functions.sh

. ${SCRIPT_DIR}/lib/footloose.sh
. ${SCRIPT_DIR}/lib/ignite.sh
. ${SCRIPT_DIR}/lib/jk.sh
. ${SCRIPT_DIR}/lib/wksctl.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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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