123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #!/usr/bin/env bash
- # shellcheck disable=SC1090,SC2034
- checkBashVersion () {
- if ! declare -n _assoc; then
- echo "You must use bash >= 4.3 (supports namerefs) to use build-wrapper"
- echo "You can still call most functions directly using arguments instead of arrays."
- _printHelpAndExit 1
- fi
- }
- getOS () {
- if [[ -e /etc/os-release ]]; then
- source /etc/os-release
- else
- echo "No /etc/os-release found!"
- echo "Your OS is unsupported"
- _printHelpAndExit 1
- fi
- }
- installPackage () {
- # We will add packages to this array if their command is not available
- local -a _pkg_array
- # parse commands
- for _pkg in "$@"; do
- _pkg=$(packageOverrides "$_pkg")
- # Insert the package name to test if already installed one element from the end
- # and silence output
- if ! "${_pkg_query_cmd[@]}" "$_pkg" > /dev/null 2>&1; then
- _pkg_array+=("$_pkg")
- else
- echo "$_pkg is already installed!"
- fi
- done
- if [[ ${#_pkg_array[@]} -ge 1 ]]; then
- [[ -n $_debug ]] && echo "${_install_cmd[@]}" "${_pkg_array[@]}"
- "${_install_cmd[@]}" "${_pkg_array[@]}"
- fi
- }
- packageOverrides () {
- if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
- if [[ "$1" == "rpm-build" ]]; then
- echo "rpm"
- elif [[ "$1" == "createrepo_c" ]]; then
- echo "createrepo"
- else
- echo "$1"
- fi
- else
- echo "$1"
- fi
- }
- getBaseDir () {
- # Get base directory name of where this script resides
- # https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself#comment54598418_246128
- _basedir=$(dirname "$(readlink -f "$0")")
- }
- sourcePlugin () {
- getBaseDir
- _plugin="$_basedir/plugins/$1"
- if [[ -f "$_plugin" ]]; then
- source "$_plugin"
- else
- echo "Plugin $_plugin does not exist!"
- fi
- }
- sourcePlugins () {
- getBaseDir
- for _file in "$_basedir"/plugins/*/*; do
- [[ -f "$_file" ]] && source "$_file"
- done
- }
- pluginExists () {
- if [[ $# -lt 1 || ! $(type -t "$1") == "function" ]]; then
- echo "Plugin not found"
- _printHelpAndExit 1
- fi
- }
- fixPermissions () {
- # Allow container access to the workdir (SELinux)
- chcon -t container_file_t -R "$1"
- }
- debug () {
- [[ -n $_debug ]] && echo "debug: " "$@"
- }
- silent () {
- [[ -z $_silent ]] && echo "$@"
- }
|