1357d6381aeefd2f0cfcbbc3b303ea22daa9ce2b
[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 [ "${url::14}" = "http://iot.bzh" ]; then
92             endUrl=${url#$SDK_AGL_IOTBZH_BASEURL}
93             name=$(echo "IoTbzh-$(echo ${endUrl} | cut -d'/' -f3,4 | sed s:/:-:g)-${version}")
94         elif [ "${endUrl::4}" = "http" ]; then
95             name="${profile}_${arch}_${version}"
96         else
97             name=$(echo "AGL-$(echo ${endUrl} | cut -d'/' -f2,3,4,5)" | sed s:/:-:g)
98         fi
99
100         # Distringuish qemux86-64 and corei7-64
101         if [[ "$name" == *"qemux86-64"* && "$arch" == "corei7-64" ]]; then
102             arch="qemux86-64"
103         fi
104
105
106         [ "${profile}" = "" ] && { echo " ERROR: profile not set" continue; }
107         [ "${version}" = "" ] && { echo " ERROR: version not set" continue; }
108         [ "${arch}" = "" ] && { echo " ERROR: arch not set" continue; }
109         [ "${name}" = "" ] && { name=${profile}_${arch}_${version}; }
110
111         sdkDate="$(echo "${htmlPage}" |egrep -o ${sdkFile/+/\\+}'</a>.*[0-9\-]+ [0-9]+:[0-9]+' |cut -d'>' -f 4|cut -d' ' -f1,2)"
112         sdkSize="$(echo "${htmlPage}" |egrep -o  "${sdkFile/+/\\+}.*${sdkDate}.*[0-9\.MG]+</td>" |cut -d'>' -f7 |cut -d'<' -f1)"
113         md5sum="$(wget -q -O - ${url}/${sdkFile/.sh/.md5} |cut -d' ' -f1)"
114
115         read -r -d '' res <<- EndOfMessage
116 {
117     "name":         "${name}",
118     "description":  "AGL SDK ${arch} (version ${version})",
119     "profile":      "${profile}",
120     "version":      "${version}",
121     "arch":         "${arch}",
122     "path":         "",
123     "url":          "${url}/${sdkFile}",
124     "status":       "Not Installed",
125     "date":         "${sdkDate}",
126     "size":         "${sdkSize}",
127     "md5sum":       "${md5sum}",
128     "setupFile":    ""
129 },
130 EndOfMessage
131
132         sdksList="${sdksList}${res}"
133     done
134 done
135
136 OUT_FILE=$(dirname "$0")/sdks_$(date +"%F_%H%m").json
137
138 echo "[" > ${OUT_FILE}
139 echo "${sdksList::-1}" >> ${OUT_FILE}
140 echo "]" >> ${OUT_FILE}
141
142 echo "SDKs list successfully saved in ${OUT_FILE}"