only do wget call when really necessary

This commit is contained in:
Alex Kaplan 2015-09-16 23:51:36 -07:00
parent ee1d5c8b17
commit 11b68441b1
2 changed files with 22 additions and 18 deletions

View File

@ -114,5 +114,4 @@ while [[ -z "$(fastboot devices)" ]]; do sleep 1; done
fastboot -u flash UBI ${BUILDROOT_OUTPUT_DIR}/images/rootfs.ubi fastboot -u flash UBI ${BUILDROOT_OUTPUT_DIR}/images/rootfs.ubi
fastboot continue fastboot continue
echo "stuff is in $TMPDIR" rm -rf ${TMPDIR}
exit 0

View File

@ -3,6 +3,8 @@ FW_DIR="$(pwd)/.firmware"
FW_IMAGE_DIR="${FW_DIR}/images" FW_IMAGE_DIR="${FW_DIR}/images"
S3_URL="https://s3-ap-northeast-1.amazonaws.com/stak-images/firmware/chip/stable/latest" S3_URL="https://s3-ap-northeast-1.amazonaws.com/stak-images/firmware/chip/stable/latest"
LATEST_URL=""
FLASH_SCRIPT=./chip-fel-flash.sh FLASH_SCRIPT=./chip-fel-flash.sh
function require_directory { function require_directory {
@ -13,6 +15,25 @@ function require_directory {
function cache_download { function cache_download {
if [[ ! -f "${1}/${2}" ]]; then if [[ ! -f "${1}/${2}" ]]; then
if [[ -z "$LATEST_URL" ]]; then
LATEST_URL="$(wget -q -O- ${S3_URL})"
echo "LATEST_URL=$LATEST_URL"
if [[ -z "${LATEST_URL}" ]]; then
echo "error: could not get URL for latest build from ${S3_URL} - check internet connection"
exit 1
fi
BUILD=${LATEST_URL%%/}
BUILD=${BUILD##*/}
echo "BUILD=$BUILD"
if [[ -z "${BUILD}" ]]; then
echo "error: could not extract build number from build"
exit 1
fi
fi
echo "$BUILD" > ${FW_IMAGE_DIR}/build echo "$BUILD" > ${FW_IMAGE_DIR}/build
wget -P "${FW_IMAGE_DIR}" "${LATEST_URL}images/${2}" || wget -P "${FW_IMAGE_DIR}" "${LATEST_URL}images/${2}" ||
@ -40,22 +61,6 @@ while getopts "uf" opt; do
esac esac
done done
LATEST_URL="$(wget -q -O- ${S3_URL})"
echo "LATEST_URL=$LATEST_URL"
if [[ -z "${LATEST_URL}" ]]; then
echo "error: could not get URL for latest build from ${S3_URL} - check internet connection"
exit 1
fi
BUILD=${LATEST_URL%%/}
BUILD=${BUILD##*/}
echo "BUILD=$BUILD"
if [[ -z "${BUILD}" ]]; then
echo "error: could not extract build number from build"
exit 1
fi
require_directory "${FW_IMAGE_DIR}" require_directory "${FW_IMAGE_DIR}"
cache_download "${FW_IMAGE_DIR}" rootfs.ubi cache_download "${FW_IMAGE_DIR}" rootfs.ubi
cache_download "${FW_IMAGE_DIR}" sun5i-r8-chip.dtb cache_download "${FW_IMAGE_DIR}" sun5i-r8-chip.dtb