Update SDK definition - add flounder
[src/xds/xds-server.git] / scripts / sdks / agl / _build-sdks-json.sh
1 #!/bin/bash
2 ###########################################################################
3 # Copyright 2017-2018 IoT.bzh
4 #
5 # author: Sebastien Douheret <sebastien@iot.bzh>
6 #
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
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
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 ###########################################################################
19
20 SDK_AGL_BASEURL="https://download.automotivelinux.org/AGL"
21 SDK_AGL_IOTBZH_BASEURL="http://iot.bzh/download/public/XDS"
22
23 # Define urls where SDKs can be downloaded
24 DOWNLOADABLE_URLS="
25     ${SDK_AGL_BASEURL}/snapshots/master/latest/*/deploy/sdk
26
27     ${SDK_AGL_BASEURL}/release/dab/4.0.2/*/deploy/sdk
28
29     ${SDK_AGL_BASEURL}/release/eel/5.0.0/*/deploy/sdk
30     ${SDK_AGL_BASEURL}/release/eel/5.0.1/*/deploy/sdk
31     ${SDK_AGL_BASEURL}/release/eel/5.0.2/*/deploy/sdk
32     ${SDK_AGL_BASEURL}/release/eel/5.0.3/*/deploy/sdk
33     ${SDK_AGL_BASEURL}/release/eel/5.1.0/*/deploy/sdk
34     ${SDK_AGL_BASEURL}/release/eel/latest/*/deploy/sdk
35
36     ${SDK_AGL_BASEURL}/release/flounder/5.99.6/*/deploy/sdk
37     ${SDK_AGL_BASEURL}/release/flounder/latest/*/deploy/sdk
38
39     ${SDK_AGL_IOTBZH_BASEURL}/images/dab-m3ulcb/*/sdk
40     ${SDK_AGL_IOTBZH_BASEURL}/images/dab-raspi/*/sdk
41
42     ${SDK_AGL_IOTBZH_BASEURL}/images/eel-intel-corei7-64/*/sdk
43     ${SDK_AGL_IOTBZH_BASEURL}/images/eel-m3ulcb/*/sdk
44
45     ${SDK_AGL_IOTBZH_BASEURL}/images/master-m3ulcb/*/sdk
46     ${SDK_AGL_IOTBZH_BASEURL}/images/master-qemux86-64/*/sdk
47 "
48 ###
49
50
51 # Compute full urls list  (parse '*' characters)
52 urls=""
53 for url in $(echo $DOWNLOADABLE_URLS); do
54     if [[ "$url" = *"*"* ]]; then
55         bUrl=$(echo $url | cut -d'*' -f 1)
56         eUrl=$(echo $url | cut -d'*' -f 2)
57         dirs=$(curl -s ${bUrl} | grep '\[DIR\]' | grep -oP  'href="[^"]*"' | cut -d'"' -f 2)
58         for dir in $(echo $dirs); do
59             urls="$urls ${bUrl::-1}/${dir::-1}/${eUrl:1}"
60         done
61     else
62         urls="$urls $url"
63     fi
64 done
65
66 # Compute list of available/installable SDKs
67 sdksList=" "
68 for url in $(echo $urls); do
69     htmlPage=$(curl -s --connect-timeout 10 "${url}/")
70     files=$(echo ${htmlPage} | egrep -o 'href="[^"]*.sh"' | cut -d '"' -f 2)
71     if [ "$?" != "0" ] || [ "${files}" = "" ]; then
72         echo " IGNORED ${url}: no valid files found"
73         continue
74     fi
75
76     for sdkFile in $(echo ${files}); do
77
78         # assume that sdk name follow this format :
79         #  _PROFILE_-_COMPILER_ARCH_-_TARGET_-crosssdk-_ARCH_-toolchain-_VERSION_.sh
80         # for example:
81         #  poky-agl-glibc-x86_64-agl-demo-platform-crosssdk-corei7-64-toolchain-4.0.1.sh
82
83         [[ "${sdkFile}" != *"crosssdk"* ]] && { echo " IGNORED ${sdkFile}, not a valid sdk file"; continue; }
84
85         echo "Processing ${sdkFile}"
86         profile=$(echo "${sdkFile}" | sed -r 's/(.*)-glibc.*/\1/')
87         version=$(echo "${sdkFile}" | sed -r 's/.*toolchain-(.*).sh/\1/')
88         arch=$(echo "${sdkFile}" | sed -r 's/.*crosssdk-(.*)-toolchain.*/\1/')
89
90         endUrl=${url#$SDK_AGL_BASEURL}
91         if [ "${endUrl::4}" = "http" ]; then
92             name=${profile}_${arch}_${version}
93         else
94             name=$(echo "AGL-$(echo ${endUrl} | cut -d'/' -f2,3,4,5)" | sed s:/:-:g)
95         fi
96
97         # Distringuish qemux86-64 and corei7-64
98         if [[ "$name" == *"qemux86-64"* && "$arch" == "corei7-64" ]]; then
99             arch="qemux86-64"
100         fi
101
102
103         [ "${profile}" = "" ] && { echo " ERROR: profile not set" continue; }
104         [ "${version}" = "" ] && { echo " ERROR: version not set" continue; }
105         [ "${arch}" = "" ] && { echo " ERROR: arch not set" continue; }
106         [ "${name}" = "" ] && { name=${profile}_${arch}_${version}; }
107
108         sdkDate="$(echo "${htmlPage}" |egrep -o ${sdkFile/+/\\+}'</a>.*[0-9\-]+ [0-9]+:[0-9]+' |cut -d'>' -f 4|cut -d' ' -f1,2)"
109         sdkSize="$(echo "${htmlPage}" |egrep -o  "${sdkFile/+/\\+}.*${sdkDate}.*[0-9\.MG]+</td>" |cut -d'>' -f7 |cut -d'<' -f1)"
110         md5sum="$(wget -q -O - ${url}/${sdkFile/.sh/.md5} |cut -d' ' -f1)"
111
112         read -r -d '' res <<- EndOfMessage
113 {
114     "name":         "${name}",
115     "description":  "AGL SDK ${arch} (version ${version})",
116     "profile":      "${profile}",
117     "version":      "${version}",
118     "arch":         "${arch}",
119     "path":         "",
120     "url":          "${url}/${sdkFile}",
121     "status":       "Not Installed",
122     "date":         "${sdkDate}",
123     "size":         "${sdkSize}",
124     "md5sum":       "${md5sum}",
125     "setupFile":    ""
126 },
127 EndOfMessage
128
129         sdksList="${sdksList}${res}"
130     done
131 done
132
133 OUT_FILE=$(dirname "$0")/sdks_$(date +"%F_%H%m").json
134
135 echo "[" > ${OUT_FILE}
136 echo "${sdksList::-1}" >> ${OUT_FILE}
137 echo "]" >> ${OUT_FILE}
138
139 echo "SDKs list successfully saved in ${OUT_FILE}"