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 () {
case "$f" in # Source scripts or run executable files in a directory
*.sh) if [[ ! -d "$1" ]] ; then
echo "$0: running $f"; . "$f" return
;; fi
*) echo "$0: running hooks in $1"
if [ -x $f ]; then for f in "$1"/*; do
echo "$0: running $f" case "$f" in
$f *.sh)
else echo "$0: running $f"
echo "$0: ignoring $f" source "$f"
fi ;;
;; *)
esac if [[ -x "$f" ]] ; then
echo echo "$0: running $f"
done "$f"
else
echo "$0: ignoring $f"
fi
;;
esac
echo "$0: done running hooks in $1"
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