Improve first time download of ubuntu images.
If a cached copy of the file doesn't exist, cache_url() passes a non-existent path to -z/--time-cond and you see this warning: Warning: Illegal date format for -z, --timecond (and not a file name). Warning: Disabling time condition. See curl_getdate(3) for valid date syntax. It works just fine, but the warning is ugly. Change-Id: Ic6f13a2c596b988308d7fca9cd1745e5d48ae5fb
This commit is contained in:
parent
207aeced03
commit
efb1f435d4
1 changed files with 12 additions and 2 deletions
|
@ -18,10 +18,20 @@ cache_url()
|
|||
{
|
||||
local url=$1
|
||||
local dest=$2
|
||||
|
||||
mkdir -p $(dirname $dest)
|
||||
local tmp=$(mktemp $(dirname $dest)/.download.XXXXXXXX)
|
||||
rcode=$(curl -o $tmp -z $dest -w '%{http_code}' $url)
|
||||
|
||||
if [ -f $dest ] ; then
|
||||
time_cond="-z $dest"
|
||||
success="Server copy has changed. Using server version of $url"
|
||||
else
|
||||
success="Downloaded and cached $url for the first time"
|
||||
fi
|
||||
|
||||
rcode=$(curl -o $tmp -w '%{http_code}' $url $time_cond)
|
||||
if [ "$rcode" == "200" ] ; then
|
||||
echo "Server copy has changed. Using server version of $url"
|
||||
echo $success
|
||||
mv $tmp $dest
|
||||
elif [ "$rcode" == "304" ] ; then
|
||||
echo "Server copy has not changed. Using locally cached $url"
|
||||
|
|
Loading…
Reference in a new issue