2 ###########################################################################
3 # Copyright 2017-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 # script_name=$(basename ${0})
21 CURL="curl -f -s --connect-timeout 10"
23 ### Define urls where SDKs can be downloaded / AGL part
24 SDK_AGL_BASEURL="https://download.automotivelinux.org/AGL/"
25 DOWNLOADABLE_AGL_URLS="
26 snapshots/master/latest/*
33 release/flounder/6.0.0/*
34 release/flounder/latest/*
45 # release/flounder/5.99.6/*
47 SDK_AGL_URL_SUFFIX="/deploy/sdk/"
48 IMG_AGL_URL_SUFFIX="/deploy/images/"
49 #######################################
51 ### Define urls where SDKs can be downloaded / IoT.bzh part
52 SDK_IOTBZH_BASEURL="http://iot.bzh/download/public/XDS/images/"
53 DOWNLOADABLE_IOTBZH_URLS="
66 SDK_IOTBZH_URL_SUFFIX="/sdk/"
67 IMG_IOTBZH_URL_SUFFIX="/images/"
68 #######################################
71 # Compute full urls list (parse '*' characters)
72 function expand_url { # url, prefix, suffix
75 if [[ "$url" = *"*"* ]]; then
76 bUrl=$(echo $url | cut -d'*' -f 1)
77 eUrl=$(echo $url | cut -d'*' -f 2)
78 dirs=$(curl -s ${bUrl} | grep '\[DIR\]' | grep -oP 'href="[^"]*"' | cut -d'"' -f 2)
79 for dir in $(echo $dirs); do
80 result="$result ${bUrl::-1}/${dir::-1}${eUrl:1}"
89 function dbg_error() { >&2 echo "ERROR:" $@; }
90 function dbg_warning(){ [ $DEBUG -ge 1 ] && { >&2 echo "WARNING:" $@; } ; }
91 function dbg_info() { [ $DEBUG -ge 1 ] && { >&2 echo "INFO:" $@; } ; }
92 function dbg_debug() { [ $DEBUG -ge 2 ] && { >&2 echo "DEBUG:" $@; } ; }
94 function count() { echo $#; }
96 function first() { echo $1; }
99 function search_image_url {
100 htmlPage=$(${CURL} ${1}/)
101 if [[ $? == 0 ]]; then # curl request without error, at least URL is OK
102 if [ "${2}" = "qemux86-64" ]; then
103 image_name=$(echo $(first $(echo ${htmlPage} | egrep -o 'href="agl-demo-platform-crosssdk-[^"]*\.vmdk(\.xz)?"')) | sed -E 's/.*href="([^"]*)".*/\1/')
105 image_name=$(echo $(first $(echo ${htmlPage} | egrep -o 'href="agl-demo-platform-crosssdk-[^"]*\.rootfs\.wic(\.xz)?"')) | sed -E 's/.*href="([^"]*)".*/\1/')
106 # search for tar.xz if no wic found...
107 if [ $(count $image_name) -eq 0 ]; then
108 image_name=$(echo $(first $(echo ${htmlPage} | egrep -o 'href="agl-demo-platform-crosssdk-[^"]*\.tar\.xz"')) | sed -E 's/.*href="([^"]*)".*/\1/')
112 dbg_warning "could not list content of ${1}, HTTP request failed."
116 # return string result
117 if [[ ${image_name} = "null" ]]; then
118 echo "null" # to be inserted as-is in the JSON output
120 echo "\"${1}/${image_name}\"" # if no image file found, but URL is valid, lets point to the directory
124 # Given an URL, generate the corresponding JSON chunk
125 function generate_json {
132 htmlPage=$(${CURL} "${SDK_URL}")
133 files=$(echo ${htmlPage} | egrep -o 'href="[^"]*crosssdk[^"]*\.sh"' | cut -d '"' -f 2)
134 if [ "$?" != "0" ] || [ "${files}" = "" ]; then
135 dbg_warning " IGNORED ${url}: no valid files found"
139 # assume that sdk name follow this format :
140 # _PROFILE_-_COMPILER_ARCH_-_TARGET_-crosssdk-_ARCH_-toolchain-_VERSION_.sh
142 # poky-agl-glibc-x86_64-agl-demo-platform-crosssdk-corei7-64-toolchain-4.0.1.sh
143 if [ $(count files) -gt 1 ]
145 dbg_warning " IGNORE ${url}: multiple shell script containing 'crosssdk' in their names"
149 dbg_info "Processing SDK: ${sdkFile} (from ${url})"
150 profile=$(echo "${sdkFile}" | sed -r 's/(.*)-glibc.*/\1/')
151 version=$(echo "${sdkFile}" | sed -r 's/.*toolchain-(.*).sh/\1/')
152 arch=$(echo "${sdkFile}" | sed -r 's/.*crosssdk-(.*)-toolchain.*/\1/')
154 endUrl=${url#$SDK_AGL_BASEURL}
155 if [ "${url::14}" = "http://iot.bzh" ]; then
156 endUrl=${url#$SDK_IOTBZH_BASEURL}
157 name=$(echo "IoTbzh-$(echo ${endUrl} | sed s:/:-:g)-${version}")
159 elif [ "${endUrl::4}" = "http" ]; then
160 name="${profile}_${arch}_${version}"
163 name=$(echo "AGL-$(echo ${endUrl} | cut -d'/' -f1,2,3,4)" | sed s:/:-:g)
164 board=$(echo ${endUrl} | cut -d'/' -f4)
165 board=${board%-nogfx}
168 # Distringuish qemux86-64 and corei7-64
169 if [[ "$name" == *"qemux86-64"* && "$arch" == "corei7-64" ]]; then
173 [ "${profile}" = "" ] && { dbg_error "profile is not set" ; return ; }
174 [ "${version}" = "" ] && { dbg_error "version is not set" ; return ; }
175 [ "${arch}" = "" ] && { dbg_error "arch is not set" ; return ; }
176 [ "${name}" = "" ] && { name=${profile}_${arch}_${version}; }
178 sdkDate="$(echo "${htmlPage}" |egrep -o ${sdkFile/+/\\+}'</a>.*[0-9\-]+ [0-9]+:[0-9]+' |cut -d'>' -f 4|cut -d' ' -f1,2)"
179 sdkSize="$(echo "${htmlPage}" |egrep -o "${sdkFile/+/\\+}.*${sdkDate}.*[0-9\.MG]+</td>" |cut -d'>' -f7 |cut -d'<' -f1)"
180 md5sum="$(wget -q -O - ${SDK_URL}/${sdkFile/.sh/.md5} |cut -d' ' -f1)"
182 image_url=$(search_image_url ${IMG_URL}${board} ${arch})
185 read -r -d '' res <<- EndOfMessage
188 "description": "AGL SDK ${arch} (version ${version})",
189 "profile": "${profile}",
190 "version": "${version}",
193 "url": "${SDK_URL}${sdkFile}",
194 "image_url": ${image_url},
195 "status": "Not Installed",
196 "date": "${sdkDate}",
197 "size": "${sdkSize}",
198 "md5sum": "${md5sum}",
203 sdksList="${sdksList}${res}"
207 if [[ ${1:0:2} = "-v" ]] ; then
208 verbose=$(echo -s ${1} | sed -E "s/-([v]+).*/\1/")
209 DEBUG=$(echo ${verbose} | wc -c)
210 echo "Set verbosity level to : ${DEBUG}"
214 # Compute list of available/installable SDKs
216 for base_url in $DOWNLOADABLE_AGL_URLS
218 dbg_debug "Look into ${base_url}"
219 urls="$(expand_url $base_url $SDK_AGL_BASEURL)"
222 dbg_debug "URL to check: ${url}"
223 generate_json $url $SDK_AGL_URL_SUFFIX $IMG_AGL_URL_SUFFIX
227 for base_url in $DOWNLOADABLE_IOTBZH_URLS
229 dbg_debug "Look into ${base_url}"
230 urls="$(expand_url $base_url $SDK_IOTBZH_BASEURL)"
233 dbg_debug "URL to check: ${url}"
234 generate_json $url $SDK_IOTBZH_URL_SUFFIX $IMG_IOTBZH_URL_SUFFIX
239 OUT_FILE=$(dirname "$0")/sdks_$(date +"%F_%H%M").json
241 echo "[" > ${OUT_FILE}
242 echo "${sdksList::-1}" >> ${OUT_FILE}
243 echo "]" >> ${OUT_FILE}
245 echo "SDKs list successfully saved in ${OUT_FILE}"