Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding check_binaries command that is distinct from check_packages to lib/common.sh #745

Merged
merged 1 commit into from
Jun 24, 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
4 changes: 2 additions & 2 deletions anago
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ check_prerequisites () {
# We check for docker here as a word which passes for docker-ce and
# docker-engine as docker packages are in transiation of deprecating
# docker-engine
common::check_packages jq pandoc docker ${PREREQUISITE_PACKAGES[*]} \
|| return 1
common::check_binaries jq pandoc docker || return 1
common::check_packages ${PREREQUISITE_PACKAGES[*]} || return 1
common::check_pip_packages yq || return 1

security_layer::auth_check 2 || return 1
Expand Down
5 changes: 1 addition & 4 deletions branchff
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ source $(dirname $(readlink -ne $BASH_SOURCE))/lib/common.sh

# Check prerequisites

PREREQUISITE_TOOLS=("git" "jq" "go" "make")
for PREREQ in ${PREREQUISITE_TOOLS[@]}; do
command -v $PREREQ > /dev/null 2>&1 || common::exit 1 "$PREREQ not installed"
done;
common::check_binaries git go jq make

[[ -w /usr/local ]] || common::exit 1 "/usr/local is not writable."

Expand Down
2 changes: 1 addition & 1 deletion find_green_build
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ MYLOG=$TMPDIR/$PROG.log
common::logfileinit $MYLOG 10

gitlib::github_api_token
common::check_packages jq
common::check_binaries jq
common::check_pip_packages yq
common::set_cloud_binaries

Expand Down
2 changes: 1 addition & 1 deletion gcbmgr
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ common::logfileinit $MYLOG 10
# BEGIN script
common::timestamp begin

common::check_packages jq git bsdmainutils || common::exit 1 "Exiting..."
common::check_binaries jq git column || common::exit 1 "Exiting..."
gitlib::repo_state || common::exit 1 "Exiting..."

# Ensure some prerequisites
Expand Down
48 changes: 48 additions & 0 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,54 @@ common::check_pip_packages () {
logecho -r "$OK"
}

##############################################################################
# Check whether required binaries are installed

common::check_binaries () {
local distro
local prereq

# Make sure a bunch of binaries are installed
logecho -n "Checking whether required binaries are available...\n"

for prereq in $*; do
which $prereq > /dev/null || missing+=($prereq)
done

if ((${#missing[@]}>0)); then
if ((FLAGS_gcb)); then
# Just force Ubuntu
distro="Ubuntu"
else
distro=$(lsb_release -si)
fi
logecho -r "$FAILED"
logecho "PREREQ: Missing prerequisites: ${missing[@]}"

case $distro in
Fedora)
logecho "Run the following command(s) to find the package(s) that contain(s) the required prerequisite(s):"
for prereq in ${missing[@]}; do
logecho "dnf provides $prereq"
done
return 1
;;
Ubuntu|LinuxMint|Debian)
logecho "Run the following command(s) to find the package(s) that contain(s) the required prerequisite(s):"
for prereq in ${missing[@]}; do
logecho "dpkg -S $prereq"
done
return 1
;;
*)
logecho "Unsupported distribution. Please consult your distribution's documentation for downloading the missing prerequisite(s)"
return 1
;;
esac
return 1
fi
logecho -r "$OK"
}

###############################################################################
# Check packages for a K8s release
Expand Down
2 changes: 1 addition & 1 deletion relnotes
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ common::timestamp begin
gitlib::github_api_token

# Check for packages
common::check_packages jq pandoc
common::check_binaries jq pandoc

# Build LAST_RELEASE dictionary
gitlib::last_releases
Expand Down
1 change: 1 addition & 0 deletions script-template
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ common::timestamp begin
# common::askyorn - Ask a simple yes or no question (see common.sh for details)
# common::stepheader - Bolded, logged bullet points for your output
# common::exit - Exit cleanly
# common::check_binaries - Checks for binary prereqs
# common::check_packages - Check for package prereqs
# common::disk_space_check - Check disk space

Expand Down