ref(install): some refactoring

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

23
install
View File

@ -200,14 +200,14 @@ cmd_docker() {
__install_from_sandbox __install_from_sandbox
} }
cmd_check() { is_target_installed() {
local not_fully_installed=0 local not_fully_installed=0
local targetfile local targetfile
for targetfile in ${TARGETS["$1"]} for targetfile in ${TARGETS["$1"]}
do do
if [ "${targetfile::1}" = "%" ]; then if [ "${targetfile::1}" = "%" ]; then
cmd_check "${targetfile:1}" || not_fully_installed=1 is_target_installed "${targetfile:1}" || not_fully_installed=1
else else
if [ ! -e "$TARGET_PATH/$targetfile" ]; then if [ ! -e "$TARGET_PATH/$targetfile" ]; then
echo "$targetfile not linked" echo "$targetfile not linked"
@ -233,17 +233,20 @@ find_targets_that_depend_on() {
done 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() { cmd_unlink() {
local target targetfile local target targetfile
for target in "$@" for target in "$@"
do do
for reverse_dependecy in $(find_targets_that_depend_on "$target") die_if_installed_targets_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
for targetfile in ${TARGETS["$target"]} for targetfile in ${TARGETS["$target"]}
do do
@ -308,7 +311,7 @@ readonly executed_command="$1"
case "$executed_command" in case "$executed_command" in
unlink) shift; cmd_unlink "$@" ;; unlink) shift; cmd_unlink "$@" ;;
check) shift; cmd_check "$@" ;; check) shift; is_target_installed "$@" ;;
list) shift; cmd_list "$@" ;; list) shift; cmd_list "$@" ;;
help) shift; cmd_help "$@" ;; help) shift; cmd_help "$@" ;;
*) shift; cmd_install "$executed_command" "$@" ;; *) shift; cmd_install "$executed_command" "$@" ;;