Martin Samuelsson <debianbts2020@nurysto.netizen.se> writes:
> I'm saying there is no /dev/fd/ at all
Oh, fair enough. That's odd.
BTW The example I pasted was just busybox running on my laptop running
full Debian, so was not supposed to be demonstrating it working under
d-i.
...
> --- http.orig 2020-09-21 17:21:24.159480072 +0200
> +++ http.simplified 2020-09-21 17:21:03.951356698 +0200
> @@ -14,10 +14,10 @@
>
> local RETVAL=$( {
> echo 1
> - wget "$@" 2>&1 >&3 && echo %OK%
> + wget "$@" 2>&1 && echo %OK%
> echo %EOF%
> - } | ( sed -ne '1{h;d};/'"$file_not_found_pattern"'/{p;s/.*/4/;h;d};/^%OK%$/{s/.*/0/;h;d};$!p;$x;$w /dev/fd/4' >&2 ) 4>&1
> - ) 3>&1
> + } | ( sed -ne '1{h;d};/'"$file_not_found_pattern"'/{p;s/.*/4/;h;d};/^%OK%$/{s/.*/0/;h;d};$!p;$x;$p '>&2 )
> + )
> return $RETVAL
> }
This mixes the stdout of wget with the %OK% %EOF% stuff, and then puts
it all into the sed, which seems flawed.
One could replace the >&3 with >/dev/null, and keep the sed, but if one
isn't trying to preserve the wget output I don't see the point of
keeping the sed at all.
I'd have thought something like this would do the trick (not tested yet):
local RETVAL=$(
{
{
wget "$@" 2>&1 >/dev/null && echo 0 >&3
} | {
grep -q "$file_not_found_pattern" && echo 4 >&3
} || echo 1 >&3
} 3>&1 | head -1
)
(the patterns will need to be tweaked to take account of sed vs. grep)
One could of course use stderr for that (>&2 ... 2>&1) for getting the
echo-ed return codes out, rather than fd #3, but I think this is clearer
(since one really isn't trying to produce stderr output) and AFAIK it
should work fine even if /dev/fd/ is missing.
I suspect there may be a way of getting this to work without the need
for a local variable and the echoing for the result codes, so I will
ponder on that...
BTW I just saw Ben's comment that we should just fix the missing /dev/fd
which strikes me as entirely sensible. Even if nothing uses /dev/fd/ in
d-i (other than here) it seems wrong to simply ignore the fact that it's
missing, since people might well try to use it in preseed scripts etc.
Cheers, Phil.
--
|)| Philip Hands [+44 (0)20 8530 9560] HANDS.COM Ltd.
|-| http://www.hands.com/ http://ftp.uk.debian.org/
|(| Hugo-Klemm-Strasse 34, 21075 Hamburg, GERMANY
Attachment:
signature.asc
Description: PGP signature