diff options
author | Galen Guyer <galen@galenguyer.com> | 2022-08-05 12:06:31 -0400 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2022-08-05 12:06:31 -0400 |
commit | 6c379fe0a506e4405e3e8d5f3dda4c94cbcd8496 (patch) | |
tree | fbd13784bf7eb1f45df4604bca44404128d6e879 | |
parent | 50631579696f541e6818112095151b917f5f1441 (diff) |
Install packages, preinstall and install methods, locations
-rwxr-xr-x | dots | 49 | ||||
-rw-r--r-- | lib/packages.sh | 10 | ||||
-rw-r--r-- | modules/test/install.sh | 11 |
3 files changed, 69 insertions, 1 deletions
@@ -1,5 +1,14 @@ #!/usr/bin/env bash -source lib/* +# load our paths first +_BASE="$(realpath $0)" +_BASENAME="$(basename $_BASE)" +_BASEDIR="$(dirname $_BASE)" + +# enter our host directory so we know where everything is +cd "$_BASEDIR" + +# source all library files +for lib in lib/*; do source $lib; done function intro() { cat <<EOF @@ -13,6 +22,44 @@ EOF function main() { intro echo "Running as $(id -un) on $(os::distro)" + + MODULES=modules/**/install.sh + + # perform preinstall tasks + REQUIRED_PACKAGES=() + for module in $MODULES; do + # make sure we're not using something from previous runs + unset -f preinstall + + # load the module + source $module + + # if we have a newly defined preinstall function, enter the module directory and run it + if [[ "$(type -t preinstall)" == "function" ]]; then + cd "$_scriptdir" + preinstall + cd "$_BASEDIR" + fi + done + + # install any requested packages + [[ ${#REQUIRED_PACKAGES[@]} -gt 0 ]] && packages::install ${REQUIRED_PACKAGES[@]} + + # perform installation tasks + for module in $MODULES; do + # make sure we're not using something from previous runs + unset -f install + + # load the module + source $module + + # if we have a newly defined install function, enter the module directory and run it + if [[ "$(type -t install)" == "function" ]]; then + cd "$_scriptdir" + install + cd "$_BASEDIR" + fi + done } main $@ diff --git a/lib/packages.sh b/lib/packages.sh new file mode 100644 index 0000000..05fac0a --- /dev/null +++ b/lib/packages.sh @@ -0,0 +1,10 @@ +function packages::install() { + case "$(os::distro)" in + "archlinux") + sudo pacman -S --needed $@ + ;; + *) + echo "Unknown distro, cannot install packages" + ;; + esac +} diff --git a/modules/test/install.sh b/modules/test/install.sh new file mode 100644 index 0000000..2adaf16 --- /dev/null +++ b/modules/test/install.sh @@ -0,0 +1,11 @@ +_script="$(realpath ${BASH_SOURCE[0]})" +_scriptname="$(basename $_script)" +_scriptdir="$(dirname $_script)" +_modulename="$(basename $_scriptdir)" + +#function preinstall() { +#} + +function install() { + echo "module name: $_modulename" +} |