#!/bin/bash
#
# Copyright (c) Citrix Systems 2008. All rights reserved.
#
# Upload a bugreport to the support website

DEFAULT_BASE_URL="ftp://support.xensource.com/uploads/"

INPUT_URL=$1
PROXY=$2

# If the user supplies a bare filename without a URI scheme,
# we ignore it -- if they _really_ want to upload named files
# to our support server, they can specify the URI scheme.
FILENAME=$(echo ${INPUT_URL} | sed -ne 's,^.*://.*/,,p')
BASE_URL=$(echo ${INPUT_URL} | sed -ne 's,\(^[^:]*://[^/]*\)\(/\([^/]*/\)*\)*[^/]*$,\1/\3,p')

# If no override is provided then use this default:
if [ -z "$FILENAME" ]; then
# Build the remote filename
  now=$(date --utc +"%Y:%m:%dT%H:%M:%SZ")
  . /etc/xensource-inventory
  FILENAME=${INSTALLATION_UUID}-${now}
fi
[ ! -z "${BASE_URL}" ] || BASE_URL="${DEFAULT_BASE_URL}"

URL="${BASE_URL}${FILENAME}"

export http_proxy=$PROXY
export ftp_proxy=$PROXY

logger "Uploading xen-bugtool to '$URL' (via proxy '$PROXY')"
/usr/sbin/xen-bugtool --output=tar --outfd 1 --yestoall --silent 2>/dev/null | curl -T - $URL 2>&1

