Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/common.sh
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2017-10-30 21:41:27 +0100
committerErich Eckner <git@eckner.net>2017-10-30 21:41:27 +0100
commitf58016e81217383daeedc615f009cd92985da609 (patch)
tree4dfca8679ceab9166ccdf55a0d5d9b169324c39a /lib/common.sh
parentd77f6c74d88ff046804db306c64c57d87afd81c7 (diff)
parent94160d62b8d3de9d737f5ec70451fefa9ceda6d1 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'lib/common.sh')
-rw-r--r--lib/common.sh100
1 files changed, 7 insertions, 93 deletions
diff --git a/lib/common.sh b/lib/common.sh
index 0fb93d9..a3c2ec2 100644
--- a/lib/common.sh
+++ b/lib/common.sh
@@ -6,62 +6,21 @@
[[ -z ${_INCLUDE_COMMON_SH:-} ]] || return 0
_INCLUDE_COMMON_SH=true
+# shellcheck disable=1091
+. /usr/share/makepkg/util.sh
+
# Avoid any encoding problems
export LANG=C
shopt -s extglob
# check if messages are to be printed using color
-declare ALL_OFF='' BOLD='' BLUE='' GREEN='' RED='' YELLOW=''
if [[ -t 2 ]]; then
- # prefer terminal safe colored and bold text when tput is supported
- if tput setaf 0 &>/dev/null; then
- ALL_OFF="$(tput sgr0)"
- BOLD="$(tput bold)"
- BLUE="${BOLD}$(tput setaf 4)"
- GREEN="${BOLD}$(tput setaf 2)"
- RED="${BOLD}$(tput setaf 1)"
- YELLOW="${BOLD}$(tput setaf 3)"
- else
- ALL_OFF="\e[1;0m"
- BOLD="\e[1;1m"
- BLUE="${BOLD}\e[1;34m"
- GREEN="${BOLD}\e[1;32m"
- RED="${BOLD}\e[1;31m"
- YELLOW="${BOLD}\e[1;33m"
- fi
+ colorize
+else
+ # shellcheck disable=2034
+ declare -gr ALL_OFF='' BOLD='' BLUE='' GREEN='' RED='' YELLOW=''
fi
-readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
-
-plain() {
- local mesg=$1; shift
- # shellcheck disable=2059
- printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-msg() {
- local mesg=$1; shift
- # shellcheck disable=2059
- printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-msg2() {
- local mesg=$1; shift
- # shellcheck disable=2059
- printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-warning() {
- local mesg=$1; shift
- # shellcheck disable=2059
- printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-error() {
- local mesg=$1; shift
- # shellcheck disable=2059
- printf "${RED}==> ERROR:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
stat_busy() {
local mesg=$1; shift
@@ -111,51 +70,6 @@ die() {
}
##
-# usage : in_array( $needle, $haystack )
-# return : 0 - found
-# 1 - not found
-##
-in_array() {
- local needle=$1; shift
- local item
- for item in "$@"; do
- [[ $item = "$needle" ]] && return 0 # Found
- done
- return 1 # Not Found
-}
-
-##
-# usage : get_full_version( [$pkgname] )
-# return : full version spec, including epoch (if necessary), pkgver, pkgrel
-##
-get_full_version() {
- # set defaults if they weren't specified in buildfile
- local pkgbase=${pkgbase:-${pkgname[0]}}
- local epoch=${epoch:-0}
- local pkgver=${pkgver}
- local pkgrel=${pkgrel}
- if [[ -z $1 ]]; then
- if (( ! epoch )); then
- printf '%s\n' "$pkgver-$pkgrel"
- else
- printf '%s\n' "$epoch:$pkgver-$pkgrel"
- fi
- else
- local pkgver_override='' pkgrel_override='' epoch_override=''
- for i in pkgver pkgrel epoch; do
- local indirect="${i}_override"
- eval "$(declare -f "package_$1" | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p")"
- [[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\"
- done
- if (( ! epoch_override )); then
- printf '%s\n' "$pkgver_override-$pkgrel_override"
- else
- printf '%s\n' "$epoch_override:$pkgver_override-$pkgrel_override"
- fi
- fi
-}
-
-##
# usage : lock( $fd, $file, $message, [ $message_arguments... ] )
##
lock() {