chore: create re-usable check-dependency.sh script (#959)

We have a little snippet to check if a dependency is installed on the
system that we're literally copy-pasting in every single script in the
build system script collection.

For re-usability purposes, this snippet has been extracted to a
`check-dependency.sh` that is called by every script that needs it.

Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
Juan Cruz Viotti 2016-12-09 10:48:01 -04:00 committed by GitHub
parent 446e457b5b
commit 47d3f0c8fa
19 changed files with 78 additions and 161 deletions

View File

@ -0,0 +1,48 @@
#!/bin/bash
###
# Copyright 2016 resin.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###
set -e
set +u
ARGV_DEPENDENCIES=$*
set -u
if [ -z "$ARGV_DEPENDENCIES" ]; then
echo "Usage: $0 <dependency...>"
exit 1
fi
RESULT=""
for dependency in $ARGV_DEPENDENCIES; do
if command -v $dependency 2>/dev/null 1>&2; then
RESULT=$dependency
break
fi
done
if [ -z "$RESULT" ]; then
echo "Dependency missing: $ARGV_DEPENDENCIES" 1>&2
exit 1
fi
# Only print back if more than one command was passed
# otherwise if the script passes, its clear that the
# single command checked is the one that exists.
if [ "$#" -ne 1 ]; then
echo $RESULT
fi

View File

@ -19,14 +19,7 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
check_dep bower
./scripts/build/check-dependency.sh bower
function usage() {
echo "Usage: $0"

View File

@ -19,15 +19,8 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
check_dep npm
check_dep python
./scripts/build/check-dependency.sh npm
./scripts/build/check-dependency.sh python
function usage() {
echo "Usage: $0"

View File

@ -19,22 +19,11 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
./scripts/build/check-dependency.sh wget
check_dep wget
if command -v sha256sum 2>/dev/null 1>&2; then
SHA256SUM=sha256sum
elif command -v shasum 2>/dev/null 1>&2; then
SHA256SUM="shasum -a 256"
else
echo "Dependency missing: sha256sum or shasum" 1>&2
exit 1
SHA256SUM=$(./scripts/build/check-dependency.sh sha256sum shasum)
if [ "$SHA256SUM" == "shasum" ]; then
SHA256SUM="$SHA256SUM -a 256"
fi
function usage() {

View File

@ -19,21 +19,14 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
OS=$(uname)
if [[ "$OS" != "Darwin" ]]; then
echo "This script is only meant to be run in OS X" 1>&2
exit 1
fi
check_dep /usr/libexec/PlistBuddy
check_dep unzip
./scripts/build/check-dependency.sh /usr/libexec/PlistBuddy
./scripts/build/check-dependency.sh unzip
function usage() {
echo "Usage: $0"

View File

@ -25,14 +25,7 @@ if [[ "$OS" != "Linux" ]]; then
exit 1
fi
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
check_dep unzip
./scripts/build/check-dependency.sh unzip
function usage() {
echo "Usage: $0"

View File

@ -19,14 +19,7 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
check_dep asar
./scripts/build/check-dependency.sh asar
function usage() {
echo "Usage: $0"

View File

@ -19,20 +19,13 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
OS=$(uname)
if [[ "$OS" != "Darwin" ]]; then
echo "This script is only meant to be run in OS X" 1>&2
exit 1
fi
check_dep hdiutil
./scripts/build/check-dependency.sh hdiutil
function usage() {
echo "Usage: $0"

View File

@ -19,24 +19,17 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
OS=$(uname)
if [[ "$OS" != "Darwin" ]]; then
echo "This script is only meant to be run in OS X" 1>&2
exit 1
fi
check_dep hdiutil
check_dep xattr
check_dep tiffutil
check_dep osascript
check_dep afsctool
./scripts/build/check-dependency.sh hdiutil
./scripts/build/check-dependency.sh xattr
./scripts/build/check-dependency.sh tiffutil
./scripts/build/check-dependency.sh osascript
./scripts/build/check-dependency.sh afsctool
function usage() {
echo "Usage: $0"

View File

@ -19,14 +19,7 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
check_dep wget
./scripts/build/check-dependency.sh wget
function usage() {
echo "Usage: $0"

View File

@ -19,21 +19,14 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
check_dep zip
OS=$(uname)
if [[ "$OS" != "Darwin" ]]; then
echo "This script is only meant to be run in OS X" 1>&2
exit 1
fi
./scripts/build/check-dependency.sh zip
function usage() {
echo "Usage: $0"
echo ""

View File

@ -20,21 +20,13 @@ set -u
set -e
set -x
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
OS=$(uname)
if [[ "$OS" != "Linux" ]]; then
echo "This script is only meant to be run in GNU/Linux" 1>&2
exit 1
fi
check_dep upx
check_dep wget
./scripts/build/check-dependency.sh upx
function usage() {
echo "Usage: $0"

View File

@ -19,20 +19,13 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
OS=$(uname)
if [[ "$OS" != "Linux" ]]; then
echo "This script is only meant to be run in GNU/Linux" 1>&2
exit 1
fi
check_dep electron-installer-debian
./scripts/build/check-dependency.sh electron-installer-debian
function usage() {
echo "Usage: $0"

View File

@ -19,21 +19,14 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
OS=$(uname)
if [[ "$OS" != "Darwin" ]]; then
echo "This script is only meant to be run in OS X" 1>&2
exit 1
fi
check_dep codesign
check_dep spctl
./scripts/build/check-dependency.sh codesign
./scripts/build/check-dependency.sh spctl
function usage() {
echo "Usage: $0"

View File

@ -19,20 +19,13 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
OS=$(uname)
if [[ "$OS" != "Darwin" ]]; then
echo "This script is only meant to be run in OS X" 1>&2
exit 1
fi
check_dep hdiutil
./scripts/build/check-dependency.sh hdiutil
function usage() {
echo "Usage: $0"

View File

@ -19,20 +19,13 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
OS=$(uname -o 2>/dev/null || true)
if [[ "$OS" != "Msys" ]]; then
echo "This script is only meant to be run in Windows" 1>&2
exit 1
fi
check_dep signtool
./scripts/build/check-dependency.sh signtool
function usage() {
echo "Usage: $0"

View File

@ -19,15 +19,8 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
check_dep browserify
check_dep rsync
./scripts/build/check-dependency.sh browserify
./scripts/build/check-dependency.sh rsync
function usage() {
echo "Usage: $0"

View File

@ -20,14 +20,7 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
check_dep aws
./scripts/build/check-dependency.sh aws
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <file>" 1>&2

View File

@ -20,14 +20,7 @@
set -u
set -e
function check_dep() {
if ! command -v $1 2>/dev/null 1>&2; then
echo "Dependency missing: $1" 1>&2
exit 1
fi
}
check_dep curl
./scripts/build/check-dependency.sh curl
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <debfile>" 1>&2