From bc9ec9a87e2dae96b4c818d12d2c21bec421b44d Mon Sep 17 00:00:00 2001 From: Alex Kaplan Date: Sat, 12 Sep 2015 13:53:04 -0700 Subject: [PATCH] chip-update-firmware.sh: added option -u to delete cache --- chip-update-firmware.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/chip-update-firmware.sh b/chip-update-firmware.sh index 6a79242..3e2ae7a 100755 --- a/chip-update-firmware.sh +++ b/chip-update-firmware.sh @@ -1,7 +1,7 @@ #!/bin/bash FW_DIR="$(pwd)/.firmware" FW_IMAGE_DIR="${FW_DIR}/images" -S3_URL="https://s3-ap-northeast-1.amazonaws.com/stak-images/firmware/chip/stable/5/images" +S3_URL="https://s3-ap-northeast-1.amazonaws.com/stak-images/firmware/chip/stable/latest" function require_directory { if [[ ! -d "${1}" ]]; then @@ -11,11 +11,29 @@ function require_directory { function cache_download { if [[ ! -f "${1}/${2}" ]]; then - wget -P "${FW_IMAGE_DIR}" "${S3_URL}/${2}" || + + LATEST_URL="$(wget -q -O- ${S3_URL})" + wget -P "${FW_IMAGE_DIR}" "${LATEST_URL}images/${2}" || exit 1 fi } + +while getopts ":u" opt; do + case $opt in + u) + echo "updating cache" + if [[ -d "$FW_IMAGE_DIR" ]]; then + rm -rf $FW_IMAGE_DIR + fi + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + esac +done + require_directory "${FW_IMAGE_DIR}" cache_download "${FW_IMAGE_DIR}" rootfs.ubi cache_download "${FW_IMAGE_DIR}" sun5i-r8-chip.dtb