summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2022-08-05 12:06:31 -0400
committerGalen Guyer <galen@galenguyer.com>2022-08-05 12:06:31 -0400
commit6c379fe0a506e4405e3e8d5f3dda4c94cbcd8496 (patch)
treefbd13784bf7eb1f45df4604bca44404128d6e879
parent50631579696f541e6818112095151b917f5f1441 (diff)
Install packages, preinstall and install methods, locations
-rwxr-xr-xdots49
-rw-r--r--lib/packages.sh10
-rw-r--r--modules/test/install.sh11
3 files changed, 69 insertions, 1 deletions
diff --git a/dots b/dots
index 4e24674..3c1807b 100755
--- a/dots
+++ b/dots
@@ -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"
+}