]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/check_links.sh
Reworked CMSIS-Core(M) and Core(A) docs for CMSIS 6. (#47)
[cmsis] / CMSIS / DoxyGen / check_links.sh
1 #!/usr/bin/env bash
2
3 set -o pipefail
4
5 DIRNAME=$(dirname $(realpath $0))
6 REQUIRED_GEN_PACK_LIB="0.8.3"
7
8 ############ gen-pack library ###########
9
10 function install_lib() {
11   local URL="https://github.com/Open-CMSIS-Pack/gen-pack/archive/refs/tags/v$1.tar.gz"
12   local STATUS=$(curl -sLI "${URL}" | grep "^HTTP" | tail -n 1 | cut -d' ' -f2 || echo "$((600+$?))")
13   if [[ $STATUS -ge 400 ]]; then
14     echo "Wrong/unavailable gen-pack lib version '$1'!" >&2
15     echo "Check REQUIRED_GEN_PACK_LIB variable."  >&2
16     echo "For available versions see https://github.com/Open-CMSIS-Pack/gen-pack/tags." >&2
17     exit 1
18   fi
19   echo "Downloading gen-pack lib version '$1' to '$2' ..."
20   mkdir -p "$2"
21   curl -L "${URL}" -s | tar -xzf - --strip-components 1 -C "$2" || exit 1
22 }
23
24 function load_lib() {
25   if [[ -d ${GEN_PACK_LIB} ]]; then
26     . "${GEN_PACK_LIB}/gen-pack"
27     return 0
28   fi
29   local GLOBAL_LIB="/usr/local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
30   local USER_LIB="${HOME}/.local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
31   if [[ ! -d "${GLOBAL_LIB}" && ! -d "${USER_LIB}" ]]; then
32     echo "Required gen-pack lib not found!" >&2
33     install_lib "${REQUIRED_GEN_PACK_LIB}" "${USER_LIB}"
34   fi
35
36   if [[ -d "${GLOBAL_LIB}" ]]; then
37     . "${GLOBAL_LIB}/gen-pack"
38   elif [[ -d "${USER_LIB}" ]]; then
39     . "${USER_LIB}/gen-pack"
40   else
41     echo "Required gen-pack lib is not installed!" >&2
42     exit 1
43   fi
44 }
45
46 load_lib
47 find_linkchecker
48
49 #########################################
50
51 check_links "${DIRNAME}/../Documentation/index.html" "${DIRNAME}"