-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbootstrap
52 lines (46 loc) · 1.82 KB
/
bootstrap
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
#
# Open-CMSIS-Pack gen-pack Bash library
#
# Copyright (c) 2022-2023 Arm Limited. All rights reserved.
#
# Provided as-is without warranty under Apache 2.0 License
# SPDX-License-Identifier: Apache-2.0
#
SCRIPT="${SCRIPT:-$(basename "$0")}"
LOG_PREFIX="${LOG_PREFIX:-"$(tput setaf 4 2>/dev/null)${SCRIPT}>$(tput sgr0 2>/dev/null) "}"
function install_lib() {
local URL="https://github.com/Open-CMSIS-Pack/gen-pack/archive/refs/tags/v$1.tar.gz"
local STATUS
STATUS=$(curl -sLI "${URL}" | grep "^HTTP" | tail -n 1 | cut -d' ' -f2 || echo "$((600+$?))")
if [[ $STATUS -ge 400 ]]; then
echo "${LOG_PREFIX}Wrong/unavailable gen-pack lib version '$1'!" >&2
echo "${LOG_PREFIX}Check REQUIRED_GEN_PACK_LIB variable." >&2
echo "${LOG_PREFIX}For available versions see https://github.com/Open-CMSIS-Pack/gen-pack/tags." >&2
exit 1
fi
echo "${LOG_PREFIX}Downloading gen-pack lib version '$1' to '$2' ..."
mkdir -p "$2"
curl -L "${URL}" -s | tar -xzf - --strip-components 1 -C "$2" || exit 1
}
function load_lib() {
if [ -z "${REQUIRED_GEN_PACK_LIB}" ]; then
echo "${LOG_PREFIX}REQUIRED_GEN_PACK_LIB variable must be set to required version." >&2
echo "${LOG_PREFIX}For available versions see https://github.com/Open-CMSIS-Pack/gen-pack/tags." >&2
exit 1
fi
local GLOBAL_LIB="/usr/local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
local USER_LIB="${HOME}/.local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
if [[ ! -d "${GLOBAL_LIB}" && ! -d "${USER_LIB}" ]]; then
echo "${LOG_PREFIX}Required gen_pack lib not found!" >&2
install_lib "${REQUIRED_GEN_PACK_LIB}" "${USER_LIB}"
fi
if [[ -d "${GLOBAL_LIB}" ]]; then
. "${GLOBAL_LIB}/gen-pack"
elif [[ -d "${USER_LIB}" ]]; then
. "${USER_LIB}/gen-pack"
else
echo "${LOG_PREFIX}Required gen-pack lib is not installed!" >&2
exit 1
fi
}
load_lib