Commit e5101816 authored by Natanael Copa's avatar Natanael Copa
Browse files

abuild-keygen: make cp non-interactive with -n

only use interactive copy when -n is omitted, so abuild-keygen --install
becomes non-interactive.

Add tests for both ineractive and non-interactive --install.

Fixes #10049
parent 62066fa2
......@@ -33,7 +33,7 @@ get_privkey_file() {
default_name="${emailaddr:-$USER}-$(printf "%x" $(date +%s))"
privkey="$ABUILD_USERDIR/$default_name.rsa"
if [ -n "$non_interactive" ]; then
if [ -z "$interactive" ]; then
return 0
fi
msg "Generating public/private rsa key pair for abuild"
......@@ -60,8 +60,8 @@ do_keygen() {
if [ -n "$install_pubkey" ]; then
msg "Installing $pubkey to /etc/apk/keys..."
$SUDO mkdir -p /etc/apk/keys
$SUDO cp -i "$pubkey" /etc/apk/keys/
$SUDO mkdir -p "${abuild_keygen_install_root}"/etc/apk/keys
$SUDO cp ${interactive:+-i} "$pubkey" "${abuild_keygen_install_root}"/etc/apk/keys/
else
msg ""
......@@ -112,7 +112,7 @@ usage() {
append_config=
install_pubkey=
non_interactive=
interactive=1
numbits=2048
quiet=
......@@ -126,7 +126,7 @@ while true; do
case $1 in
-a|--append) append_config=1;;
-i|--install) install_pubkey=1;;
-n) non_interactive=1;;
-n) unset interactive ;;
-b|--numbits) numbits="$2"; shift 1;;
-q|--quiet) quiet=1;; # suppresses msg
-h|--help) usage; exit;;
......
......@@ -4,6 +4,7 @@ setup() {
tmpdir="$BATS_TMPDIR"/abuild-keygen
export ABUILD_USERDIR="$tmpdir"/user
mkdir -p "$ABUILD_USERDIR"
export abuild_keygen_install_root=${ABUILD_USERDIR}
# provide a fake git
mkdir -p "$tmpdir"/bin
......@@ -37,3 +38,11 @@ teardown() {
[ $status -ne 0 ]
}
@test "abuild-keygen: --install option (interactive)" {
yes | SUDO= $ABUILD_KEYGEN --install
}
@test "abuild-keygen: --install -n (non-interacive)" {
SUDO= $ABUILD_KEYGEN --install -n
  • You'd probably have to run $ABUILD_KEYGEN twice here (with timeout) to actually trigger the behavior that causes it to hang. Just once is not enough.

Please register or sign in to reply
}
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