summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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"
+}