X-Original-To: alpine-devel@lists.alpinelinux.org Delivered-To: alpine-devel@mail.alpinelinux.org Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.alpinelinux.org (Postfix) with ESMTPS id DFD0FDC726E for ; Fri, 5 Jul 2013 04:21:49 +0000 (UTC) Received: from compute5.internal (compute5.nyi.mail.srv.osa [10.202.2.45]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 882C0204EC for ; Fri, 5 Jul 2013 00:21:44 -0400 (EDT) Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161]) by compute5.internal (MEProxy); Fri, 05 Jul 2013 00:21:44 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=from:to:subject:date:message-id :in-reply-to:references; s=smtpout; bh=Ki6OarRWG7dH5Bkm0tMBsVtxo dU=; b=VAAj3z93uKdmqBw0OHDW8byWJ6T5U7AavRPeJ0U1Fi6YqnZA9PxIU879e p1Ri62VSJzvmbUWwbbRWBt9Yg0uujep3VXdIvT8M9csC+WNOsavOURXx72hHNXMZ qx8wTQy+0x8tlbWBbYmqx3jeL9RI2lim+wjjYMpgSsI9YlqmCo= X-Sasl-enc: M59kJS3Q9iKbwDsR1+CRfEKekqdzI+H/N9WGbvOi9R6M 1372998104 Received: from localhost (unknown [69.86.161.244]) by mail.messagingengine.com (Postfix) with ESMTPA id 3CFC5680204 for ; Fri, 5 Jul 2013 00:21:44 -0400 (EDT) From: Dubiousjim To: alpine-devel@lists.alpinelinux.org Subject: [alpine-devel] [PATCH 07/31] various: move conf-loading and i/o to functions Date: Fri, 5 Jul 2013 00:21:16 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Mailinglist: alpine-devel Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: --- abuild-keygen.in | 20 +++++---------- abuild-sign.in | 19 ++++---------- abump.in | 23 +++++++++-------- apkgrel.in | 12 +++++++-- checkapk.in | 24 ++++++++---------- functions.sh | 34 ------------------------- functions.sh.in | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ newapkbuild.in | 21 ++++++---------- 8 files changed, 128 insertions(+), 101 deletions(-) delete mode 100644 functions.sh create mode 100644 functions.sh.in 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 ...)" -- 1.8.3.1 --- Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org Help: alpine-devel+help@lists.alpinelinux.org ---