2015-09-10 15:55:33 -04:00
|
|
|
#!/bin/bash
|
2015-09-17 02:51:36 -04:00
|
|
|
|
2015-10-23 16:25:44 -04:00
|
|
|
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
|
|
source $SCRIPTDIR/common.sh
|
|
|
|
|
2015-10-30 20:12:09 -04:00
|
|
|
if ! wait_for_fel; then
|
|
|
|
echo "ERROR: please jumper your CHIP in FEL mode then power on"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2015-09-12 20:16:25 -04:00
|
|
|
FLASH_SCRIPT=./chip-fel-flash.sh
|
2015-10-21 17:26:59 -04:00
|
|
|
WHAT=buildroot
|
2015-12-29 18:37:48 -05:00
|
|
|
BRANCH=stable
|
2015-09-12 20:16:25 -04:00
|
|
|
|
2015-09-10 15:55:33 -04:00
|
|
|
function require_directory {
|
2015-09-15 21:39:14 -04:00
|
|
|
if [[ ! -d "${1}" ]]; then
|
|
|
|
mkdir -p "${1}"
|
|
|
|
fi
|
2015-09-10 15:55:33 -04:00
|
|
|
}
|
|
|
|
|
2015-10-21 17:26:59 -04:00
|
|
|
function s3_md5 {
|
|
|
|
local URL=$1
|
|
|
|
curl -sLI $URL |grep ETag|sed -e 's/.*"\([a-fA-F0-9]\+\)["-]*.*/\1/;'
|
|
|
|
}
|
|
|
|
|
2015-09-10 15:55:33 -04:00
|
|
|
function cache_download {
|
2015-10-21 17:26:59 -04:00
|
|
|
local DEST_DIR=${1}
|
|
|
|
local SRC_URL=${2}
|
|
|
|
local FILE=${3}
|
2015-09-17 02:51:36 -04:00
|
|
|
|
2015-10-21 17:26:59 -04:00
|
|
|
if [[ -f "${DEST_DIR}/${FILE}" ]]; then
|
|
|
|
echo "${DEST_DIR}/${FILE} exists... comparing to ${SRC_URL}/${FILE}"
|
|
|
|
local S3_MD5=$(s3_md5 ${SRC_URL}/${FILE})
|
|
|
|
local MD5=$(md5sum ${DEST_DIR}/${FILE} | cut -d\ -f1)
|
|
|
|
echo "MD5: ${MD5}"
|
|
|
|
echo "S3_MD5: ${S3_MD5}"
|
|
|
|
if [[ "${S3_MD5}" != "${MD5}" ]]; then
|
|
|
|
echo "md5sum differs"
|
|
|
|
rm ${DEST_DIR}/${FILE}
|
2015-10-27 21:06:06 -04:00
|
|
|
if ! wget -P "${FW_IMAGE_DIR}" "${SRC_URL}/${FILE}"; then
|
|
|
|
echo "download of ${SRC_URL}/${FILE} failed!"
|
|
|
|
exit $?
|
|
|
|
fi
|
2015-10-21 17:26:59 -04:00
|
|
|
else
|
|
|
|
echo "file already downloaded"
|
2015-09-17 02:51:36 -04:00
|
|
|
fi
|
2015-10-21 17:26:59 -04:00
|
|
|
else
|
2015-10-27 21:06:06 -04:00
|
|
|
if ! wget -P "${FW_IMAGE_DIR}" "${SRC_URL}/${FILE}"; then
|
|
|
|
echo "download of ${SRC_URL}/${FILE} failed!"
|
|
|
|
exit $?
|
|
|
|
fi
|
2015-09-15 21:39:14 -04:00
|
|
|
fi
|
2015-09-10 15:55:33 -04:00
|
|
|
}
|
2015-09-14 21:19:01 -04:00
|
|
|
|
2015-09-12 16:53:04 -04:00
|
|
|
|
2016-01-02 05:29:53 -05:00
|
|
|
while getopts "ufdpb:w:B:" opt; do
|
2015-09-12 16:53:04 -04:00
|
|
|
case $opt in
|
|
|
|
u)
|
|
|
|
echo "updating cache"
|
|
|
|
if [[ -d "$FW_IMAGE_DIR" ]]; then
|
|
|
|
rm -rf $FW_IMAGE_DIR
|
|
|
|
fi
|
|
|
|
;;
|
2015-09-12 20:16:25 -04:00
|
|
|
f)
|
|
|
|
echo "fastboot enabled"
|
2015-10-21 17:26:59 -04:00
|
|
|
FLASH_SCRIPT_OPTION="-f"
|
|
|
|
;;
|
2015-11-20 16:00:26 -05:00
|
|
|
B)
|
|
|
|
BUILD="$OPTARG"
|
|
|
|
echo "BUILD = ${BUILD}"
|
|
|
|
;;
|
2015-10-27 21:06:06 -04:00
|
|
|
b)
|
|
|
|
BRANCH="$OPTARG"
|
|
|
|
echo "BRANCH = ${BRANCH}"
|
|
|
|
;;
|
|
|
|
w)
|
|
|
|
WHAT="$OPTARG"
|
2015-12-29 00:13:57 -05:00
|
|
|
echo "WHAT = ${WHAT}"
|
2015-10-27 21:06:06 -04:00
|
|
|
;;
|
2015-10-21 17:26:59 -04:00
|
|
|
d)
|
|
|
|
echo "debian selected"
|
|
|
|
WHAT="debian"
|
2015-09-12 20:16:25 -04:00
|
|
|
;;
|
2016-01-02 05:29:53 -05:00
|
|
|
p)
|
|
|
|
echo "PocketC.H.I.P selected"
|
|
|
|
WHAT="pocketchip"
|
|
|
|
BUILD=123
|
|
|
|
FLASH_SCRIPT=./chip-fel-flash.sh -p
|
|
|
|
;;
|
2015-09-12 16:53:04 -04:00
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2015-10-21 17:26:59 -04:00
|
|
|
|
|
|
|
FW_DIR="$(pwd)/.firmware"
|
|
|
|
FW_IMAGE_DIR="${FW_DIR}/images"
|
|
|
|
BASE_URL="http://opensource.nextthing.co/chip"
|
|
|
|
S3_URL="${BASE_URL}/${WHAT}/${BRANCH}/latest"
|
|
|
|
|
2016-01-02 05:29:53 -05:00
|
|
|
|
|
|
|
|
2016-06-13 22:20:12 -04:00
|
|
|
if [[ ! -z "$BUILD" ]]; then
|
|
|
|
case "${WHAT}" in
|
|
|
|
"buildroot")
|
|
|
|
if [[ "$BUILD" -lt "74" ]] && [[ "${BRANCH}" == "stable" ]]; then
|
|
|
|
./chip-legacy-update.sh $@ || echo "ERROR: could not flash" && exit 1
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if [[ "$BUILD" -lt "60" ]] && [[ "${BRANCH}" == "next" ]]; then
|
|
|
|
./chip-legacy-update.sh $@ || echo "ERROR: could not flash" && exit 1
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"debian")
|
|
|
|
if [[ "$BUILD" -lt "47" ]] && [[ "${BRANCH}" == "stable" ]]; then
|
|
|
|
./chip-legacy-update.sh $@ || echo "ERROR: could not flash" && exit 1
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if [[ "$BUILD" -lt "148" ]] && [[ "${BRANCH}" == "next" ]]; then
|
|
|
|
./chip-legacy-update.sh $@ || echo "ERROR: could not flash" && exit 1
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if [[ "$BUILD" -lt "4" ]] && [[ "${BRANCH}" == "stable-gui" ]]; then
|
|
|
|
./chip-legacy-update.sh $@ || echo "ERROR: could not flash" && exit 1
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if [[ "$BUILD" -lt "148" ]] && [[ "${BRANCH}" == "next-gui" ]]; then
|
|
|
|
./chip-legacy-update.sh $@ || echo "ERROR: could not flash" && exit 1
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2015-11-20 16:00:26 -05:00
|
|
|
else
|
|
|
|
ROOTFS_URL="${S3_URL%latest}$BUILD"
|
2015-10-21 17:26:59 -04:00
|
|
|
fi
|
|
|
|
|
2015-09-14 21:40:22 -04:00
|
|
|
exit $?
|