blob: c0f51d40e144d5bae3b6c1408d3231e2185f41d6 [file] [log] [blame]
#!/bin/bash
##
## Copied from:
## https://github.com/google/android-cuttlefish/blob/main/download-aosp.sh
##
set -o errexit
function print_help {
echo " $0 <options>"
echo " Options:"
echo " -a | --arch : architecture to download for: x86, x86_64, arm64"
echo " -A | --android : download the Android OS images (by default disabled)"
echo " -C | --cuttlefish : download the Cuttlefish host images (by default disabled)"
echo " -X | --no-extract : don't extract the downloaded archive (by default extracted)"
echo " -h | --help : print this help message"
}
function parse_opts() {
local help=0
local params
if params=$(getopt -o 'a:AChX' -l 'arch:,android,cuttlefish,help,no-extract' --name "$0" -- "$@"); then
eval set -- "${params}"
while true; do
case "$1" in
-a|--arch)
ARCH=$2
case "${ARCH}" in
x86)
THROTTLED=
;;
x86_64)
THROTTLED='-throttled'
;;
arm64|aarch64)
ARCH='arm64'
THROTTLED='-throttled'
;;
*)
echo "Uknown architecture ${ARCH}" 1>&2
help=1
;;
esac
shift 2
;;
-A|--android)
DOWNLOAD_ANDROID=1
shift
;;
-C|--cuttlefish)
DOWNLOAD_CF=1
shift
;;
-h|--help)
help=1
shift
;;
-X|--no-extract)
EXTRACT=0
shift
;;
--)
shift
break
;;
esac
done
fi
if [ -z "${ARCH}" ]; then
echo "You must specify an architecture." 1>&2
help=1
fi
if [[ "${DOWNLOAD_ANDROID}" -eq 0 && "${DOWNLOAD_CF}" -eq 0 ]]; then
echo "You are not downloading anything. Select -A and/or -C" 1>&2
help=1
fi
if [ "${help}" -eq 1 ]; then
print_help
exit 1
fi
}
DOWNLOAD_ANDROID=0
DOWNLOAD_CF=0
EXTRACT=1
parse_opts $*
URL=https://ci.android.com/builds/latest/branches/aosp-master${THROTTLED}/targets/aosp_cf_${ARCH}_phone-userdebug/view/BUILD_INFO
RURL=$(curl -Ls -o /dev/null -w %{url_effective} ${URL})
if [ "${DOWNLOAD_ANDROID}" -eq 1 ]; then
echo "#"
echo "# Downloading the latest Android images from AOSP"
echo "#"
set -x
IMG=aosp_cf_${ARCH}_phone-img-$(echo $RURL | awk -F\/ '{print $6}').zip
wget -nv ${RURL%/view/BUILD_INFO}/raw/${IMG}
if [ "${EXTRACT}" -eq 1 ]; then
unzip "${IMG}"
rm -v "${IMG}"
fi
set +x
fi
if [ "${DOWNLOAD_CF}" -eq 1 ]; then
echo "#"
echo "# Downloading the latest Cuttlefish images from AOSP"
echo "#"
set -x
wget -nv ${RURL%/view/BUILD_INFO}/raw/cvd-host_package.tar.gz
if [ "${EXTRACT}" -eq 1 ]; then
tar xzvf cvd-host_package.tar.gz
rm -v cvd-host_package.tar.gz
fi
set +x
fi