4ab5f0ca52968f9e1fe0dbe37ededd65a61af2d4
[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/latest/*/deploy/sdk
34
35     ${SDK_AGL_IOTBZH_BASEURL}/images/dab-m3ulcb/*/sdk
36     ${SDK_AGL_IOTBZH_BASEURL}/images/dab-raspi/*/sdk
37
38     ${SDK_AGL_IOTBZH_BASEURL}/images/eel-intel-corei7-64/*/sdk
39     ${SDK_AGL_IOTBZH_BASEURL}/images/eel-m3ulcb/*/sdk
40
41     ${SDK_AGL_IOTBZH_BASEURL}/images/master-m3ulcb/*/sdk
42     ${SDK_AGL_IOTBZH_BASEURL}/images/master-qemux86-64/*/sdk
43 "
44 ###
45
46
47 # Compute full urls list  (parse '*' characters)
48 urls=""
49 for url in $(echo $DOWNLOADABLE_URLS); do
50     if [[ "$url" = *"*"* ]]; then
51         bUrl=$(echo $url | cut -d'*' -f 1)
52         eUrl=$(echo $url | cut -d'*' -f 2)
53         dirs=$(curl -s ${bUrl} | grep '\[DIR\]' | grep -oP  'href="[^"]*"' | cut -d'"' -f 2)
54         for dir in $(echo $dirs); do
55             urls="$urls ${bUrl::-1}/${dir::-1}/${eUrl:1}"
56         done
57     else
58         urls="$urls $url"
59     fi
60 done
61
62 # Compute list of available/installable SDKs
63 sdksList=" "
64 for url in $(echo $urls); do
65     htmlPage=$(curl -s --connect-timeout 10 "${url}/")
66     files=$(echo ${htmlPage} | egrep -o 'href="[^"]*.sh"' | cut -d '"' -f 2)
67     if [ "$?" != "0" ] || [ "${files}" = "" ]; then
68         echo " IGNORED ${url}: no valid files found"
69         continue
70     fi
71
72     for sdkFile in $(echo ${files}); do
73
74         # assume that sdk name follow this format :
75         #  _PROFILE_-_COMPILER_ARCH_-_TARGET_-crosssdk-_ARCH_-toolchain-_VERSION_.sh
76         # for example:
77         #  poky-agl-glibc-x86_64-agl-demo-platform-crosssdk-corei7-64-toolchain-4.0.1.sh
78
79         [[ "${sdkFile}" != *"crosssdk"* ]] && { echo " IGNORED ${sdkFile}, not a valid sdk file"; continue; }
80
81         echo "Processing ${sdkFile}"
82         profile=$(echo "${sdkFile}" | sed -r 's/(.*)-glibc.*/\1/')
83         version=$(echo "${sdkFile}" | sed -r 's/.*toolchain-(.*).sh/\1/')
84         arch=$(echo "${sdkFile}" | sed -r 's/.*crosssdk-(.*)-toolchain.*/\1/')
85
86         endUrl=${url#$SDK_AGL_BASEURL}
87         if [ "${endUrl::4}" = "http" ]; then
88             name=${profile}_${arch}_${version}
89         else
90             name=$(echo "AGL-$(echo ${endUrl} | cut -d'/' -f2,3,4,5)" | sed s:/:-:g)
91         fi
92
93         # Distringuish qemux86-64 and corei7-64
94         if [[ "$name" == *"qemux86-64"* && "$arch" == "corei7-64" ]]; then
95             arch="qemux86-64"
96         fi
97
98
99         [ "${profile}" = "" ] && { echo " ERROR: profile not set" continue; }
100         [ "${version}" = "" ] && { echo " ERROR: version not set" continue; }
101         [ "${arch}" = "" ] && { echo " ERROR: arch not set" continue; }
102         [ "${name}" = "" ] && { name=${profile}_${arch}_${version}; }
103
104         sdkDate="$(echo "${htmlPage}" |egrep -o ${sdkFile/+/\\+}'</a>.*[0-9\-]+ [0-9]+:[0-9]+' |cut -d'>' -f 4|cut -d' ' -f1,2)"
105         sdkSize="$(echo "${htmlPage}" |egrep -o  "${sdkFile/+/\\+}.*${sdkDate}.*[0-9\.MG]+</td>" |cut -d'>' -f7 |cut -d'<' -f1)"
106         md5sum="$(wget -q -O - ${url}/${sdkFile/.sh/.md5} |cut -d' ' -f1)"
107
108         read -r -d '' res <<- EndOfMessage
109 {
110     "name":         "${name}",
111     "description":  "AGL SDK ${arch} (version ${version})",
112     "profile":      "${profile}",
113     "version":      "${version}",
114     "arch":         "${arch}",
115     "path":         "",
116     "url":          "${url}/${sdkFile}",
117     "status":       "Not Installed",
118     "date":         "${sdkDate}",
119     "size":         "${sdkSize}",
120     "md5sum":       "${md5sum}",
121     "setupFile":    ""
122 },
123 EndOfMessage
124
125         sdksList="${sdksList}${res}"
126     done
127 done
128
129 OUT_FILE=$(dirname "$0")/sdks_$(date +"%F_%H%m").json
130
131 echo "[" > ${OUT_FILE}
132 echo "${sdksList::-1}" >> ${OUT_FILE}
133 echo "]" >> ${OUT_FILE}
134
135 echo "SDKs list successfully saved in ${OUT_FILE}"