summaryrefslogtreecommitdiff
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
parent144ee3f113ffc73188c6cdc1682b908f6e28cba6 (diff)
downloadabuild-db1314ac55df59e1fbecdae280cf2b4c1784dd5a.tar.gz
abuild-db1314ac55df59e1fbecdae280cf2b4c1784dd5a.tar.bz2
abuild-db1314ac55df59e1fbecdae280cf2b4c1784dd5a.tar.xz
abuild-db1314ac55df59e1fbecdae280cf2b4c1784dd5a.zip
various: move conf-loading and i/o to functions
-rw-r--r--abuild-keygen.in20
-rw-r--r--abuild-sign.in19
-rwxr-xr-xabump.in23
-rw-r--r--apkgrel.in12
-rw-r--r--checkapk.in24
-rw-r--r--functions.sh34
-rw-r--r--functions.sh.in76
-rwxr-xr-xnewapkbuild.in21
8 files changed, 128 insertions, 101 deletions
diff --git a/abuild-keygen.in b/abuild-keygen.in
index 3cf5531..9b748d3 100644
--- a/abuild-keygen.in
+++ b/abuild-keygen.in
@@ -7,17 +7,14 @@
#
abuild_ver=@VERSION@
-sysconfdir=@sysconfdir@
+datadir=@datadir@
-abuild_conf=${ABUILD_CONF:-"$sysconfdir/abuild.conf"}
-abuild_home=${ABUILD_USERDIR:-"$HOME/.abuild"}
-abuild_userconf=${ABUILD_USERCONF:-"$abuild_home/abuild.conf"}
+if ! [ -f "$datadir/functions.sh" ]; then
+ echo "$datadir/functions.sh: not found" >&2
+ exit 1
+fi
+. "$datadir/functions.sh"
-# echo message unless quite mode
-msg() {
- [ -n "$quiet" ] && return 0
- echo "$@"
-}
# ask for privkey unless non-interactive mode
# returns value in global $privkey
@@ -107,11 +104,6 @@ usage() {
exit 1
}
-# read config
-[ -f "$abuild_conf" ] && . "$abuild_conf"
-
-# read user config if exists
-[ -f "$abuild_userconf" ] && . "$abuild_userconf"
while getopts "ahinq" opt; do
case $opt in
diff --git a/abuild-sign.in b/abuild-sign.in
index 73aabc7..3260e53 100644
--- a/abuild-sign.in
+++ b/abuild-sign.in
@@ -7,16 +7,13 @@
#
abuild_ver=@VERSION@
-sysconfdir=@sysconfdir@
+datadir=@datadir@
-abuild_conf=${ABUILD_CONF:-"$sysconfdir/abuild.conf"}
-abuild_home=${ABUILD_USERDIR:-"$HOME/.abuild"}
-abuild_userconf=${ABUILD_USERCONF:-"$abuild_home/abuild.conf"}
-
-die() {
- echo "$@" >&2
+if ! [ -f "$datadir/functions.sh" ]; then
+ echo "$datadir/functions.sh: not found" >&2
exit 1
-}
+fi
+. "$datadir/functions.sh"
do_sign() {
# we are actually only interested in the name, not the file itself
@@ -52,12 +49,6 @@ usage() {
exit 1
}
-# read config
-[ -f "$abuild_conf" ] && . "$abuild_conf"
-
-# read user config if exists
-[ -f "$abuild_userconf" ] && . "$abuild_userconf"
-
privkey="$PACKAGER_PRIVKEY"
while getopts "hk:p:q" opt; do
diff --git a/abump.in b/abump.in
index 897b50e..32ff4af 100755
--- a/abump.in
+++ b/abump.in
@@ -6,12 +6,15 @@
# Distributed under GPL-2
#
-program=${0##*/}
+abuild_ver=@VERSION@
+datadir=@datadir@
-die() {
- echo "$@" >&2
+if ! [ -f "$datadir/functions.sh" ]; then
+ echo "$datadir/functions.sh: not found" >&2
exit 1
-}
+fi
+. "$datadir/functions.sh"
+
# version bump a pkg
@@ -31,14 +34,14 @@ do_bump() {
cve=" ($cvelist)"
fi
- msg="$section/$pkgname: $upgrade to ${pkgver}${cve}"
+ message="$section/$pkgname: $upgrade to ${pkgver}${cve}"
if [ -n "$fixes" ]; then
- msg="$msg
+ message="$message
fixes #${fixes#\#}
"
fi
- echo "$msg"
+ echo "$message"
( . ./APKBUILD; type package | grep -q function ) || die "package() missing"
@@ -49,12 +52,12 @@ fixes #${fixes#\#}
abuild $abuild_opts checksum all || exit 1
git add APKBUILD
- git commit -m"$msg"
+ git commit -m"$message"
}
usage() {
- echo "$program - utility to bump pkgver in APKBUILDs"
- echo "usage: $program [-hR] [-s CVE-1,CVE-2,...] [-f ISSUE]"
+ echo "$prog - utility to bump pkgver in APKBUILDs"
+ echo "usage: $prog [-hR] [-s CVE-1,CVE-2,...] [-f ISSUE]"
echo ""
echo " -h show this help"
echo " -R run abuild with -R for recursive building"
diff --git a/apkgrel.in b/apkgrel.in
index 0934847..46e189f 100644
--- a/apkgrel.in
+++ b/apkgrel.in
@@ -6,7 +6,15 @@
# Distributed under GPL-2
#
-program=${0##*/}
+abuild_ver=@VERSION@
+datadir=@datadir@
+
+if ! [ -f "$datadir/functions.sh" ]; then
+ echo "$datadir/functions.sh: not found" >&2
+ exit 1
+fi
+. "$datadir/functions.sh"
+
do_show() {
awk -F= '$1 == "pkgrel" { print $2 }' "$@"
@@ -49,7 +57,7 @@ do_nothing() {
do_usage() {
cat <<__EOF__
-Usage: $program -a|-h|-s NUM|-t|-z [-f] FILE...
+Usage: $prog -a|-h|-s NUM|-t|-z [-f] FILE...
Commands:
-a Add 1 to current pkgrel
-g Only do the change on files that have clean git status
diff --git a/checkapk.in b/checkapk.in
index 9c1d9fd..e95249e 100644
--- a/checkapk.in
+++ b/checkapk.in
@@ -6,24 +6,22 @@
# Distributed under GPL-2
#
-die() {
- echo "$@" >&2
+abuild_ver=@VERSION@
+datadir=@datadir@
+
+if ! [ -f "$datadir/functions.sh" ]; then
+ echo "$datadir/functions.sh: not found" >&2
exit 1
-}
+fi
+. "$datadir/functions.sh"
+
-msg() {
- echo "$@"
-}
-have_abuild_conf=
-for conf in /etc/abuild.conf ~/.abuild/abuild.conf; do
- if [ -f "$conf" ]; then
- . $conf && have_abuild_conf=yes
- fi
-done
-[ -z "$have_abuild_conf" ] && die "no abuild.conf found"
+if ! [ -f "$abuild_conf" ] && ! [ -f "$abuild_userconf" ]; then
+ die "no abuild.conf found"
+fi
if ! [ -f APKBUILD ]; then
die 'This must be run in the directory of a built package.'
diff --git a/functions.sh b/functions.sh
deleted file mode 100644
index 032a7e6..0000000
--- a/functions.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-
-#colors
-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
-
-
-# functions
-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
-}
-
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
+}
diff --git a/newapkbuild.in b/newapkbuild.in
index 1a41ae9..0f95f19 100755
--- a/newapkbuild.in
+++ b/newapkbuild.in
@@ -6,22 +6,15 @@
# Distributed under GPL-2
#
-version=@VERSION@
-sysconfdir=@sysconfdir@
+abuild_ver=@VERSION@
datadir=@datadir@
-prog=${0##*/}
+if ! [ -f "$datadir/functions.sh" ]; then
+ echo "$datadir/functions.sh: not found" >&2
+ exit 1
+fi
+. "$datadir/functions.sh"
-# Source $PACKAGER
-for i in $sysconfdir/abuild.conf $HOME/.abuild/abuild.conf; do
- if [ -f "$i" ]; then
- . $i
- fi
-done
-
-error() {
- echo "$@" >&2
-}
is_url() {
case "$1" in
@@ -260,7 +253,7 @@ __EOF__
}
usage() {
- echo "$prog $version"
+ echo "$prog $abuild_ver"
echo "usage: $prog [-cfh] [-d DESC] [-l LICENSE] [-n NAME] [-u URL] PKGNAME[-PKGVER]|SRCURL"
echo "Options:"
echo " -a Create autotools (use ./configure ...)"