summaryrefslogtreecommitdiffstats
path: root/functions.sh.in
diff options
context:
space:
mode:
authorDubiousjim <dubiousjim@gmail.com>2013-07-05 00:21:16 -0400
committerNatanael Copa <ncopa@alpinelinux.org>2013-07-09 06:44:01 +0000
commitdb1314ac55df59e1fbecdae280cf2b4c1784dd5a (patch)
treef94dc44cf791559b3291a45d8470bba3f2423610 /functions.sh.in
parent144ee3f113ffc73188c6cdc1682b908f6e28cba6 (diff)
downloadabuild-db1314ac55df59e1fbecdae280cf2b4c1784dd5a.tar.bz2
abuild-db1314ac55df59e1fbecdae280cf2b4c1784dd5a.tar.xz
various: move conf-loading and i/o to functions
Diffstat (limited to 'functions.sh.in')
-rw-r--r--functions.sh.in76
1 files changed, 76 insertions, 0 deletions
diff --git a/functions.sh.in b/functions.sh.in
new file mode 100644
index 0000000..d71ef38
--- /dev/null
+++ b/functions.sh.in
@@ -0,0 +1,76 @@
+# /usr/share/abuild/functions.sh
+
+sysconfdir=@sysconfdir@
+prog=${0##*/}
+
+
+abuild_conf=${ABUILD_CONF:-"$sysconfdir/abuild.conf"}
+abuild_home=${ABUILD_USERDIR:-"$HOME/.abuild"}
+abuild_userconf=${ABUILD_USERCONF:-"$abuild_home/abuild.conf"}
+
+# read config
+if [ -f "$abuild_conf" ]; then
+ . "$abuild_conf" || abuild_conf=
+fi
+
+# read user config if exists
+if [ -f "$abuild_userconf" ]; then
+ . "$abuild_userconf" || abuild_userconf=
+fi
+
+
+# output functions
+case $prog in
+abuild)
+ if [ -n "$USE_COLORS" ]; then
+ NORMAL="\033[1;0m"
+ STRONG="\033[1;1m"
+ RED="\033[1;31m"
+ GREEN="\033[1;32m"
+ YELLOW="\033[1;33m"
+ BLUE="\033[1;34m"
+ fi
+
+ msg() {
+ local prompt="$GREEN>>>${NORMAL}"
+ local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
+ local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
+ [ -z "$quiet" ] && printf "${prompt} ${name}${fake}: $@\n" >&2
+ }
+
+ warning() {
+ local prompt="${YELLOW}>>> WARNING:${NORMAL}"
+ local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
+ local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
+ printf "${prompt} ${name}${fake}: $@\n" >&2
+ }
+
+ error() {
+ local prompt="${RED}>>> ERROR:${NORMAL}"
+ local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
+ local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
+ printf "${prompt} ${name}${fake}: $@\n" >&2
+ }
+ ;;
+*)
+ msg() {
+ # Here we write to stdout, but abuild's fancier messages write to stderr
+ [ -z "$quiet" ] && echo "$@"
+ }
+
+ error() {
+ echo "$@" >&2
+ }
+ ;;
+esac
+
+# caller may override
+cleanup() {
+ return 0
+}
+
+die() {
+ error "$@"
+ cleanup
+ exit 1
+}