From 4fbb994fec3804e57bf6b5f760713ba78f527430 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Sat, 21 Jan 2023 22:53:03 -0800 Subject: [PATCH] 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 --- src/common/scripts/container.env | 2 ++ src/common/scripts/entrypoint.sh | 6 ++++++ src/common/scripts/host-id-map.sh | 6 ++++++ src/common/scripts/shell-update.sh | 0 src/common/scripts/start.sh | 22 ++++++++++++++++++++++ 5 files changed, 36 insertions(+) create mode 100644 src/common/scripts/container.env create mode 100755 src/common/scripts/entrypoint.sh create mode 100644 src/common/scripts/host-id-map.sh create mode 100644 src/common/scripts/shell-update.sh create mode 100755 src/common/scripts/start.sh diff --git a/src/common/scripts/container.env b/src/common/scripts/container.env new file mode 100644 index 0000000..11e4fce --- /dev/null +++ b/src/common/scripts/container.env @@ -0,0 +1,2 @@ +export SHARED_DIRS="/shell /opt /data" +export INITIAL_DIR=/opt/scripts \ No newline at end of file diff --git a/src/common/scripts/entrypoint.sh b/src/common/scripts/entrypoint.sh new file mode 100755 index 0000000..4270156 --- /dev/null +++ b/src/common/scripts/entrypoint.sh @@ -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 "$@" diff --git a/src/common/scripts/host-id-map.sh b/src/common/scripts/host-id-map.sh new file mode 100644 index 0000000..739bb93 --- /dev/null +++ b/src/common/scripts/host-id-map.sh @@ -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 \ No newline at end of file diff --git a/src/common/scripts/shell-update.sh b/src/common/scripts/shell-update.sh new file mode 100644 index 0000000..e69de29 diff --git a/src/common/scripts/start.sh b/src/common/scripts/start.sh new file mode 100755 index 0000000..39f7426 --- /dev/null +++ b/src/common/scripts/start.sh @@ -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 \ No newline at end of file