32 lines
681 B
Bash
32 lines
681 B
Bash
|
# -*- mode: bash -*-
|
||
|
|
||
|
function abort() {
|
||
|
local status="${1:?"abort requires status"}"
|
||
|
local reason="${2:?"abort requires reason"}"
|
||
|
shift 2
|
||
|
# here we want the string as template
|
||
|
# shellcheck disable=SC2059
|
||
|
printf "error: ${reason}\n" "$@" >&2
|
||
|
exit "${status}"
|
||
|
}
|
||
|
|
||
|
function has_software() {
|
||
|
for software in "$@"; do
|
||
|
type "${software}" >/dev/null 2>&1 ||
|
||
|
abort 1 $"%s not found in path\n" "${software}"
|
||
|
done
|
||
|
}
|
||
|
|
||
|
function import() {
|
||
|
local name path file
|
||
|
for name in "$@"; do
|
||
|
local IFS=:; set -o noglob
|
||
|
for path in ${IMPORTPATH}; do
|
||
|
file="${path}/${name}"
|
||
|
[[ -e "${file}" && -r "${file}" ]] && {
|
||
|
source "${file}" && continue 2 || return 1
|
||
|
}
|
||
|
done
|
||
|
done
|
||
|
}
|