various: move conf-loading and i/o to functions

This commit is contained in:
Dubiousjim 2013-07-05 00:21:16 -04:00 committed by Natanael Copa
parent 144ee3f113
commit db1314ac55
8 changed files with 128 additions and 101 deletions

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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.'

View File

@ -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
}

76
functions.sh.in Normal file
View File

@ -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
}

View File

@ -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 ...)"