#!/bin/sh ################################################################################ # DO NOT ALTER THIS LINE VERSION=11 ################################################################################ SERVER=realearth.ssec.wisc.edu:80 showHelp() { echo "" echo "$0 [-hufprv] [-s server:port] file [name] [date] [time]" echo "" echo " -h: Show help" echo " -u: Check for update" echo "" echo " -f: Force overwrite if there is a conflict" echo " -p: Designate file as part of a larger product" echo "" echo " -r: Send through head node proxy" echo " -s: Specify the server and port ([server:port] required)" echo "" echo " -v: Be verbose" echo "" echo " file: Path to file" echo " Format: /path/to/[name]_[YYYYMMDD]_[HHMMSS].???" echo "" echo " name: Specify the product name" echo " Required when the file name does not contain [name]" echo " Format: Cannot contain '_'" echo " date: Specify the date" echo " Required when the file name does not contain [date]" echo " Format: YYYYMMDD" echo " time: Specify the time" echo " Required when the file name does not contain [time]" echo " Format: HHMMSS" echo "" } checkUpdate() { DL_URL="http://${SERVER}/wmsupload" URL="$DL_URL?version=${VERSION}" VERSION_CHECK=`curl -s ${URL}` if [ -n "${VERSION_CHECK}" ]; then echo "A new version is available at:" echo " ${DL_URL}" echo "Download with:" echo " curl ${DL_URL} -o $0" else echo "This version is up to date" fi } # Get the options from the command line WMS_FORCE=0 WMS_PART=0 WMS_PROXY=0 WMS_VERBOSE=0 if [ -z "$1" ]; then showHelp exit 0 fi while getopts hufprvs: o; do case "$o" in h) showHelp exit 0 ;; u) checkUpdate exit 0 ;; f) WMS_FORCE=1 ;; p) WMS_PART=1 ;; r) WMS_PROXY=1 ;; v) WMS_VERBOSE=1 ;; s) SERVER=${OPTARG} ;; *) showHelp exit 1 ;; esac done shift $((${OPTIND} -1)) # Set our variables WMS_FILE=$1 WMS_NAME=$2 WMS_DATE=$3 WMS_TIME=$4 # Does the file exist? if [ ! -f "${WMS_FILE}" ]; then echo "ERROR: Could not find file: ${WMS_FILE}" exit 1 fi # Set the defaults for sending WMS_FILE_DIR=`dirname "${WMS_FILE}"` WMS_FILE_NAME=`basename "${WMS_FILE}"` # Verify the product name if [ -n "${WMS_NAME}" ]; then match=`expr "${WMS_NAME}" : '\([a-zA-Z0-9\-]\{1,\}\)'` if [ "$match" != "${WMS_NAME}" ]; then echo "" echo "ERROR: Invalid product name" showHelp exit 1 fi fi # Verify the product date if [ -n "${WMS_DATE}" ]; then match=`expr "${WMS_DATE}" : '\([0-9]\{8\}\)'` if [ "$match" != "${WMS_DATE}" ]; then echo "" echo "ERROR: Invalid product date" showHelp exit 1 fi fi # Verify the product time if [ -n "${WMS_TIME}" ]; then match=`expr "${WMS_TIME}" : '\([0-9]\{6\}\)'` if [ "$match" != "${WMS_TIME}" ]; then echo "" echo "ERROR: Invalid product time" showHelp exit 1 fi fi # Get the direct upload name (unless -r was specified) if [ ${WMS_PROXY} -eq 0 ]; then SERVER_DIRECT= if [ -n "${WMS_NAME}" ]; then SERVER_DIRECT=`curl -s http://${SERVER}/wmsupload?name=${WMS_NAME}` else SERVER_DIRECT=`curl -s http://${SERVER}/wmsupload?file=${WMS_FILE_NAME}` fi if [ -n "${SERVER_DIRECT}" ]; then SERVER=${SERVER_DIRECT} else if [ ${WMS_VERBOSE} -ne 0 ]; then echo "WARNING: Could not determine the head node URL for proxy upload" fi fi fi # Change to the dir with the file cd "${WMS_FILE_DIR}" echo "Connecting to ${SERVER}..." # Check if the server is ready to receive the file if [ ${WMS_VERBOSE} -ne 0 ]; then echo "Checking upload availability" fi BYTES=`/bin/ls -Ll "${WMS_FILE_NAME}" |/bin/awk '{print $5}'` COMMAND="curl -s http://${SERVER}/wmsupload?bytes=${BYTES}" SUCCESS=`${COMMAND} -o - 2>/dev/null |head -1` if [ "${SUCCESS}" -eq "${SUCCESS}" ] 2>/dev/null; then if [ "${SUCCESS}" = "-1" ]; then echo " Server cannot accept the file, it is too large!" exit 3 fi while [ "${SUCCESS}" != "1" ]; do echo " Server cannot accept the file at this time, trying again in 15 seconds..." sleep 15 SUCCESS=`${COMMAND} -o - |head -1` done else if [ ${WMS_VERBOSE} -ne 0 ]; then echo " Server does not understand file size check, continuing..." fi fi # Send the file echo "Sending ${WMS_FILE_NAME}" COMMAND="curl -s http://${SERVER}/upload/ -F file=@${WMS_FILE_NAME}" if [ -n "${WMS_NAME}" ]; then COMMAND="${COMMAND} -F name=${WMS_NAME}" fi if [ -n "${WMS_DATE}" ]; then COMMAND="${COMMAND} -F date=${WMS_DATE}" fi if [ -n "${WMS_TIME}" ]; then COMMAND="${COMMAND} -F time=${WMS_TIME}" fi if [ ${WMS_PART} -ne 0 ]; then COMMAND="${COMMAND} -F part=1" fi if [ ${WMS_FORCE} -ne 0 ]; then COMMAND="${COMMAND} -F force=1" fi ${COMMAND}