diff --git a/scripts/prepare_zephyr_env.sh b/scripts/prepare_zephyr_env.sh index a844ee0..35efb26 100755 --- a/scripts/prepare_zephyr_env.sh +++ b/scripts/prepare_zephyr_env.sh @@ -12,15 +12,23 @@ PROJECT_ROOT=$(realpath $(pwd)) # setup SDK if [ ! -d "$ZEPHYR_SDK_PATH" ]; then - # determine latest SDK version - ZEPHYR_SDK_VERSION=$(curl "https://api.github.com/repos/zephyrproject-rtos/sdk-ng/tags" | jq -r '[.[].name | select(.|test("-")|not)][0]') - ZEPHYR_SDK_VERSION="${ZEPHYR_SDK_VERSION:1}" + cd /tmp + for SDK_IDX in 0 1 2 + do + # determine latest SDK version + ZEPHYR_SDK_VERSION=$(curl "https://api.github.com/repos/zephyrproject-rtos/sdk-ng/tags" | jq -r "[.[].name | select(.|test(\"-\")|not)][$SDK_IDX]") + ZEPHYR_SDK_VERSION="${ZEPHYR_SDK_VERSION:1}" - ZEPHYR_SDK_ARCHIVE="zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64_minimal.tar.xz" + ZEPHYR_SDK_ARCHIVE="zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64_minimal.tar.xz" + WGET_RETVAL=0 + wget "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZEPHYR_SDK_VERSION}/${ZEPHYR_SDK_ARCHIVE}" || WGET_RETVAL=$? + if [ "$WGET_RETVAL" -eq 0 ]; then + break + fi + echo "Fallback to older SDK version" + done mkdir -p $(dirname $ZEPHYR_SDK_PATH) - cd /tmp - wget "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZEPHYR_SDK_VERSION}/${ZEPHYR_SDK_ARCHIVE}" tar xvf ${ZEPHYR_SDK_ARCHIVE} mv ./zephyr-sdk-${ZEPHYR_SDK_VERSION} ${ZEPHYR_SDK_PATH} rm ${ZEPHYR_SDK_ARCHIVE} @@ -36,7 +44,7 @@ fi cd ${PROJECT_ROOT} # setup Zephyr project -if [ ! -d ".west" ]; then +if [ ! -d "../.west" ]; then west init -l . west update west zephyr-export