aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xhooks/housekeeping.hook14
-rwxr-xr-xinstall.sh18
-rw-r--r--lib/funcs.sh17
-rw-r--r--lib/hooks.sh18
4 files changed, 50 insertions, 17 deletions
diff --git a/hooks/housekeeping.hook b/hooks/housekeeping.hook
new file mode 100755
index 0000000..7fc77a9
--- /dev/null
+++ b/hooks/housekeeping.hook
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+git submodule init
+git submodule update
+
+#.files is used to tell scripts where to look for the dotfiles
+[ -f "$HOME/.files" ] && source "$HOME/.files"
+if [ "$DOTFILEBASE" != "$(pwd)" ] && yes_no "'.files' out of date. Regenerate?"; then
+ echo "DOTFILEBASE=\"$(pwd)\"" > $HOME/.files
+fi
+
+if [ ! -f "$HOME/.files.config" ] && yes_no ".files.config does not exist. Populate with defaults?"; then
+ cp "config.default" "$HOME/.files.config"
+fi
diff --git a/install.sh b/install.sh
index 31051b2..e0dbff0 100755
--- a/install.sh
+++ b/install.sh
@@ -12,9 +12,14 @@ cd "$WORKDIR" || fail 1 "The working directory could not be determined."
echo "Working in $WORKDIR"
echo "Homedir is $HOME"
+# For hooks
+export WORKDIR
+
# === CODE BELOW HERE ===
-source "lib/funcs.sh" || fail 1 "Failed to load components"
+for f in lib/*.sh; do
+ source "$f" || fail 1 "Failed to load $f"
+done
if [ ! -f "config.csv" ] || [ ! -f "sets.csv" ]; then
# TODO Create them
@@ -44,8 +49,8 @@ COMMANDS
a selection menu is showm.
add PATH
Add PATH to managed configs
- hk
- perform housekeeping functions
+ hook HOOK
+ manually call a hook
EOF
exit 1
fi
@@ -63,9 +68,10 @@ case $CMD in
for cnf in "${selected[@]}"; do
choose_target "$cnf"
done
- housekeeping;;
- hk)
- housekeeping;;
+
+ call_hook housekeeping;;
+ hook)
+ call_hook "$1";;
add)
test -e "$1" || fail 1 "Target file not found: $1"
diff --git a/lib/funcs.sh b/lib/funcs.sh
index 2126e9a..0122c60 100644
--- a/lib/funcs.sh
+++ b/lib/funcs.sh
@@ -100,17 +100,12 @@ choose_target() {
fi
}
-housekeeping() {
- git submodule init
- git submodule update
-
- #.files is used to tell scripts where to look for the dotfiles
- [ -f "$HOME/.files" ] && source "$HOME/.files"
- if [ "$DOTFILEBASE" != "$(pwd)" ] && yes_no "'.files' out of date. Regenerate?"; then
- echo "DOTFILEBASE=\"$(pwd)\"" > $HOME/.files
+debug() {
+ if [ "$DEBUG" = "yes" ]; then
+ echo "[DEBUG] $@"
fi
+}
- if [ ! -f "$HOME/.files.config" ] && yes_no ".files.config does not exist. Populate with defaults?"; then
- cp "config.default" "$HOME/.files.config"
- fi
+warning() {
+ echo "[WARNING] $@"
}
diff --git a/lib/hooks.sh b/lib/hooks.sh
new file mode 100644
index 0000000..8d5fc1d
--- /dev/null
+++ b/lib/hooks.sh
@@ -0,0 +1,18 @@
+# Functions for hooks
+
+# 1: Name of hook
+call_hook() {
+ if [ ! -x "hooks/$1.hook" ]; then
+ debug "$1.hook was not found. Skipping."
+ return
+ fi
+
+ debug "Running hook $1"
+
+ hooks/$1.hook 2>&1 | (while read line; do echo [hook: $1] $line; done)
+ RET=${PIPESTATUS[0]}
+
+ if [ $RET -ne 0 ]; then
+ warning "Hook $1 exitet with code $RET"
+ fi
+}