From 25b217ff52514004f3c837a9ae8ba272758d8fcd Mon Sep 17 00:00:00 2001 From: Richard Grenville Date: Sun, 11 Jan 2015 16:26:36 +0800 Subject: [PATCH] Misc: Move shared functions out of make-release.sh - Move shared functions in make-release.sh to a separate file, functions.sh . - Add more comments to make-release.sh and functions.sh . --- functions.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ make-release.sh | 36 +++------------------------------- 2 files changed, 54 insertions(+), 33 deletions(-) create mode 100755 functions.sh diff --git a/functions.sh b/functions.sh new file mode 100755 index 00000000..7d81beb0 --- /dev/null +++ b/functions.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Shared functions for various supporting scripts of compton +# Mostly copied from Gentoo gentoo-functions + +GOOD=$'\e[32;01m' +WARN=$'\e[33;01m' +BAD=$'\e[31;01m' +HILITE=$'\e[36;01m' +BRACKET=$'\e[34;01m' +NORMAL=$'\e[0m' + +# @FUNCTION: eerror +# @USAGE: [message] +# @DESCRIPTION: +# Show an error message. +eerror() { + echo -e "$@" | while read -r ; do + echo " $BAD*$NORMAL $REPLY" >&2 + done + return 0 +} + +# @FUNCTION: einfo +# @USAGE: [message] +# @DESCRIPTION: +# Show a message. +einfo() { + echo -e "$@" | while read -r ; do + echo " $GOOD*$NORMAL $REPLY" + done + return 0 +} + +# @FUNCTION: die +# @USAGE: +# @DESCRIPTION: +# Print the call stack and the working directory, then quit the shell. +die() { + eerror "Call stack:" + (( n = ${#FUNCNAME[@]} - 1 )) + while (( n > 0 )); do + funcname=${FUNCNAME[$((n - 1))]} + sourcefile=$(basename ${BASH_SOURCE[${n}]}) + lineno=${BASH_LINENO[$((n - 1))]} + eerror " ${sourcefile}:${lineno} - Called ${funcname}()" + (( n-- )) + done + eerror "Working directory: '$(pwd)'" + exit 1 +} diff --git a/make-release.sh b/make-release.sh index 718b1ef2..535cf92a 100755 --- a/make-release.sh +++ b/make-release.sh @@ -1,39 +1,9 @@ #!/bin/bash -GOOD=$'\e[32;01m' -WARN=$'\e[33;01m' -BAD=$'\e[31;01m' -HILITE=$'\e[36;01m' -BRACKET=$'\e[34;01m' -NORMAL=$'\e[0m' +# Make a release source tarball containing pre-built documentation -eerror() { - echo -e "$@" | while read -r ; do - echo " $BAD*$NORMAL $RC_INDENTATION$REPLY" >&2 - done - return 0 -} - -einfo() { - echo -e "$@" | while read -r ; do - echo " $GOOD*$NORMAL $REPLY" - done - return 0 -} - -die() { - eerror "Call stack:" - (( n = ${#FUNCNAME[@]} - 1 )) - while (( n > 0 )); do - funcname=${FUNCNAME[$((n - 1))]} - sourcefile=$(basename ${BASH_SOURCE[${n}]}) - lineno=${BASH_LINENO[$((n - 1))]} - eerror " ${sourcefile}:${lineno} - Called ${funcname}()" - (( n-- )) - done - eerror "Working directory: '$(pwd)'" - exit 1 -} +BASE_DIR=$(dirname "$0") +. "${BASE_DIR}/functions.sh" main() { TMP=/tmp