Skip to content

Commit

Permalink
refactor(install): clean up conditions and remove manual installs
Browse files Browse the repository at this point in the history
  • Loading branch information
spywhere committed Apr 9, 2024
1 parent 665692e commit cbe609a
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 281 deletions.
161 changes: 0 additions & 161 deletions installs/make.sh

This file was deleted.

40 changes: 22 additions & 18 deletions lib/process/custom.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
#!/bin/sh

_summarize_custom() {
if test -n "$_CUSTOM"; then
print "$esc_green==>$esc_reset The following installations will be run:"
eval "set -- $_CUSTOM"
for try_run_install__fn in "$@"; do
try_run_install__package_name="$(parse_field "$try_run_install__fn" package_name)"
if test -z "$_CUSTOM"; then
return
fi

if test -z "$try_run_install__package_name"; then
try_run_install__package_name="$(parse_field "$try_run_install__fn" fn)"
fi
print "$esc_green==>$esc_reset The following installations will be run:"
eval "set -- $_CUSTOM"
for try_run_install__fn in "$@"; do
try_run_install__package_name="$(parse_field "$try_run_install__fn" package_name)"

print " $esc_blue-$esc_reset $try_run_install__package_name"
done
fi
if test -z "$try_run_install__package_name"; then
try_run_install__package_name="$(parse_field "$try_run_install__fn" fn)"
fi

print " $esc_blue-$esc_reset $try_run_install__package_name"
done
}

_run_custom() {
if test -n "$_CUSTOM"; then
step "Performing custom installations..."
eval "set -- $_CUSTOM"
for try_run_install__custom in "$@"; do
try_run_install__fn="$(parse_field "$try_run_install__custom" fn)"
"$try_run_install__fn"
done
if test -z "$_CUSTOM"; then
return
fi

step "Performing custom installations..."
eval "set -- $_CUSTOM"
for try_run_install__custom in "$@"; do
try_run_install__fn="$(parse_field "$try_run_install__custom" fn)"
"$try_run_install__fn"
done
}
117 changes: 64 additions & 53 deletions lib/process/packages.sh
Original file line number Diff line number Diff line change
@@ -1,72 +1,83 @@
#!/bin/sh

_prepare_packages() {
if ! _has_skip package || test -n "$_INDICATED"; then
for try_run_install__package_path in "$HOME/$DOTFILES/packages"/*.sh; do
try_run_install__package=$(basename "$try_run_install__package_path")
try_run_install__package=${try_run_install__package%.sh}
if ! test -d "$HOME/$DOTFILES/packages"; then
warn "No package found"
return
fi

print_inline "$esc_yellow==>$esc_reset Checking package $try_run_install__package..."
if _has_skip package && test -z "$_INDICATED"; then
return
fi

# Skip requested packages
if (_has_skip package || _has_skip "$try_run_install__package") && ! _has_indicate "$try_run_install__package"; then
continue
fi
for try_run_install__package_path in "$HOME/$DOTFILES/packages"/*.sh; do
try_run_install__package=$(basename "$try_run_install__package_path")
try_run_install__package=${try_run_install__package%.sh}

# Package could be loaded from the dependency list
if has_package "$try_run_install__package"; then
continue
fi
print_inline "$esc_yellow==>$esc_reset Checking package $try_run_install__package..."

_RUNNING="$try_run_install__package"
_FULFILLED=""
# Add package to the loaded list (prevent dependency cycle)
_LOADED=$(_add_to_list "$_LOADED" "$_RUNNING")
. "$try_run_install__package_path"
# Skip requested packages
if (_has_skip package || _has_skip "$try_run_install__package") && ! _has_indicate "$try_run_install__package"; then
continue
fi

# Remove optional packages from the loaded list
if test "$_FULFILLED" = "optional"; then
try_run_install__new_loaded=""
eval "set -- $_LOADED"
for try_run_install__loaded_package in "$@"; do
if test "$try_run_install__loaded_package" = "$_RUNNING"; then
continue
fi
try_run_install__new_loaded=$(_add_to_list "$try_run_install__new_loaded" "$try_run_install__loaded_package")
done
_LOADED="$try_run_install__new_loaded"
fi
done
fi
# Package could be loaded from the dependency list
if has_package "$try_run_install__package"; then
continue
fi

_RUNNING="$try_run_install__package"
_FULFILLED=""
# Add package to the loaded list (prevent dependency cycle)
_LOADED=$(_add_to_list "$_LOADED" "$_RUNNING")
. "$try_run_install__package_path"

# Remove optional packages from the loaded list
if test "$_FULFILLED" = "optional"; then
try_run_install__new_loaded=""
eval "set -- $_LOADED"
for try_run_install__loaded_package in "$@"; do
if test "$try_run_install__loaded_package" = "$_RUNNING"; then
continue
fi
try_run_install__new_loaded=$(_add_to_list "$try_run_install__new_loaded" "$try_run_install__loaded_package")
done
_LOADED="$try_run_install__new_loaded"
fi
done
}

_summarize_packages() {
if test -n "$_PACKAGES"; then
print "$esc_green==>$esc_reset The following packages will be installed:"
eval "set -- $_PACKAGES"
for try_run_install__package in "$@"; do
try_run_install__manager_name="$(parse_field "$try_run_install__package" manager_name)"
try_run_install__package_name="$(parse_field "$try_run_install__package" package_name)"
if test -z "$try_run_install__manager_name"; then
try_run_install__manager_name="$(parse_field "$try_run_install__package" manager)"
fi
if test -z "$_PACKAGES"; then
return
fi

if test -z "$try_run_install__package_name"; then
try_run_install__package_name="$(parse_field "$try_run_install__package" package)"
fi
print "$esc_green==>$esc_reset The following packages will be installed:"
eval "set -- $_PACKAGES"
for try_run_install__package in "$@"; do
try_run_install__manager_name="$(parse_field "$try_run_install__package" manager_name)"
try_run_install__package_name="$(parse_field "$try_run_install__package" package_name)"
if test -z "$try_run_install__manager_name"; then
try_run_install__manager_name="$(parse_field "$try_run_install__package" manager)"
fi

if test -n "$try_run_install__manager_name"; then
try_run_install__manager_name=" ${esc_blue}via$esc_reset $try_run_install__manager_name"
fi
if test -z "$try_run_install__package_name"; then
try_run_install__package_name="$(parse_field "$try_run_install__package" package)"
fi

print " $esc_blue-$esc_reset $try_run_install__package_name$try_run_install__manager_name"
done
fi
if test -n "$try_run_install__manager_name"; then
try_run_install__manager_name=" ${esc_blue}via$esc_reset $try_run_install__manager_name"
fi

print " $esc_blue-$esc_reset $try_run_install__package_name$try_run_install__manager_name"
done
}

_run_packages() {
if test -n "$_PACKAGES"; then
eval "set -- $_PACKAGES"
install_packages "$@"
if test -z "$_PACKAGES"; then
return
fi

eval "set -- $_PACKAGES"
install_packages "$@"
}
Loading

0 comments on commit cbe609a

Please sign in to comment.