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