debian-cd-clone/tools/grab_file

35 lines
836 B
Bash
Executable File

#!/bin/sh
#
# grab_file
#
# extra utility script - if a file does not exist in our mirror and
# we've been told to use an http mirror, go grab it from there
#
# Takes <n> parameters: the full path to the files required (relative
# to the base dir of the mirror)
#
# The MIRROR env var must be set
# If we want to be able to download, HTTPMIRROR mus be set too
set -e
#set -x
if [ "$MIRROR"x = ""x ] ; then
echo $0: MIRROR not set
exit 1
fi
for WANTED in $@; do
WANTED=$(echo $WANTED | sed "s,^$MIRROR/,,")
if [ ! -e "$MIRROR/$WANTED" ] ; then
DIR=$(dirname "$WANTED")
mkdir -p "$MIRROR/$DIR"
wget -o /tmp/log "$HTTPMIRROR/$WANTED" -O "$MIRROR/$WANTED"
# Check that the file is non-zero in size
if [ -e "$MIRROR/$WANTED" ] && [ ! -s "$MIRROR/$WANTED" ] ; then
rm -f "$MIRROR/$WANTED"
fi
fi
done