Commit cfa6c7d6 authored by Dubiousjim's avatar Dubiousjim Committed by Natanael Copa

various: fancier readconfig, permit env overrides

parent 89afa417
......@@ -30,7 +30,7 @@ get_privkey_file() {
default_name="${emailaddr:-$USER}-$(printf "%x" $(date +%s))"
privkey="$abuild_home/$default_name.rsa"
privkey="$ABUILD_USERDIR/$default_name.rsa"
[ -n "$non_interactive" ] && return 0
msg "Generating public/private rsa key pair for abuild"
echo -n "Enter file in which to save the key [$privkey]: "
......@@ -42,7 +42,7 @@ get_privkey_file() {
}
do_keygen() {
mkdir -p "$abuild_home"
mkdir -p "$ABUILD_USERDIR"
get_privkey_file
pubkey="$privkey.pub"
......@@ -68,14 +68,14 @@ do_keygen() {
fi
if [ -n "$append_config" ]; then
if [ -f "$abuild_userconf" ]; then
if [ -f "$ABUILD_USERCONF" ]; then
# comment out the existing values
sed -i -e 's/^PACKAGER_PRIVKEY=/\#&/' "$abuild_userconf"
sed -i -e 's/^PACKAGER_PRIVKEY=/\#&/' "$ABUILD_USERCONF"
fi
echo "PACKAGER_PRIVKEY=\"$privkey\"" >> "$abuild_userconf"
echo "PACKAGER_PRIVKEY=\"$privkey\"" >> "$ABUILD_USERCONF"
else
msg ""
msg "You might want add following line to $abuild_userconf:"
msg "You might want add following line to $ABUILD_USERCONF:"
msg ""
msg "PACKAGER_PRIVKEY=\"$privkey\""
msg ""
......@@ -92,7 +92,7 @@ usage() {
$prog $abuild_ver - generate signing keys
Usage: $prog [-a|--append] [-i|--install] [-n]
Options:
-a, --append Set PACKAGER_PRIVKEY=<generated key> in $abuild_userconf
-a, --append Set PACKAGER_PRIVKEY=<generated key> in $ABUILD_USERCONF
-i, --install Install public key into /etc/apk/keys using sudo
-n Non-interactive. Use defaults
-q, --quiet
......
......@@ -85,9 +85,9 @@ if [ -z "$privkey" ]; then
cat >&2 << __EOF__
No private key found. Use 'abuild-keygen' to generate the keys.
Then you can either:
* set the PACKAGER_PRIVKEY in $abuild_userconf
* set the PACKAGER_PRIVKEY in $ABUILD_USERCONF
('abuild-keygen -a' does this for you)
* set the PACKAGER_PRIVKEY in $abuild_conf
* set the PACKAGER_PRIVKEY in $ABUILD_CONF
* specify the key with the -k option to $prog
__EOF__
......
......@@ -31,7 +31,7 @@ if [ $# -gt 0 ]; then
exit 2
fi
if ! [ -f "$abuild_conf" ] && ! [ -f "$abuild_userconf" ]; then
if ! [ -f "$ABUILD_CONF" ] && ! [ -f "$ABUILD_USERCONF" ]; then
die "no abuild.conf found"
fi
......
......@@ -3,20 +3,67 @@
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
readconfig() {
local _APORTSDIR _BUILDDIR _PKGDEST _SRCPKGDEST _REPODEST _SRCDEST
local _CARCH _CHOST _CTARGET _CPPFLAGS _CFLAGS _CXXFLAGS _LDFLAGS
local _JOBS _MAKEFLAGS _PACKAGER _USE_COLORS
local gitbase=
[ -n "${APORTSDIR+x}" ] && _APORTSDIR=$APORTSDIR
[ -n "${BUILDDIR+x}" ] && _BUILDDIR=$BUILDDIR
[ -n "${PKGDEST+x}" ] && _PKGDEST=$PKGDEST
[ -n "${SRCPKGDEST+x}" ] && _SRCPKGDEST=$SRCPKGDEST
[ -n "${REPODEST+x}" ] && _REPODEST=$REPODEST
[ -n "${SRCDEST+x}" ] && _SRCDEST=$SRCDEST
[ -n "${CARCH+x}" ] && _CARCH=$CARCH
[ -n "${CHOST+x}" ] && _CHOST=$CHOST
[ -n "${CTARGET+x}" ] && _CTARGET=$CTARGET
[ -n "${CPPFLAGS+x}" ] && _CPPFLAGS=$CPPFLAGS
[ -n "${CFLAGS+x}" ] && _CFLAGS=$CFLAGS
[ -n "${CXXFLAGS+x}" ] && _CXXFLAGS=$CXXFLAGS
[ -n "${LDFLAGS+x}" ] && _LDFLAGS=$LDFLAGS
[ -n "${JOBS+x}" ] && _JOBS=$JOBS
[ -n "${MAKEFLAGS+x}" ] && _MAKEFLAGS=$MAKEFLAGS
[ -n "${PACKAGER+x}" ] && _PACKAGER=$PACKAGER
[ -n "${USE_COLORS+x}" ] && _USE_COLORS="$USE_COLORS"
: ${ABUILD_CONF:=$sysconfdir/abuild.conf}
: ${ABUILD_USERDIR:=$HOME/.abuild}
: ${ABUILD_USERCONF:=$ABUILD_USERDIR/abuild.conf}
[ -f "$ABUILD_CONF" ] && . "$ABUILD_CONF"
[ -f "$ABUILD_USERCONF" ] && . "$ABUILD_USERCONF"
APORTSDIR=${_APORTSDIR-$APORTSDIR}
gitbase=$(git rev-parse --show-toplevel 2>/dev/null) # already is -P
if [ -d "$APORTSDIR" ]; then
APORTSDIR=$(cd "$APORTSDIR"; pwd -P)
elif [ -z "$APORTSDIR" ] && [ -d "$HOME/aports" ]; then
APORTSDIR=$(cd "$HOME/aports"; pwd -P)
else
if [ -n "$gitbase" ]; then
case $(git config remote.origin.url) in
*/aports) APORTSDIR=$gitbase ;;
*) APORTSDIR= ;;
esac
else
APORTSDIR=
fi
fi
BUILDDIR=${_BUILDDIR-$BUILDDIR}
PKGDEST=${_PKGDEST-$PKGDEST}
SRCPKGDEST=${_SRCPKGDEST-$SRCPKGDEST}
REPODEST=${_REPODEST-$REPODEST}
SRCDEST=${_SRCDEST-$SRCDEST}
CARCH=${_CARCH-$CARCH}
CHOST=${_CHOST-$CHOST}
CTARGET=${_CTARGET-$CTARGET}
CPPFLAGS=${_CPPFLAGS-$CPPFLAGS}
CFLAGS=${_CFLAGS-$CFLAGS}
CXXFLAGS=${_CXXFLAGS-$CXXFLAGS}
LDFLAGS=${_LDFLAGS-$LDFLAGS}
JOBS=${_JOBS-$JOBS}
MAKEFLAGS=${_MAKEFLAGS-$MAKEFLAGS}
PACKAGER=${_PACKAGER-$PACKAGER}
USE_COLORS=${_USE_COLORS-$USE_COLORS}
}
readconfig
# expects $1 to be a package directory in the aports tree ('foo' or 'main/foo')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment