Compare commits

...

2 Commits

Author SHA1 Message Date
b1ek 098f3a0962
(fix) fix the extra empty line printed 2024-02-22 01:09:36 +10:00
b1ek b4c9cb55d2
(feat) add dependencies 2024-02-20 11:46:57 +10:00
1 changed files with 50 additions and 1 deletions

View File

@ -78,6 +78,21 @@ tmpdir() {
exec_brick() { exec_brick() {
echo -e "$(bricksenv)\n$*" | bash 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
if ! [ "$(( "${#list[@]}" % 3 ))" == "0" ]; then
printf '\n%s' "$(inf)$(inf)"
fi
fi
i=$(( i + 1 ))
done
echo
}
# checking that brick's dependencies are installed # checking that brick's dependencies are installed
BRICK_DEPS=(curl) BRICK_DEPS=(curl)
@ -190,11 +205,45 @@ if [ "$ERRORED" == "true" ]; then
exit 1 exit 1
fi 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 if [ "${#PKGS[@]}" == "0" ]; then
inf "nothing to do" inf "nothing to do"
exit exit
else else
inf "packages to install: ${PKGS[@]}" inf "packages to install:"
print_long_list "${PKGS[@]}"
if ! user_confirm; then if ! user_confirm; then
inf "canceled" inf "canceled"
exit exit