2 ###########################################################################
3 # Copyright 2017 IoT.bzh
5 # author: Sebastien Douheret <sebastien@iot.bzh>
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 ###########################################################################
20 SCRIPTS_DIR=$(cd $(dirname "$0") && pwd)
21 . ${SCRIPTS_DIR}/_env-init.sh
24 echo "Usage: $(basename $0) [-h|--help] [-f|--file <sdk-filename>] [-u|--url <https_url>] [--force] [--no-clean]"
35 while [ $# -ne 0 ]; do
63 echo "Invalid argument: $1"
70 [ "$SDK_FILE" = "" ] && [ "$URL" = "" ] && { echo "--file or --url option must be set"; exit 1; }
72 # Create SDK root dir if needed
73 [ ! -d "${SDK_ROOT_DIR}" ] && mkdir -p "${SDK_ROOT_DIR}"
74 cd "${SDK_ROOT_DIR}" || exit 1
77 trap "cleanExit" 0 1 2 15
80 if ($do_cleanup); then
81 [[ -d ${TMPDIR} ]] && rm -rf ${TMPDIR}
86 if [ "$URL" != "" ]; then
88 SDK_FILE=${TMPDIR}/$(basename "${URL}")
89 echo "Downloading $(basename "${SDK_FILE}") ..."
90 wget --no-check-certificate "$URL" -O "${SDK_FILE}" || exit 1
93 # Compute uuid when needed
94 if [ "$UUID" = "" ] && [ "$URL" != "" ]; then
95 UUID=$(echo "$URL" | md5sum |cut -d' ' -f1)
96 elif [ "$SDK_FILE" != "" ]; then
97 UUID=$(echo $(basename $SDK_FILE) | md5sum |cut -d' ' -f1)
99 echo "UUID value must be specify using --uuid option."
104 sdkNfo=$(${SCRIPTS_DIR}/get-sdk-info --file "${SDK_FILE}" --uuid "${UUID}")
105 if [ "$?" != "0" ]; then
110 PROFILE=$(echo "$sdkNfo" |grep -Eo '"profile"[^,]*' |cut -d'"' -f4)
111 VERSION=$(echo "$sdkNfo" |grep -Eo '"version"[^,]*' |cut -d'"' -f4)
112 ARCH=$(echo "$sdkNfo" |grep -Eo '"arch"[^,]*' |cut -d'"' -f4)
113 DESTDIR=$(echo "$sdkNfo" |grep -Eo '"path"[^,]*' |cut -d'"' -f4)
115 [ "$PROFILE" = "" ] && { echo "PROFILE is not set"; exit 1; }
116 [ "$VERSION" = "" ] && { echo "VERSION is not set"; exit 1; }
117 [ "$ARCH" = "" ] && { echo "ARCH is not set"; exit 1; }
118 [ "$DESTDIR" = "" ] && { echo "DESTDIR (path) is not set"; exit 1; }
120 [ -d "${DESTDIR}" ] && [ "$do_force" != "true" ] && { echo "SDK already installed in $DESTDIR"; exit 1; }
122 # Cleanup previous install
123 rm -rf "${DESTDIR}" && mkdir -p "${DESTDIR}" || exit 1
126 chmod +x "${SDK_FILE}"
127 ${SDK_FILE} ${DEBUG_OPT} -y -d "${DESTDIR}" 2>&1