Skip to content

Commit

Permalink
Add shell functions to check for installed tools
Browse files Browse the repository at this point in the history
The new shell function `check_for_installed_tools` can be used to
check for installed tools. the function takes a list of required
executables for argument. Shell process is aborted if any of the tools
is missing. All tools missing in the list are reported.

Similar the the shell function `check_for_installed_files` checks for
installed files, here used to make sure header files are installed.
  • Loading branch information
berhoel committed Sep 23, 2024
1 parent 772f25a commit d3d2490
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
22 changes: 3 additions & 19 deletions Sming/Arch/Esp32/Tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,9 @@ case $DIST in
;;

*)
TOOLS_MISSING=0
COMMANDS=(dfu-util bison flex gperf)
for COMMAND in "${COMMANDS[@]}"; do
if ! [ -x $(command -v "${COMMAND}") ]; then
TOOLS_MISSING=1
echo "Install programm ${COMMAND}"
fi
done
INCLUDES=("/usr/include/ffi.h" "/usr/include/ssl/ssl.h")
for INCLUDE in "${INCLUDES[@]}"; do
if ! [ -f "${INCLUDE}" ]; then
TOOLS_MISSING=1
echo "Install development package providing ${INCLUDE}"
fi
done
if [ $TOOLS_MISSING != 0 ]; then
echo "ABORTING"
exit 1
fi
check_for_installed_tools dfu-util bison flex gperf

check_for_installed_files "/usr/include/ffi.h" "/usr/include/ssl/ssl.h"
PACKAGES=()
;;

Expand Down
58 changes: 42 additions & 16 deletions Tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,46 @@ FONT_PACKAGES=(\
fonts-droid-fallback \
)

check_for_installed_tools () {
REQUIRED_TOOLS="${@}"
echo -e "Checking for installed tools.\nrequirded tools: ${REQUIRED_TOOLS}"
TOOLS_MISSING=0
for TOOL in ${REQUIRED_TOOLS}; do
if ! command -v "${TOOL}" > /dev/null ; then
TOOLS_MISSING=1
echo "Install required tool ${TOOL}"
fi
done
if [ $TOOLS_MISSING != 0 ]; then
echo "ABORTING"
if [ $sourced = 1 ]; then
return 1
else
exit 1
fi
fi
}

check_for_installed_files () {
REQUIRED_FILES="${@}"
echo -e "Checking for installed files.\nrequirded files: ${REQUIRED_FILES}"
FILES_MISSING=0
for FILE in ${REQUIRED_FILES}; do
if ! [ -f "${FILE}" ]; then
FILES_MISSING=1
echo "Install required FILE ${FILE}"
fi
done
if [ $FILES_MISSING != 0 ]; then
echo "ABORTING"
if [ $sourced = 1 ]; then
return 1
else
exit 1
fi
fi
}

EXTRA_PACKAGES=()
OPTIONAL_PACKAGES=()

Expand Down Expand Up @@ -101,7 +141,7 @@ elif [ -n "$(command -v dnf)" ]; then
else
TOOLS_MISSING=0
echo "Unsupported distribution"
REQUIRED_TOOLS=(
check_for_installed_tools \
ccache \
cmake \
curl \
Expand All @@ -112,21 +152,7 @@ else
g++ \
python3 \
pip3 \
wget \
)
for TOOL in "${REQUIRED_TOOLS[@]}"; do
if ! [ -x $(command -v "${TOOL}") ]; then
TOOLS_MISSING=1
echo "Install required tool ${TOOL}"
fi
done
if [ $TOOLS_MISSING != 0 ]; then
if [ $sourced = 1 ]; then
return 1
else
exit 1
fi
fi
wget
fi

# Common install
Expand Down

0 comments on commit d3d2490

Please sign in to comment.