ref(install): some refactoring

This commit is contained in:
TheK4n 2023-10-17 22:58:06 +03:00
parent 6648edd51d
commit 685f7bdade

29
install
View File

@ -200,14 +200,14 @@ cmd_docker() {
__install_from_sandbox
}
cmd_check() {
is_target_installed() {
local not_fully_installed=0
local targetfile
for targetfile in ${TARGETS["$1"]}
do
if [ "${targetfile::1}" = "%" ]; then
cmd_check "${targetfile:1}" || not_fully_installed=1
is_target_installed "${targetfile:1}" || not_fully_installed=1
else
if [ ! -e "$TARGET_PATH/$targetfile" ]; then
echo "$targetfile not linked"
@ -233,17 +233,20 @@ find_targets_that_depend_on() {
done
}
die_if_installed_targets_depend_on() {
for reverse_dependecy in $(find_targets_that_depend_on "$1")
do
if is_target_installed "$reverse_dependecy" >/dev/null; then
_die "target '$reverse_dependecy' is depends on installed target '$1'. Exiting..." 1
fi
done
}
cmd_unlink() {
local target targetfile
for target in "$@"
do
for reverse_dependecy in $(find_targets_that_depend_on "$target")
do
if cmd_check "$reverse_dependecy" >/dev/null; then
echo "'$reverse_dependecy' is depends on installed '$target'. Exiting..."
exit 1
fi
done
die_if_installed_targets_depend_on "$target"
for targetfile in ${TARGETS["$target"]}
do
@ -307,10 +310,10 @@ unset executed_command
readonly executed_command="$1"
case "$executed_command" in
unlink) shift; cmd_unlink "$@" ;;
check) shift; cmd_check "$@" ;;
list) shift; cmd_list "$@" ;;
help) shift; cmd_help "$@" ;;
unlink) shift; cmd_unlink "$@" ;;
check) shift; is_target_installed "$@" ;;
list) shift; cmd_list "$@" ;;
help) shift; cmd_help "$@" ;;
*) shift; cmd_install "$executed_command" "$@" ;;
esac
exit 0