diff --git a/.env.scripts b/.env.scripts index 97c730b..461f466 100644 --- a/.env.scripts +++ b/.env.scripts @@ -1,12 +1,27 @@ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408111050-git +##@Version : 202509200513-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT -# @@Copyright : Copyright 2024 CasjaysDev -# @@Created : Sat Oct 12 10:50:49 AM EDT 2024 +# @@Copyright : Copyright 2025 CasjaysDev +# @@Created : Sat Sep 20 05:13:59 AM EDT 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,SC2120,SC2155,SC2199,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" @@ -19,17 +34,27 @@ ENV_VENDOR="CasjaysDev" ENV_AUTHOR="CasjaysDev" ENV_MAINTAINER="CasjaysDev " # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# REPO info -ENV_GIT_REPO_URL="https://github.com/casjaysdev/alpine" -ENV_REGISTRY_URL="https://hub.docker.com/r/casjaysdev/alpine" +# Repository URLs (Full URLs) +# ENV_GIT_REPO_URL: Complete Git repository URL for source code +ENV_GIT_REPO_URL="https://github.com/casjaysdevdocker/alpine" +# ENV_REGISTRY_URL: Complete registry URL for reference (NOT used for pushing) +ENV_REGISTRY_URL="docker.io/casjaysdevdocker/alpine" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Push image info +# Push Configuration +# ENV_IMAGE_PUSH: Complete push destination (this IS used for pushing) ENV_IMAGE_PUSH="casjaysdev/alpine" +# 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="USE_DATE" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# 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="alpine" +# ENV_DISTRO_TAG: Tag for the pull source image ENV_DISTRO_TAG="${IMAGE_VERSION}" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Env @@ -50,3 +75,5 @@ DEFAULT_TEMPLATE_DIR="/usr/local/share/template-files/defaults" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ENV_PACKAGES="bash-completion git curl wget sudo unzip iproute2 ssmtp openssl jq tzdata mailcap ncurses util-linux pciutils usbutils coreutils binutils findutils grep rsync zip tini py3-pip procps net-tools coreutils sed gawk grep attr findutils readline lsof less curl shadow certbot ca-certificates " # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.gitattributes b/.gitattributes index 39bbb67..b3786b0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ -# Template generated on Fri May 10 12:52:12 PM EDT 2024 from https://github.com/alexkaratarakis/gitattributes" +# Template generated on Tue Sep 16 08:42:38 PM EDT 2025 from https://github.com/alexkaratarakis/gitattributes" # Common settings that generally should always be used with your language specific settings # Auto detect text files and perform LF normalization * text=auto diff --git a/.gitea/workflows/docker.yaml b/.gitea/workflows/docker.yaml index 5a6a920..423fb2e 100644 --- a/.gitea/workflows/docker.yaml +++ b/.gitea/workflows/docker.yaml @@ -1,9 +1,9 @@ -name: alpine-latest +name: alpine on: push jobs: - alpine-latest: + release-alpine: runs-on: act_runner container: image: catthehacker/ubuntu:act-latest @@ -18,17 +18,14 @@ jobs: - name: Get Meta id: meta - env: - ORG: casjaysdev - TAG: ${{ vars.DOCKER_TAG }} - HUB: docker.io run: | echo DATE_TAG=$(date +'%y%m') >> $GITHUB_OUTPUT echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT - echo DOCKER_TAG=$([ -n "$TAG" ] && echo $TAG || echo "latest") >> $GITHUB_OUTPUT - echo DOCKER_HUB=$([ -n "$HUB" ] && echo $HUB || echo "docker.io") >> $GITHUB_OUTPUT - echo DOCKER_ORG=$([ -n "$ORG" ] && echo "$ORG" || echo "casjaysdev") >> $GITHUB_OUTPUT + echo DOCKER_ORG=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $1}') >> $GITHUB_OUTPUT + echo DOCKER_TAG=$([ -n "$DOCKER_TAG" ] && echo ${DOCKER_TAG} || echo "latest") >> $GITHUB_OUTPUT + echo DOCKER_HUB=$([ -n "$DOCKER_HUB" ] && echo ${DOCKER_HUB} || echo "docker.io") >> $GITHUB_OUTPUT echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | sed 's|^docker-||g') >> $GITHUB_OUTPUT + echo "$DOCKER_HUB/$DOCKER_ORG/$REPO_NAME:$DOCKER_TAG" - name: Set up Docker BuildX uses: docker/setup-buildx-action@v2 diff --git a/.gitignore b/.gitignore index deb1d0b..3ed1f2e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -# gitignore created on 08/09/24 at 14:37 +# gitignore created on 09/20/25 at 05:14 # Disable reminder in prompt ignoredirmessage @@ -96,3 +96,8 @@ $RECYCLE.BIN/ # ignore .installed files **/.installed +# ignore work in progress files +**/*.rewrite.sh +**/*.refactor.sh + + diff --git a/rootfs/root/docker/setup/00-init.sh b/rootfs/root/docker/setup/00-init.sh index f77ef00..b394d7c 100755 --- a/rootfs/root/docker/setup/00-init.sh +++ b/rootfs/root/docker/setup/00-init.sh @@ -1,22 +1,23 @@ #!/usr/bin/env bash +# shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091437-git +##@Version : 202509200513-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 Sep 20 05:13:59 AM EDT 2025 # @@File : 00-init.sh # @@Description : script to run init +# @@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 shell=bash -# 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,SC2120,SC2155,SC2199,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail @@ -25,11 +26,19 @@ set -o pipefail # 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 13a4ff4..f2b348b 100755 --- a/rootfs/root/docker/setup/01-system.sh +++ b/rootfs/root/docker/setup/01-system.sh @@ -1,22 +1,23 @@ #!/usr/bin/env bash +# shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091437-git +##@Version : 202509200513-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 Sep 20 05:13:59 AM EDT 2025 # @@File : 01-system.sh # @@Description : script to run system +# @@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 shell=bash -# 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,SC2120,SC2155,SC2199,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail @@ -25,11 +26,17 @@ set -o pipefail # 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 3296e37..e1ab96d 100755 --- a/rootfs/root/docker/setup/02-packages.sh +++ b/rootfs/root/docker/setup/02-packages.sh @@ -1,22 +1,23 @@ #!/usr/bin/env bash +# shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091437-git +##@Version : 202509200513-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 Sep 20 05:13:59 AM EDT 2025 # @@File : 02-packages.sh # @@Description : script to run packages +# @@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 shell=bash -# 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,SC2120,SC2155,SC2199,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail @@ -25,11 +26,17 @@ set -o pipefail # 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 ba2de3f..f4e9eab 100755 --- a/rootfs/root/docker/setup/03-files.sh +++ b/rootfs/root/docker/setup/03-files.sh @@ -1,22 +1,23 @@ #!/usr/bin/env bash +# shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091437-git +##@Version : 202509200514-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 Sep 20 05:14:00 AM EDT 2025 # @@File : 03-files.sh # @@Description : script to run files +# @@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 shell=bash -# 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,SC2120,SC2155,SC2199,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail @@ -25,11 +26,68 @@ set -o pipefail # 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 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # 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 b620361..0ecf5fd 100755 --- a/rootfs/root/docker/setup/04-users.sh +++ b/rootfs/root/docker/setup/04-users.sh @@ -1,22 +1,23 @@ #!/usr/bin/env bash +# shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091437-git +##@Version : 202509200514-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 Sep 20 05:14:00 AM EDT 2025 # @@File : 04-users.sh # @@Description : script to run users +# @@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 shell=bash -# 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,SC2120,SC2155,SC2199,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail @@ -25,11 +26,17 @@ set -o pipefail # 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 246b937..3b3bd9e 100755 --- a/rootfs/root/docker/setup/05-custom.sh +++ b/rootfs/root/docker/setup/05-custom.sh @@ -1,22 +1,23 @@ #!/usr/bin/env bash +# shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091437-git +##@Version : 202509200514-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 Sep 20 05:14:00 AM EDT 2025 # @@File : 05-custom.sh # @@Description : script to run custom +# @@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 shell=bash -# 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,SC2120,SC2155,SC2199,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail @@ -25,11 +26,17 @@ set -o pipefail # 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/06-post.sh b/rootfs/root/docker/setup/06-post.sh index bfd27d2..4bf039f 100755 --- a/rootfs/root/docker/setup/06-post.sh +++ b/rootfs/root/docker/setup/06-post.sh @@ -1,22 +1,23 @@ #!/usr/bin/env bash +# shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091437-git +##@Version : 202509200514-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 Sep 20 05:14:00 AM EDT 2025 # @@File : 06-post.sh # @@Description : script to run post +# @@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 shell=bash -# 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,SC2120,SC2155,SC2199,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail @@ -25,11 +26,17 @@ set -o pipefail # 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 31718d0..55aa701 100755 --- a/rootfs/root/docker/setup/07-cleanup.sh +++ b/rootfs/root/docker/setup/07-cleanup.sh @@ -1,22 +1,23 @@ #!/usr/bin/env bash +# shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091437-git +##@Version : 202509200514-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 Sep 20 05:14:00 AM EDT 2025 # @@File : 07-cleanup.sh # @@Description : script to run cleanup +# @@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 shell=bash -# 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,SC2120,SC2155,SC2199,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options set -o pipefail @@ -25,11 +26,18 @@ set -o pipefail # 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/copy b/rootfs/usr/local/bin/copy deleted file mode 100755 index 8227966..0000000 --- a/rootfs/usr/local/bin/copy +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env bash -# shellcheck shell=bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408102055-git -# @@Author : Jason Hempstead -# @@Contact : jason@casjaysdev.pro -# @@License : LICENSE.md -# @@ReadME : copy --help -# @@Copyright : Copyright: (c) 2024 Jason Hempstead, Casjays Developments -# @@Created : Saturday, Aug 10, 2024 20:55 EDT -# @@File : copy -# @@Description : copies a file and shows progress -# @@Changelog : New script -# @@TODO : Better documentation -# @@Other : -# @@Resource : -# @@Terminal App : no -# @@sudo/root : no -# @@Template : shell/bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# script variables -APPNAME="$(basename "$0" 2>/dev/null)" -VERSION="202408102055-git" -RUN_USER="$USER" -SET_UID="$(id -u)" -SCRIPT_SRC_DIR="${BASH_SOURCE%/*}" -COPY_CWD="$(realpath "$PWD")" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# script functions -if [ "$SHOW_RAW" != "true" ]; then - __printf_color() { printf "%b" "$(tput setaf "${2:-$DEFAULT_COLOR}" 2>/dev/null)" "$1\n" "$(tput sgr0 2>/dev/null)"; } -else - # Disable colorization - __printf_color() { printf '%b\n' "$1" | tr -d '\t' | sed '/^%b$/d;s,\x1B\[ 0-9;]*[a-zA-Z],,g'; } -fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# check for command -__cmd_exists() { which $1 >/dev/null 2>&1 || return 1; } -__function_exists() { builtin type $1 >/dev/null 2>&1 || return 1; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# custom functions - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Define Variables -DEFAULT_COLOR="7" -COPY_EXIT_STATUS=0 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Main application -{ [ $# -eq 2 ] || [ "$1" = "--help" ]; } || { __printf_color "Usage: $APPNAME fromFile toFile" && exit 1; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -is_link="$(ls -la "$2" 2>/dev/null | awk '{print $NF}')" -if [ "$1" != "$is_link" ]; then - if [ -d "$1" ]; then - mkdir -p "$2" - cp -Rf "$1/." "$2/" - COPY_EXIT_STATUS=$? - elif [ -e "$1" ]; then - cp -Rf "$1" "$2" - COPY_EXIT_STATUS=$? - else - COPY_EXIT_STATUS=2 - fi -fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# End application -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# lets exit with code -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -exit $COPY_EXIT_STATUS -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# 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 7f11aa5..4e8a1d9 100755 --- a/rootfs/usr/local/bin/entrypoint.sh +++ b/rootfs/usr/local/bin/entrypoint.sh @@ -1,29 +1,27 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408091437-git +##@Version : 202509200513-git # @@Author : Jason Hempstead # @@Contact : jason@casjaysdev.pro # @@License : LICENSE.md # @@ReadME : entrypoint.sh --help -# @@Copyright : Copyright: (c) 2024 Jason Hempstead, Casjays Developments -# @@Created : Friday, Aug 09, 2024 14:37 EDT +# @@Copyright : Copyright: (c) 2025 Jason Hempstead, Casjays Developments +# @@Created : Saturday, Sep 20, 2025 05:13 EDT # @@File : entrypoint.sh # @@Description : Entrypoint file for alpine # @@Changelog : New script # @@TODO : Better documentation -# @@Other : -# @@Resource : +# @@Other : +# @@Resource : # @@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,SC2120,SC2155,SC2199,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:-}" @@ -34,7 +32,7 @@ PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin" # Set bash options SCRIPT_FILE="$0" CONTAINER_NAME="alpine" -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 @@ -53,13 +51,16 @@ fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case "$1" in # Help message ---help) +-h | --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 "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 @@ -69,27 +70,28 @@ __create_env_file "/config/env/default.sh" "/root/env.sh" &>/dev/null for set_env in "/root/env.sh" "/usr/local/etc/docker/env"/*.sh "/config/env"/*.sh; do [ -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="root" # execute command as another user -SERVICE_GROUP="root" # 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 +SERVICE_UID="${SERVICE_UID:-0}" # set the user id +SERVICE_GID="${SERVICE_GID:-0}" # set the group id # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Primary server port- will be added to server ports -WEB_SERVER_PORT="" # port : 80,443 +# User and group in which the service switches to - IE: nginx,apache,mysql,postgres +SERVICE_USER="${SERVICE_USER:-alpine}" # execute command as another user +SERVICE_GROUP="${SERVICE_GROUP:-alpine}" # 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] @@ -97,7 +99,7 @@ SERVICES_LIST="tini" # comma seperated 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 @@ -109,11 +111,15 @@ __run_message() { } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ################## 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}" @@ -124,19 +130,24 @@ export CONTAINER_NAME="${ENV_CONTAINER_NAME:-$CONTAINER_NAME}" 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)}" @@ -150,14 +161,21 @@ 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 @@ -185,7 +203,7 @@ 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 @@ -233,6 +251,10 @@ EOF # Create the backup dir [ -n "$BACKUP_DIR" ] && { [ -d "$BACKUP_DIR" ] || mkdir -p "$BACKUP_DIR"; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +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 @@ -240,9 +262,9 @@ if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then 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" + { { [ -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" @@ -259,23 +281,20 @@ if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then fi fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # add .home domain + # 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%%.*}.home" "/etc/hosts" || __printf_space "40" "${CONTAINER_IP4_ADDRESS:-127.0.0.1}" "${HOSTNAME%%.*}.home" >>"/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" != "home" ] && [ -n "$DOMAINNAME" ] && [ "$HOSTNAME.$DOMAINNAME" != "$DOMAINNAME" ]; then + 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" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # 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 @@ -287,8 +306,8 @@ if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then # 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/" + if [ -n "$HOME" ] && [ -d "/usr/local/etc/skel" ]; then + [ -d "$HOME" ] && cp -Rf "/usr/local/etc/skel/." "$HOME/" fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - fi @@ -312,26 +331,28 @@ __initialize_data_dir # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - __initialize_ssl_certs # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -if [ -f "$ENTRYPOINT_PID_FILE" ] || [ -f "$ENTRYPOINT_INIT_FILE" ]; then - START_SERVICES="no" - ENTRYPOINT_MESSAGE="no" +if [ -f "$ENTRYPOINT_INIT_FILE" ]; then ENTRYPOINT_FIRST_RUN="no" - touch "$ENTRYPOINT_PID_FILE" -elif [ -d "/config" ]; then - echo "$$" >"$ENTRYPOINT_PID_FILE" +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 +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 +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +if [ -d "/config" ]; then echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_CONFIG_INIT_FILE" fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -340,8 +361,20 @@ if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then __setup_mta fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# if no pid assume container restart -[ -f "$ENTRYPOINT_PID_FILE" ] && [ -f "/run/__start_init_scripts.pid" ] || START_SERVICES="yes" +# 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" "Container ip address is:" "$CONTAINER_IP4_ADDRESS" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -369,11 +402,12 @@ __run_message START_SERVICES="${START_SERVICES:-SYSTEM_INIT}" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Start all services if no pidfile -if [ "$START_SERVICES" = "yes" ] && [ "$1" != "backup" ] && [ "$1" != "healthcheck" ]; then +if [ "$START_SERVICES" = "yes" ] && [ "$1" != "backup" ] && [ "$1" != "healthcheck" ] && [ "$1" != "cron" ] && [ "$1" != "tail" ] && [ "$1" != "logs" ] && [ "$1" != "cron" ]; then [ "$1" = "start" ] && shift 1 [ "$1" = "all" ] && shift 1 [ "$1" = "init" ] && export CONTAINER_INIT="yes" echo "$$" >"$ENTRYPOINT_PID_FILE" + rm -Rf "/run"/*/*pid __start_init_scripts "/usr/local/etc/docker/init.d" START_SERVICES="no" CONTAINER_INIT="${CONTAINER_INIT:-no}" @@ -386,36 +420,75 @@ init) 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 "$@" & + 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 + __backup $BACKUP_MAX_DAYS $1 + exit $? ;; # Docker healthcheck healthcheck) + arguments="$*" healthStatus=0 - services="${SERVICES_LIST:-$@}" 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" - services="${services//,/ }" [ "$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 '^$')" + { [ "$1" = "init" ] || [ "$1" = "test" ]; } && exit 0 for proc in $services; do if [ -n "$proc" ]; then if ! __pgrep "$proc"; then @@ -508,7 +581,6 @@ start) elif [ -f "/usr/local/etc/docker/init.d/$1" ]; then eval "/usr/local/etc/docker/init.d/$1" & __no_exit - fi fi ;; diff --git a/rootfs/usr/local/bin/pkmgr b/rootfs/usr/local/bin/pkmgr index b497592..205c2b0 100755 --- a/rootfs/usr/local/bin/pkmgr +++ b/rootfs/usr/local/bin/pkmgr @@ -5,13 +5,6 @@ USER_UID="$(id -u)" USER_GID="$(id -g)" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -while :; do - case "$@" in - --*) shift ;; - *) break ;; - esac -done -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if [ -x "$(command -v apt 2>/dev/null)" ]; then export DEBIAN_FRONTEND=noninteractive pkmgr_cmd="apt" @@ -114,7 +107,7 @@ install) else install_list="$*" fi - for pkg in $install_list; do + 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 diff --git a/rootfs/usr/local/bin/symlink b/rootfs/usr/local/bin/symlink deleted file mode 100755 index 8bfb03e..0000000 --- a/rootfs/usr/local/bin/symlink +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env bash -# shellcheck shell=bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202408102055-git -# @@Author : Jason Hempstead -# @@Contact : jason@casjaysdev.pro -# @@License : LICENSE.md -# @@ReadME : symlink --help -# @@Copyright : Copyright: (c) 2024 Jason Hempstead, Casjays Developments -# @@Created : Saturday, Aug 10, 2024 20:55 EDT -# @@File : symlink -# @@Description : -# @@Changelog : New script -# @@TODO : Better documentation -# @@Other : -# @@Resource : -# @@Terminal App : no -# @@sudo/root : no -# @@Template : shell/bash -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck disable=SC2016 -# shellcheck disable=SC2031 -# shellcheck disable=SC2120 -# shellcheck disable=SC2155 -# shellcheck disable=SC2199 -# shellcheck disable=SC2317 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# script variables -APPNAME="$(basename "$0" 2>/dev/null)" -VERSION="202408102055-git" -RUN_USER="$USER" -SET_UID="$(id -u)" -SCRIPT_SRC_DIR="${BASH_SOURCE%/*}" -SYMLINK_CWD="$(realpath "$PWD")" -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# script functions -if [ "$SHOW_RAW" != "true" ]; then - __printf_color() { printf "%b" "$(tput setaf "${2:-$DEFAULT_COLOR}" 2>/dev/null)" "$1\n" "$(tput sgr0 2>/dev/null)"; } -else - # Disable colorization - __printf_color() { printf '%b\n' "$1" | tr -d '\t' | sed '/^%b$/d;s,\x1B\[ 0-9;]*[a-zA-Z],,g'; } -fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# check for command -__cmd_exists() { which $1 >/dev/null 2>&1 || return 1; } -__function_exists() { builtin type $1 >/dev/null 2>&1 || return 1; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# custom functions - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Define Variables -DEFAULT_COLOR="7" -SYMLINK_EXIT_STATUS=0 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Main application -{ [ $# -eq 2 ] || [ "$1" = "--help" ]; } || { __printf_color "Usage: $APPNAME fromFile toFile" && exit 1; } -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -is_link="$(ls -la "$2" 2>/dev/null | awk '{print $NF}')" -if [ "$1" != "$is_link" ]; then - if [ -L "$2" ]; then - unlink "$2" - elif [ -e "$2" ]; then - rm -Rf "$2" - fi - if [ -e "$1" ]; then - ln -sf "$1" "$2" - SYMLINK_EXIT_STATUS=$? - fi -fi -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# End application -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# lets exit with code -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -exit $SYMLINK_EXIT_STATUS -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# ex: ts=2 sw=2 et filetype=sh diff --git a/rootfs/usr/local/etc/docker/functions/entrypoint.sh b/rootfs/usr/local/etc/docker/functions/entrypoint.sh index 64bb465..e1c08e1 100644 --- a/rootfs/usr/local/etc/docker/functions/entrypoint.sh +++ b/rootfs/usr/local/etc/docker/functions/entrypoint.sh @@ -18,7 +18,7 @@ # @@sudo/root : no # @@Template : functions/docker-entrypoint # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# shellcheck disable=SC1003,SC2016,SC2031,SC2120,SC2155,SC2199,SC2317 +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2120,SC2155,SC2199,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:-}" @@ -44,23 +44,41 @@ __netstat() { [ -f "$(type -P netstat)" ] && netstat "$@" || return 10; } __cd() { { [ -d "$1" ] || mkdir -p "$1"; } && builtin cd "$1" || return 1; } __is_in_file() { [ -e "$2" ] && grep -Rsq "$1" "$2" && return 0 || return 1; } __curl() { curl -q -sfI --max-time 3 -k -o /dev/null "$@" &>/dev/null || return 10; } -__find() { find "$1" -mindepth 1 -type ${2:-f,d} 2>/dev/null | grep '^' || return 10; } +__find() { find "$1" -mindepth 1 -type ${2:-f,d} 2>/dev/null | grep '.' || return 10; } __pcheck() { [ -n "$(which pgrep 2>/dev/null)" ] && pgrep -o "$1$" &>/dev/null || return 10; } __file_exists_with_content() { [ -n "$1" ] && [ -f "$1" ] && [ -s "$1" ] && return 0 || return 2; } __sed() { sed -i 's|'$1'|'$2'|g' "$3" &>/dev/null || sed -i "s|$1|$2|g" "$3" &>/dev/null || return 1; } -__pgrep() { __pcheck "${1:-SERVICE_NAME}" || __ps "${1:-$SERVICE_NAME}" | grep -qv ' grep' || return 10; } __ps() { [ -f "$(type -P ps)" ] && ps "$@" 2>/dev/null | sed 's|:||g' | grep -Fw " ${1:-$SERVICE_NAME}$" || return 10; } __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_file_relative() { 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() { find "$1"/* -not -path '*env/*' -not -path '.git*' -type d 2>/dev/null | sed 's|'$1'/||g' | sort -u | grep -v '^$' | grep '^' || false; } +__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'; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__pgrep() { + local count=3 + local srvc="${1:-SERVICE_NAME}" + while [ $count -ge 0 ]; do + __pcheck "${1:-SERVICE_NAME}" || __ps "${1:-$SERVICE_NAME}" | grep -qv ' grep' + sleep 1 + count=$((count - 1)) + done + [ $count -ne 0 ] && return 0 || 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() { ps -ax --no-header | sed 's/^[[:space:]]*//g' | awk -F' ' '{print $1}' | sed 's|:||g' | grep '[0-9]' | sort -uV | grep "^$1$" && return 0 || return 1; } __is_running() { ps -eo args --no-header | awk '{print $1,$2,$3}' | sed 's|:||g' | sort -u | grep -vE 'grep|COMMAND|awk|tee|ps|sed|sort|tail' | grep "$1" | grep -q "${2:-^}" && return 0 || return 1; } -__get_pid() { ps -ax --no-header | 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 '^' && return 0 || return 1; } +__get_pid() { ps -ax --no-header | 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 '.' && return 0 || return 1; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__format_variables() { printf '%s\n' "${@//,/ }" | tr ' ' '\n' | sort -RVu | grep -v '^$' | tr '\n' ' ' | __clean_variables | grep '^' || return 3; } +__format_variables() { printf '%s\n' "${@//,/ }" | tr ' ' '\n' | sort -RVu | grep -v '^$' | tr '\n' ' ' | __clean_variables | grep '.' || return 0; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - __clean_variables() { local var="$*" @@ -70,7 +88,45 @@ __clean_variables() { printf '%s' "$var" | grep -v '^$' } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__no_exit() { [ -f "/run/no_exit.pid" ] || exec bash -c "trap 'sleep 1;rm -Rf /run/*;/tmp/*;/data/logs/start.log;exit 0' TERM INT;(while true; do echo $$ >/run/no_exit.pid;tail -qf /data/logs/start.log 2>/dev/null||sleep 20; done) & wait"; } +__no_exit() { + local monitor_interval="${SERVICE_MONITOR_INTERVAL:-60}" + local failure_threshold="${SERVICE_FAILURE_THRESHOLD:-3}" + local monitor_services="${SERVICES_LIST:-tini}" + local failed_services="" + local failure_count=0 + + [ -f "/run/no_exit.pid" ] && return 0 + + exec bash -c " + trap 'echo \"Container shutdown requested\"; rm -f /run/no_exit.pid /run/*.pid; exit 0' TERM INT + echo \$\$ > /run/no_exit.pid + + while true; do + if [ -n \"$monitor_services\" ] && [ \"$monitor_services\" != \"tini\" ]; then + for service in \$(echo \"$monitor_services\" | tr ',' ' '); do + if [ \"\$service\" != \"tini\" ] && ! pgrep -x \"\$service\" >/dev/null 2>&1; then + echo \"⚠️ Service \$service is not running\" >&2 + failed_services=\"\$failed_services \$service\" + failure_count=\$((failure_count + 1)) + fi + done + + if [ \$failure_count -ge $failure_threshold ]; then + echo \"❌ Too many service failures (\$failure_count), exiting container\" >&2 + exit 1 + fi + + if [ -n \"\$failed_services\" ]; then + echo \"⚠️ Failed services:\$failed_services\" >&2 + failed_services=\"\" + fi + fi + + sleep $monitor_interval + done & + wait + " +} # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - __trim() { local var="${*//;/ }" @@ -80,18 +136,35 @@ __trim() { printf '%s' "$var" | sed 's|;||g' | grep -v '^$' } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__banner() { printf '# - - - %-60s - - - #\n' "$*"; } -__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 ''; } +__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}" + local service="${3:-service}" + local full_message="$message $service" + local total_width=80 + local content_width=$((total_width - 14)) # Account for "# - - - " and " - - - #" + local icon_width=2 # Most emojis are 2 chars wide + 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_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_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; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -112,8 +185,8 @@ __init_working_dir() { # create needed directories [ -n "$home" ] && { [ -d "$home" ] || mkdir -p "$home"; } [ -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" + [ "$SERVICE_USER" = "root" ] || [ -d "$home" ] && chmod -f 777 "$home" + [ "$SERVICE_USER" = "root" ] || [ -d "$workdir" ] && chmod -f 777 "$workdir" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # cd to dir __cd "${workdir:-$home}" @@ -128,7 +201,7 @@ __exec_service() { echo "Starting $1" eval "$@" 2>>/dev/stderr >>/data/logs/start.log & while [ $count -ne 0 ]; do - sleep 10 + sleep 3 __pgrep $1 && touch "/run/init.d/$1.pid" && break || count=$((count - 1)) done } @@ -155,7 +228,7 @@ __certbot() { local certbot_key_opts="--key-path $SSL_KEY --fullchain-path $SSL_CERT" mkdir -p "/config/letsencrypt" __symlink "/etc/letsencrypt" "/config/letsencrypt" - is_renewal="$(find /etc/letsencrypt/renewal -type -f 2>/dev/null || false)" + is_renewal="$(find /etc/letsencrypt/renewal -type f 2>/dev/null || false)" [ -f "/config/env/ssl.sh" ] && . "/config/env/ssl.sh" [ -f "/config/certbot/env.sh" ] && . "/config/certbot/env.sh" [ -n "$SSL_KEY" ] && { mkdir -p "$(dirname "$SSL_KEY")" || true; } || { echo "The variable $SSL_KEY is not set" >&2 && return 1; } @@ -165,7 +238,7 @@ __certbot() { [ "$CERT_BOT_ENABLED" = "true" ] || { export CERT_BOT_ENABLED="" && return 10; } [ -n "$CERT_BOT_MAIL" ] || { echo "The variable CERT_BOT_MAIL is not set" >&2 && return 1; } [ -n "$CERTBOT_DOMAINS" ] || { echo "The variable CERTBOT_DOMAINS is not set" >&2 && return 1; } - for domain in $$CERTBOT_DOMAINS; do + for domain in $CERTBOT_DOMAINS; do [ -n "$domain" ] && ADD_CERTBOT_DOMAINS+="-d $domain " done [ -n "$is_renewal" ] && options="renew" ADD_CERTBOT_DOMAINS="" || options="certonly" @@ -420,7 +493,7 @@ __file_copy() { } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - __generate_random_uids() { - local set_random_uid="$(seq 3000 5000 | sort -R | head -n 1)" + local set_random_uid="$(seq 100 999 | sort -R | head -n 1)" while :; do if grep -shq "x:.*:$set_random_uid:" "/etc/group" && ! grep -shq "x:$set_random_uid:.*:" "/etc/passwd"; then set_random_uid=$((set_random_uid + 1)) @@ -519,7 +592,7 @@ __set_user_group_id() { local random_id="$(__generate_random_uids)" set_uid="$(__get_uid "$set_user" || echo "$set_uid")" set_gid="$(__get_gid "$set_user" || echo "$set_gid")" - grep -shq "^$create_user:" "/etc/passwd" "/etc/group" || return 0 + grep -shq "^$set_user:" "/etc/passwd" "/etc/group" || return 0 [ -n "$set_user" ] && [ "$set_user" != "root" ] || return if grep -shq "^$set_user:" "/etc/passwd" "/etc/group"; then if __check_for_guid "$set_gid"; then @@ -550,8 +623,8 @@ __create_service_user() { create_uid="${create_uid:-1000}" create_gid="${create_gid:-1000}" fi - create_uid="$(__get_uid "$set_user" || echo "$create_uid")" - create_gid="$(__get_gid "$set_user" || echo "$create_gid")" + create_uid="$(__get_uid "$create_user" || echo "$create_uid")" + create_gid="$(__get_gid "$create_user" || echo "$create_gid")" [ -n "$create_uid" ] && [ "$create_uid" != "0" ] || create_uid="$random_id" [ -n "$create_gid" ] && [ "$create_gid" != "0" ] || create_gid="$random_id" while :; do @@ -570,7 +643,7 @@ __create_service_user() { 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 fi - grep -shq "$create_group" "/etc/group" || exitStatus=$((exitCode + 1)) + grep -shq "$create_group" "/etc/group" || exitStatus=$((exitStatus + 1)) grep -shq "$create_user" "/etc/passwd" || exitStatus=$((exitCode + 1)) if [ $exitStatus -eq 0 ]; then export WORK_DIR="${create_home_dir:-}" @@ -580,7 +653,7 @@ __create_service_user() { fi if [ -d "/etc/sudoers.d" ] && [ ! -f "/etc/sudoers.d/$create_user" ]; then echo "$create_user ALL=(ALL) NOPASSWD: ALL" >"/etc/sudoers.d/$create_user" - elif [ -f "/etc/sudoers" ] && grep -qs "$create_user" "/etc/sudoers"; then + 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" @@ -649,11 +722,19 @@ __start_init_scripts() { local init_pids="" local retstatus="0" local initStatus="0" + local critical_failures="0" 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}" + + # Clean stale PID files from previous runs + if [ ! -f "/run/__start_init_scripts.pid" ]; then + echo "🧹 Cleaning stale PID files from previous container run" + rm -f /run/*.pid /run/init.d/*.pid 2>/dev/null || true + fi + touch /run/__start_init_scripts.pid - mkdir -p "/tmp" "/run" "/run/init.d" "/usr/local/etc/docker/exec" - chmod -R 777 "/tmp" "/run" "/run/init.d" "/usr/local/etc/docker/exec" + if [ "$init_count" -eq 0 ] || [ ! -d "$init_dir" ]; then mkdir -p "/data/logs/init" while :; do echo "Running: $(date)" >"/data/logs/init/keep_alive" && sleep 3600; done & @@ -661,26 +742,79 @@ __start_init_scripts() { if [ -d "$init_dir" ]; then [ -f "$init_dir/service.sample" ] && __rm "$init_dir"/*.sample chmod -Rf 755 "$init_dir"/*.sh + + echo "🚀 Starting container services initialization" + echo "📂 Init directory: $init_dir" + echo "📊 Services to start: $init_count" + echo "📋 Found $init_count service scripts to execute" + echo "" + for init in "$init_dir"/*.sh; do if [ -x "$init" ]; then name="$(basename "$init")" service="$(printf '%s' "$name" | sed 's/^[^-]*-//;s|.sh$||g')" - printf '# - - - executing file: %s\n' "$init" - eval "$init" && sleep 5 || sleep 3 - retPID=$(__get_pid "$service") - if [ -n "$retPID" ]; then - initStatus="0" - printf '# - - - %s has been started - pid: %s\n' "$service" "${retPID:-error}" + __service_banner "🔧" "Executing service script:" "$(basename "$init")" + # Execute the init script and capture the exit code + if source "$init"; then + # Check if service was disabled first + if [ -n "$SERVICE_DISABLED" ]; then + initStatus="0" + __service_banner "🚫" "Service $service is disabled -" "skipping" + unset SERVICE_DISABLED + else + sleep 2 + # Check for service success indicators + local expected_pid_file="/run/init.d/$service.pid" + if [ "$SERVICE_USES_PID" = "no" ]; then + # Service doesn't use PID files - check if expected PID file exists or assume success + if [ -f "$expected_pid_file" ]; then + retPID="$(cat "$expected_pid_file" 2>/dev/null || echo "0")" + initStatus="0" + __service_banner "✅" "Service $service started successfully -" "PID file" + else + initStatus="0" + __service_banner "✅" "Service $service started successfully -" "no PID tracking" + fi + else + # Service uses PID tracking - get actual PID + retPID=$(__get_pid "$service") + if [ -n "$retPID" ] && [ "$retPID" != "0" ]; then + initStatus="0" + __service_banner "✅" "Service $service started successfully -" "PID: ${retPID}" + elif [ -f "$expected_pid_file" ]; then + retPID="$(cat "$expected_pid_file" 2>/dev/null || echo "0")" + initStatus="0" + __service_banner "✅" "Service $service started successfully -" "PID file" + else + initStatus="1" + critical_failures=$((critical_failures + 1)) + __service_banner "⚠️" "Service $service appears to have started but" "no process found" + fi + fi + fi else initStatus="1" - printf '# - - - %s has falied to start - check log %s\n' "$service" "docker log $CONTAINER_NAME" + critical_failures=$((critical_failures + 1)) + __service_banner "❌" "Service $service failed to start -" "check logs" fi echo "" fi - retstatus=$(($retstatus + $initStatus)) + retstatus=$((retstatus + initStatus)) done + + # Summary + if [ $critical_failures -gt 0 ]; then + echo "⚠️ Warning: $critical_failures service(s) failed to start" + if [ "$exit_on_failure" = "true" ] && [ $critical_failures -ge 1 ]; then + echo "❌ Exiting due to critical service failures" + return 1 + fi + else + echo "✅ All services started successfully" + fi fi fi + printf '%s\n' "$SERVICE_NAME started on $(date)" >"/data/logs/start.log" return $retstatus } @@ -894,8 +1028,8 @@ __initialize_system_etc() { local file=() local directories="" if [ -n "$conf_dir" ] && [ -e "$conf_dir" ]; then - files="$(find "$conf_dir"/* -not -path '*/env/*' -type f 2>/dev/null | sed 's|'/config/'||g' | sort -u | grep -v '^$' | grep '^' || false)" - directories="$(find "$conf_dir"/* -not -path '*/env/*' -type d 2>/dev/null | sed 's|'/config/'||g' | sort -u | grep -v '^$' | grep '^' || false)" + files="$(find "$conf_dir"/* -not -path '*/env/*' -type f 2>/dev/null | sed 's|'/config/'||g' | sort -u | grep -v '^$' | grep '.' || false)" + directories="$(find "$conf_dir"/* -not -path '*/env/*' -type d 2>/dev/null | sed 's|'/config/'||g' | sort -u | grep -v '^$' | grep '.' || false)" echo "Copying config files to system: $conf_dir > /etc/${conf_dir//\/config\//}" if [ -n "$directories" ]; then for d in $directories; do 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..e81257f 100644 --- a/rootfs/usr/local/share/template-files/config/env/default.sample +++ b/rootfs/usr/local/share/template-files/config/env/default.sample @@ -20,6 +20,7 @@ #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}" @@ -112,7 +113,7 @@ DATABASE_DIR_COUCHDB="${DATABASE_DIR_COUCHDB:-$DATABASE_BASE_DIR/couchdb}" DATABASE_DIR_SUPABASE="${DATABASE_DIR_SUPABASE:-$DATABASE_BASE_DIR/supabase}" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # docker env -DOCKER_HOST="unix://var/run/docker.sock" +DOCKER_HOST="unix:///run/docker.sock" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # File locations ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-/run/init.d/entrypoint.pid}"