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 . $(dirname "$0")/_env-init.sh
23 echo "Usage: $(basename $0) [-h|--help] [-f|--file <sdk-filename>] [-u|--url <https_url>] [--force] [--no-clean]"
32 while [ $# -ne 0 ]; do
52 echo "Invalid argument: $1"
59 [ "$SDK_FILE" = "" ] && [ "$URL" = "" ] && { echo "--file or --url option must be set"; exit 1; }
61 # Create SDK root dir if needed
62 [ ! -d ${SDK_ROOT_DIR} ] && mkdir -p ${SDK_ROOT_DIR}
63 cd ${SDK_ROOT_DIR} || exit 1
66 trap "cleanExit" 0 1 2 15
69 if ($do_cleanup); then
70 [[ -d ${TMPDIR} ]] && rm -rf ${TMPDIR}
75 if [ "$URL" != "" ]; then
77 SDK_FILE=${TMPDIR}/$(basename ${URL})
78 echo "Downloading $(basename ${SDK_FILE}) ..."
79 wget "$URL" -O "${SDK_FILE}" || exit 1
82 # Retreive default install dir to extract version
83 offset=$(grep -na -m1 "^MARKER:$" "${SDK_FILE}" | cut -d':' -f1)
84 eval $(head -n $offset "${SDK_FILE}" | grep ^DEFAULT_INSTALL_DIR= )
86 PROFILE=$(basename $(dirname $DEFAULT_INSTALL_DIR))
87 VERSION=$(basename $DEFAULT_INSTALL_DIR)
88 ARCH=$(echo "$SDK_FILE" | sed -r 's/.*crosssdk-(.*)-toolchain.*/\1/')
90 [ "$PROFILE" = "" ] && { echo "PROFILE is not set"; exit 1; }
91 [ "$VERSION" = "" ] && { echo "VERSION is not set"; exit 1; }
92 [ "$ARCH" = "" ] && { echo "ARCH is not set"; exit 1; }
94 DESTDIR=${SDK_ROOT_DIR}/${PROFILE}/${VERSION}/${ARCH}
96 [ -d ${DESTDIR} ] && [ "$do_force" != "true" ] && { echo "SDK already installed in $DESTDIR"; exit 1; }
98 # Cleanup previous install
99 rm -rf ${DESTDIR} && mkdir -p ${DESTDIR} || exit 1
103 ${SDK_FILE} -y -d ${DESTDIR}