PS4='$(date "+%s.%N ($LINENO) + ")'
set -x
elif [ "$IMAGE_DEBUG" != "no" ]; then
- echo "Warning: Unsupported IMAGE_DEBUG value: \`$IMAGE_DEBUG'"
+ log_warning "Unsupported IMAGE_DEBUG value: \`$IMAGE_DEBUG'"
fi
monitor_pipe=$(mktemp -u)
trap report_and_cleanup EXIT
+echo "Processing image with ID: \`$IMG_ID' and type: \`$IMAGE_TYPE'" >&2
+
case $BACKEND_TYPE in
local)
- image_file="$IMAGE_DIR/$(echo "$IMAGE_NAME" | sed 's/^file://').$IMAGE_TYPE"
- if [ ! -e "$image_file" ]; then
- log_error "Image file \`$image_file' does not exit."
+ if [[ "$IMAGE_NAME" =~ ^local:// ]]; then
+ IMAGE_NAME="${IMAGE_NAME:8}"
+ elif [[ "$IMAGE_NAME" =~ ^file:// ]]; then
+ IMAGE_NAME="${IMAGE_NAME:7}"
+ log_warning "The file:// back-end identifier is deprecated and" \
+ "will be removed in the future. Use local:// instead."
+ fi
+
+ canonical_image_dir="$(canonicalize "$IMAGE_DIR")"
+ if [ ! -d "$canonical_image_dir" ]; then
+ log_error "The IMAGE_DIR directory: \`$IMAGE_DIR' does not exist."
report_error "Unable to retrieve image file."
+ fi
+
+ image_file="$IMAGE_DIR/$IMAGE_NAME"
+ if [ ! -e "$image_file" ]; then
+ if [ -e "$image_file.$IMAGE_TYPE" ] ; then
+ image_file="$image_file.$IMAGE_TYPE"
+ log_warning "The \`.$IMAGE_TYPE' extension is missing from" \
+ "the local back-end id. This id form is deprecated and" \
+ " will be remove in the future."
+ else
+ log_error "Image file \`$image_file' does not exist."
+ report_error "Unable to retrieve image file."
+ exit 1
+ fi
+ fi
+
+ canonical_image_file="$(canonicalize "$image_file")"
+
+ if [[ "$canonical_image_file" != "$canonical_image_dir"* ]]; then
+ log_error "Image ID points to a file outside the image directory: \`$IMAGE_DIR'"
+ report_error "Invalid image ID"
exit 1
fi
+
image_size="$(stat -L -c %s "$image_file")"
;;
null)
BACKEND_TYPE="local"
;;
network)
- image_cmd="$CURL $(printf "%q" "$IMAGE_NAME") 2> /dev/null"
+ image_cmd="$CURL $(printf "%q" "$IMAGE_NAME")"
image_size=$($CURL -sI "$IMAGE_NAME" | grep ^Content-Length: | cut -d" " -f2)
;;
pithos)