Bug#422088: [Patch] wish preseed_fetch could distinguish between non-existance of a requested file and other failures to fetch file.
Package: preseed-common
Severity: wishlist
Version: 1.29
Attached is a patch against d-i SVN trunk so that file_preseed can
distinuish between a failure to fetch a file because it does not exist
and any other failure.
If a file does not exist then exit status is 4 otherwise it is 1.
I chose 4 as shorthand for HTTP 404 error.
This should be backwards compatable with existing code that just
checks for sucsess/fail.
New code (I'm thinking custom preseed systems here) can then pase the
exit code.
A custom preseed setup could have 2 dirs such as:
$base/standard
$base/local
a master preseed script could then try to do
"preseed_fetch $base/local/script"
and if this exits with status 4 fall back to
"preseed_fetch $base/standard/script"
If some other failure occurs the master preseed script can act accordingly.
I'm thinking of the "Hands-Off" preseed system here.
Feel free to change the exit code 4 to someother non-zero value if you will!
I'm afraid this code is as yet untested.
Regards
Alex Owen
Index: preseed/fetch-methods/file
===================================================================
--- preseed/fetch-methods/file (revision 46683)
+++ preseed/fetch-methods/file (working copy)
@@ -1,6 +1,8 @@
protocol_fetch() {
FILE="${1#file://*}"
- if [ ! -e "$FILE" ] || ! cp "$FILE" $2; then
+ if [ ! -e "$FILE" ] ; then
+ return 4
+ elif ! cp "$FILE" $2; then
return 1
else
return 0
Index: preseed/fetch-methods/http
===================================================================
--- preseed/fetch-methods/http (revision 46683)
+++ preseed/fetch-methods/http (working copy)
@@ -1,6 +1,7 @@
protocol_fetch() {
local url="$1"
local file="$2"
+ local log=/tmp/preseed_fetch_http
iters=0
# use the proxy for wgets (should speed things up)
@@ -10,10 +11,15 @@
while [ $iters -lt 3 ]; do
# TODO add progress bar
- if wget -q "$url" -O "$file"; then
+ if wget -q "$url" -O "$file" 2>$log ; then
+ rm -f $log
return 0
+ elif grep "server returned error 404" $log >/dev/null ; then
+ rm -f $log
+ return 4
fi
iters=$(($iters + 1))
done
+ rm -f $log
return 1
}
Index: preseed/fetch-methods/floppy
===================================================================
--- preseed/fetch-methods/floppy (revision 46683)
+++ preseed/fetch-methods/floppy (working copy)
@@ -4,7 +4,9 @@
mountfloppy || true
touch /var/run/preseed-usedfloppy
- if [ ! -e "$FILE" ] || ! cp "$FILE" $2; then
+ if [ ! -e "$FILE" ] ; then
+ return 4
+ elif ! cp "$FILE" $2; then
return 1
else
return 0
Reply to: