Skip to content

Commit

Permalink
feat: ✨ add before and after hooks for exectuable scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Villard <[email protected]>
  • Loading branch information
eviweb committed Sep 5, 2022
1 parent 994a7b1 commit 18629f8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Every files in:
* `config/copy/[HOSTNAME]/[TARGET_PATH]`: are copied to *[TARGET_PATH]* only if *[HOSTNAME]* corresponds to the current `${HOSTNAME}`
* `config/link/common/[TARGET_PATH]`: are symlinked to *[TARGET_PATH]*
* `config/link/[HOSTNAME]/[TARGET_PATH]`: are symlinked to *[TARGET_PATH]* only if *[HOSTNAME]* corresponds to the current `${HOSTNAME}`
* `config/run/common`: are executed
* `config/run/[HOSTNAME]`: are executed only if *[HOSTNAME]* corresponds to the current `${HOSTNAME}`
* `config/run/common/after`: are executed after all other actions on all hosts
* `config/run/[HOSTNAME]/after`: are executed after all other actions only if *[HOSTNAME]* corresponds to the current `${HOSTNAME}`
* `config/run/common/before`: are executed before all other actions on all hosts
* `config/run/[HOSTNAME]/before`: are executed before all other actions only if *[HOSTNAME]* corresponds to the current `${HOSTNAME}`

> Pkease note that the `common` namespace is used to share configurations across many hosts, while using a `HOSTNAME` namespace permits to dedicate configurations to a specific host.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified images/config-tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 25 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,16 @@ link_files()
done
}

find_scripts()
{
local priority="$1"

find "$(config_run_dir)" -path "*/$1/*" -and \( -name "*.sh" -or -name "*.bash" \) -executable | sort
}

run_scripts()
{
local scripts=( $(find_files "$(config_run_dir)") )
local scripts=( $@ )
local msg=""
local result

Expand Down Expand Up @@ -198,6 +205,17 @@ if ! is_sourced; then
esac
done

before_scripts=(
$(find_scripts "before")
)

if [ 0 -lt "${#before_scripts[@]}" ]; then
log "\e[34mRun configuration scripts...\e[0m"
run_scripts "${before_scripts[@]}"
else
log "\e[34mNothing to execute\e[0m"
fi

if [ -d "$(config_copy_dir)" ]; then
log "\e[34mCopy configuration files...\e[0m"
copy_files
Expand All @@ -212,9 +230,13 @@ if ! is_sourced; then
log "\e[34mNothing to link\e[0m"
fi

if [ -d "$(config_run_dir)" ]; then
after_scripts=(
$(find_scripts "after")
)

if [ 0 -lt "${#after_scripts[@]}" ]; then
log "\e[34mRun configuration scripts...\e[0m"
run_scripts
run_scripts "${after_scripts[@]}"
else
log "\e[34mNothing to execute\e[0m"
fi
Expand Down

0 comments on commit 18629f8

Please sign in to comment.