aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/sdks/agl/_build-sdks-json.sh
blob: b97edd0e75bab04c9cdcfaedec98fe8b2d2aec4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
###########################################################################
# Copyright 2017-2018 IoT.bzh
#
# author: Sebastien Douheret <sebastien@iot.bzh>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###########################################################################

SDK_AGL_BASEURL="https://download.automotivelinux.org/AGL"
SDK_AGL_IOTBZH_BASEURL="http://iot.bzh/download/public/XDS"

# Define urls where SDKs can be downloaded
DOWNLOADABLE_URLS="
    ${SDK_AGL_BASEURL}/snapshots/master/latest/*/deploy/sdk

    ${SDK_AGL_BASEURL}/release/dab/4.0.2/*/deploy/sdk

    ${SDK_AGL_BASEURL}/release/eel/5.0.0/*/deploy/sdk
    ${SDK_AGL_BASEURL}/release/eel/5.0.1/*/deploy/sdk
    ${SDK_AGL_BASEURL}/release/eel/5.0.2/*/deploy/sdk
    ${SDK_AGL_BASEURL}/release/eel/5.0.3/*/deploy/sdk
    ${SDK_AGL_BASEURL}/release/eel/5.1.0/*/deploy/sdk
    ${SDK_AGL_BASEURL}/release/eel/latest/*/deploy/sdk

    ${SDK_AGL_BASEURL}/release/flounder/5.99.6/*/deploy/sdk
    ${SDK_AGL_BASEURL}/release/flounder/6.0.0/*/deploy/sdk
    ${SDK_AGL_BASEURL}/release/flounder/latest/*/deploy/sdk

    ${SDK_AGL_IOTBZH_BASEURL}/images/dab-m3ulcb/*/sdk
    ${SDK_AGL_IOTBZH_BASEURL}/images/dab-raspi/*/sdk

    ${SDK_AGL_IOTBZH_BASEURL}/images/eel-intel-corei7-64/*/sdk
    ${SDK_AGL_IOTBZH_BASEURL}/images/eel-m3ulcb/*/sdk

    ${SDK_AGL_IOTBZH_BASEURL}/images/flounder-h3ulcb/*/sdk
    ${SDK_AGL_IOTBZH_BASEURL}/images/flounder-m3ulcb/*/sdk

    ${SDK_AGL_IOTBZH_BASEURL}/images/master-m3ulcb/*/sdk
"
###


# Compute full urls list  (parse '*' characters)
urls=""
for url in $(echo $DOWNLOADABLE_URLS); do
    if [[ "$url" = *"*"* ]]; then
        bUrl=$(echo $url | cut -d'*' -f 1)
        eUrl=$(echo $url | cut -d'*' -f 2)
        dirs=$(curl -s ${bUrl} | grep '\[DIR\]' | grep -oP  'href="[^"]*"' | cut -d'"' -f 2)
        for dir in $(echo $dirs); do
            urls="$urls ${bUrl::-1}/${dir::-1}/${eUrl:1}"
        done
    else
        urls="$urls $url"
    fi
done

# Compute list of available/installable SDKs
sdksList=" "
for url in $(echo $urls); do
    htmlPage=$(curl -s --connect-timeout 10 "${url}/")
    files=$(echo ${htmlPage} | egrep -o 'href="[^"]*.sh"' | cut -d '"' -f 2)
    if [ "$?" != "0" ] || [ "${files}" = "" ]; then
        echo " IGNORED ${url}: no valid files found"
        continue
    fi

    for sdkFile in $(echo ${files}); do

        # assume that sdk name follow this format :
        #  _PROFILE_-_COMPILER_ARCH_-_TARGET_-crosssdk-_ARCH_-toolchain-_VERSION_.sh
        # for example:
        #  poky-agl-glibc-x86_64-agl-demo-platform-crosssdk-corei7-64-toolchain-4.0.1.sh

        [[ "${sdkFile}" != *"crosssdk"* ]] && { echo " IGNORED ${sdkFile}, not a valid sdk file"; echo " (url: ${url})"; continue; }

        echo "Processing ${sdkFile}"
        profile=$(echo "${sdkFile}" | sed -r 's/(.*)-glibc.*/\1/')
        version=$(echo "${sdkFile}" | sed -r 's/.*toolchain-(.*).sh/\1/')
        arch=$(echo "${sdkFile}" | sed -r 's/.*crosssdk-(.*)-toolchain.*/\1/')

        endUrl=${url#$SDK_AGL_BASEURL}
        if [ "${endUrl::4}" = "http" ]; then
            name=${profile}_${arch}_${version}
        else
            name=$(echo "AGL-$(echo ${endUrl} | cut -d'/' -f2,3,4,5)" | sed s:/:-:g)
        fi

        # Distringuish qemux86-64 and corei7-64
        if [[ "$name" == *"qemux86-64"* && "$arch" == "corei7-64" ]]; then
            arch="qemux86-64"
        fi


        [ "${profile}" = "" ] && { echo " ERROR: profile not set" continue; }
        [ "${version}" = "" ] && { echo " ERROR: version not set" continue; }
        [ "${arch}" = "" ] && { echo " ERROR: arch not set" continue; }
        [ "${name}" = "" ] && { name=${profile}_${arch}_${version}; }

        sdkDate="$(echo "${htmlPage}" |egrep -o ${sdkFile/+/\\+}'</a>.*[0-9\-]+ [0-9]+:[0-9]+' |cut -d'>' -f 4|cut -d' ' -f1,2)"
        sdkSize="$(echo "${htmlPage}" |egrep -o  "${sdkFile/+/\\+}.*${sdkDate}.*[0-9\.MG]+</td>" |cut -d'>' -f7 |cut -d'<' -f1)"
        md5sum="$(wget -q -O - ${url}/${sdkFile/.sh/.md5} |cut -d' ' -f1)"

        read -r -d '' res <<- EndOfMessage
{
    "name":         "${name}",
    "description":  "AGL SDK ${arch} (version ${version})",
    "profile":      "${profile}",
    "version":      "${version}",
    "arch":         "${arch}",
    "path":         "",
    "url":          "${url}/${sdkFile}",
    "status":       "Not Installed",
    "date":         "${sdkDate}",
    "size":         "${sdkSize}",
    "md5sum":       "${md5sum}",
    "setupFile":    ""
},
EndOfMessage

        sdksList="${sdksList}${res}"
    done
done

OUT_FILE=$(dirname "$0")/sdks_$(date +"%F_%H%m").json

echo "[" > ${OUT_FILE}
echo "${sdksList::-1}" >> ${OUT_FILE}
echo "]" >> ${OUT_FILE}

echo "SDKs list successfully saved in ${OUT_FILE}"