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}
93 sdkDate=$(stat -c %y "${SDK_FILE}")
94 sdkSize=$(/bin/ls -sh "${SDK_FILE}" |cut -d' ' -f1)
96 elif [ "${URL}" != "" ]; then
98 filename=$(basename "${URL}")
105 echo "--file or --url option must be set"
109 # assume that sdk name follow this format :
110 # _PROFILE_-_COMPILER_ARCH_-_TARGET_-crosssdk-_ARCH_-toolchain-_VERSION_.sh
112 # poky-agl-glibc-x86_64-agl-demo-platform-crosssdk-corei7-64-toolchain-4.0.1.sh
115 if [[ "${filename}" != *"crosssdk"* ]]; then
116 echo "malformed sdk file name"
120 profile=$(echo "${filename}" | sed -r 's/(.*)-glibc.*/\1/')
121 version=$(echo "${filename}" | sed -r 's/.*toolchain-(.*).sh/\1/')
122 arch=$(echo "${filename}" | sed -r 's/.*crosssdk-(.*)-toolchain.*/\1/')
123 installPath=${SDK_ROOT_DIR}/${profile}/${version}/${arch}
125 [ "${profile}" = "" ] && { echo "profile not set"; exit 7; }
126 [ "${version}" = "" ] && { echo "version not set"; exit 8; }
127 [ "${arch}" = "" ] && { echo " arch not set"; exit 9; }
129 sdkName=${profile}_${arch}_${version}
131 # Define a unique ID to be able to distinguish for example corei7-64 from qemux86-64
132 if [ "${UUID}" = "" ]; then
133 curInstDir=$(ls -d "${installPath}/*" 2> /dev/null)
134 if [ -d "${curInstDir}" ]; then
135 UUID="basename ${curInstDir}"
136 elif [ "$URL" != "" ]; then
137 UUID=$(echo "$URL" | md5sum |cut -d' ' -f1)
138 elif [ "$filename" != "" ]; then
139 UUID=$(echo $(basename $filename) | md5sum |cut -d' ' -f1)
141 echo "UUID value must be specify using --uuid option."
145 installPath="${installPath}/${UUID}"
147 status="Not Installed"
148 if [ -d "${installPath}" ]; then
149 envFile=$(find "${installPath}" -maxdepth 1 -name "${SDK_ENV_SETUP_FILENAME}")
150 [ "${envFile}" != "" ] && status="Installed"
154 if [ "${UUID}" != "" ]; then
155 sdkDef=$($(dirname "$0")/db-dump | jq '.[] | select(.uuid=="'${UUID}'")')
156 elif [ "${URL}" != "" ]; then
157 sdkDef=$($(dirname "$0")/db-dump | jq '.[] | select(.url=="'${URL}'")')
160 if [ "${sdkDef}" != "" ]; then
161 sdkName=$(echo "$sdkDef" | jq -r .name)
162 [ "$UUID" = "" ] && UUID=$(echo "$sdkDef" | jq -r .uuid)
163 [ "$sdkUrl" = "" ] && sdkUrl=$(echo "$sdkDef" | jq -r .url)
164 [ "$imageUrl" = "" ] && imageUrl=$(echo "$sdkDef" | jq -r .image_url)
165 [ "$sdkDate" = "" ] && sdkDate=$(echo "$sdkDef" | jq -r .date)
166 [ "$sdkSize" = "" ] && sdkSize=$(echo "$sdkDef" | jq -r .size)
167 [ "$MD5VAL" = "" ] && MD5VAL=$(echo "$sdkDef" | jq -r .md5sum)
170 read -r -d '' res <<- EndOfMessage
172 "name": "${sdkName}",
174 "description": "AGL SDK ${arch} (version ${version})",
175 "profile": "${profile}",
176 "version": "${version}",
178 "path": "${installPath}",
180 "image_url": "${imageUrl}",
181 "status": "${status}",
182 "date": "${sdkDate}",
183 "size": "${sdkSize}",
184 "md5sum": "${MD5VAL}",
185 "setupFile": "${envFile}"