#!/bin/bash ########################################################################### # Copyright 2017 IoT.bzh # # author: Sebastien Douheret # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ########################################################################### SCRIPTS_DIR=$(cd $(dirname "$0") && pwd) . ${SCRIPTS_DIR}/_env-init.sh usage() { echo "Usage: $(basename $0) [-h|--help] [-f|--file ] [-u|--url ] [--force] [--no-clean]" exit 1 } TMPDIR="" SDK_FILE="" URL="" DEBUG_OPT="" do_cleanup=true do_force=false while [ $# -ne 0 ]; do case $1 in --debug) set -x DEBUG_OPT="-D" ;; -f|--file) shift SDK_FILE=$1 ;; --force) do_force=true ;; -u|--url) shift URL=$1 ;; -no-clean) do_cleanup=false ;; -h|--help) usage ;; *) echo "Invalid argument: $1" usage ;; esac shift done [ "$SDK_FILE" = "" ] && [ "$URL" = "" ] && { echo "--file or --url option must be set"; exit 1; } # Create SDK root dir if needed [ ! -d "${SDK_ROOT_DIR}" ] && mkdir -p "${SDK_ROOT_DIR}" cd "${SDK_ROOT_DIR}" || exit 1 # Cleanup trap "cleanExit" 0 1 2 15 cleanExit () { if ($do_cleanup); then [[ -d ${TMPDIR} ]] && rm -rf ${TMPDIR} fi } # Download sdk if [ "$URL" != "" ]; then TMPDIR=$(mktemp -d) SDK_FILE=${TMPDIR}/$(basename "${URL}") echo "Downloading $(basename "${SDK_FILE}") ..." wget --no-check-certificate "$URL" -O "${SDK_FILE}" || exit 1 fi # Retreive SDK info sdkNfo=$(${SCRIPTS_DIR}/get-sdk-info --file "${SDK_FILE}") if [ "$?" != "0" ]; then echo "$sdkNfo" exit 1 fi PROFILE=$(echo "$sdkNfo" |grep -Eo '"profile"[^,]*' |cut -d'"' -f4) VERSION=$(echo "$sdkNfo" |grep -Eo '"version"[^,]*' |cut -d'"' -f4) ARCH=$(echo "$sdkNfo" |grep -Eo '"arch"[^,]*' |cut -d'"' -f4) DESTDIR=$(echo "$sdkNfo" |grep -Eo '"path"[^,]*' |cut -d'"' -f4) [ "$PROFILE" = "" ] && { echo "PROFILE is not set"; exit 1; } [ "$VERSION" = "" ] && { echo "VERSION is not set"; exit 1; } [ "$ARCH" = "" ] && { echo "ARCH is not set"; exit 1; } [ "$DESTDIR" = "" ] && { echo "DESTDIR (path) is not set"; exit 1; } [ -d "${DESTDIR}" ] && [ "$do_force" != "true" ] && { echo "SDK already installed in $DESTDIR"; exit 1; } # Cleanup previous install rm -rf "${DESTDIR}" && mkdir -p "${DESTDIR}" || exit 1 # Install sdk chmod +x "${SDK_FILE}" ${SDK_FILE} ${DEBUG_OPT} -y -d "${DESTDIR}" 2>&1