blob: 9359e18e6590d999b86a46ab529224751cef0bb1 [file] [log] [blame]
#!/bin/bash
#
# upload assets from the out (as generated by build-all.sh and
# reported as needing upload by ready4lorry.sh
#
# one at a time
# invocation:
# upload2lorry.sh <local-file> <destination path>
# e.g.
# upload2lorry.sh \
# out/frameworks/av/media/module/mpeg2ts/test/Mpeg2tsUnitTest-1.0.zip
# https://dl.google.com/android-unittest/media/frameworks/av/media/module/mpeg2ts/test/Mpeg2tsUnitTest-1.0.zip
#
# i want the https://dl.google.com piece to be optional
# ready4lorry provides it, but I don't need it as part of the upload process
#
# TODO
# figure out perhaps reading from a script, in addition to single invocation
#
# per wenshan:
# stubby call blade:download-lorry-api LorryService.CreatePayloads \
# 'autoapprove: true \
# payload: <url_path: "{the URL}" \
# source_path: "{the Path}" \
# restrictions: <serve_domain: "CORE" serve_domain: "CN">>'
local_file=$1
url=$2
if [ "${local_file}" = "" -o "${url}" = "" ] ; then
echo Missing parameters
echo "Usage: $0 <localfile> <destination-url>"
exit 1
fi
if [ ! -f ${local_file} ] ; then
echo "File Not Found: ${local_file}"
exit 1
fi
url_prefix="https://dl.google.com"
case ${url} in
https://dl.google.com/*)
url0=${url}
url=${url#${url_prefix}}
echo "Mapped from ${url0}"
echo " to ${url}"
;;
*)
echo "Unrecognized destination: ${url}"
exit 1
;;
esac
if [ "${USER}" = "" ] ; then
echo unable to get a value for USER
exit 1
fi
# copy the local file over to CNS
filename=`echo ${local_file} | sed -e 's,/,.,g'`
cns_dir=/cns/sandbox/home/${USER}
cns_file=${cns_dir}/${filename}
fileutil test -d ${cns_dir}
existence=$?
if [ ${existence} != 0 ] ; then
echo "creating staging directory ${cns_dir}"
fileutil mkdir ${cns_dir} || exit 3
fi
fileutil cp ${local_file} ${cns_file} || exit 4
# autoapprove works as of 2023/09/19
stubby call blade:download-lorry-api LorryService.CreatePayloads \
'autoapprove: true payload: <url_path: "'${url}'" source_path: "'${cns_file}'" restrictions: <serve_domain: "CORE" serve_domain: "CN">>'
result=$?
echo "upload result: ${result}"
# be a good citizen, clean up after ourselves in /cns
fileutil rm -f ${cns_file}
exit ${result}