From 35b17f6ce19093ca1ea2ab07e0c01c04b2b36d5b Mon Sep 17 00:00:00 2001 From: casjay Date: Sat, 29 Nov 2025 08:22:47 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Update=20configuration=20files?= =?UTF-8?q?=20=F0=9F=94=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dockerfile .env.scripts rootfs/root/docker/setup/00-init.sh rootfs/root/docker/setup/01-system.sh rootfs/root/docker/setup/02-packages.sh rootfs/root/docker/setup/03-files.sh rootfs/root/docker/setup/04-users.sh rootfs/root/docker/setup/05-custom.sh rootfs/root/docker/setup/06-post.sh rootfs/root/docker/setup/07-cleanup.sh rootfs/usr/local/bin/entrypoint.sh rootfs/usr/local/bin/pkmgr rootfs/usr/local/etc/docker/functions/entrypoint.sh rootfs/usr/local/etc/docker/init.d/00-opengist.sh rootfs/usr/local/share/template-files/config/env/default.sample rootfs/usr/local/share/template-files/config/env/examples/00-directory.sh rootfs/usr/local/share/template-files/config/env/examples/addresses.sh rootfs/usr/local/share/template-files/config/env/examples/certbot.sh rootfs/usr/local/share/template-files/config/env/examples/couchdb.sh rootfs/usr/local/share/template-files/config/env/examples/dockerd.sh rootfs/usr/local/share/template-files/config/env/examples/global.sh rootfs/usr/local/share/template-files/config/env/examples/healthcheck.sh rootfs/usr/local/share/template-files/config/env/examples/mariadb.sh rootfs/usr/local/share/template-files/config/env/examples/mongodb.sh rootfs/usr/local/share/template-files/config/env/examples/networking.sh rootfs/usr/local/share/template-files/config/env/examples/other.sh rootfs/usr/local/share/template-files/config/env/examples/php.sh rootfs/usr/local/share/template-files/config/env/examples/postgres.sh rootfs/usr/local/share/template-files/config/env/examples/redis.sh rootfs/usr/local/share/template-files/config/env/examples/services.sh rootfs/usr/local/share/template-files/config/env/examples/ssl.sh rootfs/usr/local/share/template-files/config/env/examples/supabase.sh rootfs/usr/local/share/template-files/config/env/examples/webservers.sh rootfs/usr/local/share/template-files/config/env/examples/zz-entrypoint.sh --- .env.scripts | 63 +- Dockerfile | 38 +- rootfs/root/docker/setup/00-init.sh | 47 +- rootfs/root/docker/setup/01-system.sh | 45 +- rootfs/root/docker/setup/02-packages.sh | 45 +- rootfs/root/docker/setup/03-files.sh | 98 ++- rootfs/root/docker/setup/04-users.sh | 45 +- rootfs/root/docker/setup/05-custom.sh | 72 +- rootfs/root/docker/setup/06-post.sh | 45 +- rootfs/root/docker/setup/07-cleanup.sh | 49 +- rootfs/usr/local/bin/entrypoint.sh | 730 ++++++++++-------- rootfs/usr/local/bin/pkmgr | 66 +- .../local/etc/docker/functions/entrypoint.sh | 234 +++--- .../local/etc/docker/init.d/00-opengist.sh | 580 ++++++++------ .../template-files/config/env/default.sample | 49 +- .../config/env/examples/00-directory.sh | 4 +- .../config/env/examples/addresses.sh | 4 +- .../config/env/examples/certbot.sh | 4 +- .../config/env/examples/couchdb.sh | 4 +- .../config/env/examples/dockerd.sh | 4 +- .../config/env/examples/global.sh | 6 +- .../config/env/examples/healthcheck.sh | 4 +- .../config/env/examples/mariadb.sh | 4 +- .../config/env/examples/mongodb.sh | 4 +- .../config/env/examples/networking.sh | 4 +- .../config/env/examples/other.sh | 4 +- .../template-files/config/env/examples/php.sh | 4 +- .../config/env/examples/postgres.sh | 4 +- .../config/env/examples/redis.sh | 4 +- .../config/env/examples/services.sh | 4 +- .../template-files/config/env/examples/ssl.sh | 6 +- .../config/env/examples/supabase.sh | 4 +- .../config/env/examples/webservers.sh | 4 +- .../config/env/examples/zz-entrypoint.sh | 8 +- 34 files changed, 1343 insertions(+), 947 deletions(-) mode change 100644 => 100755 rootfs/usr/local/etc/docker/init.d/00-opengist.sh diff --git a/.env.scripts b/.env.scripts index c067f0d..6848b17 100644 --- a/.env.scripts +++ b/.env.scripts @@ -1,52 +1,79 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408121936-git +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202511290813-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT -# @@Copyright : Copyright 2024 CasjaysDev -# @@Created : Mon Aug 12 07:36:47 PM EDT 2024 +# @@Copyright : Copyright 2025 CasjaysDev +# @@Created : Sat Nov 29 08:13:04 AM EST 2025 # @@File : .env.scripts # @@Description : Variables for gen-dockerfile and buildx scripts -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# @@Changelog : newScript +# @@TODO : Refactor code +# @@Other : N/A +# @@Resource : N/A +# @@Terminal App : yes +# @@sudo/root : yes +# @@Template : templates/dockerfiles/dotenv.template +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - +# entrypoint Settings +DOCKER_ENTYPOINT_PORTS_WEB="${DOCKER_ENTYPOINT_PORTS_WEB}" +DOCKER_ENTYPOINT_PORTS_SRV="${DOCKER_ENTYPOINT_PORTS_SRV}" +DOCKER_ENTYPOINT_HEALTH_APPS="$DOCKER_ENTYPOINT_HEALTH_APPS" +DOCKER_ENTYPOINT_HEALTH_ENDPOINTS="$DOCKER_ENTYPOINT_HEALTH_ENDPOINTS" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Dockerfile info ENV_DOCKERFILE="Dockerfile" ENV_IMAGE_NAME="opengist" ENV_USE_TEMPLATE="alpine" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Maintainer info ENV_ORG_NAME="casjaysdevdocker" ENV_VENDOR="CasjaysDev" ENV_AUTHOR="CasjaysDev" ENV_MAINTAINER="CasjaysDev " -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# REPO info +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Repository URLs (Full URLs) +# ENV_GIT_REPO_URL: Complete Git repository URL for source code ENV_GIT_REPO_URL="https://github.com/casjaysdevdocker/opengist" -ENV_REGISTRY_URL="https://hub.docker.com/r/casjaysdevdocker/opengist" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Push image info +# ENV_REGISTRY_URL: Complete registry URL for reference (NOT used for pushing) +ENV_REGISTRY_URL="https://hub.docker.com/casjaysdevdocker/opengist" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Push Configuration +# ENV_IMAGE_PUSH: Complete push destination (this IS used for pushing) ENV_IMAGE_PUSH="casjaysdevdocker/opengist" +# ENV_IMAGE_TAG: Default tag for the image ENV_IMAGE_TAG="latest" +# ENV_ADD_TAGS: Additional tags, comma-separated (USE_DATE = auto date tag) ENV_ADD_TAGS="" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Pull image info +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Additional push destinations (if needed) +ENV_ADD_IMAGE_PUSH="" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Pull Configuration +# ENV_PULL_URL: Source image to pull from (base image) ENV_PULL_URL="casjaysdev/alpine" +# ENV_DISTRO_TAG: Tag for the pull source image ENV_DISTRO_TAG="${IMAGE_VERSION}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Env SERVICE_PORT="80" EXPOSE_PORTS="22" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Versions PHP_VERSION="system" NODE_VERSION="system" NODE_MANAGER="system" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Default directories WWW_ROOT_DIR="/usr/local/share/httpd/default" DEFAULT_FILE_DIR="/usr/local/share/template-files" DEFAULT_DATA_DIR="/usr/local/share/template-files/data" DEFAULT_CONF_DIR="/usr/local/share/template-files/config" DEFAULT_TEMPLATE_DIR="/usr/local/share/template-files/defaults" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - ENV_PACKAGES="git openssh" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Dockerfile b/Dockerfile index a5a9a43..47aaec8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,7 @@ -# syntax=docker/dockerfile:1 # Docker image for opengist using the alpine template ARG IMAGE_NAME="opengist" ARG PHP_SERVER="opengist" -ARG BUILD_DATE="202408121936" +ARG BUILD_DATE="202511290813" ARG LANGUAGE="en_US.UTF-8" ARG TIMEZONE="America/New_York" ARG WWW_ROOT_DIR="/usr/local/share/httpd/default" @@ -10,6 +9,7 @@ ARG DEFAULT_FILE_DIR="/usr/local/share/template-files" ARG DEFAULT_DATA_DIR="/usr/local/share/template-files/data" ARG DEFAULT_CONF_DIR="/usr/local/share/template-files/config" ARG DEFAULT_TEMPLATE_DIR="/usr/local/share/template-files/defaults" +ARG PATH="/usr/local/etc/docker/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ARG USER="root" ARG SHELL_OPTS="set -e -o pipefail" @@ -52,11 +52,13 @@ ARG NODE_MANAGER ARG PHP_VERSION ARG PHP_SERVER ARG SHELL_OPTS +ARG PATH ARG PACK_LIST="git openssh " ENV ENV=~/.profile ENV SHELL="/bin/sh" +ENV PATH="${PATH}" ENV TZ="${TIMEZONE}" ENV TIMEZONE="${TZ}" ENV LANG="${LANGUAGE}" @@ -68,6 +70,10 @@ WORKDIR /root COPY ./rootfs/usr/local/bin/. /usr/local/bin/ +RUN set -e; \ + echo "Updating the system and ensuring bash is installed"; \ + pkmgr update;pkmgr install bash + RUN set -e; \ echo "Setting up prerequisites"; \ true @@ -86,7 +92,6 @@ RUN echo "Initializing the system"; \ RUN echo "Creating and editing system files "; \ $SHELL_OPTS; \ [ -f "/root/.profile" ] || touch "/root/.profile"; \ - mkdir -p "${DEFAULT_DATA_DIR}" "${DEFAULT_CONF_DIR}" "${DEFAULT_TEMPLATE_DIR}" "/root/docker/setup" "/etc/profile.d"; \ if [ -f "/root/docker/setup/01-system.sh" ];then echo "Running the system script";/root/docker/setup/01-system.sh||{ echo "Failed to execute /root/docker/setup/01-system.sh" >&2 && exit 10; };echo "Done running the system script";fi; \ echo "" @@ -118,13 +123,12 @@ RUN echo "Updating system files "; \ pip_bin="$(command -v python3 2>/dev/null || command -v python2 2>/dev/null || command -v python 2>/dev/null || true)"; \ py_version="$(command $pip_bin --version | sed 's|[pP]ython ||g' | awk -F '.' '{print $1$2}' | grep '[0-9]' || true)"; \ [ "$py_version" -gt "310" ] && pip_opts="--break-system-packages " || pip_opts=""; \ - if [ -n "$pip_bin" ];then $pip_bin -m pip install certbot-dns-rfc2136 certbot-dns-duckdns certbot-dns-cloudflare certbot-nginx $pip_opts || true;fi; \ [ -f "/usr/share/zoneinfo/${TZ}" ] && ln -sf "/usr/share/zoneinfo/${TZ}" "/etc/localtime" || true; \ [ -n "$PHP_BIN" ] && [ -z "$(command -v php 2>/dev/null)" ] && ln -sf "$PHP_BIN" "/usr/bin/php" 2>/dev/null || true; \ [ -n "$PHP_FPM" ] && [ -z "$(command -v php-fpm 2>/dev/null)" ] && ln -sf "$PHP_FPM" "/usr/bin/php-fpm" 2>/dev/null || true; \ if [ -f "/etc/profile.d/color_prompt.sh.disabled" ]; then mv -f "/etc/profile.d/color_prompt.sh.disabled" "/etc/profile.d/color_prompt.sh";fi ; \ { [ -f "/etc/bash/bashrc" ] && cp -Rf "/etc/bash/bashrc" "/root/.bashrc"; } || { [ -f "/etc/bashrc" ] && cp -Rf "/etc/bashrc" "/root/.bashrc"; } || { [ -f "/etc/bash.bashrc" ] && cp -Rf "/etc/bash.bashrc" "/root/.bashrc"; } || true; \ - if [ -z "$(command -v "apt-get" 2>/dev/null)" ];then grep -s -q 'alias quit' "/root/.bashrc" || printf '# Profile\n\n%s\n%s\n%s\n' '. /etc/profile' '. /root/.profile' "alias quit='exit 0 2>/dev/null'" >>"/root/.bashrc"; fi; \ + if [ -z "$(command -v "apt-get" 2>/dev/null)" ];then grep -sh -q 'alias quit' "/root/.bashrc" || printf '# Profile\n\n%s\n%s\n%s\n' '. /etc/profile' '. /root/.profile' "alias quit='exit 0 2>/dev/null'" >>"/root/.bashrc"; fi; \ if [ "$PHP_VERSION" != "system" ] && [ -e "/etc/php" ] && [ -d "/etc/${PHP_VERSION}" ];then rm -Rf "/etc/php";fi; \ if [ "$PHP_VERSION" != "system" ] && [ -n "${PHP_VERSION}" ] && [ -d "/etc/${PHP_VERSION}" ];then ln -sf "/etc/${PHP_VERSION}" "/etc/php";fi; \ if [ -f "/root/docker/setup/03-files.sh" ];then echo "Running the files script";/root/docker/setup/03-files.sh||{ echo "Failed to execute /root/docker/setup/03-files.sh" >&2 && exit 10; };echo "Done running the files script";fi; \ @@ -179,6 +183,7 @@ RUN echo "Deleting unneeded files"; \ RUN echo "Init done" FROM scratch ARG TZ +ARG PATH ARG USER ARG TIMEZONE ARG LANGUAGE @@ -199,7 +204,7 @@ ARG NODE_MANAGER ARG PHP_VERSION ARG PHP_SERVER ARG LICENSE="WTFPL" -ARG ENV_PORTS="22" +ARG ENV_PORTS="${EXPOSE_PORTS}" USER ${USER} WORKDIR /root @@ -208,24 +213,25 @@ LABEL maintainer="CasjaysDev " LABEL org.opencontainers.image.vendor="CasjaysDev" LABEL org.opencontainers.image.authors="CasjaysDev" LABEL org.opencontainers.image.description="Containerized version of ${IMAGE_NAME}" -LABEL org.opencontainers.image.name="${IMAGE_NAME}" +LABEL org.opencontainers.image.title="${IMAGE_NAME}" LABEL org.opencontainers.image.base.name="${IMAGE_NAME}" -LABEL org.opencontainers.image.license="${LICENSE}" -LABEL org.opencontainers.image.build-date="${BUILD_DATE}" +LABEL org.opencontainers.image.authors="${LICENSE}" +LABEL org.opencontainers.image.created="${BUILD_DATE}" LABEL org.opencontainers.image.version="${BUILD_VERSION}" LABEL org.opencontainers.image.schema-version="${BUILD_VERSION}" -LABEL org.opencontainers.image.url="https://hub.docker.com/r/casjaysdevdocker/opengist" -LABEL org.opencontainers.image.url.source="https://hub.docker.com/r/casjaysdevdocker/opengist" +LABEL org.opencontainers.image.url="https://hub.docker.com/casjaysdevdocker/opengist" +LABEL org.opencontainers.image.source="https://hub.docker.com/casjaysdevdocker/opengist" LABEL org.opencontainers.image.vcs-type="Git" -LABEL org.opencontainers.image.vcs-ref="${BUILD_VERSION}" -LABEL org.opencontainers.image.vcs-url="https://github.com/casjaysdevdocker/opengist" +LABEL org.opencontainers.image.revision="${BUILD_VERSION}" +LABEL org.opencontainers.image.source="https://github.com/casjaysdevdocker/opengist" LABEL org.opencontainers.image.documentation="https://github.com/casjaysdevdocker/opengist" LABEL com.github.containers.toolbox="false" ENV ENV=~/.bashrc ENV USER="${USER}" -ENV SHELL="/bin/bash" +ENV PATH="${PATH}" ENV TZ="${TIMEZONE}" +ENV SHELL="/bin/bash" ENV TIMEZONE="${TZ}" ENV LANG="${LANGUAGE}" ENV TERM="xterm-256color" @@ -246,6 +252,8 @@ VOLUME [ "/config","/data" ] EXPOSE ${SERVICE_PORT} ${ENV_PORTS} +STOPSIGNAL SIGRTMIN+3 + CMD [ "tail", "-f", "/dev/null" ] -ENTRYPOINT [ "tini","--","/usr/local/bin/entrypoint.sh" ] +ENTRYPOINT [ "tini", "-p", "SIGTERM","--", "/usr/local/bin/entrypoint.sh" ] HEALTHCHECK --start-period=10m --interval=5m --timeout=15s CMD [ "/usr/local/bin/entrypoint.sh", "healthcheck" ] diff --git a/rootfs/root/docker/setup/00-init.sh b/rootfs/root/docker/setup/00-init.sh index ec40af4..faa26e4 100755 --- a/rootfs/root/docker/setup/00-init.sh +++ b/rootfs/root/docker/setup/00-init.sh @@ -1,35 +1,44 @@ #!/usr/bin/env bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091650-git +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202511290809-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT -# @@ReadME : -# @@Copyright : Copyright 2023 CasjaysDev -# @@Created : Mon Aug 28 06:48:42 PM EDT 2023 +# @@Copyright : Copyright 2025 CasjaysDev +# @@Created : Sat Nov 29 08:09:47 AM EST 2025 # @@File : 00-init.sh # @@Description : script to run init -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck shell=bash -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# @@Changelog : newScript +# @@TODO : Refactor code +# @@Other : N/A +# @@Resource : N/A +# @@Terminal App : yes +# @@sudo/root : yes +# @@Template : templates/dockerfiles/init_scripts/00-init.sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables exitCode=0 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Predefined actions +if [ -d "/usr/local/share/template-files/data" ]; then rm -Rf "/usr/local/share/template-files/data"/*; fi +if [ -d "/usr/local/share/template-files/config" ]; then rm -Rf "/usr/local/share/template-files/config"/*; fi +if [ -d "/usr/local/share/template-files/defaults" ]; then rm -Rf "/usr/local/share/template-files/defaults"/*; fi +# - - - - - - - - - - - - - - - - - - - - - - - - - # Main script -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set the exit code -exitCode=$? -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#exitCode=$? +# - - - - - - - - - - - - - - - - - - - - - - - - - exit $exitCode +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/root/docker/setup/01-system.sh b/rootfs/root/docker/setup/01-system.sh index b66c2a4..060f835 100755 --- a/rootfs/root/docker/setup/01-system.sh +++ b/rootfs/root/docker/setup/01-system.sh @@ -1,35 +1,42 @@ #!/usr/bin/env bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091650-git +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202511290809-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT -# @@ReadME : -# @@Copyright : Copyright 2023 CasjaysDev -# @@Created : Mon Aug 28 06:48:42 PM EDT 2023 +# @@Copyright : Copyright 2025 CasjaysDev +# @@Created : Sat Nov 29 08:09:47 AM EST 2025 # @@File : 01-system.sh # @@Description : script to run system -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck shell=bash -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# @@Changelog : newScript +# @@TODO : Refactor code +# @@Other : N/A +# @@Resource : N/A +# @@Terminal App : yes +# @@sudo/root : yes +# @@Template : templates/dockerfiles/init_scripts/01-system.sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables exitCode=0 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Predefined actions + +# - - - - - - - - - - - - - - - - - - - - - - - - - # Main script -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set the exit code -exitCode=$? -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#exitCode=$? +# - - - - - - - - - - - - - - - - - - - - - - - - - exit $exitCode +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/root/docker/setup/02-packages.sh b/rootfs/root/docker/setup/02-packages.sh index d1f4bc8..ee69e4d 100755 --- a/rootfs/root/docker/setup/02-packages.sh +++ b/rootfs/root/docker/setup/02-packages.sh @@ -1,35 +1,42 @@ #!/usr/bin/env bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091650-git +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202511290809-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT -# @@ReadME : -# @@Copyright : Copyright 2023 CasjaysDev -# @@Created : Mon Aug 28 06:48:42 PM EDT 2023 +# @@Copyright : Copyright 2025 CasjaysDev +# @@Created : Sat Nov 29 08:09:47 AM EST 2025 # @@File : 02-packages.sh # @@Description : script to run packages -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck shell=bash -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# @@Changelog : newScript +# @@TODO : Refactor code +# @@Other : N/A +# @@Resource : N/A +# @@Terminal App : yes +# @@sudo/root : yes +# @@Template : templates/dockerfiles/init_scripts/02-packages.sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables exitCode=0 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Predefined actions + +# - - - - - - - - - - - - - - - - - - - - - - - - - # Main script -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set the exit code -exitCode=$? -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#exitCode=$? +# - - - - - - - - - - - - - - - - - - - - - - - - - exit $exitCode +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/root/docker/setup/03-files.sh b/rootfs/root/docker/setup/03-files.sh index 767ff14..0a2be1c 100755 --- a/rootfs/root/docker/setup/03-files.sh +++ b/rootfs/root/docker/setup/03-files.sh @@ -1,35 +1,93 @@ #!/usr/bin/env bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091650-git +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202511290809-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT -# @@ReadME : -# @@Copyright : Copyright 2023 CasjaysDev -# @@Created : Mon Aug 28 06:48:42 PM EDT 2023 +# @@Copyright : Copyright 2025 CasjaysDev +# @@Created : Sat Nov 29 08:09:47 AM EST 2025 # @@File : 03-files.sh # @@Description : script to run files -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck shell=bash -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# @@Changelog : newScript +# @@TODO : Refactor code +# @@Other : N/A +# @@Resource : N/A +# @@Terminal App : yes +# @@sudo/root : yes +# @@Template : templates/dockerfiles/init_scripts/03-files.sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables exitCode=0 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Predefined actions +if [ -d "/tmp/bin" ]; then + mkdir -p "/usr/local/bin" + for bin in "/tmp/bin"/*; do + name="$(basename -- "$bin")" + echo "Installing $name to /usr/local/bin/$name" + copy "$bin" "/usr/local/bin/$name" + chmod -f +x "/usr/local/bin/$name" + done +fi +unset bin +if [ -d "/tmp/var" ]; then + for var in "/tmp/var"/*; do + name="$(basename -- "$var")" + echo "Installing $var to /var/$name" + if [ -d "$var" ]; then + mkdir -p "/var/$name" + copy "$var/." "/var/$name/" + else + copy "$var" "/var/$name" + fi + done +fi +unset var +if [ -d "/tmp/etc" ]; then + for config in "/tmp/etc"/*; do + name="$(basename -- "$config")" + echo "Installing $config to /etc/$name" + if [ -d "$config" ]; then + mkdir -p "/etc/$name" + copy "$config/." "/etc/$name/" + mkdir -p "/usr/local/share/template-files/config/$name" + copy "$config/." "/usr/local/share/template-files/config/$name/" + else + copy "$config" "/etc/$name" + copy "$config" "/usr/local/share/template-files/config/$name" + fi + done +fi +unset config +if [ -d "/tmp/data" ]; then + for data in "/tmp/data"/*; do + name="$(basename -- "$data")" + echo "Installing $data to /usr/local/share/template-files/data" + if [ -d "$data" ]; then + mkdir -p "/usr/local/share/template-files/data/$name" + copy "$data/." "/usr/local/share/template-files/data/$name/" + else + copy "$data" "/usr/local/share/template-files/data/$name" + fi + done +fi +unset data +# - - - - - - - - - - - - - - - - - - - - - - - - - # Main script -if [ -d "/tmp/etc" ]; then copy "/tmp/etc/." "/etc/"; fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set the exit code -exitCode=$? -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#exitCode=$? +# - - - - - - - - - - - - - - - - - - - - - - - - - exit $exitCode +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/root/docker/setup/04-users.sh b/rootfs/root/docker/setup/04-users.sh index 97f3fea..68c582c 100755 --- a/rootfs/root/docker/setup/04-users.sh +++ b/rootfs/root/docker/setup/04-users.sh @@ -1,35 +1,42 @@ #!/usr/bin/env bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091650-git +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202511290809-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT -# @@ReadME : -# @@Copyright : Copyright 2023 CasjaysDev -# @@Created : Mon Aug 28 06:48:42 PM EDT 2023 +# @@Copyright : Copyright 2025 CasjaysDev +# @@Created : Sat Nov 29 08:09:47 AM EST 2025 # @@File : 04-users.sh # @@Description : script to run users -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck shell=bash -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# @@Changelog : newScript +# @@TODO : Refactor code +# @@Other : N/A +# @@Resource : N/A +# @@Terminal App : yes +# @@sudo/root : yes +# @@Template : templates/dockerfiles/init_scripts/04-users.sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables exitCode=0 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Predefined actions + +# - - - - - - - - - - - - - - - - - - - - - - - - - # Main script -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set the exit code -exitCode=$? -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#exitCode=$? +# - - - - - - - - - - - - - - - - - - - - - - - - - exit $exitCode +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/root/docker/setup/05-custom.sh b/rootfs/root/docker/setup/05-custom.sh index eba69f6..bb2649d 100755 --- a/rootfs/root/docker/setup/05-custom.sh +++ b/rootfs/root/docker/setup/05-custom.sh @@ -1,49 +1,59 @@ #!/usr/bin/env bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091650-git +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202511290809-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT -# @@ReadME : -# @@Copyright : Copyright 2023 CasjaysDev -# @@Created : Mon Aug 28 06:48:42 PM EDT 2023 +# @@Copyright : Copyright 2025 CasjaysDev +# @@Created : Sat Nov 29 08:09:47 AM EST 2025 # @@File : 05-custom.sh # @@Description : script to run custom -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck shell=bash -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# @@Changelog : newScript +# @@TODO : Refactor code +# @@Other : N/A +# @@Resource : N/A +# @@Terminal App : yes +# @@sudo/root : yes +# @@Template : templates/dockerfiles/init_scripts/05-custom.sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables -ARCH="$(uname -m | tr '[:upper]' '[:lower]')" exitCode=0 +TMP_DIR="/tmp/opengist" +TMP_BIN="$TMP_DIR/opengist" +TMP_FILE="/tmp/opengist.tar.gz" BIN_PATH="/usr/local/bin/opengist" +ARCH="$(uname -m | tr '[:upper]' '[:lower]')" case "$ARCH" in x86_64) ARCH="amd64" ;; aarch64) ARCH="arm64" ;; *) echo "$ARCH is not supported by this script" >&2 && exit 1 ;; esac API_URL="$(curl -q -LSsf https://api.github.com/repos/thomiceli/opengist/releases/latest | jq -r '.assets[] | select(.name|match("linux.*tar.gz")) | .browser_download_url' | grep "$ARCH.tar.gz" || false)" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Main script +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Predefined actions if [ -n "$API_URL" ]; then - echo "Dowloading from $API_URL" - curl -q -LSsf "$API_URL" -o "/tmp/opengist.tar.gz" && tar xzf /tmp/opengist.tar.gz -C "/tmp" - if [ -f "/tmp/opengist/opengist" ]; then - [ -d "/etc/opengist" ] || mkdir -p "/etc/opengist" - mv -f "/tmp/opengist/opengist" "$BIN_PATH" && chmod -Rf 755 "$BIN_PATH" - rm -Rf "/tmp/opengist.tar.gz" "/tmp/opengist" - [ -x "$BIN_PATH" ] && echo "opengist installed to: $BIN_PATH" || exitCode=5 - else - exitCode=1 - fi + echo "Dowloading from $API_URL" + curl -q -LSsf "$API_URL" -o "$TMP_FILE" && tar xzf "$TMP_FILE" -C "/tmp" + if [ -f "$TMP_DIR/opengist" ]; then + [ -d "/etc/opengist" ] || mkdir -p "/etc/opengist" + mv -f "$$TMP_BIN" "$BIN_PATH" && chmod -Rf 755 "$BIN_PATH" + rm -Rf "$TMP_FILE" "$TMP_DIR" + else + exitCode=1 + fi fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +[ -x "$BIN_PATH" ] && echo "opengist installed to: $BIN_PATH" || exitCode=5 +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Main script + +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set the exit code -[ $exitCode -eq 0 ] || echo "Failed to install opengist" >&2 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#exitCode=$? +# - - - - - - - - - - - - - - - - - - - - - - - - - exit $exitCode +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/root/docker/setup/06-post.sh b/rootfs/root/docker/setup/06-post.sh index 4de8cf9..2db4767 100755 --- a/rootfs/root/docker/setup/06-post.sh +++ b/rootfs/root/docker/setup/06-post.sh @@ -1,35 +1,42 @@ #!/usr/bin/env bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091650-git +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202511290809-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT -# @@ReadME : -# @@Copyright : Copyright 2023 CasjaysDev -# @@Created : Mon Aug 28 06:48:42 PM EDT 2023 +# @@Copyright : Copyright 2025 CasjaysDev +# @@Created : Sat Nov 29 08:09:47 AM EST 2025 # @@File : 06-post.sh # @@Description : script to run post -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck shell=bash -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# @@Changelog : newScript +# @@TODO : Refactor code +# @@Other : N/A +# @@Resource : N/A +# @@Terminal App : yes +# @@sudo/root : yes +# @@Template : templates/dockerfiles/init_scripts/06-post.sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables exitCode=0 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Predefined actions + +# - - - - - - - - - - - - - - - - - - - - - - - - - # Main script -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set the exit code -exitCode=$? -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#exitCode=$? +# - - - - - - - - - - - - - - - - - - - - - - - - - exit $exitCode +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/root/docker/setup/07-cleanup.sh b/rootfs/root/docker/setup/07-cleanup.sh index 0b6c43c..ab4f856 100755 --- a/rootfs/root/docker/setup/07-cleanup.sh +++ b/rootfs/root/docker/setup/07-cleanup.sh @@ -1,35 +1,46 @@ #!/usr/bin/env bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091650-git +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202511290809-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT -# @@ReadME : -# @@Copyright : Copyright 2023 CasjaysDev -# @@Created : Mon Aug 28 06:48:42 PM EDT 2023 +# @@Copyright : Copyright 2025 CasjaysDev +# @@Created : Sat Nov 29 08:09:47 AM EST 2025 # @@File : 07-cleanup.sh # @@Description : script to run cleanup -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck shell=bash -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# @@Changelog : newScript +# @@TODO : Refactor code +# @@Other : N/A +# @@Resource : N/A +# @@Terminal App : yes +# @@sudo/root : yes +# @@Template : templates/dockerfiles/init_scripts/07-cleanup.sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Load functions +__find_and_remove() { [ -z "$1" ] || find "${2:-/etc}" -iname "$1" -exec rm -Rf {} \; 2>/dev/null; } +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables exitCode=0 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Predefined actions +if [ -d "/tmp" ]; then rm -Rf "/tmp"/*; fi +if [ -d "$HOME/.cache" ]; then rm -Rf "$HOME/.cache"; fi +# - - - - - - - - - - - - - - - - - - - - - - - - - # Main script -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set the exit code -exitCode=$? -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#exitCode=$? +# - - - - - - - - - - - - - - - - - - - - - - - - - exit $exitCode +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/bin/entrypoint.sh b/rootfs/usr/local/bin/entrypoint.sh index ad8bf19..52e28b5 100755 --- a/rootfs/usr/local/bin/entrypoint.sh +++ b/rootfs/usr/local/bin/entrypoint.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash # shellcheck shell=bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408121912-git +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202511290809-git # @@Author : Jason Hempstead # @@Contact : jason@casjaysdev.pro # @@License : WTFPL # @@ReadME : entrypoint.sh --help -# @@Copyright : Copyright: (c) 2024 Jason Hempstead, Casjays Developments -# @@Created : Monday, Aug 12, 2024 19:12 EDT +# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments +# @@Created : Saturday, Nov 29, 2025 08:09 EST # @@File : entrypoint.sh # @@Description : Entrypoint file for opengist # @@Changelog : New script @@ -17,126 +17,137 @@ # @@Terminal App : no # @@sudo/root : no # @@Template : other/docker-entrypoint -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - +# run trap command on exit +trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' INT TERM PWR +# - - - - - - - - - - - - - - - - - - - - - - - - - # setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html [ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}" { [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -o pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options SCRIPT_FILE="$0" CONTAINER_NAME="opengist" -SCRIPT_NAME="$(basename "$SCRIPT_FILE" 2>/dev/null)" +SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)" CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # remove whitespaces from beginning argument while :; do [ "$1" = " " ] && shift 1 || break; done -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - [ "$1" = "$SCRIPT_FILE" ] && shift 1 [ "$1" = "$SCRIPT_NAME" ] && shift 1 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # import the functions file if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then - . "/usr/local/etc/docker/functions/entrypoint.sh" + . "/usr/local/etc/docker/functions/entrypoint.sh" else - echo "Can not load functions from /usr/local/etc/docker/functions/entrypoint.sh" - exit 1 + echo "Can not load functions from /usr/local/etc/docker/functions/entrypoint.sh" + exit 1 fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - case "$1" in # Help message ---help) - shift 1 - echo 'Docker container for '$CONTAINER_NAME'' - echo "Usage: $CONTAINER_NAME [cron exec start init shell certbot ssl procs ports healthcheck backup command]" - echo "" - exit 0 - ;; +-h | --help) + shift 1 + echo 'Docker container for '$CONTAINER_NAME'' + echo "Usage: $CONTAINER_NAME [help tail cron exec start init shell certbot ssl procs ports healthcheck backup command]" + echo "" + exit 0 + ;; +-*) + shift + ;; esac -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Create the default env files __create_env_file "/config/env/default.sh" "/root/env.sh" &>/dev/null -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # import variables from files for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do - [ -f "$set_env" ] && . "$set_env" + [ -f "$set_env" ] && . "$set_env" done -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +unset set_env +# - - - - - - - - - - - - - - - - - - - - - - - - - # User to use to launch service - IE: postgres RUNAS_USER="root" # normally root -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# User and group in which the service switches to - IE: nginx,apache,mysql,postgres -SERVICE_USER="git" # execute command as another user -SERVICE_GROUP="git" # Set the service group -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Set user and group from env +SERVICE_USER="${PUID:-$SERVICE_USER}" +SERVICE_GROUP="${PGID:-$SERVICE_GROUP}" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set user and group ID -SERVICE_UID="0" # set the user id -SERVICE_GID="0" # set the group id -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Primary server port- will be added to server ports -WEB_SERVER_PORT="" # port : 80,443 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SERVICE_UID="${SERVICE_UID:-0}" # set the user id +SERVICE_GID="${SERVICE_GID:-0}" # set the group id +# - - - - - - - - - - - - - - - - - - - - - - - - - +# User and group in which the service switches to - IE: nginx,apache,mysql,postgres +SERVICE_USER="${SERVICE_USER:-git}" # execute command as another user +SERVICE_GROUP="${SERVICE_GROUP:-git}" # Set the service group +# - - - - - - - - - - - - - - - - - - - - - - - - - # Secondary ports SERVER_PORTS="" # specifiy other ports -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Server directories -WWW_ROOT_DIR="" # set default web dir -DATABASE_DIR="" # set database dir -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Primary server port- will be added to server ports +WEB_SERVER_PORT="" # port : 80,443 +# - - - - - - - - - - - - - - - - - - - - - - - - - # Healthcheck variables -HEALTH_ENABLED="yes" # enable healthcheck [yes/no] -SERVICES_LIST="tini,opengist" # comma seperated list of processes for the healthcheck -HEALTH_ENDPOINTS="" # url endpoints: [http://localhost/health,http://localhost/test] -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +HEALTH_ENABLED="yes" # enable healthcheck [yes/no] +SERVICES_LIST="tini" # comma separated list of processes for the healthcheck +HEALTH_ENDPOINTS="" # url endpoints: [http://localhost/health,http://localhost/test] +# - - - - - - - - - - - - - - - - - - - - - - - - - # Update path var -export PATH="${PATH:-}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +export PATH RUNAS_USER SERVICE_USER SERVICE_GROUP SERVICE_UID SERVICE_GID WWW_ROOT_DIR DATABASE_DIR +# - - - - - - - - - - - - - - - - - - - - - - - - - # Custom variables -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # show message __run_message() { - return + return } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - ################## END OF CONFIGURATION ##################### -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Lets get containers ip address +IP4_ADDRESS="$(__get_ip4)" +IP6_ADDRESS="$(__get_ip6)" +CONTAINER_IP4_ADDRESS="${CONTAINER_IP4_ADDRESS:-$IP4_ADDRESS}" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Startup variables export INIT_DATE="${INIT_DATE:-$(date)}" export CONTAINER_INIT="${CONTAINER_INIT:-no}" -export START_SERVICES="${START_SERVICES:-yes}" +export START_SERVICES="${START_SERVICES:-no}" export ENTRYPOINT_MESSAGE="${ENTRYPOINT_MESSAGE:-yes}" export ENTRYPOINT_FIRST_RUN="${ENTRYPOINT_FIRST_RUN:-yes}" export DATA_DIR_INITIALIZED="${DATA_DIR_INITIALIZED:-no}" export CONFIG_DIR_INITIALIZED="${CONFIG_DIR_INITIALIZED:-no}" export CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # System export LANG="${LANG:-C.UTF-8}" export LC_ALL="${LANG:-C.UTF-8}" export TZ="${TZ:-${TIMEZONE:-America/New_York}}" -export HOSTNAME="${FULL_DOMAIN_NAME:-${SERVER_HOSTNAME:-$HOSTNAME}}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +export HOSTNAME="$(hostname -s)" +export DOMAINNAME="$(hostname -d)" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Default directories export SSL_DIR="${SSL_DIR:-/config/ssl}" export SSL_CA="${SSL_CERT:-/config/ssl/ca.crt}" export SSL_KEY="${SSL_KEY:-/config/ssl/localhost.pem}" export SSL_CERT="${SSL_CERT:-/config/ssl/localhost.crt}" -export BACKUP_DIR="${BACKUP_DIR:-/data/backups}" export LOCAL_BIN_DIR="${LOCAL_BIN_DIR:-/usr/local/bin}" export DEFAULT_DATA_DIR="${DEFAULT_DATA_DIR:-/usr/local/share/template-files/data}" export DEFAULT_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config}" export DEFAULT_TEMPLATE_DIR="${DEFAULT_TEMPLATE_DIR:-/usr/local/share/template-files/defaults}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Backup settings +export BACKUP_MAX_DAYS="${BACKUP_MAX_DAYS:-}" +export BACKUP_RUN_CRON="${BACKUP_RUN_CRON:-}" +export BACKUP_DIR="${BACKUP_DIR:-/data/backups}" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Additional export PHP_INI_DIR="${PHP_INI_DIR:-$(__find_php_ini)}" export PHP_BIN_DIR="${PHP_BIN_DIR:-$(__find_php_bin)}" @@ -149,45 +160,52 @@ export ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-$ENTRYPOINT_PID_FILE}" export ENTRYPOINT_INIT_FILE="${ENTRYPOINT_INIT_FILE:-/config/.entrypoint.done}" export ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has_run}" export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -if [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; then - START_SERVICES="no" ENTRYPOINT_MESSAGE="no" ENTRYPOINT_FIRST_RUN="no" +# - - - - - - - - - - - - - - - - - - - - - - - - - +if [ -n "$CONTAINER_WEB_SERVER_WWW_REPO" ]; then + www_temp_dir="/tmp/git/$(basename -- "$CONTAINER_WEB_SERVER_WWW_REPO")" + rm -Rf "${WWW_ROOT_DIR:?}"/* "${www_temp_dir:?}"/* + mkdir -p "$WWW_ROOT_DIR" "$www_temp_dir" + git clone -q "$CONTAINER_WEB_SERVER_WWW_REPO" "$www_temp_dir" 2>/dev/null + rm -Rf "$www_temp_dir/.git" "$www_temp_dir"/.git* + rsync -ra "$www_temp_dir/" "$WWW_ROOT_DIR" --delete >/dev/null 2>&1 + rm -Rf "$www_temp_dir" fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # variables based on env/files [ -f "/config/enable/ssl" ] && SSL_ENABLED="yes" [ -f "/config/enable/ssh" ] && SSH_ENABLED="yes" [ "$WEB_SERVER_PORT" = "443" ] && SSL_ENABLED="yes" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +[ "$CONTAINER_WEB_SERVER_PROTOCOL" = "https" ] && SSL_ENABLED="yes" +# - - - - - - - - - - - - - - - - - - - - - - - - - # export variables -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # is already Initialized [ -f "$ENTRYPOINT_DATA_INIT_FILE" ] && DATA_DIR_INITIALIZED="yes" || DATA_DIR_INITIALIZED="no" [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && CONFIG_DIR_INITIALIZED="yes" || CONFIG_DIR_INITIALIZED="no" { [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; } && ENTRYPOINT_FIRST_RUN="no" || ENTRYPOINT_FIRST_RUN="yes" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # clean ENV_PORTS variables ENV_PORTS="${ENV_PORTS//,/ }" # ENV_PORTS="${ENV_PORTS//\/*/}" # -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # clean SERVER_PORTS variables SERVER_PORTS="${SERVER_PORTS//,/ }" # SERVER_PORTS="${SERVER_PORTS//\/*/}" # -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # clean WEB_SERVER_PORTS variables WEB_SERVER_PORTS="${WEB_SERVER_PORT//\/*/}" # WEB_SERVER_PORTS="${WEB_SERVER_PORTS//\/*/}" # WEB_SERVER_PORTS="${WEB_SERVER_PORT//,/ } ${ENV_WEB_SERVER_PORTS//,/ }" # -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # rewrite and merge variables ENV_PORTS="$(__format_variables "$ENV_PORTS" || false)" WEB_SERVER_PORTS="$(__format_variables "$WEB_SERVER_PORTS" || false)" ENV_PORTS="$(__format_variables "$SERVER_PORTS" "$WEB_SERVER_PORTS" "$ENV_PORTS" "$SERVER_PORTS" || false)" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Remove the commas from env HEALTH_ENDPOINTS="${HEALTH_ENDPOINTS//,/ }" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # create required directories mkdir -p "/run" mkdir -p "/tmp" @@ -200,11 +218,11 @@ mkdir -p "/run/init.d" mkdir -p "/config/enable" mkdir -p "/config/secure" mkdir -p "/usr/local/etc/docker/exec" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # create required files touch "/data/logs/start.log" touch "/data/logs/entrypoint.log" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # fix permissions chmod -f 777 "/run" chmod -f 777 "/tmp" @@ -218,316 +236,388 @@ chmod -f 777 "/config/enable" chmod -f 777 "/config/secure" chmod -f 777 "/data/logs/entrypoint.log" chmod -f 777 "/usr/local/etc/docker/exec" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # lets ensure everyone can write to std* [ -f "/dev/stdin" ] && chmod -f 777 "/dev/stdin" [ -f "/dev/stderr" ] && chmod -f 777 "/dev/stderr" [ -f "/dev/stdout" ] && chmod -f 777 "/dev/stdout" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - cat </dev/null export LANG="\${LANG:-C.UTF-8}" export LC_ALL="\${LANG:-C.UTF-8}" export TZ="\${TZ:-\${TIMEZONE:-America/New_York}}" EOF -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Create the backup dir [ -n "$BACKUP_DIR" ] && { [ -d "$BACKUP_DIR" ] || mkdir -p "$BACKUP_DIR"; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then - # Show start message - if [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then - [ "$ENTRYPOINT_MESSAGE" = "yes" ] && echo "Executing entrypoint script for opengist" - fi - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set reusable variables - { { [ -w "/etc" ] && [ ! -e "/etc/hosts" ]; } || [ -w "/etc/hosts" ]; } && UPDATE_FILE_HOSTS="yes" - { { [ -w "/etc" ] && [ ! -e "/etc/timezone" ]; } || [ -w "/etc/timezone" ]; } && UPDATE_FILE_TZ="yes" - { { [ -w "/etc" ] && [ ! -e "/etc/resolv.conf" ]; } || [ -w "/etc/resolv.conf" ]; } && UPDATE_FILE_RESOLV="yes" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set timezone - [ -n "$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && echo "$TZ" >"/etc/timezone" - [ -f "/usr/share/zoneinfo/$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && ln -sf "/usr/share/zoneinfo/$TZ" "/etc/localtime" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # if ipv6 add it to /etc/hosts - if [ "$UPDATE_FILE_HOSTS" = "yes" ]; then - echo "# known hostname mappings" >"/etc/hosts" - if [ -n "$(ip a 2>/dev/null | grep 'inet6.*::' || ifconfig 2>/dev/null | grep 'inet6.*::')" ]; then - __printf_space "40" "::1" "localhost" >>"/etc/hosts" - __printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts" - else - __printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts" - fi - fi - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # add .home domain - if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ -n "$HOSTNAME" ]; then - __grep_test " $HOSTNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "$HOSTNAME" >>"/etc/hosts" - __grep_test " ${HOSTNAME%%.*}.home" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.home" >>"/etc/hosts" - fi - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # add domainname - if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ "$DOMAINNAME" != "home" ] && [ -n "$DOMAINNAME" ] && [ "$HOSTNAME.$DOMAINNAME" != "$DOMAINNAME" ]; then - __grep_test " ${HOSTNAME%%.*}.$DOMAINNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.$DOMAINNAME" >>"/etc/hosts" - fi - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set containers hostname - [ -n "$HOSTNAME" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && echo "$HOSTNAME" >"/etc/hostname" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set containers hostname with domain - # [ -n "$DOMAINNAME" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && echo "$HOSTNAME.$DOMAINNAME" >"/etc/hostname" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if [ -f "/etc/hostname" ]; then - [ -n "$(type -P hostname)" ] && hostname -F "/etc/hostname" &>/dev/null || HOSTNAME="$(<"/etc/hostname")" - export HOSTNAME - fi - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # import hosts file into container - [ -f "/usr/local/etc/hosts" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && cat "/usr/local/etc/hosts" | grep -vF "$HOSTNAME" >>"/etc/hosts" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # import resolv.conf file into container - [ "$CUSTOM_DNS" != "yes" ] && [ -f "/usr/local/etc/resolv.conf" ] && [ "$UPDATE_FILE_RESOLV" = "yes" ] && cat "/usr/local/etc/resolv.conf" >"/etc/resolv.conf" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if [ -d "/usr/local/etc/skel" ]; then - cp -Rf "/usr/local/etc/skel/." "$HOME/" - fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +if [ -f "$ENTRYPOINT_INIT_FILE" ]; then + ENTRYPOINT_MESSAGE="no" ENTRYPOINT_FIRST_RUN="no" fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then + # Show start message + if [ "$CONFIG_DIR_INITIALIZED" = "no" ] || [ "$DATA_DIR_INITIALIZED" = "no" ]; then + [ "$ENTRYPOINT_MESSAGE" = "yes" ] && echo "Executing entrypoint script for opengist" + fi + # - - - - - - - - - - - - - - - - - - - - - - - - - + # Set reusable variables + { { [ -w "/etc" ] && [ ! -f "/etc/hosts" ]; } || [ -w "/etc/hosts" ]; } && UPDATE_FILE_HOSTS="yes" && touch "/etc/hosts" + { { [ -w "/etc" ] && [ ! -f "/etc/timezone" ]; } || [ -w "/etc/timezone" ]; } && UPDATE_FILE_TZ="yes" && touch "/etc/timezone" + { { [ -w "/etc" ] && [ ! -f "/etc/resolv.conf" ]; } || [ -w "/etc/resolv.conf" ]; } && UPDATE_FILE_RESOLV="yes" && touch "/etc/resolv.conf" + # - - - - - - - - - - - - - - - - - - - - - - - - - + # Set timezone + [ -n "$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && echo "$TZ" >"/etc/timezone" + [ -f "/usr/share/zoneinfo/$TZ" ] && [ "$UPDATE_FILE_TZ" = "yes" ] && ln -sf "/usr/share/zoneinfo/$TZ" "/etc/localtime" + # - - - - - - - - - - - - - - - - - - - - - - - - - + # if ipv6 add it to /etc/hosts + if [ "$UPDATE_FILE_HOSTS" = "yes" ]; then + echo "# known hostname mappings" >"/etc/hosts" + if [ -n "$(ip a 2>/dev/null | grep 'inet6.*::' || ifconfig 2>/dev/null | grep 'inet6.*::')" ]; then + __printf_space "40" "::1" "localhost" >>"/etc/hosts" + __printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts" + else + __printf_space "40" "127.0.0.1" "localhost" >>"/etc/hosts" + fi + fi + # - - - - - - - - - - - - - - - - - - - - - - - - - + # add .internal domain + if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ -n "$HOSTNAME" ]; then + __grep_test " $HOSTNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "$HOSTNAME" >>"/etc/hosts" + __grep_test " ${HOSTNAME%%.*}.internal" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.internal" >>"/etc/hosts" + fi + # - - - - - - - - - - - - - - - - - - - - - - - - - + # add domainname + if [ "$UPDATE_FILE_HOSTS" = "yes" ] && [ "$DOMAINNAME" != "internal" ] && [ -n "$DOMAINNAME" ] && [ "$HOSTNAME.$DOMAINNAME" != "$DOMAINNAME" ]; then + __grep_test " ${HOSTNAME%%.*}.$DOMAINNAME" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.$DOMAINNAME" >>"/etc/hosts" + fi + # - - - - - - - - - - - - - - - - - - - - - - - - - + # Set containers hostname + [ -n "$HOSTNAME" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && echo "$HOSTNAME" >"/etc/hostname" + # - - - - - - - - - - - - - - - - - - - - - - - - - + if [ -f "/etc/hostname" ]; then + [ -n "$(type -P hostname)" ] && hostname -F "/etc/hostname" &>/dev/null || HOSTNAME="$(<"/etc/hostname")" + export HOSTNAME + fi + # - - - - - - - - - - - - - - - - - - - - - - - - - + # import hosts file into container + [ -f "/usr/local/etc/hosts" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ] && cat "/usr/local/etc/hosts" | grep -vF "$HOSTNAME" >>"/etc/hosts" + # - - - - - - - - - - - - - - - - - - - - - - - - - + # import resolv.conf file into container + [ "$CUSTOM_DNS" != "yes" ] && [ -f "/usr/local/etc/resolv.conf" ] && [ "$UPDATE_FILE_RESOLV" = "yes" ] && cat "/usr/local/etc/resolv.conf" >"/etc/resolv.conf" + # - - - - - - - - - - - - - - - - - - - - - - - - - + if [ -n "$HOME" ] && [ -d "/usr/local/etc/skel" ]; then + [ -d "$HOME" ] && cp -Rf "/usr/local/etc/skel/." "$HOME/" + fi +# - - - - - - - - - - - - - - - - - - - - - - - - - +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - # Delete any .gitkeep files [ -d "/data" ] && rm -Rf "/data/.gitkeep" "/data"/*/*.gitkeep [ -d "/config" ] && rm -Rf "/config/.gitkeep" "/config"/*/*.gitkeep [ -f "/usr/local/bin/.gitkeep" ] && rm -Rf "/usr/local/bin/.gitkeep" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Setup bin directory - /config/bin > /usr/local/bin __initialize_custom_bin_dir -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Copy default system configs - /usr/local/share/template-files/defaults > /config/ __initialize_default_templates -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Copy custom config files - /usr/local/share/template-files/config > /config/ __initialize_config_dir -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Copy custom data files - /usr/local/share/template-files/data > /data/ __initialize_data_dir -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_ssl_certs -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -if [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; then - START_SERVICES="no" - ENTRYPOINT_MESSAGE="no" - ENTRYPOINT_FIRST_RUN="no" - touch "$ENTRYPOINT_PID_FILE" -elif [ -d "/config" ]; then - echo "$$" >"$ENTRYPOINT_PID_FILE" - echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE" +# - - - - - - - - - - - - - - - - - - - - - - - - - +if [ -f "$ENTRYPOINT_INIT_FILE" ]; then + ENTRYPOINT_FIRST_RUN="no" fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +if [ -d "/config" ]; then + echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - # Check if this is a new container if [ -f "$ENTRYPOINT_DATA_INIT_FILE" ]; then - DATA_DIR_INITIALIZED="yes" -elif [ -d "/data" ]; then - echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_DATA_INIT_FILE" + DATA_DIR_INITIALIZED="yes" fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +if [ -d "/data" ]; then + echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_DATA_INIT_FILE" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - if [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ]; then - CONFIG_DIR_INITIALIZED="yes" -elif [ -d "/config" ]; then - echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE" + CONFIG_DIR_INITIALIZED="yes" fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +if [ -d "/config" ]; then + echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then - # setup the smtp server - __setup_mta + # setup the smtp server + __setup_mta fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# if no pid assume container restart -[ -f "$ENTRYPOINT_PID_FILE" ] && [ -f "/run/__start_init_scripts.pid" ] || START_SERVICES="yes" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[ "$ENTRYPOINT_MESSAGE" = "yes" ] && __printf_space "40" "Container ip address is:" "$CONTAINER_IP4_ADDRESS" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# if no pid assume container restart - clean stale files on restart +if [ -f "$ENTRYPOINT_PID_FILE" ]; then + START_SERVICES="no" + touch "$ENTRYPOINT_PID_FILE" +else + START_SERVICES=yes + # Clean any stale PID files on first run + rm -f /run/__start_init_scripts.pid /run/init.d/*.pid /run/*.pid 2>/dev/null || true +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - +if [ ! -f "/run/__start_init_scripts.pid" ]; then + START_SERVICES="yes" + touch /run/__start_init_scripts.pid +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - +[ "$ENTRYPOINT_MESSAGE" = "yes" ] && __printf_space "40" "The containers ip address is:" "$CONTAINER_IP4_ADDRESS" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Show configured listing processes if [ "$ENTRYPOINT_MESSAGE" = "yes" ] && [ -n "$ENV_PORTS" ]; then - show_port="" - for port in $ENV_PORTS; do [ -n "$port" ] && show_port+="$(printf '%s ' "${port// /}") "; done - __printf_space "40" "The following ports are open:" "$show_port" - unset port show_port + show_port="" + for port in $ENV_PORTS; do [ -n "$port" ] && show_port+="$(printf '%s ' "${port// /}") "; done + __printf_space "40" "The following ports are open:" "$show_port" + unset port show_port fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # execute init script if [ -f "/tmp/init" ]; then sh "/tmp/init"; fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # create user if needed __create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Modify user if needed __set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-} -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Show message __run_message -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Just start services START_SERVICES="${START_SERVICES:-SYSTEM_INIT}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Never start services for these options +[ "$1" = "cron" ] && START_SERVICES="no" +[ "$1" = "tail" ] && START_SERVICES="no" +[ "$1" = "logs" ] && START_SERVICES="no" +[ "$1" = "cron" ] && START_SERVICES="no" +[ "$1" = "backup" ] && START_SERVICES="no" +[ "$1" = "healthcheck" ] && START_SERVICES="no" +[ "$1" = "init" ] && START_SERVICES="no" && CONTAINER_INIT="yes" +[ "$2" = "init" ] && START_SERVICES="no" && CONTAINER_INIT="yes" +echo "$1" | grep -qE '^(sh|bash)$|/*/(sh|bash)$' && START_SERVICES="no" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Start all services if no pidfile -if [ "$START_SERVICES" = "yes" ] && [ "$1" != "backup" ] && [ "$1" != "healthcheck" ]; then - [ "$1" = "start" ] && shift 1 - [ "$1" = "all" ] && shift 1 - [ "$1" = "init" ] && export CONTAINER_INIT="yes" - echo "$$" >"$ENTRYPOINT_PID_FILE" - __start_init_scripts "/usr/local/etc/docker/init.d" - START_SERVICES="no" - CONTAINER_INIT="${CONTAINER_INIT:-no}" +if [ "$START_SERVICES" = "yes" ] || [ -z "$1" ]; then + [ "$1" = "start" ] && shift 1 + [ "$1" = "all" ] && shift 1 + rm -Rf "/run"/*/*pid 2>/dev/null || true + echo "$$" >"$ENTRYPOINT_PID_FILE" + __start_init_scripts "/usr/local/etc/docker/init.d" + START_SERVICES="no" + CONTAINER_INIT="${CONTAINER_INIT:-no}" fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +export START_SERVICES CONTAINER_INIT ENTRYPOINT_PID_FILE +# - - - - - - - - - - - - - - - - - - - - - - - - - # Begin options case "$1" in init) - shift 1 - echo "Container has been Initialized" - exit 0 - ;; - + shift 1 + echo "Container has been Initialized" + exit 0 + ;; +tail) + shift 1 + case "$1" in + null) + shift $# + tail -F "/dev/null" + ;; + app) + shift $# + tail -F /data/logs/*/*.log + ;; + -*) + tail "$@" + ;; + *) + tail -F "${@:-/dev/null}" + ;; + esac + ;; +logs) + shift 1 + case "$1" in + follow) + tail -Fq /data/logs/*/* + ;; + clean) + log_files="$(find "/data/logs" -type f)" + for log in "${log_files[@]}"; do + echo "clearing $log" + printf '' >$log + done + ;; + *) + echo "Usage: logs [follow,clean]" + exit 0 + ;; + esac + ;; cron) - shift 1 - __cron "$@" & - exit - ;; + shift 1 + __cron "$@" & + echo "cron script is running with pid: $!" + exit + ;; # backup data and config dirs backup) - shift 1 - save="${1:-$BACKUP_DIR}" - backupExit=0 - date="$(date '+%Y%m%d-%H%M')" - file="$save/$date.tar.gz" - echo "Backing up /data /config to $file" - sleep 1 - tar cfvz "$file" --exclude="$save" "/data" "/config" || false - backupExit=$? - [ $backupExit -eq 0 ] && echo "Backed up /data /config has finished" || echo "Backup of /data /config has failed" - exit $backupExit - ;; + shift 1 + __backup $BACKUP_MAX_DAYS $1 + exit $? + ;; # Docker healthcheck healthcheck) - healthStatus=0 - services="${SERVICES_LIST:-$@}" - healthEnabled="${HEALTH_ENABLED:-}" - healthPorts="${WEB_SERVER_PORTS:-}" - healthEndPoints="${HEALTH_ENDPOINTS:-}" - healthMessage="Everything seems to be running" - services="${services//,/ }" - [ "$healthEnabled" = "yes" ] || exit 0 - for proc in $services; do - if [ -n "$proc" ]; then - if ! __pgrep "$proc"; then - echo "$proc is not running" >&2 - healthStatus=$((healthStatus + 1)) - fi - fi - done - for port in $ports; do - if [ -n "$(type -P netstat)" ] && [ -n "$port" ]; then - if ! netstat -taupln | grep -q ":$port "; then - echo "$port isn't open" >&2 - healthStatus=$((healthStatus + 1)) - fi - fi - done - for endpoint in $healthEndPoints; do - if [ -n "$endpoint" ]; then - if ! __curl "$endpoint"; then - echo "Can not connect to $endpoint" >&2 - healthStatus=$((healthStatus + 1)) - fi - fi - done - [ "$healthStatus" -eq 0 ] || healthMessage="Errors reported see: docker logs --follow $CONTAINER_NAME" - [ -n "$healthMessage" ] && echo "$healthMessage" - exit $healthStatus - ;; - # show open ports + shift 1 + case "$1" in + init | test) + exit 0 + ;; + *) + arguments="$*" + healthStatus=0 + healthEnabled="${HEALTH_ENABLED:-}" + healthPorts="${WEB_SERVER_PORTS:-}" + healthEndPoints="${HEALTH_ENDPOINTS:-}" + SERVICES_LIST="${arguments:-$SERVICES_LIST}" + services="$(echo "${SERVICES_LIST//,/ }")" + healthMessage="Everything seems to be running" + [ "$healthEnabled" = "yes" ] || exit 0 + if [ -d "/run/healthcheck" ] && [ "$(ls -A "/run/healthcheck" | wc -l)" -ne 0 ]; then + for service in /run/healthcheck/*; do + name=$(basename -- $service) + services+="$name " + done + fi + services="$(echo "$services" | tr ' ' '\n' | sort -u | grep -v '^$')" + for proc in $services; do + if [ -n "$proc" ]; then + if ! __pgrep "$proc"; then + echo "$proc is not running" >&2 + healthStatus=$((healthStatus + 1)) + fi + fi + done + for port in $ports; do + if [ -n "$(type -P netstat)" ] && [ -n "$port" ]; then + if ! netstat -taupln | grep -q ":$port "; then + echo "$port isn't open" >&2 + healthStatus=$((healthStatus + 1)) + fi + fi + done + for endpoint in $healthEndPoints; do + if [ -n "$endpoint" ]; then + if ! __curl "$endpoint"; then + echo "Can not connect to $endpoint" >&2 + healthStatus=$((healthStatus + 1)) + fi + fi + done + [ "$healthStatus" -eq 0 ] || healthMessage="Errors reported see: docker logs --follow $CONTAINER_NAME" + [ -n "$healthMessage" ] && echo "$healthMessage" + exit $healthStatus + ;; + esac + ;; + # show open ports ports) - shift 1 - ports="$(__netstat -taupln | awk -F ' ' '{print $4}' | awk -F ':' '{print $2}' | sort --unique --version-sort | grep -v '^$' | grep '^' || echo '')" - [ -n "$ports" ] && printf '%s\n%s\n' "The following are servers:" "$ports" | tr '\n' ' ' - exit $? - ;; - # show running processes + shift 1 + ports="$(__netstat -taupln | awk -F ' ' '{print $4}' | awk -F ':' '{print $2}' | sort --unique --version-sort | grep -v '^$' | grep '^' || echo '')" + [ -n "$ports" ] && printf '%s\n%s\n' "The following are servers:" "$ports" | tr '\n' ' ' + exit $? + ;; + # show running processes procs) - shift 1 - ps="$(__ps axco command | grep -vE 'COMMAND|grep|ps' | sort -u || grep '^' || echo '')" - [ -n "$ps" ] && printf '%s\n%s\n' "Found the following processes" "$ps" | tr '\n' ' ' - exit $? - ;; - # setup ssl + shift 1 + ps="$(__ps axco command | grep -vE 'COMMAND|grep|ps' | sort -u || grep '^' || echo '')" + [ -n "$ps" ] && printf '%s\n%s\n' "Found the following processes" "$ps" | tr '\n' ' ' + exit $? + ;; + # setup ssl ssl) - shift 1 - __create_ssl_cert - exit $? - ;; + shift 1 + __create_ssl_cert + exit $? + ;; # manage ssl certificate certbot) - shift 1 - CERT_BOT_ENABLED="yes" - if [ "$1" = "create" ]; then - shift 1 - __certbot "create" - elif [ "$1" = "renew" ]; then - shift 1 - __certbot "renew certonly --force-renew" - else - __exec_command "certbot" "$@" - fi - exit $? - ;; + shift 1 + CERT_BOT_ENABLED="yes" + if [ "$1" = "create" ]; then + shift 1 + __certbot "create" + elif [ "$1" = "renew" ]; then + shift 1 + __certbot "renew certonly --force-renew" + else + __exec_command "certbot" "$@" + fi + exit $? + ;; # Launch shell */bin/sh | */bin/bash | bash | sh | shell) - shift 1 - __exec_command "${@:-/bin/bash -l}" - exit $? - ;; + shift 1 + __exec_command "${@:-/bin/bash -l}" + exit $? + ;; # execute commands exec) - shift 1 - __exec_command "${@:-echo "No commands given"}" - exit $? - ;; + shift 1 + __exec_command "${@:-echo "No commands given"}" + exit $? + ;; # show/start init scripts start) - shift 1 - export PATH="/usr/local/etc/docker/init.d:$PATH" - if [ $# -eq 0 ]; then - scripts="$(ls -A "/usr/local/etc/docker/init.d")" - [ -n "$scripts" ] && echo "$scripts" || echo "No scripts found in: /usr/local/etc/docker/init.d" - exit - elif [ "$1" = "all" ]; then - shift $# - if [ "$START_SERVICES" = "yes" ]; then - echo "$$" >"$ENTRYPOINT_PID_FILE" - __start_init_scripts "/usr/local/etc/docker/init.d" - __no_exit - elif [ -f "/usr/local/etc/docker/init.d/$1" ]; then - eval "/usr/local/etc/docker/init.d/$1" & - __no_exit - - fi - fi - ;; + shift 1 + export PATH="/usr/local/etc/docker/init.d:$PATH" + if [ $# -eq 0 ]; then + scripts="$(ls -A "/usr/local/etc/docker/init.d")" + [ -n "$scripts" ] && echo "$scripts" || echo "No scripts found in: /usr/local/etc/docker/init.d" + exit + elif [ "$1" = "all" ]; then + shift $# + if [ "$START_SERVICES" = "yes" ]; then + echo "$$" >"$ENTRYPOINT_PID_FILE" + __start_init_scripts "/usr/local/etc/docker/init.d" + __no_exit + elif [ -f "/usr/local/etc/docker/init.d/$1" ]; then + eval "/usr/local/etc/docker/init.d/$1" & + __no_exit + fi + fi + ;; # Execute primary command *) - if [ $# -eq 0 ]; then - if [ ! -f "$ENTRYPOINT_PID_FILE" ]; then - echo "$$" >"$ENTRYPOINT_PID_FILE" - [ "$START_SERVICES" = "no" ] && [ "$CONTAINER_INIT" = "yes" ] || __start_init_scripts "/usr/local/etc/docker/init.d" - fi - __no_exit - else - __exec_command "$@" - fi - exit $? - ;; + if [ $# -eq 0 ]; then + if [ ! -f "$ENTRYPOINT_PID_FILE" ]; then + echo "$$" >"$ENTRYPOINT_PID_FILE" + [ "$START_SERVICES" = "no" ] && [ "$CONTAINER_INIT" = "yes" ] || __start_init_scripts "/usr/local/etc/docker/init.d" + fi + __no_exit + else + __exec_command "$@" + fi + exit $? + ;; esac -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # end of entrypoint -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # ex: ts=2 sw=2 et filetype=sh diff --git a/rootfs/usr/local/bin/pkmgr b/rootfs/usr/local/bin/pkmgr index 137af81..fbd269a 100755 --- a/rootfs/usr/local/bin/pkmgr +++ b/rootfs/usr/local/bin/pkmgr @@ -1,17 +1,10 @@ -#!/usr/bin/env bash -# shellcheck shell=bash +#!/usr/bin/env sh +# shellcheck shell=sh # shellcheck disable=SC2016 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[ -n "$_DEBUG" ] && _DEBUG_OPTIONS="-x" -[ "$1" = "--debug" ] && _DEBUG_OPTIONS="-x" && shift 1 -[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS -set -e $_DEBUG_OPTIONS -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - USER_UID="$(id -u)" USER_GID="$(id -g)" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[ -f "/etc/pkmgr/options.conf" ] && . "/etc/pkmgr/options.conf" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - if [ -x "$(command -v apt 2>/dev/null)" ]; then export DEBIAN_FRONTEND=noninteractive pkmgr_cmd="apt" @@ -19,6 +12,7 @@ if [ -x "$(command -v apt 2>/dev/null)" ]; then pkmgr_mkcache_cmd="$pkmgr_cmd update" pkmgr_update_cmd="$pkmgr_cmd upgrade -yy" pkmgr_install_cmd="$pkmgr_cmd install -yy $PKMGR_OPTS" + pkmgr_install_post="$pkmgr_cmd --fix-broken install" elif [ -x "$(command -v apt-get 2>/dev/null)" ]; then export DEBIAN_FRONTEND=noninteractive pkmgr_cmd="apt-get" @@ -26,6 +20,7 @@ elif [ -x "$(command -v apt-get 2>/dev/null)" ]; then pkmgr_mkcache_cmd="$pkmgr_cmd update" pkmgr_update_cmd="$pkmgr_cmd upgrade -yy" pkmgr_install_cmd="$pkmgr_cmd install -yy $PKMGR_OPTS" + pkmgr_install_post="$pkmgr_cmd --fix-broken install" elif [ -x "$(command -v dnf 2>/dev/null)" ]; then pkmgr_cmd="dnf" pkmgr_clean_cmd="$pkmgr_cmd clean all" @@ -63,7 +58,7 @@ else pkmgr_update_cmd="$pkmgr_cmd" pkmgr_install_cmd="$pkmgr_cmd" fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - if [ -f "/config/pkmgr/settings.conf" ]; then . "/config/pkmgr/settings.conf" elif [ -f "/etc/pkmgr/settings.conf" ]; then @@ -78,9 +73,9 @@ pkmgr_install_cmd="$pkmgr_install_cmd" pkmgr_mkcache_cmd="$pkmgr_mkcache_cmd" EEOF fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - [ -n "$pkmgr_cmd" ] || { echo "Can not determine the package manager" && exit 1; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - case "$1" in pip) shift 1 @@ -90,13 +85,34 @@ pip) case "$1" in install) shift 1 - $pip_bin -m $pip_opts "$@" + pkg_list="$*" + for pkg in $pkg_list; do + $pip_bin -m pip $pip_opts "$pkg" + done ;; *) - $pip_bin "$@" + for pkg in "$@"; do + $pip_bin -m pip "$pkg" + done ;; esac - exit $? + exit + ;; +install) + shift 1 + [ -n "$1" ] || exit 0 + [ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_install_cmd="sudo $pkmgr_install_cmd" + if [ -f "$1" ]; then + install_list="$(cat "$1")" + else + install_list="$*" + fi + for pkg in $install_list;do + echo "installing packages command: $pkmgr_install_cmd $pkg" + $pkmgr_install_cmd $pkg + if [ -n "$pkmgr_install_post" ]; then eval $pkmgr_install_post; fi + done + exit ;; update | upgrade) shift $# @@ -114,20 +130,6 @@ clean) $pkmgr_clean_cmd exit $? ;; -install) - shift 1 - [ -n "$1" ] || exit 0 - [ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_install_cmd="sudo $pkmgr_install_cmd" - if [ -f "$1" ]; then - install_list="$(cat "$1")" - echo 'installing packages from file with command: '$pkmgr_install_cmd' "$(<"$1")"' - else - install_list="$*" - echo "installing packages command: $pkmgr_install_cmd $install_list" - fi - $pkmgr_install_cmd $install_list - exit $? - ;; *) [ -n "$1" ] || exit 0 [ "$USER_UID" -eq 0 ] || [ "$USER" = "root" ] || pkmgr_cmd="sudo $pkmgr_cmd" @@ -136,5 +138,5 @@ install) exit $? ;; esac -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # end diff --git a/rootfs/usr/local/etc/docker/functions/entrypoint.sh b/rootfs/usr/local/etc/docker/functions/entrypoint.sh index b44ed1b..983c0ce 100644 --- a/rootfs/usr/local/etc/docker/functions/entrypoint.sh +++ b/rootfs/usr/local/etc/docker/functions/entrypoint.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # shellcheck shell=bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - ##@Version : 202407241259-git # @@Author : Jason Hempstead # @@Contact : git-admin@casjaysdev.pro @@ -17,15 +17,15 @@ # @@Terminal App : no # @@sudo/root : no # @@Template : functions/docker-entrypoint -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317,SC2329 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - # setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html -[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}" -{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || true +{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail +# - - - - - - - - - - - - - - - - - - - - - - - - - __remove_extra_spaces() { sed 's/\( \)*/\1/g;s|^ ||g'; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __printf_space() { local pad=$(printf '%0.1s' " "{1..60}) local padlength=$1 @@ -37,7 +37,8 @@ __printf_space() { message+="$(printf '%s\n' "$string2") " printf '%s\n' "$message" } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +__mkdir() { [ -n "$1" ] && mkdir -p "$@" || return 1; } __rm() { [ -n "$1" ] && [ -e "$1" ] && rm -Rf "${1:?}"; } __grep_test() { grep -sh "$1" "$2" | grep -qwF "${3:-$1}" || return 1; } __netstat() { [ -f "$(type -P netstat)" ] && netstat "$@" || return 10; } @@ -52,7 +53,8 @@ __ps() { [ -f "$(type -P ps)" ] && ps "$@" 2>/dev/null | sed 's|:||g' | grep -Fw __is_dir_empty() { if [ -n "$1" ]; then [ "$(ls -A "$1" 2>/dev/null | wc -l)" -eq 0 ] && return 0 || return 1; else return 1; fi; } __get_ip6() { ip a 2>/dev/null | grep -w 'inet6' | awk '{print $2}' | grep -vE '^::1|^fe' | sed 's|/.*||g' | head -n1 | grep '.' || echo ''; } __get_ip4() { ip a 2>/dev/null | grep -w 'inet' | awk '{print $2}' | grep -vE '^127.0.0' | sed 's|/.*||g' | head -n1 | grep '.' || echo '127.0.0.1'; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__find_and_remove() { find "${2:-/etc}" -iname "$1" -exec rm -Rfv {} \; 2>/dev/null; } +# - - - - - - - - - - - - - - - - - - - - - - - - - __pgrep() { local count=3 local srvc="${1:-SERVICE_NAME}" @@ -64,28 +66,28 @@ __pgrep() { done return 10 } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __find_file_relative() { [ -e "$1" ] || return 0 find "$1"/* -not -path '*env/*' -not -path '.git*' -type f 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '.' || false } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __find_directory_relative() { [ -d "$1" ] || return 0 find "$1"/* -not -path '*env/*' -not -path '.git*' -type d 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '.' || false } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__pid_exists() { +# - - - - - - - - - - - - - - - - - - - - - - - - - +__pid_exists() { local result="" result="$(ps -ax --no-header 2>/dev/null | sed 's/^[[:space:]]*//g' | awk -F' ' '{print $1}' | sed 's|:||g' | grep '[0-9]' | sort -uV | grep "^$1$" 2>/dev/null || echo '')" [ -n "$result" ] && return 0 || return 1 } -__is_running() { +__is_running() { local result="" result="$(ps -eo args --no-header 2>/dev/null | awk '{print $1,$2,$3}' | sed 's|:||g' | sort -u | grep -vE 'grep|COMMAND|awk|tee|ps|sed|sort|tail' | grep "$1" | grep "${2:-^}" 2>/dev/null || echo '')" [ -n "$result" ] && return 0 || return 1 } -__get_pid() { +__get_pid() { local result="" result="$(ps -ax --no-header 2>/dev/null | sed 's/^[[:space:]]*//g;s|;||g;s|:||g' | awk '{print $1,$5}' | sed 's|:||g' | grep "$1$" | grep -v 'grep' | awk -F' ' '{print $1}' | grep '[0-9]' | sort -uV | head -n1 | grep '.' 2>/dev/null || echo '')" if [ -n "$result" ]; then @@ -95,9 +97,9 @@ __get_pid() { return 1 fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __format_variables() { printf '%s\n' "${@//,/ }" | tr ' ' '\n' | sort -RVu | grep -v '^$' | tr '\n' ' ' | __clean_variables | grep '.' || return 0; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __clean_variables() { local var="$*" var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters @@ -105,7 +107,7 @@ __clean_variables() { var="$(printf '%s\n' "$var" | sed 's/\( \)*/\1/g;s|^ ||g')" printf '%s' "$var" | grep -v '^$' } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __no_exit() { local monitor_interval="${SERVICE_MONITOR_INTERVAL:-60}" local failure_threshold="${SERVICE_FAILURE_THRESHOLD:-3}" @@ -145,7 +147,7 @@ __no_exit() { wait " } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __trim() { local var="${*//;/ }" var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters @@ -153,14 +155,14 @@ __trim() { var="$(echo "$var" | __remove_extra_spaces | sed "s| |; |g;s|;$| |g" | __remove_extra_spaces)" printf '%s' "$var" | sed 's|;||g' | grep -v '^$' } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __banner() { local message="$*" local total_width=80 local content_width=$((total_width - 14)) # Account for "# - - - " and " - - - #" printf '# - - - %-*s - - - #\n' "$content_width" "$message" } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __service_banner() { local icon="${1:-🔧}" local message="${2:-Processing}" @@ -172,23 +174,23 @@ __service_banner() { local text_width=$((content_width - icon_width * 2 - 2)) # Account for both icons and spaces printf '# - - - %s %-*s %s - - - #\n' "$icon" "$text_width" "$full_message" "$icon" } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __find_php_bin() { find -L '/usr'/*bin -maxdepth 4 -name 'php-fpm*' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_php_ini() { find -L '/etc' -maxdepth 4 -name 'php.ini' 2>/dev/null | head -n1 | sed 's|/php.ini||g' | grep '.' || echo ''; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __find_nginx_conf() { find -L '/etc' -maxdepth 4 -name 'nginx.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_caddy_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'caddy.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_lighttpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'lighttpd.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_cherokee_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'cherokee.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_httpd_conf() { find -L '/etc' -maxdepth 4 -type f -iname 'httpd.conf' -o -iname 'apache2.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __find_mysql_conf() { find -L '/etc' -maxdepth 4 -type f -name 'my.cnf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_pgsql_conf() { find -L '/var/lib' '/etc' -maxdepth 8 -type f -name 'postgresql.conf' 2>/dev/null | head -n1 | grep '.' || echo ''; } __find_couchdb_conf() { return; } __find_mongodb_conf() { return; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __random_password() { cat "/dev/urandom" | tr -dc '0-9a-zA-Z' | head -c${1:-16} && echo ""; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __init_working_dir() { local service_name="$SERVICE_NAME" # get service name local workdir="$(eval echo "${WORK_DIR:-}")" # expand variables @@ -206,15 +208,15 @@ __init_working_dir() { [ -n "$workdir" ] && { [ -d "$workdir" ] || mkdir -p "$workdir"; } [ "$SERVICE_USER" = "root" ] || [ -d "$home" ] && chmod -f 777 "$home" [ "$SERVICE_USER" = "root" ] || [ -d "$workdir" ] && chmod -f 777 "$workdir" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # - - - - - - - - - - - - - - - - - - - - - - - - - # cd to dir __cd "${workdir:-$home}" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # - - - - - - - - - - - - - - - - - - - - - - - - - echo "Setting the working directory to: $PWD" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # - - - - - - - - - - - - - - - - - - - - - - - - - export WORK_DIR="$workdir" HOME="$home" } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __exec_service() { local count=6 echo "Starting $1" @@ -224,7 +226,7 @@ __exec_service() { __pgrep $1 && touch "/run/init.d/$1.pid" && break || count=$((count - 1)) done } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __update_ssl_certs() { [ -f "/config/env/ssl.sh" ] && . "/config/env/ssl.sh" if [ -f "$SSL_CERT" ] && [ -f "$SSL_KEY" ]; then @@ -234,7 +236,7 @@ __update_ssl_certs() { [ -f "$SSL_CERT" ] && cp -Rf "$SSL_CERT" "/etc/ssl/$SSL_CERT" fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __certbot() { [ -n "$(type -P 'certbot')" ] || return 1 local options="$1" @@ -295,7 +297,7 @@ __certbot() { [ $statusCode -eq 0 ] && __update_ssl_certs return $statusCode } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __display_user_info() { if [ -n "$user_name" ] || [ -n "$user_pass" ] || [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then __banner "User info" @@ -306,7 +308,7 @@ __display_user_info() { __banner "" fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __init_config_etc() { local copy="no" local name="$(find "/etc/$SERVICE_NAME" -maxdepth 0 2>/dev/null | head -n1)" @@ -321,7 +323,7 @@ __init_config_etc() { __copy_templates "$etc_dir" "$conf_dir" fi fi - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # - - - - - - - - - - - - - - - - - - - - - - - - - } __create_ssl_cert() { local SSL_DIR="${SSL_DIR:-/etc/ssl}" @@ -353,7 +355,7 @@ __create_ssl_cert() { return 2 fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __init_apache() { local etc_dir="" conf_dir="" conf_dir="" www_dir="" apache_bin="" etc_dir="/etc/${1:-apache2}" @@ -363,7 +365,7 @@ __init_apache() { # return 0 } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __init_nginx() { local etc_dir="/etc/${1:-nginx}" local conf_dir="/config/${1:-nginx}" @@ -371,14 +373,14 @@ __init_nginx() { local nginx_bin="$(type -P 'nginx')" return 0 } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __init_php() { local etc_dir="/etc/${1:-php}" local conf_dir="/config/${1:-php}" local php_bin="${PHP_BIN_DIR:-$(__find_php_bin)}" return 0 } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __init_mysql() { local db_dir="/data/db/mysql" local etc_dir="${home:-/etc/${1:-mysql}}" @@ -391,28 +393,28 @@ __init_mysql() { local mysqld_bin="$(type -P 'mysqld')" return 0 } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __init_mongodb() { local home="${MONGODB_CONFIG_FILE:-$(__find_mongodb_conf)}" local user_name="${INITDB_ROOT_USERNAME:-root}" local user_pass="${MONGO_INITDB_ROOT_PASSWORD:-$_ROOT_PASSWORD}" return } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __init_postgres() { local home="${PGSQL_CONFIG_FILE:-$(__find_pgsql_conf)}" local user_name="${POSTGRES_USER:-root}" local user_pass="${POSTGRES_PASSWORD:-$POSTGRES_ROOT_PASSWORD}" return } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __init_couchdb() { local home="${COUCHDB_CONFIG_FILE:-$(__find_couchdb_conf)}" local user_name="${COUCHDB_USER:-root}" local user_pass="${COUCHDB_PASSWORD:-$SET_RANDOM_PASS}" return } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Show available init functions __init_help() { echo ' @@ -422,7 +424,7 @@ __create_ssl_cert ' return } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __run_once() { if [ "$CONFIG_DIR_INITIALIZED" = "false" ] || [ "$DATA_DIR_INITIALIZED" = "false" ] || [ ! -f "/config/.docker_has_run" ]; then return 0 @@ -430,7 +432,7 @@ __run_once() { return 1 fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # run program ever n minutes __cron() { trap 'retVal=$?;[ -f "/run/cron/$bin.run" ] && rm -Rf "/run/cron/$bin.run";[ -f "/run/cron/$bin.pid" ] && rm -Rf "/run/cron/$bin.pid";exit ${retVal:-0}' SIGINT ERR EXIT @@ -449,19 +451,19 @@ __cron() { [ -f "/run/cron/$bin.run" ] || break done 2>/dev/stderr >>"/data/logs/cron.log" } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __replace() { local search="$1" replace="$2" file="${3:-$2}" [ -e "$file" ] || return 1 __sed "$search" "$replace" "$file" || return 0 } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __find_replace() { local search="$1" replace="$2" file="${3:-$2}" [ -e "$file" ] || return 1 find "$file" -type f -not -path '.git*' -exec sed -i "s|$search|$replace|g" {} \; 2>/dev/null } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # /config > /etc __copy_templates() { local from="$1" to="$2" @@ -471,7 +473,7 @@ __copy_templates() { __file_copy "$from" "$to" fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # /config/file > /etc/file __symlink() { local from="$1" to="$2" @@ -480,7 +482,7 @@ __symlink() { ln -sf "$to" "$from" && echo "Created symlink to $from > $to" fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __file_copy() { local from="$1" local dest="$2" @@ -510,7 +512,7 @@ __file_copy() { fi fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __generate_random_uids() { local set_random_uid="$(seq 100 999 | sort -R | head -n 1)" while :; do @@ -522,7 +524,7 @@ __generate_random_uids() { fi done } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __setup_directories() { APPLICATION_DIRS="${APPLICATION_DIRS//,/ }" APPLICATION_FILES="${APPLICATION_FILES//,/ }" @@ -555,7 +557,7 @@ __setup_directories() { fi done } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # set user on files/folders __fix_permissions() { change_user="${1:-${SERVICE_USER:-root}}" @@ -580,14 +582,14 @@ __fix_permissions() { fi fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __get_gid() { grep "^$1:" /etc/group | awk -F ':' '{print $3}' || false; } __get_uid() { grep "^$1:" /etc/passwd | awk -F ':' '{print $3}' || false; } __check_for_uid() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -q "^$1$" || false; } __check_for_guid() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $3}' | sort -u | grep -q "^$1$" || false; } __check_for_user() { cat "/etc/passwd" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -q "^$1$" || false; } __check_for_group() { cat "/etc/group" 2>/dev/null | awk -F ':' '{print $1}' | sort -u | grep -q "^$1$" || false; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # check if process is already running __proc_check() { cmd_bin="$(type -P "${1:-$EXEC_CMD_BIN}")" @@ -601,7 +603,7 @@ __proc_check() { fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __set_user_group_id() { local exitStatus=0 local set_user="${1:-$SERVICE_USER}" @@ -614,16 +616,16 @@ __set_user_group_id() { [ -n "$set_user" ] && [ "$set_user" != "root" ] || return if grep -shq "^$set_user:" "/etc/passwd" "/etc/group"; then if __check_for_guid "$set_gid"; then - groupmod -g "${set_gid}" $set_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null && chown -Rf ":$set_gid" + groupmod -g "${set_gid}" $set_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null fi if __check_for_uid "$set_uid"; then - usermod -u "${set_uid}" -g "${set_gid}" $set_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null && chown -Rf $set_uid:$set_gid + usermod -u "${set_uid}" -g "${set_gid}" $set_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null fi fi export SERVICE_UID="$set_uid" export SERVICE_GID="$set_gid" } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __create_service_user() { local exitStatus=0 local create_user="${1:-$SERVICE_USER}" @@ -634,7 +636,9 @@ __create_service_user() { local random_id="$(__generate_random_uids)" local create_home_dir="${create_home_dir:-/home/$create_user}" grep -shq "^$create_user:" "/etc/passwd" && grep -shq "^$create_group:" "/etc/group" && return - [ "$create_user" = "root" ] && [ "$create_group" = "root" ] && return 0 + if [ "$create_user" = "root" ] && [ "$create_group" = "root" ]; then + return 0 + fi if [ "$RUNAS_USER" != "root" ] && [ "$RUNAS_USER" != "" ]; then create_user="$RUNAS_USER" create_group="$RUNAS_USER" @@ -653,17 +657,17 @@ __create_service_user() { break fi done - if ! __check_for_group "$create_group"; then + if [ -n "$create_group" ] && ! __check_for_group "$create_group"; then echo "creating system group $create_group" - groupadd --force --system -g $create_gid $create_group 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null + groupadd --force --system -g $create_gid $create_group 2>/dev/stderr | tee -a "/data/logs/init.txt" >/dev/null + grep -shq "$create_group" "/etc/group" || exitStatus=$((exitStatus + 1)) fi - if ! __check_for_user "$create_user"; then + if [ -n "$create_user" ] && ! __check_for_user "$create_user"; then echo "creating system user $create_user" - useradd --system -u $create_uid -g $create_group -c "Account for $create_user" -d "$create_home_dir" -s /bin/false $create_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null + useradd --system --uid $create_uid --gid $create_group --comment "Account for $create_user" --home-dir "$create_home_dir" --shell /bin/false $create_user 2>/dev/stderr | tee -a "/data/logs/init.txt" >/dev/null + grep -shq "$create_user" "/etc/passwd" || exitStatus=$((exitStatus + 1)) fi - grep -shq "$create_group" "/etc/group" || exitStatus=$((exitStatus + 1)) - grep -shq "$create_user" "/etc/passwd" || exitStatus=$((exitCode + 1)) - if [ $exitStatus -eq 0 ]; then + if [ $exitStatus -eq 0 ] && [ -n "$create_group" ] && [ -n "$create_user" ]; then export WORK_DIR="${create_home_dir:-}" if [ -n "$WORK_DIR" ]; then [ -d "$WORK_DIR" ] || mkdir -p "$WORK_DIR" @@ -674,20 +678,22 @@ __create_service_user() { elif [ -f "/etc/sudoers" ] && ! grep -qs "$create_user" "/etc/sudoers"; then echo "$create_user ALL=(ALL) NOPASSWD: ALL" >"/etc/sudoers" fi - export SERVICE_UID="$create_uid" - export SERVICE_GID="$create_gid" - export SERVICE_USER="$create_user" - export SERVICE_GROUP="$create_group" + exitStatus=0 + SERVICE_UID="$create_uid" + SERVICE_GID="$create_gid" + SERVICE_USER="$create_user" + SERVICE_GROUP="$create_group" else - export USER_UID=0 - export USER_GID=0 - export SERVICE_USER=root - export SERVICE_GROUP=root + SERVICE_UID=0 + SERVICE_GID=0 + SERVICE_USER=root + SERVICE_GROUP=root exitStatus=2 fi + export SERVICE_UID SERVICE_GID SERVICE_USER SERVICE_GROUP return $exitStatus } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __create_env_file() { local dir="" local envStatus=0 @@ -707,7 +713,7 @@ EOF rm -f "$sample_file" return $envStatus } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __exec_command() { local bin="" local arg=("$@") @@ -730,7 +736,7 @@ __exec_command() { fi return $exitCode } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Setup the server init scripts __start_init_scripts() { [ "$1" = " " ] && shift 1 @@ -741,6 +747,7 @@ __start_init_scripts() { local retstatus="0" local initStatus="0" local critical_failures="0" + local pidFile="/run/__start_init_scripts.pid" local init_dir="${1:-/usr/local/etc/docker/init.d}" local init_count="$(ls -A "$init_dir"/* 2>/dev/null | grep -v '\.sample' | wc -l)" local exit_on_failure="${EXIT_ON_SERVICE_FAILURE:-true}" @@ -751,7 +758,7 @@ __start_init_scripts() { rm -f /run/*.pid /run/init.d/*.pid 2>/dev/null || true fi - touch /run/__start_init_scripts.pid + touch "$pidFile" if [ "$init_count" -eq 0 ] || [ ! -d "$init_dir" ]; then mkdir -p "/data/logs/init" @@ -769,6 +776,7 @@ __start_init_scripts() { for init in "$init_dir"/*.sh; do if [ -x "$init" ]; then + touch "$pidFile" name="$(basename "$init")" service="$(printf '%s' "$name" | sed 's/^[^-]*-//;s|.sh$||g')" __service_banner "🔧" "Executing service script:" "$(basename "$init")" @@ -779,8 +787,13 @@ __start_init_scripts() { initStatus="0" __service_banner "🚫" "Service $service is disabled -" "skipping" unset SERVICE_DISABLED + # Continue to next service + elif [ "$CONTAINER_INIT" = "yes" ]; then + initStatus="0" + __service_banner "✅" "Service $service completed successfully -" "configuration service" else - sleep 2 + # Allow some time for service to initialize + sleep 1 # Check for service success indicators local expected_pid_file="/run/init.d/$service.pid" if [ "$SERVICE_USES_PID" = "no" ]; then @@ -795,9 +808,8 @@ __start_init_scripts() { fi else # Service uses PID tracking - verify actual running processes - set +e # Temporarily disable exit on error + set +e # Temporarily disable exit on error retPID="" - # First, try to find actual running process with various name patterns for name_variant in "$service" "${service}84" "${service}d" "$(echo "$service" | sed 's/-//g')" "$(echo "$service" | tr -d '-')"; do if [ -z "$retPID" ]; then @@ -805,9 +817,7 @@ __start_init_scripts() { [ -n "$retPID" ] && found_process="$name_variant" && break fi done - - set -e # Re-enable exit on error - + set -e # Re-enable exit on error if [ -n "$retPID" ] && [ "$retPID" != "0" ]; then # Found actual running process initStatus="0" @@ -859,7 +869,7 @@ __start_init_scripts() { printf '%s\n' "$SERVICE_NAME started on $(date)" >"/data/logs/start.log" return $retstatus } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __setup_mta() { [ -d "/etc/ssmtp" ] || [ -d "/etc/postfix" ] || return if [ ! -d "/config/ssmtp" ] || [ ! -d "/config/postfix" ]; then @@ -966,7 +976,7 @@ EOF [ -f "/root/dead.letter" ] && __rm "/root/dead.letter" return $exitCode } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_web_health() { local www_dir="${1:-${WWW_ROOT_DIR:-/usr/local/share/httpd/default}}" if [ -d "$www_dir" ]; then @@ -975,7 +985,7 @@ __initialize_web_health() { __find_replace "REPLACE_LAST_UPDATED_ON_MESSAGE" "${LAST_UPDATED_ON_MESSAGE:-$(date +'Last updated on: %Y-%m-%d at %H:%M:%S')}" "/usr/local/share/httpd" fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # file_dir __initialize_replace_variables() { local set_dir="" get_dir="$*" @@ -1018,7 +1028,7 @@ __initialize_replace_variables() { mkdir -p "${TMP_DIR:-/tmp/$SERVICE_NAME}" "${RUN_DIR:-/run/$SERVICE_NAME}" "${LOG_DIR:-/data/logs/$SERVICE_NAME}" chmod -f 777 "${TMP_DIR:-/tmp/$SERVICE_NAME}" "${RUN_DIR:-/run/$SERVICE_NAME}" "${LOG_DIR:-/data/logs/$SERVICE_NAME}" } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_database() { [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ] || return 0 local dir="${1:-$ETC_DIR}" @@ -1049,7 +1059,7 @@ __initialize_database() { __find_replace "REPLACE_DATABASE_DIR" "$DATABASE_DIR" "/etc" fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_db_users() { [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ] || return 0 db_normal_user="${DATABASE_USER_NORMAL:-$user_name}" @@ -1062,7 +1072,7 @@ __initialize_db_users() { export DATABASE_PASS_ROOT="$db_admin_pass" export db_normal_user db_normal_pass db_admin_user db_admin_pass } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_system_etc() { local conf_dir="$1" local dir="" @@ -1089,7 +1099,7 @@ __initialize_system_etc() { done fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_custom_bin_dir() { local SET_USR_BIN="" [ -d "/data/bin" ] && SET_USR_BIN+="$(__find /data/bin f) " @@ -1107,7 +1117,7 @@ __initialize_custom_bin_dir() { unset create_bin_template create_bin_name SET_USR_BIN fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_default_templates() { if [ -n "$DEFAULT_TEMPLATE_DIR" ]; then if [ "$CONFIG_DIR_INITIALIZED" = "false" ] && [ -d "/config" ]; then @@ -1127,7 +1137,7 @@ __initialize_default_templates() { fi fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_config_dir() { if [ -n "$DEFAULT_CONF_DIR" ]; then if [ "$CONFIG_DIR_INITIALIZED" = "false" ] && [ -d "/config" ]; then @@ -1147,7 +1157,7 @@ __initialize_config_dir() { fi fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_data_dir() { if [ -d "/data" ]; then if [ "$DATA_DIR_INITIALIZED" = "false" ] && [ -n "$DEFAULT_DATA_DIR" ]; then @@ -1167,7 +1177,7 @@ __initialize_data_dir() { fi fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_www_root() { local WWW_INIT="" local WWW_TEMPLATE="" @@ -1180,7 +1190,7 @@ __initialize_www_root() { fi __initialize_web_health "$WWW_ROOT_DIR" } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __is_htdocs_mounted() { WWW_ROOT_DIR="${WWW_ROOT_DIR:-/data/htdocs}" [ -n "$ENV_WWW_ROOT_DIR" ] && WWW_ROOT_DIR="$ENV_WWW_ROOT_DIR" @@ -1207,7 +1217,7 @@ __is_htdocs_mounted() { [ -d "$WWW_ROOT_DIR" ] || mkdir -p "$WWW_ROOT_DIR" export WWW_ROOT_DIR="${WWW_ROOT_DIR:-/usr/local/share/httpd/default}" } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_ssl_certs() { [ "$SSL_ENABLED" = "yes" ] && __certbot if [ -d "/config/letsencrypt" ]; then @@ -1234,7 +1244,7 @@ __initialize_ssl_certs() { fi type update-ca-certificates &>/dev/null && update-ca-certificates &>/dev/null } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __start_php_dev_server() { if [ "$2" = "yes" ]; then if [ -d "/usr/local/share/httpd" ]; then @@ -1247,7 +1257,7 @@ __start_php_dev_server() { fi fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __check_service() { if [ "$1" = "check" ]; then shift $# @@ -1255,7 +1265,7 @@ __check_service() { exit $? fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __switch_to_user() { if [ "$RUNAS_USER" = "root" ]; then su_exec="" @@ -1278,7 +1288,7 @@ __switch_to_user() { fi export su_exec } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # usage backup "days" "hours" __backup() { local dirs="" backup_dir backup_name backup_exclude runTime cronTime maxDays @@ -1316,7 +1326,7 @@ __backup() { [ -n "$cronTime" ] && runTime=$((cronTime * 3600)) || return $exitStatus sleep $runTime && __backup "$maxDays" "$cronTime" } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # set variables from function calls export INIT_DATE="${INIT_DATE:-$(date)}" export START_SERVICES="${START_SERVICES:-yes}" @@ -1324,13 +1334,13 @@ export ENTRYPOINT_MESSAGE="${ENTRYPOINT_MESSAGE:-yes}" export ENTRYPOINT_FIRST_RUN="${ENTRYPOINT_FIRST_RUN:-yes}" export DATA_DIR_INITIALIZED="${DATA_DIR_INITIALIZED:-false}" export CONFIG_DIR_INITIALIZED="${CONFIG_DIR_INITIALIZED:-false}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # System export LANG="${LANG:-C.UTF-8}" export LC_ALL="${LANG:-C.UTF-8}" export TZ="${TZ:-${TIMEZONE:-America/New_York}}" export HOSTNAME="${FULL_DOMAIN_NAME:-${SERVER_HOSTNAME:-$HOSTNAME}}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Default directories export SSL_DIR="${SSL_DIR:-/config/ssl}" export SSL_CA="${SSL_CERT:-/config/ssl/ca.crt}" @@ -1340,15 +1350,15 @@ export LOCAL_BIN_DIR="${LOCAL_BIN_DIR:-/usr/local/bin}" export DEFAULT_DATA_DIR="${DEFAULT_DATA_DIR:-/usr/local/share/template-files/data}" export DEFAULT_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config}" export DEFAULT_TEMPLATE_DIR="${DEFAULT_TEMPLATE_DIR:-/usr/local/share/template-files/defaults}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Backup settings export BACKUP_MAX_DAYS="${BACKUP_MAX_DAYS:-}" export BACKUP_RUN_CRON="${BACKUP_RUN_CRON:-}" export BACKUP_DIR="${BACKUP_DIR:-/data/backups}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - CONTAINER_IP4_ADDRESS="${CONTAINER_IP4_ADDRESS:-$(__get_ip4)}" CONTAINER_IP6_ADDRESS="${CONTAINER_IP6_ADDRESS:-$(__get_ip6)}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Additional export WORK_DIR="${ENV_WORK_DIR:-$WORK_DIR}" export SET_RANDOM_PASS="${SET_RANDOM_PASS:-$(__random_password 16)}" @@ -1366,15 +1376,15 @@ export ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-/run/init.d/entrypoint.pid}" export ENTRYPOINT_INIT_FILE="${ENTRYPOINT_INIT_FILE:-/config/.entrypoint.done}" export ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has_run}" export ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # is already Initialized [ -z "$DATA_DIR_INITIALIZED" ] && { [ -f "$ENTRYPOINT_DATA_INIT_FILE" ] && DATA_DIR_INITIALIZED="true" || DATA_DIR_INITIALIZED="false"; } [ -z "$CONFIG_DIR_INITIALIZED" ] && { [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && CONFIG_DIR_INITIALIZED="true" || CONFIG_DIR_INITIALIZED="false"; } [ -z "$ENTRYPOINT_FIRST_RUN" ] && { { [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; } && ENTRYPOINT_FIRST_RUN="no" || ENTRYPOINT_FIRST_RUN="true"; } export ENTRYPOINT_DATA_INIT_FILE DATA_DIR_INITIALIZED ENTRYPOINT_CONFIG_INIT_FILE CONFIG_DIR_INITIALIZED export ENTRYPOINT_PID_FILE ENTRYPOINT_INIT_FILE ENTRYPOINT_FIRST_RUN -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # export the functions export -f __get_pid __start_init_scripts __is_running __certbot __update_ssl_certs __create_ssl_cert -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # end of functions diff --git a/rootfs/usr/local/etc/docker/init.d/00-opengist.sh b/rootfs/usr/local/etc/docker/init.d/00-opengist.sh old mode 100644 new mode 100755 index 7004d8c..d4f88cb --- a/rootfs/usr/local/etc/docker/init.d/00-opengist.sh +++ b/rootfs/usr/local/etc/docker/init.d/00-opengist.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash # shellcheck shell=bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091628-git +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202511290807-git # @@Author : Jason Hempstead # @@Contact : jason@casjaysdev.pro -# @@License : WTFPL +# @@License : LICENSE.md # @@ReadME : 00-opengist.sh --help -# @@Copyright : Copyright: (c) 2024 Jason Hempstead, Casjays Developments -# @@Created : Friday, Aug 09, 2024 16:28 EDT +# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments +# @@Created : Saturday, Nov 29, 2025 08:07 EST # @@File : 00-opengist.sh # @@Description : # @@Changelog : New script @@ -17,25 +17,19 @@ # @@Terminal App : no # @@sudo/root : no # @@Template : other/start-service -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - +set -e +# - - - - - - - - - - - - - - - - - - - - - - - - - # run trap command on exit -trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE";exit $retVal' SIGINT SIGTERM EXIT -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html -[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}" -{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +trap 'retVal=$?; echo "❌ Fatal error occurred: Exit code $retVal at line $LINENO in command: $BASH_COMMAND"; kill -TERM 1' ERR +trap 'retVal=$?;if [ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ]; then rm -Rf "$SERVICE_PID_FILE"; fi;exit $retVal' SIGINT SIGTERM SIGPWR +# - - - - - - - - - - - - - - - - - - - - - - - - - SCRIPT_FILE="$0" SERVICE_NAME="opengist" +SCRIPT_NAME="$(basename -- "$SCRIPT_FILE" 2>/dev/null)" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Function to exit appropriately based on context __script_exit() { local exit_code="${1:-0}" @@ -47,145 +41,181 @@ __script_exit() { exit "$exit_code" fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -SCRIPT_NAME="$(basename "$SCRIPT_FILE" 2>/dev/null)" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Exit if service is disabled +[ -z "$OPENGIST_APPNAME_ENABLED" ] || if [ "$OPENGIST_APPNAME_ENABLED" != "yes" ]; then export SERVICE_DISABLED="$SERVICE_NAME" && __script_exit 0; fi +# - - - - - - - - - - - - - - - - - - - - - - - - - +# setup debugging - https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html +[ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}" +{ [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; } && echo "Enabling debugging" && set -xo pipefail -x$DEBUGGER_OPTIONS && export DEBUGGER="on" || set -o pipefail +# - - - - - - - - - - - - - - - - - - - - - - - - - +export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# import the functions file +if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then + . "/usr/local/etc/docker/functions/entrypoint.sh" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - +# import variables +for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do + [ -f "$set_env" ] && . "$set_env" +done +# - - - - - - - - - - - - - - - - - - - - - - - - - # exit if __start_init_scripts function hasn't been Initialized if [ ! -f "/run/__start_init_scripts.pid" ]; then echo "__start_init_scripts function hasn't been Initialized" >&2 SERVICE_IS_RUNNING="no" __script_exit 1 fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# import the functions file -if [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ]; then - . "/usr/local/etc/docker/functions/entrypoint.sh" +# Clean up any stale PID file for this service on startup +if [ -n "$SERVICE_NAME" ] && [ -f "/run/init.d/$SERVICE_NAME.pid" ]; then + old_pid=$(cat "/run/init.d/$SERVICE_NAME.pid" 2>/dev/null) + if [ -n "$old_pid" ] && ! kill -0 "$old_pid" 2>/dev/null; then + echo "🧹 Removing stale PID file for $SERVICE_NAME" + rm -f "/run/init.d/$SERVICE_NAME.pid" + fi fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# import variables -for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do - [ -f "$set_env" ] && . "$set_env" -done -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Custom functions -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Script to execute START_SCRIPT="/usr/local/etc/docker/exec/$SERVICE_NAME" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Reset environment before executing service RESET_ENV="no" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Set the database root dir -DATABASE_BASE_DIR="${DATABASE_BASE_DIR:-/data/db}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# set the database directory -DATABASE_DIR="${DATABASE_DIR_OPENGIST:-$DATABASE_BASE_DIR/sqlite}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set webroot WWW_ROOT_DIR="/usr/local/share/httpd/default" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Default predefined variables DATA_DIR="/data/opengist" # set data directory CONF_DIR="/config/opengist" # set config directory -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # set the containers etc directory ETC_DIR="/etc/opengist" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # set the var dir VAR_DIR="" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - TMP_DIR="/tmp/opengist" # set the temp dir RUN_DIR="/run/opengist" # set scripts pid dir LOG_DIR="/data/logs/opengist" # set log directory -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set the working dir WORK_DIR="" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # port which service is listening on -SERVICE_PORT="80" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SERVICE_PORT="" +# - - - - - - - - - - - - - - - - - - - - - - - - - # User to use to launch service - IE: postgres RUNAS_USER="root" # normally root -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # User and group in which the service switches to - IE: nginx,apache,mysql,postgres SERVICE_USER="git" # execute command as another user SERVICE_GROUP="git" # Set the service group -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Set password length +RANDOM_PASS_USER="" +RANDOM_PASS_ROOT="" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set user and group ID -#SERVICE_UID="0" # set the user id -#SERVICE_GID="0" # set the group id -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SERVICE_UID="0" # set the user id +SERVICE_GID="0" # set the group id +# - - - - - - - - - - - - - - - - - - - - - - - - - # execute command variables - keep single quotes variables will be expanded later EXEC_CMD_BIN='opengist' # command to execute EXEC_CMD_ARGS='--config $ETC_DIR/config.yaml start' # command arguments EXEC_PRE_SCRIPT='' # execute script before -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SERVICE_USES_PID='' # Set to no if the service is not running otherwise leave blank +# - - - - - - - - - - - - - - - - - - - - - - - - - # Is this service a web server IS_WEB_SERVER="no" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Is this service a database server IS_DATABASE_SERVICE="no" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Does this service use a database server -USES_DATABASE_SERVICE="yes" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +USES_DATABASE_SERVICE="no" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Set defualt type - [custom,sqlite,redis,postgres,mariadb,mysql,couchdb,mongodb,supabase] +DATABASE_SERVICE_TYPE="sqlite" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Show message before execute PRE_EXEC_MESSAGE="" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Set the wait time to execute __post_execute function - minutes +POST_EXECUTE_WAIT_TIME="1" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Update path var PATH="$PATH:." -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Lets get containers ip address +IP4_ADDRESS="$(__get_ip4)" +IP6_ADDRESS="$(__get_ip6)" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Where to save passwords to ROOT_FILE_PREFIX="/config/secure/auth/root" # directory to save username/password for root user USER_FILE_PREFIX="/config/secure/auth/user" # directory to save username/password for normal user -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # root/admin user info password/random] root_user_name="${OPENGIST_ROOT_USER_NAME:-}" # root user name root_user_pass="${OPENGIST_ROOT_PASS_WORD:-}" # root user password -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Normal user info [password/random] user_name="${OPENGIST_USER_NAME:-}" # normal user name user_pass="${OPENGIST_USER_PASS_WORD:-}" # normal user password -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Load variables from config [ -f "/config/env/opengist.script.sh" ] && . "/config/env/opengist.script.sh" # Generated by my dockermgr script [ -f "/config/env/opengist.sh" ] && . "/config/env/opengist.sh" # Overwrite the variabes -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Additional predefined variables -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Additional variables -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Specifiy custom directories to be created ADD_APPLICATION_FILES="" ADD_APPLICATION_DIRS="" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - APPLICATION_FILES="$LOG_DIR/$SERVICE_NAME.log" -APPLICATION_DIRS="$RUN_DIR $ETC_DIR $CONF_DIR $LOG_DIR $TMP_DIR" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +APPLICATION_DIRS="$ETC_DIR $CONF_DIR $DATA_DIR $LOG_DIR $TMP_DIR $RUN_DIR $VAR_DIR" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Additional config dirs - will be Copied to /etc/$name ADDITIONAL_CONFIG_DIRS="" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # define variables that need to be loaded into the service - escape quotes - var=\"value\",other=\"test\" CMD_ENV="" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Overwrite based on file/directory -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Per Application Variables or imports -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Custom commands to run before copying to /config +__run_precopy() { + # Define environment + local hostname=${HOSTNAME} + [ -d "/run/healthcheck" ] || mkdir -p "/run/healthcheck" + # Define actions/commands + + # allow custom functions + if builtin type -t __run_precopy_local | grep -q 'function'; then __run_precopy_local; fi +} +# - - - - - - - - - - - - - - - - - - - - - - - - - # Custom prerun functions - IE setup WWW_ROOT_DIR __execute_prerun() { - # Setup /config directories - __init_config_etc - - # Define other actions/commands + # Define environment + local hostname=${HOSTNAME} + # Define actions/commands + # allow custom functions + if builtin type -t __execute_prerun_local | grep -q 'function'; then __execute_prerun_local; fi } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Run any pre-execution checks __run_pre_execute_checks() { # Set variables @@ -206,127 +236,120 @@ __run_pre_execute_checks() { [ -f "$SERVICE_PID_FILE" ] && rm -Rf "$SERVICE_PID_FILE" __script_exit 1 fi + # allow custom functions + if builtin type -t __run_pre_execute_checks_local | grep -q 'function'; then __run_pre_execute_checks_local; fi + # exit function return $exitStatus } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # use this function to update config files - IE: change port __update_conf_files() { local exitCode=0 # default exit code local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # CD into temp to bybass any permission errors - cd /tmp || false # lets keep shellcheck happy by adding false - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # - - - - - - - - - - - - - - - - - - - - - - - - - # delete files #__rm "" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # - - - - - - - - - - - - - - - - - - - - - - - - - # custom commands - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # - - - - - - - - - - - - - - - - - - - - - - - - - # replace variables # __replace "" "" "$CONF_DIR/opengist.conf" # replace variables recursively - # __find_replace "" "" "$CONF_DIR" + # __find_replace "" "" "$CONF_DIR" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # - - - - - - - - - - - - - - - - - - - - - - - - - # define actions + # allow custom functions + if builtin type -t __update_conf_files_local | grep -q 'function'; then __update_conf_files_local; fi # exit function return $exitCode } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # function to run before executing __pre_execute() { local exitCode=0 # default exit code local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname - - # define commands - # execute if directories is empty - __is_dir_empty "" && true - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set permissions - __fix_permissions "$SERVICE_USER" "$SERVICE_GROUP" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Copy /config to /etc - for config_2_etc in $CONF_DIR $ADDITIONAL_CONFIG_DIRS; do - __initialize_system_etc "$config_2_etc" 2>/dev/stderr | tee -p -a "$LOG_DIR/init.txt" - done - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Replace variables - HOSTNAME="$sysname" __initialize_replace_variables "$ETC_DIR" "$CONF_DIR" "$WWW_ROOT_DIR" - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # __is_dir_empty "$CONF_DIR" && true + # - - - - - - - - - - - - - - - - - - - - - - - - - + # define actions to run after copying to /config + + # - - - - - - - - - - - - - - - - - - - - - - - - - # unset unneeded variables - unset filesperms filename config_2_etc change_user change_user ADDITIONAL_CONFIG_DIRS application_files filedirs + unset sysname # Lets wait a few seconds before continuing - sleep 5 + sleep 2 + # allow custom functions + if builtin type -t __pre_execute_local | grep -q 'function'; then __pre_execute_local; fi + # exit function return $exitCode } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # function to run after executing __post_execute() { local pid="" # init pid var local retVal=0 # set default exit code - local waitTime=60 # how long to wait before executing + local ctime=${POST_EXECUTE_WAIT_TIME:-1} # how long to wait before executing + local waitTime=$((ctime * 60)) # convert minutes to seconds local postMessageST="Running post commands for $SERVICE_NAME" # message to show at start local postMessageEnd="Finished post commands for $SERVICE_NAME" # message to show at completion - local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname - # wait sleep $waitTime - # execute commands + # execute commands after waiting ( # show message __banner "$postMessageST" # commands to execute - true + sleep 5 # show exit message __banner "$postMessageEnd: Status $retVal" - ) 2>"/dev/stderr" | tee -p -a "$LOG_DIR/init.txt" & + ) 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" & pid=$! - # set exitCode ps ax | awk '{print $1}' | grep -v grep | grep -q "$execPid$" && retVal=0 || retVal=10 + # allow custom functions + if builtin type -t __post_execute_local | grep -q 'function'; then __post_execute_local; fi + # exit function return $retVal } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # use this function to update config files - IE: change port __pre_message() { local exitCode=0 - if [ -n "$user_name" ] || [ -n "$user_pass" ] || [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then - __banner "User info" - [ -n "$user_name" ] && __printf_space "40" "username:" "$user_name" && echo "$user_name" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_name" - [ -n "$user_pass" ] && __printf_space "40" "password:" "saved to ${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" && echo "$user_pass" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" - [ -n "$root_user_name" ] && __printf_space "40" "root username:" "$root_user_name" && echo "$root_user_name" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name" - [ -n "$root_user_pass" ] && __printf_space "40" "root password:" "saved to ${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" && echo "$root_user_pass" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" - __banner "" - fi [ -n "$PRE_EXEC_MESSAGE" ] && eval echo "$PRE_EXEC_MESSAGE" # execute commands - # set exitCode + # allow custom functions + if builtin type -t __pre_message_local | grep -q 'function'; then __pre_message_local; fi + # exit function return $exitCode } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # use this function to setup ssl support __update_ssl_conf() { local exitCode=0 local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname # execute commands + # allow custom functions + if builtin type -t __update_ssl_conf_local | grep -q 'function'; then __update_ssl_conf_local; fi # set exitCode return $exitCode } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - __create_service_env() { - cat </dev/null -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + local exitCode=0 + if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ]; then + cat </dev/null +# - - - - - - - - - - - - - - - - - - - - - - - - - # root/admin user info [password/random] #ENV_ROOT_USER_NAME="${ENV_ROOT_USER_NAME:-$OPENGIST_ROOT_USER_NAME}" # root user name #ENV_ROOT_USER_PASS="${ENV_ROOT_USER_NAME:-$OPENGIST_ROOT_PASS_WORD}" # root user password #root_user_name="${ENV_ROOT_USER_NAME:-$root_user_name}" # #root_user_pass="${ENV_ROOT_USER_PASS:-$root_user_pass}" # -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - #Normal user info [password/random] #ENV_USER_NAME="${ENV_USER_NAME:-$OPENGIST_USER_NAME}" # #ENV_USER_PASS="${ENV_USER_PASS:-$OPENGIST_USER_PASS_WORD}" # @@ -334,9 +357,31 @@ __create_service_env() { #user_pass="${ENV_USER_PASS:-$user_pass}" # normal user password EOF - __file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" || return 1 + fi + if [ ! -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" ]; then + # - - - - - - - - - - - - - - - - - - - - - - - - - + __run_precopy_local() { true; } + # - - - - - - - - - - - - - - - - - - - - - - - - - + __execute_prerun_local() { true; } + # - - - - - - - - - - - - - - - - - - - - - - - - - + __run_pre_execute_checks_local() { true; } + # - - - - - - - - - - - - - - - - - - - - - - - - - + __update_conf_files_local() { true; } + # - - - - - - - - - - - - - - - - - - - - - - - - - + __pre_execute_local() { true; } + # - - - - - - - - - - - - - - - - - - - - - - - - - + __post_execute_local() { true; } + # - - - - - - - - - - - - - - - - - - - - - - - - - + __pre_message_local() { true; } + # - - - - - - - - - - - - - - - - - - - - - - - - - + __update_ssl_conf_local() { true; } + # - - - - - - - - - - - - - - - - - - - - - - - - - + fi + __file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" || exitCode=$((exitCode + 1)) + __file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" || exitCode=$((exitCode + 1)) + return $exitCode } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # script to start server __run_start_script() { local runExitCode=0 @@ -353,10 +398,8 @@ __run_start_script() { local sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" # set hostname [ -f "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh" ] && . "$CONF_DIR/$SERVICE_NAME.exec_cmd.sh" # - __run_pre_execute_checks 2>/dev/stderr | tee -a -p "/data/logs/entrypoint.log" "$LOG_DIR/init.txt" || return 20 - # if [ -z "$cmd" ]; then - __post_execute 2>"/dev/stderr" | tee -p -a "$LOG_DIR/init.txt" + __post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" retVal=$? echo "Initializing $SCRIPT_NAME has completed" __script_exit $retVal @@ -368,10 +411,9 @@ __run_start_script() { fi # check and exit if already running if __proc_check "$name" || __proc_check "$cmd"; then - echo "$name is already running" >&2 return 0 else - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # - - - - - - - - - - - - - - - - - - - - - - - - - # show message if env exists if [ -n "$cmd" ]; then [ -n "$SERVICE_USER" ] && echo "Setting up $cmd to run as $SERVICE_USER" || SERVICE_USER="root" @@ -384,29 +426,32 @@ __run_start_script() { export cmd_exec="$cmd $args" message="Starting service: $name $args" fi - [ -n "$su_exec" ] && echo "using $su_exec" | tee -a -p "$LOG_DIR/init.txt" - echo "$message" | tee -a -p "$LOG_DIR/init.txt" + [ -n "$su_exec" ] && echo "using $su_exec" | tee -a -p "/data/logs/init.txt" + echo "$message" | tee -a -p "/data/logs/init.txt" su_cmd touch "$SERVICE_PID_FILE" - __post_execute 2>"/dev/stderr" | tee -p -a "$LOG_DIR/init.txt" & if [ "$RESET_ENV" = "yes" ]; then env_command="$(echo "env -i HOME=\"$home\" LC_CTYPE=\"$lc_type\" PATH=\"$path\" HOSTNAME=\"$sysname\" USER=\"${SERVICE_USER:-$RUNAS_USER}\" $extra_env")" execute_command="$(__trim "$su_exec $env_command $cmd_exec")" if [ ! -f "$START_SCRIPT" ]; then cat <"$START_SCRIPT" #!/usr/bin/env bash -trap 'exitCode=\$?;if [ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ]; then rm -Rf "\$SERVICE_PID_FILE"; fi; exit \$exitCode' EXIT +trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT # set -Eeo pipefail # Setting up $cmd to run as ${SERVICE_USER:-root} with env retVal=10 cmd="$cmd" +args="$args" +SERVICE_NAME="$SERVICE_NAME" SERVICE_PID_FILE="$SERVICE_PID_FILE" -$execute_command 2>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" & +LOG_DIR="$LOG_DIR" +execute_command="$execute_command" +\$execute_command 2>"/dev/stderr" >>"\$LOG_DIR/\$SERVICE_NAME.log" & execPid=\$! -sleep 10 +sleep 1 checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)" [ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10 -[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "\$cmd has failed to start - args: $args" >&2 +[ "\$retVal" = 0 ] && printf '%s\n' "\$SERVICE_NAME: \$execPid" >"/run/healthcheck/\$SERVICE_NAME" || echo "Failed to start $execute_command" >&2 exit \$retVal EOF @@ -416,19 +461,23 @@ EOF execute_command="$(__trim "$su_exec $cmd_exec")" cat <"$START_SCRIPT" #!/usr/bin/env bash -trap 'exitCode=\$?;if [ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ]; then rm -Rf "\$SERVICE_PID_FILE"; fi; exit \$exitCode' EXIT +trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f "\$SERVICE_PID_FILE" ] && rm -Rf "\$SERVICE_PID_FILE";exit \$exitCode' EXIT # set -Eeo pipefail # Setting up $cmd to run as ${SERVICE_USER:-root} retVal=10 cmd="$cmd" +args="$args" +SERVICE_NAME="$SERVICE_NAME" SERVICE_PID_FILE="$SERVICE_PID_FILE" -$execute_command 2>>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" & +LOG_DIR="$LOG_DIR" +execute_command="$execute_command" +\$execute_command 2>>"/dev/stderr" >>"\$LOG_DIR/\$SERVICE_NAME.log" & execPid=\$! -sleep 10 +sleep 1 checkPID="\$(ps ax | awk '{print \$1}' | grep -v grep | grep "\$execPid$" || false)" [ -n "\$execPid" ] && [ -n "\$checkPID" ] && echo "\$execPid" >"\$SERVICE_PID_FILE" && retVal=0 || retVal=10 -[ "\$retVal" = 0 ] && echo "\$cmd has been started" || echo "\$cmd has failed to start - args: $args" >&2 +[ "\$retVal" = 0 ] || echo "Failed to start $execute_command" >&2 exit \$retVal EOF @@ -438,19 +487,20 @@ EOF [ -x "$START_SCRIPT" ] || chmod 755 -Rf "$START_SCRIPT" [ "$CONTAINER_INIT" = "yes" ] || eval sh -c "$START_SCRIPT" runExitCode=$? - return $runExitCode fi + return $runExitCode } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # username and password actions __run_secure_function() { + local filesperms if [ -n "$user_name" ] || [ -n "$user_pass" ]; then for filesperms in "${USER_FILE_PREFIX}"/*; do if [ -e "$filesperms" ]; then chmod -Rf 600 "$filesperms" chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null fi - done 2>/dev/null | tee -p -a "$LOG_DIR/init.txt" + done 2>/dev/null | tee -p -a "/data/logs/init.txt" fi if [ -n "$root_user_name" ] || [ -n "$root_user_pass" ]; then for filesperms in "${ROOT_FILE_PREFIX}"/*; do @@ -458,120 +508,212 @@ __run_secure_function() { chmod -Rf 600 "$filesperms" chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null fi - done 2>/dev/null | tee -p -a "$LOG_DIR/init.txt" + done 2>/dev/null | tee -p -a "/data/logs/init.txt" fi + unset filesperms } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Allow ENV_ variable - Import env file __file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__file_exists_with_content "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.local.sh" +# - - - - - - - - - - - - - - - - - - - - - - - - - SERVICE_EXIT_CODE=0 # default exit code # application specific -EXEC_CMD_NAME="$(basename "$EXEC_CMD_BIN")" # set the binary name +EXEC_CMD_NAME="$(basename -- "$EXEC_CMD_BIN")" # set the binary name SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid" # set the pid file location -SERVICE_PID_NUMBER="$(__pgrep)" # check if running +SERVICE_PID_NUMBER="$(__pgrep "$EXEC_CMD_NAME" || echo '')" # check if running EXEC_CMD_BIN="$(type -P "$EXEC_CMD_BIN" || echo "$EXEC_CMD_BIN")" # set full path EXEC_PRE_SCRIPT="$(type -P "$EXEC_PRE_SCRIPT" || echo "$EXEC_PRE_SCRIPT")" # set full path -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Only run check -__check_service "$1" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__check_service "$1" && SERVICE_IS_RUNNING=yes || SERVICE_IS_RUNNING="no" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ensure needed directories exists +[ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR" +[ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR" +# - - - - - - - - - - - - - - - - - - - - - - - - - # create auth directories [ -n "$USER_FILE_PREFIX" ] && { [ -d "$USER_FILE_PREFIX" ] || mkdir -p "$USER_FILE_PREFIX"; } [ -n "$ROOT_FILE_PREFIX" ] && { [ -d "$ROOT_FILE_PREFIX" ] || mkdir -p "$ROOT_FILE_PREFIX"; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[ "$IS_WEB_SERVER" = "yes" ] && RESET_ENV="yes" +# - - - - - - - - - - - - - - - - - - - - - - - - - [ -n "$RUNAS_USER" ] || RUNAS_USER="root" -[ -n "$SERVICE_USER" ] || SERVICE_USER="${RUNAS_USER:-root}" -[ -n "$SERVICE_GROUP" ] || SERVICE_GROUP="${RUNAS_USER:-root}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +[ -n "$SERVICE_USER" ] || SERVICE_USER="$RUNAS_USER" +[ -n "$SERVICE_GROUP" ] || SERVICE_GROUP="${SERVICE_USER:-$RUNAS_USER}" +[ "$IS_WEB_SERVER" = "yes" ] && RESET_ENV="yes" && __is_htdocs_mounted +[ "$IS_WEB_SERVER" = "yes" ] && [ -z "$SERVICE_PORT" ] && SERVICE_PORT="80" +# - - - - - - - - - - - - - - - - - - - - - - - - - # Database env if [ "$IS_DATABASE_SERVICE" = "yes" ] || [ "$USES_DATABASE_SERVICE" = "yes" ]; then RESET_ENV="no" DATABASE_CREATE="${ENV_DATABASE_CREATE:-$DATABASE_CREATE}" - DATABASE_USER="${ENV_DATABASE_USER:-${DATABASE_USER:-$user_name}}" - DATABASE_PASSWORD="${ENV_DATABASE_PASSWORD:-${DATABASE_PASSWORD:-$user_pass}}" - DATABASE_ROOT_USER="${ENV_DATABASE_ROOT_USER:-${DATABASE_ROOT_USER:-$root_user_name}}" - DATABASE_ROOT_PASSWORD="${ENV_DATABASE_ROOT_PASSWORD:-${DATABASE_ROOT_PASSWORD:-$root_user_pass}}" + DATABASE_USER_NORMAL="${ENV_DATABASE_USER:-${DATABASE_USER_NORMAL:-$user_name}}" + DATABASE_PASS_NORMAL="${ENV_DATABASE_PASSWORD:-${DATABASE_PASS_NORMAL:-$user_pass}}" + DATABASE_USER_ROOT="${ENV_DATABASE_ROOT_USER:-${DATABASE_USER_ROOT:-$root_user_name}}" + DATABASE_PASS_ROOT="${ENV_DATABASE_ROOT_PASSWORD:-${DATABASE_PASS_ROOT:-$root_user_pass}}" + if [ -n "$DATABASE_PASS_NORMAL" ] && [ ! -f "${USER_FILE_PREFIX}/db_pass_user" ]; then + echo "$DATABASE_PASS_NORMAL" >"${USER_FILE_PREFIX}/db_pass_user" + fi + if [ -n "$DATABASE_PASS_ROOT" ] && [ ! -f "${ROOT_FILE_PREFIX}/db_pass_root" ]; then + echo "$DATABASE_PASS_ROOT" >"${ROOT_FILE_PREFIX}/db_pass_root" + fi fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Allow per init script usernames and passwords -__file_exists_with_content "$ETC_DIR/auth/user/name" && user_name="$(<"$ETC_DIR/auth/user/name")" -__file_exists_with_content "$ETC_DIR/auth/user/pass" && user_pass="$(<"$ETC_DIR/auth/user/pass")" -__file_exists_with_content "$ETC_DIR/auth/root/name" && root_user_name="$(<"$ETC_DIR/auth/root/name")" -__file_exists_with_content "$ETC_DIR/auth/root/pass" && root_user_pass="$(<"$ETC_DIR/auth/root/pass")" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# set password to random if variable is random -[ "$user_pass" = "random" ] && user_pass="$(__random_password)" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[ "$root_user_pass" = "random" ] && root_user_pass="$(__random_password)" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Allow setting initial users and passwords via environment -user_name="$(eval echo "${ENV_USER_NAME:-$user_name}")" -user_pass="$(eval echo "${ENV_USER_PASS:-$user_pass}")" -root_user_name="$(eval echo "${ENV_ROOT_USER_NAME:-$root_user_name}")" -root_user_pass="$(eval echo "${ENV_ROOT_USER_PASS:-$root_user_pass}")" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# [DATABASE_DIR_[SQLITE,REDIS,POSTGRES,MARIADB,COUCHDB,MONGODB,SUPABASE]] +if [ "$DATABASE_SERVICE_TYPE" = "custom" ]; then + DATABASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}" + DATABASE_BASE_DIR="${DATABASE_DIR_CUSTOM:-/data/db/custom}" + DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_CUSTOM:-/usr/local/share/httpd/admin/databases}" + [ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_CUSTOM:-/admin/dbadmin}" +elif [ "$SERVICE_NAME" = "redis" ] || [ "$DATABASE_SERVICE_TYPE" = "redis" ]; then + DATABASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}" + DATABASE_BASE_DIR="${DATABASE_DIR_REDIS:-/data/db/redis}" + DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_REDIS:-/usr/local/share/httpd/admin/redis}" + [ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_REDIS:-/admin/redis}" +elif [ "$SERVICE_NAME" = "postgres" ] || [ "$DATABASE_SERVICE_TYPE" = "postgres" ]; then + DATABASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}" + DATABASE_BASE_DIR="${DATABASE_DIR_POSTGRES:-/data/db/postgres}" + DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_POSTGRES:-/usr/local/share/httpd/admin/postgres}" + [ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_POSTGRES:-/admin/postgres}" +elif [ "$SERVICE_NAME" = "mariadb" ] || [ "$DATABASE_SERVICE_TYPE" = "mariadb" ]; then + DATABASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}" + DATABASE_BASE_DIR="${DATABASE_DIR_MARIADB:-/data/db/mariadb}" + DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MARIADB:-/usr/local/share/httpd/admin/mysql}" + [ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MARIADB:-/admin/mysql}" +elif [ "$SERVICE_NAME" = "mysql" ] || [ "$DATABASE_SERVICE_TYPE" = "mysql" ]; then + DATABASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}" + DATABASE_BASE_DIR="${DATABASE_DIR_MYSQL:-/data/db/mysql}" + DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MYSQL:-/usr/local/share/httpd/admin/mysql}" + [ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MYSQL:-/admin/mysql}" +elif [ "$SERVICE_NAME" = "couchdb" ] || [ "$DATABASE_SERVICE_TYPE" = "couchdb" ]; then + DATABASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}" + DATABASE_BASE_DIR="${DATABASE_DIR_COUCHDB:-/data/db/couchdb}" + DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_COUCHDB:-/usr/local/share/httpd/admin/couchdb}" + [ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_COUCHDB:-/admin/couchdb}" +elif [ "$SERVICE_NAME" = "mongodb" ] || [ "$DATABASE_SERVICE_TYPE" = "mongodb" ]; then + DATABASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}" + DATABASE_BASE_DIR="${DATABASE_DIR_MONGODB:-/data/db/mongodb}" + DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_MONGODB:-/usr/local/share/httpd/admin/mongodb}" + [ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_MONGODB:-/admin/mongodb}" +elif [ "$SERVICE_NAME" = "supabase" ] || [ "$DATABASE_SERVICE_TYPE" = "supabase" ]; then + DATABASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}" + DATABASE_BASE_DIR="${DATABASE_DIR_SUPABASE:-/data/db/supabase}" + DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SUPABASE:-/usr/local/share/httpd/admin/supabase}" + [ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SUPBASE:-/admin/supabase}" +elif [ "$SERVICE_NAME" = "sqlite" ] || [ "$DATABASE_SERVICE_TYPE" = "sqlite" ]; then + DATABASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME" + DATABASE_BASE_DIR="${DATABASE_DIR_SQLITE:-/data/db/sqlite}/$SERVER_NAME" + DATABASE_ADMIN_WWW_ROOT="${DATABASE_ADMIN_WWW_ROOT_SQLITE:-/usr/local/share/httpd/admin/sqlite}" + [ -d "$DATABASE_ADMIN_WWW_ROOT" ] && SERVER_ADMIN_URL="${SERVER_ADMIN_URL_SQLITE:-/admin/sqlite}" + [ -d "$DATABASE_DIR" ] || mkdir -p "$DATABASE_DIR" + chmod 777 "$DATABASE_DIR" +fi +[ -n "$DATABASE_ADMIN_WWW_ROOT" ] && { [ ! -d "$DATABASE_ADMIN_WWW_ROOT" ] || mkdir -p "${DATABASE_ADMIN_WWW_ROOT}"; } +# - - - - - - - - - - - - - - - - - - - - - - - - - # Allow variables via imports - Overwrite existing -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ -f "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" ] && . "/config/env/${SERVICE_NAME:-$SCRIPT_NAME}.sh" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# ensure needed directories exists +# - - - - - - - - - - - - - - - - - - - - - - - - - +# set password to random if variable is random +[ "$user_pass" = "random" ] && user_pass="$(__random_password ${RANDOM_PASS_USER:-16})" +# - - - - - - - - - - - - - - - - - - - - - - - - - +[ "$root_user_pass" = "random" ] && root_user_pass="$(__random_password ${RANDOM_PASS_ROOT:-16})" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Allow setting initial users and passwords via environment and save to file +[ -n "$user_name" ] && echo "$user_name" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_name" +[ -n "$user_pass" ] && echo "$user_pass" >"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" +[ -n "$root_user_name" ] && echo "$root_user_name" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name" +[ -n "$root_user_pass" ] && echo "$root_user_pass" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# create needed dirs [ -d "$LOG_DIR" ] || mkdir -p "$LOG_DIR" [ -d "$RUN_DIR" ] || mkdir -p "$RUN_DIR" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Allow per init script usernames and passwords +__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_name" && user_name="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_name")" +__file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_pass" && user_pass="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_pass")" +__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name" && root_user_name="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_name")" +__file_exists_with_content "${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" && root_user_pass="$(<"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass")" +__file_exists_with_content "${USER_FILE_PREFIX}/db_pass_user" && DATABASE_PASS_NORMAL="$(<"${USER_FILE_PREFIX}/db_pass_user")" +__file_exists_with_content "${ROOT_FILE_PREFIX}/db_pass_root" && DATABASE_PASS_ROOT="$(<"${ROOT_FILE_PREFIX}/db_pass_root")" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# set hostname for script +sysname="${SERVER_NAME:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" +# - - - - - - - - - - - - - - - - - - - - - - - - - +__create_service_env +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup /config directories +__init_config_etc +# - - - - - - - - - - - - - - - - - - - - - - - - - # pre-run function __execute_prerun -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # create user if needed __create_service_user "$SERVICE_USER" "$SERVICE_GROUP" "${WORK_DIR:-/home/$SERVICE_USER}" "${SERVICE_UID:-}" "${SERVICE_GID:-}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Modify user if needed __set_user_group_id $SERVICE_USER ${SERVICE_UID:-} ${SERVICE_GID:-} -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Create base directories __setup_directories -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # set switch user command __switch_to_user -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Initialize the home/working dir __init_working_dir -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # show init message __pre_message -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # __initialize_db_users -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Initialize ssl __update_ssl_conf __update_ssl_certs -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Updating config files -__create_service_env -__update_conf_files -__initialize_database -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Set permissions in ${USER_FILE_PREFIX} and ${ROOT_FILE_PREFIX} __run_secure_function -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +__run_precopy +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Copy /config to /etc +for config_2_etc in $CONF_DIR $ADDITIONAL_CONFIG_DIRS; do + __initialize_system_etc "$config_2_etc" 2>/dev/stderr | tee -p -a "/data/logs/init.txt" +done +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Replace variables +__initialize_replace_variables "$ETC_DIR" "$CONF_DIR" "$ADDITIONAL_CONFIG_DIRS" "$WWW_ROOT_DIR" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# +__initialize_database +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Updating config files +__update_conf_files +# - - - - - - - - - - - - - - - - - - - - - - - - - # run the pre execute commands __pre_execute -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__run_start_script 2>>/dev/stderr | tee -p -a "/data/logs/entrypoint.log" && errorCode=0 || errorCode=10 +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Set permissions +__fix_permissions "$SERVICE_USER" "$SERVICE_GROUP" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# +__run_pre_execute_checks 2>/dev/stderr | tee -a -p "/data/logs/entrypoint.log" "/data/logs/init.txt" || return 20 +# - - - - - - - - - - - - - - - - - - - - - - - - - +__run_start_script 2>>/dev/stderr | tee -p -a "/data/logs/entrypoint.log" +errorCode=$? if [ -n "$EXEC_CMD_BIN" ]; then - if [ "$errorCode" -ne 0 ]; then - echo "Failed to execute: ${cmd_exec:-$EXEC_CMD_BIN $EXEC_CMD_ARGS}" | tee -p -a "/data/logs/entrypoint.log" "$LOG_DIR/init.txt" - rm -Rf "$SERVICE_PID_FILE" - SERVICE_EXIT_CODE=10 - SERVICE_IS_RUNNING="no" - else + if [ "$errorCode" -eq 0 ]; then SERVICE_EXIT_CODE=0 - SERVICE_IS_RUNNING="no" + SERVICE_IS_RUNNING="yes" + else + SERVICE_EXIT_CODE=$errorCode + SERVICE_IS_RUNNING="${SERVICE_IS_RUNNING:-no}" + [ -s "$SERVICE_PID_FILE" ] || rm -Rf "$SERVICE_PID_FILE" fi SERVICE_EXIT_CODE=0 fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__banner "Initializing of $SERVICE_NAME has completed with statusCode: $SERVICE_EXIT_CODE" | tee -p -a "/data/logs/entrypoint.log" "$LOG_DIR/init.txt" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - +# start the post execute function in background +__post_execute 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" & +# - - - - - - - - - - - - - - - - - - - - - - - - - __script_exit $SERVICE_EXIT_CODE diff --git a/rootfs/usr/local/share/template-files/config/env/default.sample b/rootfs/usr/local/share/template-files/config/env/default.sample index c4271ed..2d4a7ef 100644 --- a/rootfs/usr/local/share/template-files/config/env/default.sample +++ b/rootfs/usr/local/share/template-files/config/env/default.sample @@ -1,17 +1,17 @@ #!/usr/bin/env bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -o pipefail -x$DEBUGGER_OPTIONS || set -o pipefail -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # import the functions file [ -f "/usr/local/etc/docker/functions/entrypoint.sh" ] && . "/usr/local/etc/docker/functions/entrypoint.sh" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # GLOBAL enviroment variables #USER="${USER:-root}" #LANG="${LANG:-C.UTF-8}" #TZ="${TZ:-America/New_York}" #SERVICE_USER="${SERVICE_USER:-root}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # directory settings #BACKUP_DIR="${BACKUP_DIR:-/data/backups}" #WWW_ROOT_DIR="${WWW_ROOT_DIR:-/usr/local/share/httpd/default}" @@ -20,39 +20,40 @@ #DEFAULT_DATA_DIR="${DEFAULT_DATA_DIR:-/usr/local/share/template-files/data}" #DEFAULT_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config}" #DEFAULT_TEMPLATE_DIR="${DEFAULT_TEMPLATE_DIR:-/usr/local/share/template-files/defaults}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#DBTYPE="sqlite" +# - - - - - - - - - - - - - - - - - - - - - - - - - # healthcheck #HEALTH_ENABLED="${HEALTH_ENABLED:-$ENV_HEALTH_ENABLED}" #HEALTH_URL="${HEALTH_URL:-}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # php settings #PHP_VERSION="${PHP_VERSION//php/}" #PHP_INI_DIR="${PHP_INI_DIR:-$(__find_php_ini)}" #PHP_BIN_DIR="${PHP_BIN_DIR:-$(__find_php_bin)}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # services/ports #ENV_PORTS="${ENV_PORTS:-}" #SERVICE_PORT="${SERVICE_PORT:-$PORT}" #WEB_SERVER_PORTS="${WEB_SERVER_PORTS:-$ENV_WEB_SERVER_PORTS}" #SERVICES_LIST="${PROCS_LIST:-$SERVICES_LIST} " -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # networing info DOMAINNAME="${DOMAINNAME:-}" HOSTNAME="${HOSTNAME:-casjaysdev-GEN_SCRIPT_REPLACE_APPNAME}" FULL_DOMAIN_NAME="${FULL_DOMAIN_NAME:-${DOMAINNAME:-$HOSTNAME}}" SERVER_ADMIN="${SERVER_ADMIN:-root@${EMAIL_DOMAIN:-${DOMAINNAME:-$FULL_DOMAIN_NAME}}}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - EMAIL_RELAY="${EMAIL_RELAY:-}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # get ip addresses CONTAINER_IP4_ADDRESS="${CONTAINER_IP4_ADDRESS:-$(__get_ip4)}" CONTAINER_IP6_ADDRESS="${CONTAINER_IP6_ADDRESS:-$(__get_ip6)}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # cerbot #CERT_BOT_MAIL="${CERT_BOT_MAIL:-}" #CERTBOT_DOMAINS="${CERTBOT_DOMAINS:-}" #CERT_BOT_ENABLED="${CERT_BOT_ENABLED:-false}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # ssl server settings #SSL_ENABLED="${SSL_ENABLED:-false}" #SSL_DIR="${SSL_DIR:-/config/ssl}" @@ -68,22 +69,22 @@ CONTAINER_IP6_ADDRESS="${CONTAINER_IP6_ADDRESS:-$(__get_ip6)}" #DAYS_VALID="${DAYS_VALID:-3650}" #RSA="${RSA:-4096}" #CN="${CN:-$FULL_DOMAIN_NAME}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # web server configs HTTPD_CONFIG_FILE="${HTTPD_CONFIG_FILE:-$(__find_httpd_conf)}" NGINX_CONFIG_FILE="${NGINX_CONFIG_FILE:-$(__find_nginx_conf)}" LIGHTTPD_CONFIG_FILE="${LIGHTTPD_CONFIG_FILE:-$(__find_lighttpd_conf)}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # redis env DATABASE_DIR_REDIS="${DATABASE_DIR_REDIS:-$DATABASE_BASE_DIR/redis}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # postgresql env DATABASE_DIR_PGSQL="${DATABASE_DIR_PGSQL:-$PGDATA}" PGDATA="${DATABASE_DIR_PGSQL:-$DATABASE_BASE_DIR/postgres}" POSTGRES_USER="${DATABASE_USER_ROOT:-$POSTGRES_USER}" POSTGRES_PASSWORD="${DATABASE_PASS_ROOT:-$POSTGRES_PASSWORD}" POSTGRES_CONFIG_FILE="${POSTGRES_CONFIG_FILE:-$(__find_pgsql_conf)}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # mariadb env MARIADB_ROOT_HOST="${MARIADB_ROOT_HOST:-%}" MARIADB_AUTO_UPGRADE="${MARIADB_AUTO_UPGRADE:-yes}" @@ -96,30 +97,30 @@ MARIADB_ALLOW_EMPTY_ROOT_PASSWORD="${MARIADB_ALLOW_EMPTY_ROOT_PASSWORD:-}" MARIADB_INITDB_SKIP_TZINFO="${MARIADB_INITDB_SKIP_TZINFO}:-" MARIADB_RANDOM_ROOT_PASSWORD="${MARIADB_RANDOM_ROOT_PASSWORD:-}" MARIADB_CONFIG_FILE="${MARIADB_CONFIG_FILE:-$(__find_mysql_conf)}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # mongodb env INITDB_ROOT_USERNAME="${DATABASE_USER_ROOT:-$INITDB_ROOT_USERNAME}" DATABASE_DIR_MONGODB="${DATABASE_DIR_MONGODB:-$DATABASE_BASE_DIR/mongodb}" MONGO_INITDB_ROOT_PASSWORD="${DATABASE_PASS_ROOT:-$MONGO_INITDB_ROOT_PASSWORD}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # couchdb env NODENAME="${NODENAME:-}" COUCHDB_USER="${DATABASE_USER_ROOT:-$COUCHDB_USER}" COUCHDB_PASSWORD="${DATABASE_PASS_ROOT:-$COUCHDB_PASSWORD}" DATABASE_DIR_COUCHDB="${DATABASE_DIR_COUCHDB:-$DATABASE_BASE_DIR/couchdb}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Supabase DATABASE_DIR_SUPABASE="${DATABASE_DIR_SUPABASE:-$DATABASE_BASE_DIR/supabase}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # docker env DOCKER_HOST="unix://var/run/docker.sock" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # File locations ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-/run/init.d/entrypoint.pid}" ENTRYPOINT_INIT_FILE="${ENTRYPOINT_INIT_FILE:-/config/.entrypoint.done}" ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has_run}" ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Startup variables INIT_DATE="${INIT_DATE:-$(date)}" START_SERVICES="${START_SERVICES:-yes}" @@ -127,8 +128,8 @@ ENTRYPOINT_MESSAGE="${ENTRYPOINT_MESSAGE:-yes}" ENTRYPOINT_FIRST_RUN="${ENTRYPOINT_FIRST_RUN:-yes}" DATA_DIR_INITIALIZED="${DATA_DIR_INITIALIZED:-false}" CONFIG_DIR_INITIALIZED="${CONFIG_DIR_INITIALIZED:-false}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - if [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; then START_SERVICES="no" ENTRYPOINT_MESSAGE="no" ENTRYPOINT_FIRST_RUN="no" fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/00-directory.sh b/rootfs/usr/local/share/template-files/config/env/examples/00-directory.sh index b41c7b7..8253a15 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/00-directory.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/00-directory.sh @@ -1,4 +1,4 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # directory settings WWW_ROOT_DIR="${ENV_WWW_ROOT_DIR:-${WWW_ROOT_DIR}}" BACKUP_DIR="${ENV_BACKUP_DIR:-${BACKUP_DIR:-/data/backups}}" @@ -7,4 +7,4 @@ DATABASE_BASE_DIR="${ENV_DATABASE_BASE_DIR:-${DATABASE_BASE_DIR:-/data/db}}" DEFAULT_DATA_DIR="${ENV_DEFAULT_DATA_DIR:-${DEFAULT_DATA_DIR:-/usr/local/share/template-files/data}}" DEFAULT_CONF_DIR="${ENV_DEFAULT_CONF_DIR:-${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config}}" DEFAULT_TEMPLATE_DIR="${ENV_DEFAULT_TEMPLATE_DIR:-${EDEFAULT_TEMPLATE_DIR:-/usr/local/share/template-files/defaults}}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/addresses.sh b/rootfs/usr/local/share/template-files/config/env/examples/addresses.sh index 695428c..48a3941 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/addresses.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/addresses.sh @@ -1,5 +1,5 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # get ip addresses CONTAINER_IP4_ADDRESS="${CONTAINER_IP4_ADDRESS:-$(__get_ip4)}" CONTAINER_IP6_ADDRESS="${CONTAINER_IP6_ADDRESS:-$(__get_ip6)}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/certbot.sh b/rootfs/usr/local/share/template-files/config/env/examples/certbot.sh index 9f52b28..44bb230 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/certbot.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/certbot.sh @@ -1,6 +1,6 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # cerbot CERT_BOT_MAIL="${ENV_CERT_BOT_MAIL:-$CERT_BOT_MAIL}" CERTBOT_DOMAINS="${ENV_CERTBOT_DOMAINS:-$CERTBOT_DOMAINS}" CERT_BOT_ENABLED="${ENV_CERT_BOT_ENABLED:-${CERT_BOT_ENABLED:-false}}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/couchdb.sh b/rootfs/usr/local/share/template-files/config/env/examples/couchdb.sh index 4a7fb91..a9bee9d 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/couchdb.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/couchdb.sh @@ -1,7 +1,7 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # couchdb env COUCHDB_NODENAME="${ENV_COUCHDB_NODENAME:-${COUCHDB_NODENAME:-$NODENAME}}" COUCHDB_USER="${ENV_COUCHDB_USER:-${COUCHDB_USER:-$DATABASE_USER_ROOT}}" COUCHDB_PASSWORD="${ENV_COUCHDB_PASSWORD:-${COUCHDB_PASSWORD:-$DATABASE_PASS_ROOT}}" DATABASE_DIR_COUCHDB="${ENV_DATABASE_DIR_COUCHDB:-${DATABASE_DIR_COUCHDB:-/data/db/couchdb}}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/dockerd.sh b/rootfs/usr/local/share/template-files/config/env/examples/dockerd.sh index a93d690..a0c68a2 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/dockerd.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/dockerd.sh @@ -1,4 +1,4 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # docker env DOCKER_HOST="${DOCKER_HOST:-unix://var/run/docker.sock}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/global.sh b/rootfs/usr/local/share/template-files/config/env/examples/global.sh index fece9c8..9e9d446 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/global.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/global.sh @@ -1,13 +1,13 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # GLOBAL enviroment variables USER="${USER:-root}" LANG="${LANG:-C.UTF-8}" TZ="${TZ:-America/New_York}" ENV_PORTS="${ENV_PORTS//\/*/}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # How to set permissions SERVICE_USER="${SERVICE_USER:-}" SERVICE_GROUP="${SERVICE_GROUP:-}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - SERVICE_UID="${SERVICE_UID:-}" # set the user id SERVICE_GID="${SERVICE_GID:-}" # set the group id diff --git a/rootfs/usr/local/share/template-files/config/env/examples/healthcheck.sh b/rootfs/usr/local/share/template-files/config/env/examples/healthcheck.sh index 0dd7d39..11141b9 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/healthcheck.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/healthcheck.sh @@ -1,5 +1,5 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # healthcheck HEALTH_ENABLED="${HEALTH_ENABLED:-}" HEALTH_URL="${HEALTH_URL:-}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/mariadb.sh b/rootfs/usr/local/share/template-files/config/env/examples/mariadb.sh index 223fce3..34afe76 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/mariadb.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/mariadb.sh @@ -1,4 +1,4 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # mariadb env MARIADB_ROOT_HOST="${MARIADB_ROOT_HOST:-%}" MARIADB_AUTO_UPGRADE="${MARIADB_AUTO_UPGRADE:-yes}" @@ -11,4 +11,4 @@ MARIADB_ALLOW_EMPTY_ROOT_PASSWORD="${MARIADB_ALLOW_EMPTY_ROOT_PASSWORD:-}" MARIADB_INITDB_SKIP_TZINFO="${MARIADB_INITDB_SKIP_TZINFO}:-" MARIADB_RANDOM_ROOT_PASSWORD="${MARIADB_RANDOM_ROOT_PASSWORD:-}" MARIADB_CONFIG_FILE="${MARIADB_CONFIG_FILE:-$(__find_mysql_conf)}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/mongodb.sh b/rootfs/usr/local/share/template-files/config/env/examples/mongodb.sh index 8e014de..1f90f96 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/mongodb.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/mongodb.sh @@ -1,4 +1,4 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # mongodb env DATABASE_DIR_MONGODB="${DATABASE_DIR_MONGODB:-/data/db/mongodb}" INITDB_ROOT_USERNAME="${DATABASE_USER_ROOT:-$INITDB_ROOT_USERNAME}" @@ -17,4 +17,4 @@ ME_CONFIG_MONGODB_AUTH_PASSWORD_FILE="${ME_CONFIG_MONGODB_AUTH_PASSWORD_FILE:-}" ME_CONFIG_MONGODB_CA_FILE="${ME_CONFIG_MONGODB_CA_FILE:-}" VCAP_APP_HOST="${VCAP_APP_HOST:-0.0.0.0}" VCAP_APP_PORT="${VCAP_APP_PORT:-19054}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/networking.sh b/rootfs/usr/local/share/template-files/config/env/examples/networking.sh index 3af24bb..0f0d464 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/networking.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/networking.sh @@ -1,4 +1,4 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # networing info DOMAINNAME="${DOMAINNAME:-}" EMAIL_RELAY="${EMAIL_RELAY:-}" @@ -6,4 +6,4 @@ HOSTNAME="${HOSTNAME:-casjaysdev-GEN_SCRIPT_REPLACE_APPNAME}" EMAIL_DOMAIN="${EMAIL_DOMAIN:-${DOMAINNAME:-$HOSTNAME}}" FULL_DOMAIN_NAME="${FULL_DOMAIN_NAME:-${DOMAINNAME:-$HOSTNAME}}" SERVER_ADMIN="${SERVER_ADMIN:-root@${EMAIL_DOMAIN:-$FULL_DOMAIN_NAME}}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/other.sh b/rootfs/usr/local/share/template-files/config/env/examples/other.sh index 1a59689..d75cc03 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/other.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/other.sh @@ -1,4 +1,4 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # other -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/php.sh b/rootfs/usr/local/share/template-files/config/env/examples/php.sh index a005543..d9bbad1 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/php.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/php.sh @@ -1,6 +1,6 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # php settings PHP_VERSION="${PHP_VERSION//php/}" PHP_INI_DIR="${PHP_INI_DIR:-$(__find_php_ini)}" PHP_BIN_DIR="${PHP_BIN_DIR:-$(__find_php_bin)}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/postgres.sh b/rootfs/usr/local/share/template-files/config/env/examples/postgres.sh index 348b4bf..7fb8536 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/postgres.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/postgres.sh @@ -1,8 +1,8 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # postgresql env PGDATA="${DATABASE_DIR_PGSQL:-$PGDATA}" DATABASE_DIR_PGSQL="${DATABASE_DIR_PGSQL:-/data/db/postgres}" POSTGRES_USER="${DATABASE_USER_ROOT:-$POSTGRES_USER}" POSTGRES_PASSWORD="${DATABASE_PASS_ROOT:-$POSTGRES_PASSWORD}" POSTGRES_CONFIG_FILE="${POSTGRES_CONFIG_FILE:-$(__find_pgsql_conf)}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/redis.sh b/rootfs/usr/local/share/template-files/config/env/examples/redis.sh index 805a14d..623e0ba 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/redis.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/redis.sh @@ -1,4 +1,4 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # redis env DATABASE_DIR_REDIS="${DATABASE_DIR_REDIS:-/data/db/redis}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/services.sh b/rootfs/usr/local/share/template-files/config/env/examples/services.sh index e330031..c3a9333 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/services.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/services.sh @@ -1,7 +1,7 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # services/ports ENV_PORTS="${ENV_PORTS:-}" SERVICE_PORT="${SERVICE_PORT:-$PORT}" WEB_SERVER_PORTS="${WEB_SERVER_PORTS:-}" SERVICES_LIST="${PROCS_LIST:-$SERVICES_LIST} " -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/ssl.sh b/rootfs/usr/local/share/template-files/config/env/examples/ssl.sh index 78b1686..b1e8876 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/ssl.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/ssl.sh @@ -1,4 +1,4 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # ssl server settings SSL_ENABLED="${SSL_ENABLED:-false}" SSL_DIR="${SSL_CONTAINER_DIR:-/config/ssl}" @@ -6,7 +6,7 @@ SSL_DIR="${SSL_DIR:-$SSL_DIR}" SSL_CA="${SSL_CA:-$SSL_DIR/ca.crt}" SSL_KEY="${SSL_KEY:-$SSL_DIR/server.key}" SSL_CERT="${SSL_CERT:-$SSL_DIR/server.crt}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # certificate settings RSA="${RSA:-4096}" STATE="${STATE:-NY}" @@ -16,4 +16,4 @@ UNIT="${UNIT:-CasjaysDev}" ORG="${ORG:-"Casjays Developments"}" DAYS_VALID="${DAYS_VALID:-3650}" CN="${CN:-${FULL_DOMAIN_NAME:-$HOSTNAME}}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/supabase.sh b/rootfs/usr/local/share/template-files/config/env/examples/supabase.sh index f25a9ca..49bae3a 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/supabase.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/supabase.sh @@ -1,4 +1,4 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Supabase DATABASE_DIR_SUPABASE="${DATABASE_DIR_SUPABASE:-/data/db/supabase}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/webservers.sh b/rootfs/usr/local/share/template-files/config/env/examples/webservers.sh index 15ba1af..554e47a 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/webservers.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/webservers.sh @@ -1,8 +1,8 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # web server configs HTTPD_CONFIG_FILE="${HTTPD_CONFIG_FILE:-$(__find_httpd_conf)}" NGINX_CONFIG_FILE="${NGINX_CONFIG_FILE:-$(__find_nginx_conf)}" CADDY_CONFIG_FILE="${CHEROKEE_CONFIG_FILE:-$(__find_caddy_conf)}" LIGHTTPD_CONFIG_FILE="${LIGHTTPD_CONFIG_FILE:-$(__find_lighttpd_conf)}" CHEROKEE_CONFIG_FILE="${CHEROKEE_CONFIG_FILE:-$(__find_cherokee_conf)}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/share/template-files/config/env/examples/zz-entrypoint.sh b/rootfs/usr/local/share/template-files/config/env/examples/zz-entrypoint.sh index cc9505b..8cc487b 100644 --- a/rootfs/usr/local/share/template-files/config/env/examples/zz-entrypoint.sh +++ b/rootfs/usr/local/share/template-files/config/env/examples/zz-entrypoint.sh @@ -1,10 +1,10 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # File locations ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-/run/init.d/entrypoint.pid}" ENTRYPOINT_INIT_FILE="${ENTRYPOINT_INIT_FILE:-/config/.entrypoint.done}" ENTRYPOINT_DATA_INIT_FILE="${ENTRYPOINT_DATA_INIT_FILE:-/data/.docker_has_run}" ENTRYPOINT_CONFIG_INIT_FILE="${ENTRYPOINT_CONFIG_INIT_FILE:-/config/.docker_has_run}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Startup variables INIT_DATE="${INIT_DATE:-$(date)}" START_SERVICES="${START_SERVICES:-yes}" @@ -12,10 +12,10 @@ ENTRYPOINT_MESSAGE="${ENTRYPOINT_MESSAGE:-yes}" ENTRYPOINT_FIRST_RUN="${ENTRYPOINT_FIRST_RUN:-yes}" DATA_DIR_INITIALIZED="${DATA_DIR_INITIALIZED:-false}" CONFIG_DIR_INITIALIZED="${CONFIG_DIR_INITIALIZED:-false}" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - - # Check if this is a new container [ -f "$ENTRYPOINT_PID_FILE" ] && START_SERVICES="no" [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && ENTRYPOINT_FIRST_RUN="no" [ -f "$ENTRYPOINT_DATA_INIT_FILE" ] && DATA_DIR_INITIALIZED="true" [ -f "$ENTRYPOINT_CONFIG_INIT_FILE" ] && CONFIG_DIR_INITIALIZED="true" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# - - - - - - - - - - - - - - - - - - - - - - - - -