Cleanup useless SDKs from SDKs db/list
[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.3/*/deploy/sdk
28
29     ${SDK_AGL_BASEURL}/release/eel/5.1.0/*/deploy/sdk
30     ${SDK_AGL_BASEURL}/release/eel/latest/*/deploy/sdk
31
32     ${SDK_AGL_BASEURL}/release/flounder/6.0.0/*/deploy/sdk
33     ${SDK_AGL_BASEURL}/release/flounder/latest/*/deploy/sdk
34
35     ${SDK_AGL_IOTBZH_BASEURL}/images/dab-m3ulcb/*/sdk
36
37     ${SDK_AGL_IOTBZH_BASEURL}/images/eel-intel-corei7-64/*/sdk
38     ${SDK_AGL_IOTBZH_BASEURL}/images/eel-m3ulcb/*/sdk
39
40     ${SDK_AGL_IOTBZH_BASEURL}/images/flounder-h3ulcb/*/sdk
41     ${SDK_AGL_IOTBZH_BASEURL}/images/flounder-m3ulcb/*/sdk
42
43     ${SDK_AGL_IOTBZH_BASEURL}/images/master-m3ulcb/*/sdk
44 "
45 ###
46
47
48 # Compute full urls list  (parse '*' characters)
49 urls=""
50 for url in $(echo $DOWNLOADABLE_URLS); do
51     if [[ "$url" = *"*"* ]]; then
52         bUrl=$(echo $url | cut -d'*' -f 1)
53         eUrl=$(echo $url | cut -d'*' -f 2)
54         dirs=$(curl -s ${bUrl} | grep '\[DIR\]' | grep -oP  'href="[^"]*"' | cut -d'"' -f 2)
55         for dir in $(echo $dirs); do
56             urls="$urls ${bUrl::-1}/${dir::-1}/${eUrl:1}"
57         done
58     else
59         urls="$urls $url"
60     fi
61 done
62
63 # Compute list of available/installable SDKs
64 sdksList=" "
65 for url in $(echo $urls); do
66     htmlPage=$(curl -s --connect-timeout 10 "${url}/")
67     files=$(echo ${htmlPage} | egrep -o 'href="[^"]*.sh"' | cut -d '"' -f 2)
68     if [ "$?" != "0" ] || [ "${files}" = "" ]; then
69         echo " IGNORED ${url}: no valid files found"
70         continue
71     fi
72
73     for sdkFile in $(echo ${files}); do
74
75                 # Ignored silent some known files
76                 [[ "${sdkFile}" = "agl-sdk-latest.sh" ]] && continue
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"; echo " (url: ${url})"; 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}"