From 37d5e7f81969666a6c3434a4e94858193abb816e Mon Sep 17 00:00:00 2001 From: modem7 Date: Wed, 24 Apr 2024 21:09:28 +0100 Subject: [PATCH] Add ability to have custom scripts --- README.md | 12 +++++++++-- .../s6-rc.d/init-custom-packages/run | 4 ++-- .../dependencies.d/init-custom-packages | 0 .../s6-rc.d/init-custom-scripts/run | 21 +++++++++++++++++++ .../s6-rc.d/init-custom-scripts/type | 1 + .../s6-overlay/s6-rc.d/init-custom-scripts/up | 1 + .../dependencies.d/init-custom-scripts | 0 .../user/contents.d/init-custom-scripts | 0 8 files changed, 35 insertions(+), 4 deletions(-) rename base-fullbuild/root/etc/s6-overlay/s6-rc.d/{svc-cron => init-custom-scripts}/dependencies.d/init-custom-packages (100%) create mode 100644 base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/run create mode 100644 base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/type create mode 100644 base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/up create mode 100644 base-fullbuild/root/etc/s6-overlay/s6-rc.d/svc-cron/dependencies.d/init-custom-scripts create mode 100644 base-fullbuild/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-custom-scripts diff --git a/README.md b/README.md index 3443c66..5e21a5a 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,16 @@ It uses cron to run the backups at a time you can configure in `data/borgmatic.d | CRON_COMMAND | Command cron will run | borgmatic --stats -v 0 2>&1 | borgmatic --stats -v 0 2>&1 | | EXTRA_CRON | Extra cron lines | 0 5 2 * * command1 | Empty | -## Breaking change -dockercli tag has been removed as there is now a variable to install it at container startup. +## Customising the container +Simply mount a volume located at /custom-cont-init.d and add any scripts you want. These scripts can contain logic for installing packages, copying over custom files to other locations, or installing plugins. + +For example: +```yaml +services: + borgmatic: + volumes: + - /home/foo/my-custom-files:/custom-cont-init.d:ro +``` ### Usage diff --git a/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-packages/run b/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-packages/run index 2dea932..b24f074 100644 --- a/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-packages/run +++ b/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-packages/run @@ -2,13 +2,13 @@ # Install DockerCLI if true if [ "${DOCKERCLI}" == "true" ]; then - echo "Installing Docker CLI and Compose..." + echo "[custom-init] Installing Docker CLI and Compose..." apk add -U --quiet docker-cli docker-cli-compose fi # Install additional packages if [ -v EXTRA_PKGS ] then - echo Installing extra packages: "$EXTRA_PKGS" + echo "[custom-init] Installing extra packages: $EXTRA_PKGS" apk add -U --quiet $EXTRA_PKGS fi \ No newline at end of file diff --git a/base-fullbuild/root/etc/s6-overlay/s6-rc.d/svc-cron/dependencies.d/init-custom-packages b/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/dependencies.d/init-custom-packages similarity index 100% rename from base-fullbuild/root/etc/s6-overlay/s6-rc.d/svc-cron/dependencies.d/init-custom-packages rename to base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/dependencies.d/init-custom-packages diff --git a/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/run b/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/run new file mode 100644 index 0000000..36ea70e --- /dev/null +++ b/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/run @@ -0,0 +1,21 @@ +#!/usr/bin/with-contenv bash + +# Directories +SCRIPTS_DIR="/custom-cont-init.d" + +# Make sure custom init directory exists and has files in it +if [[ -e "${SCRIPTS_DIR}" ]] && [[ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]]; then + echo "[custom-init] Files found, executing" + for SCRIPT in "${SCRIPTS_DIR}"/*; do + NAME="$(basename "${SCRIPT}")" + if [[ -f "${SCRIPT}" ]]; then + echo "[custom-init] ${NAME}: executing..." + /bin/bash "${SCRIPT}" + echo "[custom-init] ${NAME}: exited $?" + elif [[ ! -f "${SCRIPT}" ]]; then + echo "[custom-init] ${NAME}: is not a file" + fi + done +else + echo "[custom-init] No custom files found, skipping..." +fi diff --git a/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/type b/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/type @@ -0,0 +1 @@ +oneshot diff --git a/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/up b/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/up new file mode 100644 index 0000000..4beedc9 --- /dev/null +++ b/base-fullbuild/root/etc/s6-overlay/s6-rc.d/init-custom-scripts/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/init-custom-scripts/run diff --git a/base-fullbuild/root/etc/s6-overlay/s6-rc.d/svc-cron/dependencies.d/init-custom-scripts b/base-fullbuild/root/etc/s6-overlay/s6-rc.d/svc-cron/dependencies.d/init-custom-scripts new file mode 100644 index 0000000..e69de29 diff --git a/base-fullbuild/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-custom-scripts b/base-fullbuild/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-custom-scripts new file mode 100644 index 0000000..e69de29