feat: new entrypoint script, calls start script which in turn has case statement

to be more flexible passing commands or executing a script when staring container
by default will start a shell
can map host user set of to be shared directories in the container (via volumes) if HOST_MAP is set
master
Kebler Network System Administrator 2023-01-21 22:53:03 -08:00
parent 94d6e720e0
commit 4fbb994fec
5 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,2 @@
export SHARED_DIRS="/shell /opt /data"
export INITIAL_DIR=/opt/scripts

View File

@ -0,0 +1,6 @@
#!/bin/bash
export SCRIPTS_DIR="$(dirname $(realpath "${BASH_SOURCE:-$0}"))"
# echo arguments in entry $@
# execute the start script in a login shell so that the uci shell will be sourced
# see https://stackoverflow.com/a/1711985/4695378 passing $@
/bin/bash -l -c '${SCRIPTS_DIR}/start.sh $@' $0 "$@"

View File

@ -0,0 +1,6 @@
#!/bin/bash
source $SCRIPTS_DIR/container.env
if [[ $HOST_MAP ]]; then
echo changing ownership of $SHARED_DIRS to $HOST_MAP
$([[ ! $EUID -eq 0 ]] && echo sudo) chown -R $HOST_MAP $SHARED_DIRS
fi

View File

22
src/common/scripts/start.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
# echo arguments in start script: "$@"
source $SCRIPTS_DIR/container.env
source $SCRIPTS_DIR/host-id-map.sh
case "$1" in
shell_update)
echo updating shell repos
;;
cmd)
shift 1
"$@"
;;
script)
shift 1
module_load path
script=$([[ $(isAbsPath $1) ]] && echo $1 || echo $SCRIPTS_DIR/$1)
shift 1
/bin/bash $script "$@"
;;
*)
/bin/bash -c "cd ${INITIAL_DIR:-$HOME}; exec bash -l"
esac