From 1a8b7603899f30f052ad123b7607b45a6d4c8772 Mon Sep 17 00:00:00 2001 From: Sebastien Douheret Date: Thu, 4 Jan 2018 23:40:25 +0100 Subject: Improved and fixed local SDK tarball installation. Signed-off-by: Sebastien Douheret --- scripts/sdks/agl/add | 25 +++++-- scripts/sdks/agl/db-dump | 137 ++++++++++++++++++++++++++++++++++ scripts/sdks/agl/db-update | 22 ++++++ scripts/sdks/agl/get-config | 33 --------- scripts/sdks/agl/get-family-config | 33 +++++++++ scripts/sdks/agl/get-sdk-info | 146 +++++++++++++++++++++++++++++++++++++ scripts/sdks/agl/list | 138 ----------------------------------- scripts/sdks/agl/remove | 5 ++ scripts/sdks/agl/update | 22 ------ 9 files changed, 360 insertions(+), 201 deletions(-) create mode 100755 scripts/sdks/agl/db-dump create mode 100755 scripts/sdks/agl/db-update delete mode 100755 scripts/sdks/agl/get-config create mode 100755 scripts/sdks/agl/get-family-config create mode 100755 scripts/sdks/agl/get-sdk-info delete mode 100755 scripts/sdks/agl/list delete mode 100755 scripts/sdks/agl/update (limited to 'scripts/sdks/agl') diff --git a/scripts/sdks/agl/add b/scripts/sdks/agl/add index e9a9fd1..7c8321c 100755 --- a/scripts/sdks/agl/add +++ b/scripts/sdks/agl/add @@ -17,7 +17,8 @@ # limitations under the License. ########################################################################### -. $(dirname "$0")/_env-init.sh +SCRIPTS_DIR=$(cd $(dirname "$0") && pwd) +. ${SCRIPTS_DIR}/_env-init.sh usage() { echo "Usage: $(basename $0) [-h|--help] [-f|--file ] [-u|--url ] [--force] [--no-clean]" @@ -27,10 +28,15 @@ usage() { TMPDIR="" SDK_FILE="" URL="" +DEBUG_OPT="" do_cleanup=true do_force=false while [ $# -ne 0 ]; do case $1 in + --debug) + set -x + DEBUG_OPT="-D" + ;; -f|--file) shift SDK_FILE=$1 @@ -79,13 +85,16 @@ if [ "$URL" != "" ]; then wget --no-check-certificate "$URL" -O "${SDK_FILE}" || exit 1 fi -# Retreive default install dir to extract version -offset=$(grep -na -m1 "^MARKER:$" "${SDK_FILE}" | cut -d':' -f1) -eval $(head -n $offset "${SDK_FILE}" | grep ^DEFAULT_INSTALL_DIR= ) +# Retreive SDK info +sdkNfo=$(${SCRIPTS_DIR}/get-sdk-info --file "${SDK_FILE}") +if [ "$?" != "0" ]; then + echo $sdkNfo + exit 1 +fi -PROFILE=$(basename $(dirname $DEFAULT_INSTALL_DIR)) -VERSION=$(basename $DEFAULT_INSTALL_DIR) -ARCH=$(echo "$SDK_FILE" | sed -r 's/.*crosssdk-(.*)-toolchain.*/\1/') +PROFILE=$(echo "$sdkNfo" |egrep -o '"profile"[^,]*' |cut -d'"' -f4) +VERSION=$(echo "$sdkNfo" |egrep -o '"version"[^,]*' |cut -d'"' -f4) +ARCH=$(echo "$sdkNfo" |egrep -o '"arch"[^,]*' |cut -d'"' -f4) [ "$PROFILE" = "" ] && { echo "PROFILE is not set"; exit 1; } [ "$VERSION" = "" ] && { echo "VERSION is not set"; exit 1; } @@ -100,4 +109,4 @@ rm -rf ${DESTDIR} && mkdir -p ${DESTDIR} || exit 1 # Install sdk chmod +x ${SDK_FILE} -${SDK_FILE} -y -d ${DESTDIR} +${SDK_FILE} ${DEBUG_OPT} -y -d ${DESTDIR} 2>&1 diff --git a/scripts/sdks/agl/db-dump b/scripts/sdks/agl/db-dump new file mode 100755 index 0000000..e13a8d8 --- /dev/null +++ b/scripts/sdks/agl/db-dump @@ -0,0 +1,137 @@ +#! /usr/bin/env nodejs + +/************************************************************************** + * Copyright 2017 IoT.bzh + * + * author: Sebastien Douheret + * + * 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. + **************************************************************************/ + +const fs = require('fs'); +const process = require('process'); +const execSync = require('child_process').execSync; +const path = require('path'); + + +// Only used for debug purpose +const DEBUG = false || (process.argv.length > 2 && process.argv[2] == '-debug'); +dbgPrint = function () { + if (DEBUG) console.log.apply(console, arguments); +} +// Get env vars +var envMap = {}; +envData = execSync(path.join(__dirname, '_env-init.sh -print')); +envData.toString().split('\n').forEach(e => envMap[e.split('=')[0]] = e.split('=')[1]); +const opts = { + cwd: __dirname, + env: envMap +}; + +// Get list of available SDKs +sdksDBFile = path.join(envMap["SDK_ROOT_DIR"], "sdks_latest.json") +try { + // Fetch SDK Json database file when not existing + if (!fs.existsSync(sdksDBFile)) { + var data = execSync(path.join(__dirname, 'update-db ' + sdksDBFile), opts); + } + // Read SDK Json database file + var data = fs.readFileSync(sdksDBFile); + var sdks = JSON.parse(data); + + // Force some default fields value + sdks.forEach(sdk => { + sdk.status = 'Not Installed'; + }); +} catch (err) { + dbgPrint('ERROR: ', err); + process.exit(-1) +} + +// Get list of installed SDKs +try { + const cmd = 'find "${SDK_ROOT_DIR}" -maxdepth 4 -name "${SDK_ENV_SETUP_FILENAME}"'; + var data = execSync(cmd, opts); + data.toString().split('\n').forEach(envFile => { + if (envFile == '') return; + + dbgPrint('Processing ', envFile); + const profile = envFile.split('/')[3]; + const version = envFile.split('/')[4]; + const arch = envFile.split('/')[5]; + const dir = path.dirname(envFile); + if (profile == '' || version == '' || arch == '' || dir == '') { + return; + } + + sdkDate = '' + versionFile = path.join(path.dirname(envFile), 'version-*') + try { + cmdVer = "[ -f " + versionFile + " ] && grep Timestamp " + versionFile + " |cut -d' ' -f2" + var data = execSync(cmdVer); + } catch (err) { + dbgPrint('IGNORING SDK ', dir); + dbgPrint(err.toString()); + if (DEBUG) { + process.exit(-1); + } else { + return; + } + } + d = data.toString() + if (d != "") { + sdkDate = d.substring(0, 4) + "-" + d.substring(4, 6) + "-" + d.substring(6, 8) + sdkDate += " " + d.substring(8, 10) + ":" + d.substring(10, 12) + } + + var found = false; + sdks.forEach(sdk => { + // Update sdk with local info when found + if (profile == sdk.profile && version == sdk.version && arch == sdk.arch) { + found = true; + dbgPrint(" OK found, updating..."); + sdk.path = dir; + sdk.status = 'Installed'; + sdk.data = sdkDate; + sdk.setupFile = envFile; + return + } + }); + if (found == false) { + dbgPrint(" NOT found in database, adding it..."); + sdks.push({ + name: profile + '-' + arch + '-' + version, + description: 'AGL SDK ' + arch + ' (version ' + version + ')', + profile: profile, + version: version, + arch: arch, + path: dir, + url: "", + status: "Installed", + date: sdkDate, + size: "", + md5sum: "", + setupFile: envFile + }); + } + }); + +} catch (err) { + dbgPrint('ERROR: ', err); + process.exit(-1) +} + +// Print result +console.log(JSON.stringify(sdks)); + +process.exit(0) diff --git a/scripts/sdks/agl/db-update b/scripts/sdks/agl/db-update new file mode 100755 index 0000000..a222db9 --- /dev/null +++ b/scripts/sdks/agl/db-update @@ -0,0 +1,22 @@ +#!/bin/bash + ########################################################################### +# Copyright 2017 IoT.bzh +# +# author: Sebastien Douheret +# +# 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. +########################################################################### + +. $(dirname "$0")/_env-init.sh + +wget -q --connect-timeout=30 ${SDK_DATABASE} -O $1 diff --git a/scripts/sdks/agl/get-config b/scripts/sdks/agl/get-config deleted file mode 100755 index 8d370b8..0000000 --- a/scripts/sdks/agl/get-config +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - ########################################################################### -# Copyright 2017 IoT.bzh -# -# author: Sebastien Douheret -# -# 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. -########################################################################### - -SCRIPTS_DIR=$(dirname "$0") -. ${SCRIPTS_DIR}/_env-init.sh - -read -r -d '' res <<- EndOfMessage -{ - "familyName": "${SDK_FAMILY_NAME}", - "description": "Automotive Grade Linux SDK", - "rootDir": "${SDK_ROOT_DIR}", - "envSetupFilename": "${SDK_ENV_SETUP_FILENAME}", - "scriptsDir": "${SCRIPTS_DIR}" -} -EndOfMessage - -echo "$res" diff --git a/scripts/sdks/agl/get-family-config b/scripts/sdks/agl/get-family-config new file mode 100755 index 0000000..8d370b8 --- /dev/null +++ b/scripts/sdks/agl/get-family-config @@ -0,0 +1,33 @@ +#!/bin/bash + ########################################################################### +# Copyright 2017 IoT.bzh +# +# author: Sebastien Douheret +# +# 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. +########################################################################### + +SCRIPTS_DIR=$(dirname "$0") +. ${SCRIPTS_DIR}/_env-init.sh + +read -r -d '' res <<- EndOfMessage +{ + "familyName": "${SDK_FAMILY_NAME}", + "description": "Automotive Grade Linux SDK", + "rootDir": "${SDK_ROOT_DIR}", + "envSetupFilename": "${SDK_ENV_SETUP_FILENAME}", + "scriptsDir": "${SCRIPTS_DIR}" +} +EndOfMessage + +echo "$res" diff --git a/scripts/sdks/agl/get-sdk-info b/scripts/sdks/agl/get-sdk-info new file mode 100755 index 0000000..19bf685 --- /dev/null +++ b/scripts/sdks/agl/get-sdk-info @@ -0,0 +1,146 @@ +#!/bin/bash + ########################################################################### +# Copyright 2018 IoT.bzh +# +# author: Sebastien Douheret +# +# 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. +########################################################################### + +. $(dirname "$0")/_env-init.sh + +usage() { + echo "Usage: $(basename $0) [-h|--help] [-f|--file ] [-u|--url ] [--md5 ]" + exit 1 +} + +SDK_FILE="" +MD5VAL="" +URL="" + +while [ $# -ne 0 ]; do + case $1 in + -f|--file) + shift + SDK_FILE=$1 + ;; + -h|--help) + usage + ;; + --md5) + shift + MD5VAL=$1 + ;; + -u|--url) + shift + URL=$1 + ;; + *) + echo "Invalid argument: $1" + usage + ;; + esac + shift +done + +if [ "${SDK_FILE}" != "" ]; then + + if [ ! -f "${SDK_FILE}" ]; then + echo "sdk file doesn't exist" + exit 1 + fi + + # Criteria to consider that SDK is a valid AGL sdk: + # - shell and binary file type + # - "$MARKER:$" string found + # - md5sum match MD5VAL if MD5VAL is set + + if ! file "${SDK_FILE}" |grep shell |grep -q binary ; then + echo "Not expected file type" + exit 2 + fi + + if ! grep -aq -m1 "^MARKER:$" "${SDK_FILE}"; then + echo "marker not found" + exit 4 + fi + + if [ "${MD5VAL}" != "" ]; then + if ! echo "${MD5VAL} ${SDK_FILE}" | md5sum --status -c -; then + echo "md5sum dit not match" + exit 5 + fi + fi + + filename=$(basename "${SDK_FILE}") + sdkUrl=file://${SDK_FILE} + sdkDate=$(stat -c %y "${SDK_FILE}") + sdkSize=$(/bin/ls -sh "${SDK_FILE}" |cut -d' ' -f1) + +elif [ "${URL}" != "" ]; then + + filename=$(basename "${URL}") + sdkUrl=${URL} + sdkDate="" + sdkSize="" + +else + echo "--file or --url option must be set" + exit 1 +fi + +# 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 + + +if [[ "${filename}" != *"crosssdk"* ]]; then + echo "malformed sdk file name" + exit 6 +fi + +profile=$(echo "${filename}" | sed -r 's/(.*)-glibc.*/\1/') +version=$(echo "${filename}" | sed -r 's/.*toolchain-(.*).sh/\1/') +arch=$(echo "${filename}" | sed -r 's/.*crosssdk-(.*)-toolchain.*/\1/') +installPath=${SDK_ROOT_DIR}/${profile}/${version}/${arch} + +[ "${profile}" = "" ] && { echo "profile not set"; exit 7; } +[ "${version}" = "" ] && { echo "version not set"; exit 8; } +[ "${arch}" = "" ] && { echo " arch not set"; exit 9; } + +status="Not Installed" +if [ -d ${installPath} ]; then + envFile=$(find "${installPath}" -maxdepth 1 -name "${SDK_ENV_SETUP_FILENAME}") + [ "${envFile}" != "" ] && status="Installed" +fi + +read -r -d '' res <<- EndOfMessage +{ + "name": "${profile}_${arch}_${version}", + "description": "AGL SDK ${arch} (version ${version})", + "profile": "${profile}", + "version": "${version}", + "arch": "${arch}", + "path": "${installPath}", + "url": "${sdkUrl}", + "status": "${status}", + "date": "${sdkDate}", + "size": "${sdkSize}", + "md5sum": "${MD5VAL}", + "setupFile": "${envFile}" +} +EndOfMessage + +echo "$res" +exit 0 diff --git a/scripts/sdks/agl/list b/scripts/sdks/agl/list deleted file mode 100755 index af1d19f..0000000 --- a/scripts/sdks/agl/list +++ /dev/null @@ -1,138 +0,0 @@ -#! /usr/bin/env nodejs - -/************************************************************************** - * Copyright 2017 IoT.bzh - * - * author: Sebastien Douheret - * - * 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. - **************************************************************************/ - -const fs = require('fs'); -const process = require('process'); -const execSync = require('child_process').execSync; -const path = require('path'); - - -// Only used for debug purpose -const DEBUG = false || (process.argv.length > 2 && process.argv[2] == '-debug'); -dbgPrint = function () { - if (DEBUG) console.log.apply(console, arguments); -} -// Get env vars -var envMap = {}; -envData = execSync(path.join(__dirname, '_env-init.sh -print')); -envData.toString().split('\n').forEach(e => envMap[e.split('=')[0]] = e.split('=')[1]); -const opts = { - cwd: __dirname, - env: envMap -}; - -// Get list of available SDKs -sdksDBFile = path.join(envMap["SDK_ROOT_DIR"], "sdks_latest.json") -try { - // Fetch SDK Json database file when not existing - if (!fs.existsSync(sdksDBFile)) { - - var data = execSync(path.join(__dirname, 'update ' + sdksDBFile), opts); - } - // Read SDK Json database file - var data = fs.readFileSync(sdksDBFile); - var sdks = JSON.parse(data); - - // Force some default fields value - sdks.forEach(sdk => { - sdk.status = 'Not Installed'; - }); -} catch (err) { - dbgPrint('ERROR: ', err); - process.exit(-1) -} - -// Get list of installed SDKs -try { - const cmd = 'find "${SDK_ROOT_DIR}" -maxdepth 4 -name "${SDK_ENV_SETUP_FILENAME}"'; - var data = execSync(cmd, opts); - data.toString().split('\n').forEach(envFile => { - if (envFile == '') return; - - dbgPrint('Processing ', envFile); - const profile = envFile.split('/')[3]; - const version = envFile.split('/')[4]; - const arch = envFile.split('/')[5]; - const dir = path.dirname(envFile); - if (profile == '' || version == '' || arch == '' || dir == '') { - return; - } - - sdkDate = '' - versionFile = path.join(path.dirname(envFile), 'version-*') - try { - cmdVer = "[ -f " + versionFile + " ] && grep Timestamp " + versionFile + " |cut -d' ' -f2" - var data = execSync(cmdVer); - } catch (err) { - dbgPrint('IGNORING SDK ', dir); - dbgPrint(err.toString()); - if (DEBUG) { - process.exit(-1); - } else { - return; - } - } - d = data.toString() - if (d != "") { - sdkDate = d.substring(0, 4) + "-" + d.substring(4, 6) + "-" + d.substring(6, 8) - sdkDate += " " + d.substring(8, 10) + ":" + d.substring(10, 12) - } - - var found = false; - sdks.forEach(sdk => { - // Update sdk with local info when found - if (profile == sdk.profile && version == sdk.version && arch == sdk.arch) { - found = true; - dbgPrint(" OK found, updating..."); - sdk.path = dir; - sdk.status = 'Installed'; - sdk.data = sdkDate; - sdk.setupFile = envFile; - return - } - }); - if (found == false) { - dbgPrint(" NOT found in database, adding it..."); - sdks.push({ - name: profile + '-' + arch + '-' + version, - description: 'AGL SDK ' + arch + ' (version ' + version + ')', - profile: profile, - version: version, - arch: arch, - path: dir, - url: "", - status: "Installed", - date: sdkDate, - size: "", - md5sum: "", - setupFile: envFile - }); - } - }); - -} catch (err) { - dbgPrint('ERROR: ', err); - process.exit(-1) -} - -// Print result -console.log(JSON.stringify(sdks)); - -process.exit(0) diff --git a/scripts/sdks/agl/remove b/scripts/sdks/agl/remove index d0f30b1..ec98f72 100755 --- a/scripts/sdks/agl/remove +++ b/scripts/sdks/agl/remove @@ -30,3 +30,8 @@ if [ ! -d "${1}" ]; then fi rm -rf "${1}" && echo "SDK successfully removed." + +# Potentially remove parent directory when it is the latest SDK for this version +rmdir "$(dirname ${1})" + +exit 0 diff --git a/scripts/sdks/agl/update b/scripts/sdks/agl/update deleted file mode 100755 index a222db9..0000000 --- a/scripts/sdks/agl/update +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - ########################################################################### -# Copyright 2017 IoT.bzh -# -# author: Sebastien Douheret -# -# 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. -########################################################################### - -. $(dirname "$0")/_env-init.sh - -wget -q --connect-timeout=30 ${SDK_DATABASE} -O $1 -- cgit 1.2.3-korg