(feat) add dependencies

This commit is contained in:
b1ek 2024-02-20 11:46:57 +10:00
parent 44afad7241
commit b4c9cb55d2
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 48 additions and 1 deletions

View File

@ -78,6 +78,19 @@ tmpdir() {
exec_brick() {
echo -e "$(bricksenv)\n$*" | bash
}
print_long_list() {
list=($@)
i=0
printf '%s' "$(inf)$(inf)"
for el in ${list[@]}; do
printf '%s ' $el
if [ "$i" == "2" ]; then
printf '\n%s' "$(inf)$(inf)"
fi
i=$(( i + 1 ))
done
echo
}
# checking that brick's dependencies are installed
BRICK_DEPS=(curl)
@ -190,11 +203,45 @@ if [ "$ERRORED" == "true" ]; then
exit 1
fi
# lets resolve the dependencies huh
find_deps_for() {
brick=$1
deps=()
SCRIPT="
source $(getbrick $brick)\n
if ! [ \"\$dependencies\" == \"\" ]; then\n
echo \"\${dependencies[@]}\"\n
fi\n
"
deps=$(exec_brick $SCRIPT)
deps=(${deps[@]})
if ! [ "${#deps[@]}" == "0" ]; then
for dep in "${deps[@]}"; do
if ! [ -f "$(getbrick $dep)" ]; then
err "$brick depends on $dep, which is not an available package"
ERRORED=true
fi
ndeps=$(find_deps_for $dep)
deps=(${deps[@]} ${ndeps[@]})
done
fi
echo ${deps[@]}
}
for pkg in "${PKGS[@]}"; do
PKGS=(${PKGS[@]} $(find_deps_for $pkg))
done
if [ "$ERRORED" == "true" ]; then
exit 1
fi
if [ "${#PKGS[@]}" == "0" ]; then
inf "nothing to do"
exit
else
inf "packages to install: ${PKGS[@]}"
inf "packages to install:"
print_long_list "${PKGS[@]}"
if ! user_confirm; then
inf "canceled"
exit