Commit 6fa9a4a1 authored by Richard Darst's avatar Richard Darst

Create run-hooks function and switch pre-start hook to that

- This is initial prototype of a more flexible hooks system.
- Add /usr/local/bin/before-notebook.d hooks which is run right before
  the notebook runs.
parent a73212ea
...@@ -11,22 +11,33 @@ else ...@@ -11,22 +11,33 @@ else
cmd=$* cmd=$*
fi fi
for f in /usr/local/bin/start-notebook.d/*; do run-hooks () {
# Source scripts or run executable files in a directory
if [[ ! -d "$1" ]] ; then
return
fi
echo "$0: running hooks in $1"
for f in "$1"/*; do
case "$f" in case "$f" in
*.sh) *.sh)
echo "$0: running $f"; . "$f" echo "$0: running $f"
source "$f"
;; ;;
*) *)
if [ -x $f ]; then if [[ -x "$f" ]] ; then
echo "$0: running $f" echo "$0: running $f"
$f "$f"
else else
echo "$0: ignoring $f" echo "$0: ignoring $f"
fi fi
;; ;;
esac esac
echo echo "$0: done running hooks in $1"
done done
}
run-hooks /usr/local/bin/start-notebook.d
# Handle special flags if we're root # Handle special flags if we're root
if [ $(id -u) == 0 ] ; then if [ $(id -u) == 0 ] ; then
...@@ -89,7 +100,7 @@ if [ $(id -u) == 0 ] ; then ...@@ -89,7 +100,7 @@ if [ $(id -u) == 0 ] ; then
# Exec the command as NB_USER with the PATH and the rest of # Exec the command as NB_USER with the PATH and the rest of
# the environment preserved # the environment preserved
eval "$NB_PRE_START_HOOK" run-hooks /usr/local/bin/before-notebook.d
echo "Executing the command: $cmd" echo "Executing the command: $cmd"
exec sudo -E -H -u $NB_USER PATH=$PATH XDG_CACHE_HOME=/home/$NB_USER/.cache PYTHONPATH=$PYTHONPATH $cmd exec sudo -E -H -u $NB_USER PATH=$PATH XDG_CACHE_HOME=/home/$NB_USER/.cache PYTHONPATH=$PYTHONPATH $cmd
else else
...@@ -133,7 +144,7 @@ else ...@@ -133,7 +144,7 @@ else
fi fi
# Execute the command # Execute the command
run-hooks /usr/local/bin/before-notebook.d
echo "Executing the command: $cmd" echo "Executing the command: $cmd"
eval "$NB_PRE_START_HOOK"
exec $cmd exec $cmd
fi fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment