#!/bin/bash set -eo pipefail RUNNER="${RUNNER:-docker}" IMAGE="${IMAGE:-rancher/shell:dev}" function run(){ "${RUNNER}" run --rm "${IMAGE}" $1 } function stat(){ run "stat -c $1 $2" } function expected_file(){ file="$1" owner="$2" perms="$3" actualPerms=$(stat '%a' "${file}") actualOwner=$(stat '%u:%g' "${file}") if [[ "${actualPerms}" != "${perms}" ]] || \ [[ "${actualOwner}" != "${owner}" ]]; then echo "${file}: expected (${owner} ${perms}) got (${actualOwner} ${actualPerms})" exit 1 else echo "${file}: OK" fi } function check_files(){ echo "checking expected binaries:" expected_file "/usr/local/bin/helm" "0:0" "755" expected_file "/usr/local/bin/helm-cmd" "0:0" "755" expected_file "/usr/local/bin/k9s" "0:0" "755" expected_file "/usr/local/bin/kubectl" "0:0" "755" expected_file "/usr/local/bin/kustomize" "0:0" "755" expected_file "/usr/local/bin/welcome" "0:0" "755" expected_file "/home/shell/kustomize.sh" "1000:1000" "755" } function expected_version(){ cmd="$1" version="$2" if [[ -z "${version}" ]]; then echo "expected version for ${cmd} not set" exit 1 fi output=$(run "${cmd} version" 2> /dev/null) if echo "${output}" | grep -q "${version}"; then echo "${cmd} ${version}: OK" else echo "${cmd} expected ${version}: ${output}" exit 1 fi } function check_versions(){ echo "checking command versions:" expected_version "helm" "${HELM_VERSION}" expected_version "kustomize" "${KUSTOMIZE_VERSION}" expected_version "k9s" "${K9S_VERSION}" # --client=true is used so that it does not fail trying to # identify the server version. expected_version "kubectl --client=true" "${KUBECTL_VERSION}" } function main(){ check_files check_versions } main