From b3f25262c260e81a4bffaa6444b48013f902a04a Mon Sep 17 00:00:00 2001 From: Jarkko Kniivilä Date: Sat, 5 Sep 2015 23:31:42 +0300 Subject: Fix hooks so that they are run in the directory where they are located Calls `find(1)` with the `-exec` action just like before but instead of `run_hooks()` letting `find` execute the hook directly it is wrapped in a shell one-liner which changes to the hook's directory and executes the hook with "./" prepended to its basename. These changes allow hooks to refer to dotfiles with relative paths. For instance we can call a Makefile two directories up simply with `make -C ../..`. Also make sure we are compatible with Solaris' Bourne shell and `find(1)`. Closes #150. Closes #149. --- share/rcm.sh.in | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'share/rcm.sh.in') diff --git a/share/rcm.sh.in b/share/rcm.sh.in index d8fc19e..c7a3dfb 100644 --- a/share/rcm.sh.in +++ b/share/rcm.sh.in @@ -126,7 +126,14 @@ run_hooks() { find_opts=-print fi - find "$hook_file" -type f \( \( -user $USER -perm -100 \) -o -perm -001 \) $find_opts -exec {} \; + # Emulate the non-POSIX-compliant `-execdir` action with `-exec` and a shell one-liner. + # The former is however a bit better when it comes to security. On the other hand + # running these hooks imply some level of trust; surely one doesn't clone somebody + # else's dotfiles repository without reviewing the hooks before doing an `rcup`? + find "$hook_file" -type f \( \( -user $USER -perm -100 \) -o -perm -001 \) \ + -exec \ + sh -c 'cd "`dirname $1`" && ./"`basename $1`"' arg0 '{}' \ + \; else $DEBUG "no $when-$direction hook present for $dotfiles_dir, skipping" fi -- cgit v1.2.3