diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 00:39:23 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 00:39:23 +0000 |
commit | e3b16b3856bdd5c1645f4609d61bf5a16c026930 (patch) | |
tree | d9def3b6f6f46b166fc6f516775350fedeefbef6 /test/lib_test_uscan | |
parent | Initial commit. (diff) | |
download | devscripts-upstream/2.19.5+deb10u1.tar.xz devscripts-upstream/2.19.5+deb10u1.zip |
Adding upstream version 2.19.5+deb10u1.upstream/2.19.5+deb10u1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/lib_test_uscan')
-rw-r--r-- | test/lib_test_uscan | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/test/lib_test_uscan b/test/lib_test_uscan new file mode 100644 index 0000000..3532f70 --- /dev/null +++ b/test/lib_test_uscan @@ -0,0 +1,97 @@ +#!/bin/bash + +# Copyright (C) 2018, Xavier <yadd@debian.org> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# On Debian systems, the complete text of the GNU General Public License +# version 3 can be found in the /usr/share/common-licenses/GPL-3 file. + +echo '=======================================================================' +echo "*** uscan $TESTTYPE test ***" +echo '=======================================================================' + +test_dir=$(readlink -f "${0%/*}") + +# Operation mode +if test "${1:-}" = --installed; then + shift +else + top_srcdir=$(readlink -f "${0%/*}/..") + make -C "$top_srcdir/scripts" uscan mk-origtargz uupdate debchange + PATH="$top_srcdir/scripts:$PATH" + export PATH + PERL5LIB="$top_srcdir/lib" + export PERL5LIB +fi + +GPGHOME=$(mktemp -d -t gpg.XXXXX) + +GPG=gpg +if ! command -v $GPG >/dev/null 2>&1; then + echo "$GPG missing" + GPG=gpg2 + if ! command -v $GPG >/dev/null 2>&1; then + echo "$GPG missing" + exit 1 + fi +fi + +PRIVATE_KEY=$test_dir/uscan/PRIVATE_KEY.asc +PUBLIC_KEY=$test_dir/uscan/PUBLIC_KEY.asc +PRIVATE_KEYRING=$GPGHOME/secring.gpg +PUBLIC_KEYRING=$GPGHOME/pubring.gpg + +# magic function that pipes stdout and stderr into a pipe, and prints it only +# on command failure. +# This uses a pipe, so it has limited capacity. Do not use it with stuff +# outputting too much data. +chronic_sh (){ + local pipe + pipe=$(mktemp -u) + mkfifo "$pipe" + # one can't open a reading fd and a writing fd without blocking, because + # they want to already have something on the other side of the pipe. + # the temporary fd 5 will be that something. + exec 5<>"$pipe" # hack + exec 3>"$pipe" # writing fd + exec 4<"$pipe" # reading fd + exec 5>&- # end hack + rm "$pipe" + + if ! "$@" >&3 2>&3 ; then + exec 3>&- + cat <&4- + return 1 + fi +} + +oneTimeSetUp () { + chronic_sh $GPG -v --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \ + --output "$PRIVATE_KEYRING" --dearmor "$PRIVATE_KEY" + + chronic_sh $GPG -v --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \ + --output "$PUBLIC_KEYRING" --dearmor "$PUBLIC_KEY" + + echo "Using test gpg key:" + $GPG --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \ + --secret-keyring "$PRIVATE_KEYRING" --default-key \ + CF218F0E7EABF584B7E20402C77E2D6872543FAF \ + --list-keys --verbose + + export GNUPGHOME=$GPGHOME +} + +oneTimeTearDown () { + gpgconf --homedir "$GPGHOME" --verbose --kill gpg-agent + rm -rf "$GPGHOME" +} + |