aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/sdks/agl/add
blob: 80a0487bbf5ad609b564a1f70c65df2446e0011c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
 ###########################################################################
# Copyright 2017 IoT.bzh
#
# author: Sebastien Douheret <sebastien@iot.bzh>
#
# 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 <sdk-filename>] [-u|--url <https_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