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.3/*
34 release/flounder/latest/*
36 release/guppy/6.99.2/*
37 release/guppy/latest/*
48 # release/flounder/5.99.6/*
50 SDK_AGL_URL_SUFFIX="/deploy/sdk/"
51 IMG_AGL_URL_SUFFIX="/deploy/images/"
52 #######################################
54 ### Define urls where SDKs can be downloaded / IoT.bzh part
55 SDK_IOTBZH_BASEURL="https://iot.bzh/download/public/XDS/images/"
56 DOWNLOADABLE_IOTBZH_URLS="
69 SDK_IOTBZH_URL_SUFFIX="/sdk/"
70 IMG_IOTBZH_URL_SUFFIX="/images/"
71 #######################################
74 # Compute full urls list (parse '*' characters)
75 function expand_url { # url, prefix, suffix
78 if [[ "$url" = *"*"* ]]; then
79 bUrl=$(echo $url | cut -d'*' -f 1)
80 eUrl=$(echo $url | cut -d'*' -f 2)
81 dirs=$(curl -s ${bUrl} | grep '\[DIR\]' | grep -oP 'href="[^"]*"' | cut -d'"' -f 2)
82 for dir in $(echo $dirs); do
83 result="$result ${bUrl::-1}/${dir::-1}${eUrl:1}"
92 function dbg_error() { >&2 echo "ERROR:" $@; }
93 function dbg_warning(){ [ $DEBUG -ge 1 ] && { >&2 echo "WARNING:" $@; } ; }
94 function dbg_info() { [ $DEBUG -ge 1 ] && { >&2 echo "INFO:" $@; } ; }
95 function dbg_debug() { [ $DEBUG -ge 2 ] && { >&2 echo "DEBUG:" $@; } ; }
97 function count() { echo $#; }
99 function first() { echo $1; }
102 function search_image_url {
103 htmlPage=$(${CURL} ${1}/)
104 if [[ $? == 0 ]]; then # curl request without error, at least URL is OK
105 if [ "${2}" = "qemux86-64" ]; then
106 image_name=$(echo $(first $(echo ${htmlPage} | egrep -o 'href="agl-demo-platform-crosssdk-[^"]*\.vmdk(\.xz)?"')) | sed -E 's/.*href="([^"]*)".*/\1/')
108 image_name=$(echo $(first $(echo ${htmlPage} | egrep -o 'href="agl-demo-platform-crosssdk-[^"]*\.rootfs\.wic(\.xz)?"')) | sed -E 's/.*href="([^"]*)".*/\1/')
109 # search for tar.xz if no wic found...
110 if [ $(count $image_name) -eq 0 ]; then
111 image_name=$(echo $(first $(echo ${htmlPage} | egrep -o 'href="agl-demo-platform-crosssdk-[^"]*\.tar\.xz"')) | sed -E 's/.*href="([^"]*)".*/\1/')
115 dbg_warning "could not list content of ${1}, HTTP request failed."
119 # return string result
120 if [[ ${image_name} = "null" ]]; then
121 echo "null" # to be inserted as-is in the JSON output
123 echo "\"${1}/${image_name}\"" # if no image file found, but URL is valid, lets point to the directory
127 # Given an URL, generate the corresponding JSON chunk
128 function generate_json {
135 htmlPage=$(${CURL} "${SDK_URL}")
136 files=$(echo ${htmlPage} | egrep -o 'href="[^"]*crosssdk[^"]*\.sh"' | cut -d '"' -f 2)
137 if [ "$?" != "0" ] || [ "${files}" = "" ]; then
138 dbg_warning " IGNORED ${url}: no valid files found"
142 # assume that sdk name follow this format :
143 # _PROFILE_-_COMPILER_ARCH_-_TARGET_-crosssdk-_ARCH_-toolchain-_VERSION_.sh
145 # poky-agl-glibc-x86_64-agl-demo-platform-crosssdk-corei7-64-toolchain-4.0.1.sh
146 if [ $(count files) -gt 1 ]
148 dbg_warning " IGNORE ${url}: multiple shell script containing 'crosssdk' in their names"
152 dbg_info "Processing SDK: ${sdkFile} (from ${url})"
153 profile=$(echo "${sdkFile}" | sed -r 's/(.*)-glibc.*/\1/')
154 version=$(echo "${sdkFile}" | sed -r 's/.*toolchain-(.*).sh/\1/')
155 arch=$(echo "${sdkFile}" | sed -r 's/.*crosssdk-(.*)-toolchain.*/\1/')
157 endUrl=${url#$SDK_AGL_BASEURL}
158 if [ "${url::14}" = "http://iot.bzh" ]; then
159 endUrl=${url#$SDK_IOTBZH_BASEURL}
160 name=$(echo "IoTbzh-$(echo ${endUrl} | sed s:/:-:g)-${version}")
162 elif [ "${endUrl::4}" = "http" ]; then
163 name="${profile}_${arch}_${version}"
166 name=$(echo "AGL-$(echo ${endUrl} | cut -d'/' -f1,2,3,4)" | sed s:/:-:g)
167 board=$(echo ${endUrl} | cut -d'/' -f4)
168 board=${board%-nogfx}
171 # Distringuish qemux86-64 and corei7-64
172 if [[ "$name" == *"qemux86-64"* && "$arch" == "corei7-64" ]]; then
176 [ "${profile}" = "" ] && { dbg_error "profile is not set" ; return ; }
177 [ "${version}" = "" ] && { dbg_error "version is not set" ; return ; }
178 [ "${arch}" = "" ] && { dbg_error "arch is not set" ; return ; }
179 [ "${name}" = "" ] && { name=${profile}_${arch}_${version}; }
181 sdkDate="$(echo "${htmlPage}" |egrep -o ${sdkFile/+/\\+}'</a>.*[0-9\-]+ [0-9]+:[0-9]+' |cut -d'>' -f 4|cut -d' ' -f1,2)"
182 sdkSize="$(echo "${htmlPage}" |egrep -o "${sdkFile/+/\\+}.*${sdkDate}.*[0-9\.MG]+</td>" |cut -d'>' -f7 |cut -d'<' -f1)"
183 md5sum="$(wget -q -O - ${SDK_URL}/${sdkFile/.sh/.md5} |cut -d' ' -f1)"
185 image_url=$(search_image_url ${IMG_URL}${board} ${arch})
188 read -r -d '' res <<- EndOfMessage
191 "description": "AGL SDK ${arch} (version ${version})",
192 "profile": "${profile}",
193 "version": "${version}",
196 "url": "${SDK_URL}${sdkFile}",
197 "image_url": ${image_url},
198 "status": "Not Installed",
199 "date": "${sdkDate}",
200 "size": "${sdkSize}",
201 "md5sum": "${md5sum}",
206 sdksList="${sdksList}${res}"
210 if [ "${1}" = "-v" ] ; then
213 echo "Set verbosity level to : ${DEBUG}"
217 # Compute list of available/installable SDKs
219 for base_url in $DOWNLOADABLE_AGL_URLS
221 dbg_debug "Look into ${base_url}"
222 urls="$(expand_url ${base_url} $SDK_AGL_BASEURL)"
223 [ "$urls" = "" ] && { echo "ERROR: empty response while expanding ${SDK_AGL_BASEURL}${base_url}"; exit 1; }
226 dbg_debug "URL to check: ${url}"
227 generate_json $url $SDK_AGL_URL_SUFFIX $IMG_AGL_URL_SUFFIX
231 for base_url in $DOWNLOADABLE_IOTBZH_URLS
233 dbg_debug "Look into ${base_url}"
234 urls="$(expand_url ${base_url} $SDK_IOTBZH_BASEURL)"
235 [ "$urls" = "" ] && { echo "ERROR: empty response while expanding ${SDK_IOTBZH_BASEURL}${base_url}"; exit 1; }
238 dbg_debug "URL to check: ${url}"
239 generate_json $url $SDK_IOTBZH_URL_SUFFIX $IMG_IOTBZH_URL_SUFFIX
244 OUT_FILE=$(dirname "$0")/sdks_$(date +"%F_%H%M").json
246 echo "[" > ${OUT_FILE}
247 echo "${sdksList::-1}" >> ${OUT_FILE}
248 echo "]" >> ${OUT_FILE}
250 echo "SDKs list successfully saved in ${OUT_FILE}"