2 ###########################################################################
3 # Copyright 2018 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>] [--md5 <string>]"
32 while [ $# -ne 0 ]; do
54 echo "Invalid argument: $1"
61 if [ "${SDK_FILE}" != "" ]; then
63 if [ ! -f "${SDK_FILE}" ]; then
64 echo "sdk file doesn't exist"
68 # Criteria to consider that SDK is a valid AGL sdk:
69 # - shell and binary file type
70 # - "$MARKER:$" string found
71 # - md5sum match MD5VAL if MD5VAL is set
73 if ! file "${SDK_FILE}" |grep shell |grep -q binary ; then
74 echo "Not expected file type"
78 if ! grep -aq -m1 "^MARKER:$" "${SDK_FILE}"; then
79 echo "marker not found"
83 if [ "${MD5VAL}" != "" ]; then
84 if ! echo "${MD5VAL} ${SDK_FILE}" | md5sum --status -c -; then
85 echo "md5sum dit not match"
90 filename=$(basename "${SDK_FILE}")
91 sdkUrl=file://${SDK_FILE}
92 sdkDate=$(stat -c %y "${SDK_FILE}")
93 sdkSize=$(/bin/ls -sh "${SDK_FILE}" |cut -d' ' -f1)
95 elif [ "${URL}" != "" ]; then
97 filename=$(basename "${URL}")
103 echo "--file or --url option must be set"
107 # assume that sdk name follow this format :
108 # _PROFILE_-_COMPILER_ARCH_-_TARGET_-crosssdk-_ARCH_-toolchain-_VERSION_.sh
110 # poky-agl-glibc-x86_64-agl-demo-platform-crosssdk-corei7-64-toolchain-4.0.1.sh
113 if [[ "${filename}" != *"crosssdk"* ]]; then
114 echo "malformed sdk file name"
118 profile=$(echo "${filename}" | sed -r 's/(.*)-glibc.*/\1/')
119 version=$(echo "${filename}" | sed -r 's/.*toolchain-(.*).sh/\1/')
120 arch=$(echo "${filename}" | sed -r 's/.*crosssdk-(.*)-toolchain.*/\1/')
121 installPath=${SDK_ROOT_DIR}/${profile}/${version}/${arch}
123 [ "${profile}" = "" ] && { echo "profile not set"; exit 7; }
124 [ "${version}" = "" ] && { echo "version not set"; exit 8; }
125 [ "${arch}" = "" ] && { echo " arch not set"; exit 9; }
127 # Define a unique ID to be able to distinguish for example corei7-64 from qemux86-64
128 if [ "${UUID}" = "" ]; then
129 curInstDir=$(ls -d "${installPath}/*" 2> /dev/null)
130 if [ -d "${curInstDir}" ]; then
131 UUID="basename ${curInstDir}"
132 elif [ "$URL" != "" ]; then
133 UUID=$(echo "$URL" | md5sum |cut -d' ' -f1)
135 echo "UUID value must be specify using --uuid option."
139 installPath="${installPath}/${UUID}"
141 status="Not Installed"
142 if [ -d "${installPath}" ]; then
143 envFile=$(find "${installPath}" -maxdepth 1 -name "${SDK_ENV_SETUP_FILENAME}")
144 [ "${envFile}" != "" ] && status="Installed"
147 read -r -d '' res <<- EndOfMessage
149 "name": "${profile}_${arch}_${version}",
150 "description": "AGL SDK ${arch} (version ${version})",
151 "profile": "${profile}",
152 "version": "${version}",
154 "path": "${installPath}",
156 "status": "${status}",
157 "date": "${sdkDate}",
158 "size": "${sdkSize}",
159 "md5sum": "${MD5VAL}",
160 "setupFile": "${envFile}"