From b646f7a7261531f5ad27eaf3e969409a600b616f Mon Sep 17 00:00:00 2001 From: casjay Date: Sat, 30 May 2026 02:19:11 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Apply=20template=20updates=20fro?= =?UTF-8?q?m=20/tmp/templates/go=20=F0=9F=94=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sync project with updated upstream template files while preserving all Go-specific customizations (EXEC_CMD_BIN='', DATA_DIR='', Go env vars, /data/go symlink, Go-named dirs, etc.). - .env.scripts: bump version stamp to 202605292219-git - .gitattributes: update date stamp from template - .gitea/workflows/docker.yaml: replace bare echo with printf %q for GITHUB_OUTPUT assignments; use local var assignments for docker org/tag - .gitignore: expand with editor configs (VSCode/JetBrains/Vim), AI tool configs (Claude/.cursor/Copilot), env/secrets, build artifacts, dependency dirs, logs, test/coverage dirs from updated template - Dockerfile: bump BUILD_DATE to 202605292219; fix PHP_FPM detection from ls subshell to set -- glob pattern; fix systemd cleanup to use for loop instead of rm -f $(ls | grep -v ...) - rootfs/root/docker/setup/00-init.sh through 07-cleanup.sh: update version/date stamps to 202605292220-git template versions - rootfs/usr/local/bin/entrypoint.sh: update stamp; fix echo quoting to use double quotes for CONTAINER_NAME expansion - rootfs/usr/local/etc/docker/init.d/00-go.sh: apply template improvements: split SIGPWR trap onto separate line with 2>/dev/null || true; expand debugger setup to multi-line if/else; use $( # @@License : MIT diff --git a/.gitattributes b/.gitattributes index 07f3b95..b6611c7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ -# Template generated on Sat Nov 29 11:57:12 AM EST 2025 from https://github.com/alexkaratarakis/gitattributes" +# Template generated on Sun May 17 10:58:44 PM EDT 2026 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 a2a7531..3c8c9a4 100644 --- a/.gitea/workflows/docker.yaml +++ b/.gitea/workflows/docker.yaml @@ -19,13 +19,20 @@ jobs: - name: Get Meta id: meta run: | - echo DATE_TAG=$(date +'%y%m') >> $GITHUB_OUTPUT - echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $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" + repo_version="$(git describe --tags --always)" + repo_version="${repo_version#v}" + docker_org="${GITHUB_REPOSITORY%%/*}" + repo_name="${GITHUB_REPOSITORY#*/}" + repo_name="${repo_name#docker-}" + docker_tag="${DOCKER_TAG:-latest}" + docker_hub="${DOCKER_HUB:-docker.io}" + printf 'DATE_TAG=%s\n' "$(date +'%y%m')" >> "$GITHUB_OUTPUT" + printf 'REPO_VERSION=%s\n' "$repo_version" >> "$GITHUB_OUTPUT" + printf 'DOCKER_ORG=%s\n' "$docker_org" >> "$GITHUB_OUTPUT" + printf 'DOCKER_TAG=%s\n' "$docker_tag" >> "$GITHUB_OUTPUT" + printf 'DOCKER_HUB=%s\n' "$docker_hub" >> "$GITHUB_OUTPUT" + printf 'REPO_NAME=%s\n' "$repo_name" >> "$GITHUB_OUTPUT" + printf '%s\n' "$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 0058ea8..d155d5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -# gitignore created on 04/22/26 at 19:23 +# gitignore created on 05/29/26 at 22:20 # Disable reminder in prompt ignoredirmessage @@ -6,10 +6,12 @@ ignoredirmessage **/.build_failed* # OS generated files + ### Linux ### +# Backup files left by editors *~ -# temporary files which can be created if a process still has a handle open of a deleted file +# Temporary files left when a process holds an open handle to a deleted file .fuse_hidden* # KDE directory preferences @@ -18,11 +20,11 @@ ignoredirmessage # Linux trash folder which might appear on any partition or disk .Trash-* -# .nfs files are created when an open file is removed but is still being accessed +# NFS stale file handles .nfs* ### macOS ### -# General +.DS_Store .DS_Store? .AppleDouble .LSOverride @@ -46,20 +48,23 @@ Network Trash Folder Temporary Items .apdisk -### macOS Patch ### # iCloud generated files *.icloud ### Windows ### -# Windows thumbnail cache files Thumbs.db Thumbs.db:encryptable ehthumbs.db ehthumbs_vista.db -# Dump file +# Crash dump files *.stackdump +# Core dumps (Linux/macOS) +core +core.* +vgcore.* + # Folder config file [Dd]esktop.ini @@ -73,20 +78,146 @@ $RECYCLE.BIN/ *.msm *.msp -# misc -!*/README* -!inc/main.bash - # Windows shortcuts *.lnk -# ignore commit message +### Editors ### +# Visual Studio Code +.vscode/ +!.vscode/extensions.json + +# JetBrains IDEs (IntelliJ, GoLand, RustRover, PyCharm, etc.) +.idea/ +*.iml +*.iws +*.ipr + +# Vim / Neovim +*.swp +*.swo +.netrwhist +Session.vim +.vim/ + +# Sublime Text +*.sublime-workspace +*.sublime-project + +# Eclipse / generic Java IDEs +.project +.classpath +.factorypath +.settings/ + +### AI tool local configs (personal settings, never commit) ### +# Claude Code +.claude/settings.local.json +.claude/*.lock + +# Cursor +.cursor/ +.cursorignore +.cursorindexingignore + +# GitHub Copilot +.copilot/ + +# Codeium +.codeium/ + +# Tabnine +.tabnine/ + +# Aider +.aider/ +.aider.conf.yml +.aider.model.settings.yml +.aiderignore + +# General AI assistant local state +.ai/ +.ai.local/ + +### Environment and secrets ### +# Local env overrides โ€” never commit credentials +.env +.env.local +.env.*.local + +# Private keys and certificates +*.pem +*.key +*.p12 +*.pfx + +### Build artifacts ### +build/ +dist/ +out/ + +# Rust +target/ + +# C / C++ / compiled objects +*.o +*.a +*.so +*.dylib +*.dll +*.exe + +### Dependency directories ### +# Node +node_modules/ + +# Go (vendored deps are sometimes committed intentionally, so gitignore only the cache) +# vendor/ + +# Python +__pycache__/ +*.pyc +*.pyo +*.pyd +.Python +*.egg-info/ +.eggs/ +.venv/ +venv/ +env/ + +### Logs ### +*.log +logs/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +### Temporary and cache ### +tmp/ +.tmp/ +*.tmp +*.cache +.cache/ + +### Test and coverage ### +coverage/ +.coverage +*.cover +*.coverprofile +htmlcov/ +.nyc_output/ +.pytest_cache/ +.tox/ + +### Misc โ€” always allow ### +!*/README* +!inc/main.bash + +### Project-specific patterns ### +# ignore commit message files **/.gitcommit -# ignore .build_failed files -**/.build_failed* - -# ignore .bak files +# ignore backup files **/*.bak # ignore .no_push files @@ -95,10 +226,16 @@ $RECYCLE.BIN/ # ignore .no_git files **/.no_git -# ignore .installed files +# ignore .installed marker files **/.installed -# ignore work in progress files +# ignore work-in-progress rewrite/refactor scripts **/*.rewrite.sh **/*.refactor.sh +# ignore local override scripts and configs +**/*.local.sh +**/*.local.conf +**/*.local.yaml +**/*.local.yml + diff --git a/Dockerfile b/Dockerfile index 31e7ab8..1863ac1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Docker image for go using the alpine template ARG IMAGE_NAME="go" ARG PHP_SERVER="go" -ARG BUILD_DATE="202604221922" +ARG BUILD_DATE="202605292219" ARG LANGUAGE="en_US.UTF-8" ARG TIMEZONE="America/New_York" ARG WWW_ROOT_DIR="/usr/local/share/httpd/default" @@ -123,7 +123,7 @@ RUN echo "Updating system files "; \ echo 'hosts: files dns' >"/etc/nsswitch.conf"; \ [ "$PHP_VERSION" = "system" ] && PHP_VERSION="php" || true; \ PHP_BIN="$(command -v ${PHP_VERSION} 2>/dev/null || true)"; \ - PHP_FPM="$(ls /usr/*bin/php*fpm* 2>/dev/null || true)"; \ + set -- /usr/*bin/php*fpm*; [ -e "$1" ] && PHP_FPM="$1" || PHP_FPM=""; \ 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=""; \ @@ -180,7 +180,7 @@ RUN echo "Deleting unneeded files"; \ rm -rf /lib/systemd/system/sockets.target.wants/*udev* || true; \ rm -rf /lib/systemd/system/sockets.target.wants/*initctl* || true; \ rm -Rf /usr/share/doc/* /var/tmp/* /var/cache/*/* /root/.cache/* /usr/share/info/* /tmp/* || true; \ - if [ -d "/lib/systemd/system/sysinit.target.wants" ];then cd "/lib/systemd/system/sysinit.target.wants" && rm -f $(ls | grep -v systemd-tmpfiles-setup);fi; \ + if [ -d "/lib/systemd/system/sysinit.target.wants" ];then cd "/lib/systemd/system/sysinit.target.wants" && for want_file in *; do [ "$want_file" = "systemd-tmpfiles-setup" ] || rm -f "$want_file"; done; fi; \ if [ -f "/root/docker/setup/07-cleanup.sh" ];then echo "Running the cleanup script";/root/docker/setup/07-cleanup.sh||{ echo "Failed to execute /root/docker/setup/07-cleanup.sh" >&2 && exit 10; };echo "Done running the cleanup script";fi; \ echo "" diff --git a/rootfs/root/docker/setup/00-init.sh b/rootfs/root/docker/setup/00-init.sh index c134819..ae6ff51 100755 --- a/rootfs/root/docker/setup/00-init.sh +++ b/rootfs/root/docker/setup/00-init.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605242059-git +##@Version : 202605292220-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Sun May 24 08:59:09 PM EDT 2026 +# @@Created : Fri May 29 10:20:08 PM EDT 2026 # @@File : 00-init.sh # @@Description : script to run init # @@Changelog : newScript diff --git a/rootfs/root/docker/setup/01-system.sh b/rootfs/root/docker/setup/01-system.sh index bf4343a..df88580 100755 --- a/rootfs/root/docker/setup/01-system.sh +++ b/rootfs/root/docker/setup/01-system.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605242059-git +##@Version : 202605292220-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Sun May 24 08:59:09 PM EDT 2026 +# @@Created : Fri May 29 10:20:08 PM EDT 2026 # @@File : 01-system.sh # @@Description : script to run system # @@Changelog : newScript diff --git a/rootfs/root/docker/setup/02-packages.sh b/rootfs/root/docker/setup/02-packages.sh index f85327d..7373ddc 100755 --- a/rootfs/root/docker/setup/02-packages.sh +++ b/rootfs/root/docker/setup/02-packages.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605242139-git +##@Version : 202605292220-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Sun May 24 08:59:10 PM EDT 2026 +# @@Created : Fri May 29 10:20:09 PM EDT 2026 # @@File : 02-packages.sh # @@Description : script to run packages # @@Changelog : newScript diff --git a/rootfs/root/docker/setup/03-files.sh b/rootfs/root/docker/setup/03-files.sh index c8e064d..c1fc0ee 100755 --- a/rootfs/root/docker/setup/03-files.sh +++ b/rootfs/root/docker/setup/03-files.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605242059-git +##@Version : 202605292220-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Sun May 24 08:59:10 PM EDT 2026 +# @@Created : Fri May 29 10:20:09 PM EDT 2026 # @@File : 03-files.sh # @@Description : script to run files # @@Changelog : newScript diff --git a/rootfs/root/docker/setup/04-users.sh b/rootfs/root/docker/setup/04-users.sh index a6c8bc2..98b6c12 100755 --- a/rootfs/root/docker/setup/04-users.sh +++ b/rootfs/root/docker/setup/04-users.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605242059-git +##@Version : 202605292220-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Sun May 24 08:59:10 PM EDT 2026 +# @@Created : Fri May 29 10:20:09 PM EDT 2026 # @@File : 04-users.sh # @@Description : script to run users # @@Changelog : newScript diff --git a/rootfs/root/docker/setup/05-custom.sh b/rootfs/root/docker/setup/05-custom.sh index 052f4b5..f18f4aa 100755 --- a/rootfs/root/docker/setup/05-custom.sh +++ b/rootfs/root/docker/setup/05-custom.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605242059-git +##@Version : 202605292220-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Sun May 24 08:59:10 PM EDT 2026 +# @@Created : Fri May 29 10:20:10 PM EDT 2026 # @@File : 05-custom.sh # @@Description : script to run custom # @@Changelog : newScript diff --git a/rootfs/root/docker/setup/06-post.sh b/rootfs/root/docker/setup/06-post.sh index 365ee54..9702709 100755 --- a/rootfs/root/docker/setup/06-post.sh +++ b/rootfs/root/docker/setup/06-post.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605242059-git +##@Version : 202605292220-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Sun May 24 08:59:10 PM EDT 2026 +# @@Created : Fri May 29 10:20:11 PM EDT 2026 # @@File : 06-post.sh # @@Description : script to run post # @@Changelog : newScript diff --git a/rootfs/root/docker/setup/07-cleanup.sh b/rootfs/root/docker/setup/07-cleanup.sh index cbf05e6..5ce7f9d 100755 --- a/rootfs/root/docker/setup/07-cleanup.sh +++ b/rootfs/root/docker/setup/07-cleanup.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605242059-git +##@Version : 202605292220-git # @@Author : CasjaysDev # @@Contact : CasjaysDev # @@License : MIT # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Sun May 24 08:59:10 PM EDT 2026 +# @@Created : Fri May 29 10:20:11 PM EDT 2026 # @@File : 07-cleanup.sh # @@Description : script to run cleanup # @@Changelog : newScript diff --git a/rootfs/usr/local/bin/entrypoint.sh b/rootfs/usr/local/bin/entrypoint.sh index 24576d0..587f151 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 : 202605241245-git +##@Version : 202605260122-git # @@Author : Jason Hempstead # @@Contact : jason@casjaysdev.pro # @@License : WTFPL # @@ReadME : entrypoint.sh --help # @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments -# @@Created : Sunday, May 24, 2026 20:59 EDT +# @@Created : Friday, May 29, 2026 22:19 EDT # @@File : entrypoint.sh # @@Description : Entrypoint file for alpine # @@Changelog : New script @@ -61,7 +61,7 @@ case "$1" in # Help message -h | --help) shift 1 - echo 'Docker container for '$CONTAINER_NAME'' + echo "Docker container for $CONTAINER_NAME" echo "Usage: $CONTAINER_NAME [help tail cron exec start init shell procs ports healthcheck backup command]" echo "" exit 0 diff --git a/rootfs/usr/local/etc/docker/init.d/00-go.sh b/rootfs/usr/local/etc/docker/init.d/00-go.sh index 923aacc..5e8d563 100755 --- a/rootfs/usr/local/etc/docker/init.d/00-go.sh +++ b/rootfs/usr/local/etc/docker/init.d/00-go.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202602061352-git +##@Version : 202605260122-git # @@Author : Jason Hempstead # @@Contact : jason@casjaysdev.pro # @@License : WTFPL # @@ReadME : 00-go.sh --help # @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments -# @@Created : Wednesday, Apr 22, 2026 19:24 EDT +# @@Created : Friday, May 29, 2026 22:22 EDT # @@File : 00-go.sh # @@Description : # @@Changelog : New script @@ -24,7 +24,8 @@ set -e # - - - - - - - - - - - - - - - - - - - - - - - - - # run trap command on exit trap '__trap_err_handler' ERR -trap 'retVal=$?;if [ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ]; then rm -Rf "$SERVICE_PID_FILE"; fi;exit $retVal' SIGINT SIGTERM SIGPWR +trap 'retVal=$?;if [ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ]; then rm -Rf "$SERVICE_PID_FILE"; fi;exit $retVal' SIGINT SIGTERM +trap 'retVal=$?;if [ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ]; then rm -Rf "$SERVICE_PID_FILE"; fi;exit $retVal' SIGPWR 2>/dev/null || true # - - - - - - - - - - - - - - - - - - - - - - - - - # ERR trap handler - smart about critical vs non-critical errors __trap_err_handler() { @@ -74,7 +75,14 @@ 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 +if [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; then + echo "Enabling debugging" + set -o pipefail + [ -n "$DEBUGGER_OPTIONS" ] && set -"$DEBUGGER_OPTIONS" + export DEBUGGER="on" +else + set -o pipefail +fi # - - - - - - - - - - - - - - - - - - - - - - - - - export PATH="/go/bin:/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin" # - - - - - - - - - - - - - - - - - - - - - - - - - @@ -98,7 +106,7 @@ if [ ! -f "/run/.start_init_scripts.pid" ]; then fi # 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) + old_pid=$(<"/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" @@ -276,7 +284,7 @@ __run_precopy() { # Define actions/commands # allow custom functions - if builtin type -t __run_precopy_local | grep -q 'function'; then + if builtin type -t __run_precopy_local | grep -q -- 'function'; then __run_precopy_local fi } @@ -288,7 +296,7 @@ __execute_prerun() { # Define actions/commands # allow custom functions - if builtin type -t __execute_prerun_local | grep -q 'function'; then + if builtin type -t __execute_prerun_local | grep -q -- 'function'; then __execute_prerun_local fi } @@ -318,7 +326,7 @@ __run_pre_execute_checks() { __script_exit 1 fi # allow custom functions - if builtin type -t __run_pre_execute_checks_local | grep -q 'function'; then + if builtin type -t __run_pre_execute_checks_local | grep -q -- 'function'; then __run_pre_execute_checks_local fi # exit function @@ -348,7 +356,7 @@ __update_conf_files() { # define actions # allow custom functions - if builtin type -t __update_conf_files_local | grep -q 'function'; then + if builtin type -t __update_conf_files_local | grep -q -- 'function'; then __update_conf_files_local fi # exit function @@ -372,7 +380,7 @@ __pre_execute() { # Lets wait a few seconds before continuing sleep 2 # allow custom functions - if builtin type -t __pre_execute_local | grep -q 'function'; then + if builtin type -t __pre_execute_local | grep -q -- 'function'; then __pre_execute_local fi # exit function @@ -405,13 +413,13 @@ __post_execute() { __banner "$postMessageEnd: Status $retVal" ) 2>"/dev/stderr" | tee -p -a "/data/logs/init.txt" & pid=$! - if ps ax | awk '{print $1}' | grep -v grep | grep -q "$execPid$"; then + if ps ax | awk -v pid="$execPid" '$1 == pid {found=1} END {exit !found}'; then retVal=0 else retVal=10 fi # allow custom functions - if builtin type -t __post_execute_local | grep -q 'function'; then + if builtin type -t __post_execute_local | grep -q -- 'function'; then __post_execute_local fi # exit function @@ -427,7 +435,7 @@ __pre_message() { # execute commands # allow custom functions - if builtin type -t __pre_message_local | grep -q 'function'; then + if builtin type -t __pre_message_local | grep -q -- 'function'; then __pre_message_local fi # exit function @@ -441,7 +449,7 @@ __update_ssl_conf() { # execute commands # allow custom functions - if builtin type -t __update_ssl_conf_local | grep -q 'function'; then + if builtin type -t __update_ssl_conf_local | grep -q -- 'function'; then __update_ssl_conf_local fi # set exitCode @@ -553,7 +561,7 @@ __run_start_script() { SERVICE_PORT="" fi fi - if [ -n "$pre" ] && [ -n "$(command -v "$pre" 2>/dev/null)" ]; then + if [ -n "$pre" ] && command -v "$pre" &>/dev/null; then export cmd_exec="$pre $cmd $args" message="Starting service: $name $args through $pre" else @@ -565,58 +573,88 @@ __run_start_script() { fi __log_info "$message" | tee -a -p "/data/logs/init.txt" su_cmd touch "$SERVICE_PID_FILE" + # W14: invalidate cached START_SCRIPT if key variables changed + local _script_hash_src="$cmd $args $SERVICE_USER $RESET_ENV $su_exec" + local _script_hash + _script_hash=$(printf '%s' "$_script_hash_src" | md5sum 2>/dev/null | cut -c1-8 || true) + if [ -f "${START_SCRIPT}.hash" ] && [ -f "$START_SCRIPT" ]; then + if [ "$(cat "${START_SCRIPT}.hash" 2>/dev/null)" != "$_script_hash" ]; then + rm -f "$START_SCRIPT" "${START_SCRIPT}.hash" + fi + fi 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")" + # RESET_ENV=yes intentionally strips all inherited vars; only explicit vars are passed if [ ! -f "$START_SCRIPT" ]; then - cat <"$START_SCRIPT" -#!/usr/bin/env bash -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" -LOG_DIR="$LOG_DIR" -execute_command="$execute_command" -\$execute_command 2>"/dev/stderr" >>"\$LOG_DIR/\$SERVICE_NAME.log" & -execPid=\$! -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 ] && printf '%s\n' "\$SERVICE_NAME: \$execPid" >"/run/healthcheck/\$SERVICE_NAME" || echo "Failed to start $execute_command" >&2 -exit \$retVal - -EOF + # Use printf %q to safely quote each env component for embedding in the script + local _q_home _q_lc _q_path _q_sysname _q_svcuser _q_su _q_cmd _q_args _q_extra + _q_home=$(printf '%q' "$home") + _q_lc=$(printf '%q' "$lc_type") + _q_path=$(printf '%q' "$path") + _q_sysname=$(printf '%q' "$sysname") + _q_svcuser=$(printf '%q' "${SERVICE_USER:-$RUNAS_USER}") + _q_su='' + [ -n "$su_exec" ] && _q_su=$(printf '%q ' $su_exec) + _q_cmd=$(printf '%q' "$cmd") + _q_args='' + [ -n "$args" ] && _q_args=$(printf '%q ' $args) + _q_extra='' + [ -n "$extra_env" ] && _q_extra=$(printf '%q ' $extra_env) + { + printf '#!/usr/bin/env bash\n' + printf "trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f \"\$SERVICE_PID_FILE\" ] && rm -Rf \"\$SERVICE_PID_FILE\";exit \$exitCode' EXIT\n" + printf 'set -Eeo pipefail\n' + printf '# Setting up %s to run as %s with env\n' "$cmd" "${SERVICE_USER:-root}" + printf 'retVal=10\n' + printf 'SERVICE_NAME=%q\n' "$SERVICE_NAME" + printf 'SERVICE_PID_FILE=%q\n' "$SERVICE_PID_FILE" + printf 'LOG_DIR=%q\n' "$LOG_DIR" + printf '%s env -i HOME=%s LC_CTYPE=%s PATH=%s HOSTNAME=%s USER=%s %s %s %s 2>>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &\n' \ + "$_q_su" "$_q_home" "$_q_lc" "$_q_path" "$_q_sysname" "$_q_svcuser" "$_q_extra" "$_q_cmd" "$_q_args" + printf 'execPid=$!\n' + printf 'sleep 1\n' + printf 'if [ -n "$execPid" ] && kill -0 "$execPid" 2>/dev/null; then\n' + printf ' echo "$execPid" >"$SERVICE_PID_FILE"\n' + printf ' retVal=0\n' + printf ' printf '"'"'%%s\n'"'"' "$SERVICE_NAME: $execPid" >"/run/healthcheck/$SERVICE_NAME"\n' + printf 'else\n' + printf ' retVal=10\n' + printf ' echo "Failed to start service %s" >&2\n' "$cmd" + printf 'fi\n' + printf 'exit $retVal\n' + } >"$START_SCRIPT" + printf '%s' "$_script_hash" >"${START_SCRIPT}.hash" fi else if [ ! -f "$START_SCRIPT" ]; then - execute_command="$(__trim "$su_exec $cmd_exec")" - cat <"$START_SCRIPT" -#!/usr/bin/env bash -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" -LOG_DIR="$LOG_DIR" -execute_command="$execute_command" -\$execute_command 2>>"/dev/stderr" >>"\$LOG_DIR/\$SERVICE_NAME.log" & -execPid=\$! -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 "Failed to start $execute_command" >&2 -exit \$retVal - -EOF + local _q_su _q_cmd _q_args + _q_su='' + [ -n "$su_exec" ] && _q_su=$(printf '%q ' $su_exec) + _q_cmd=$(printf '%q' "$cmd") + _q_args='' + [ -n "$args" ] && _q_args=$(printf '%q ' $args) + { + printf '#!/usr/bin/env bash\n' + printf "trap 'exitCode=\$?;[ \$exitCode -ne 0 ] && [ -f \"\$SERVICE_PID_FILE\" ] && rm -Rf \"\$SERVICE_PID_FILE\";exit \$exitCode' EXIT\n" + printf 'set -Eeo pipefail\n' + printf '# Setting up %s to run as %s\n' "$cmd" "${SERVICE_USER:-root}" + printf 'retVal=10\n' + printf 'SERVICE_NAME=%q\n' "$SERVICE_NAME" + printf 'SERVICE_PID_FILE=%q\n' "$SERVICE_PID_FILE" + printf 'LOG_DIR=%q\n' "$LOG_DIR" + printf '%s %s %s 2>>"/dev/stderr" >>"$LOG_DIR/$SERVICE_NAME.log" &\n' \ + "$_q_su" "$_q_cmd" "$_q_args" + printf 'execPid=$!\n' + printf 'sleep 1\n' + printf 'if [ -n "$execPid" ] && kill -0 "$execPid" 2>/dev/null; then\n' + printf ' echo "$execPid" >"$SERVICE_PID_FILE"\n' + printf ' retVal=0\n' + printf 'else\n' + printf ' retVal=10\n' + printf ' echo "Failed to start service %s" >&2\n' "$cmd" + printf 'fi\n' + printf 'exit $retVal\n' + } >"$START_SCRIPT" + printf '%s' "$_script_hash" >"${START_SCRIPT}.hash" fi fi fi @@ -624,7 +662,8 @@ EOF chmod 755 -Rf "$START_SCRIPT" fi if [ "$CONTAINER_INIT" != "yes" ]; then - eval sh -c "$START_SCRIPT" + # W15: launch as bash, not sh, since the generated script uses bash-specific features + bash "$START_SCRIPT" runExitCode=$? fi fi @@ -638,7 +677,7 @@ __run_secure_function() { 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 + [ -n "$SERVICE_USER" ] && chown -Rf "$SERVICE_USER:$SERVICE_USER" "$filesperms" 2>/dev/null fi done 2>/dev/null | tee -p -a "/data/logs/init.txt" fi @@ -646,7 +685,7 @@ __run_secure_function() { for filesperms in "${ROOT_FILE_PREFIX}"/*; do if [ -e "$filesperms" ]; then chmod -Rf 600 "$filesperms" - chown -Rf $SERVICE_USER:$SERVICE_USER "$filesperms" 2>/dev/null + [ -n "$SERVICE_USER" ] && chown -Rf "$SERVICE_USER:$SERVICE_USER" "$filesperms" 2>/dev/null fi done 2>/dev/null | tee -p -a "/data/logs/init.txt" fi @@ -666,18 +705,16 @@ SERVICE_EXIT_CODE=0 # application specific EXEC_CMD_NAME="${EXEC_CMD_BIN##*/}" SERVICE_PID_FILE="/run/init.d/$EXEC_CMD_NAME.pid" -SERVICE_PID_NUMBER="$(__pgrep "$EXEC_CMD_NAME" 2>/dev/null || echo '')" -if type -P "$EXEC_CMD_BIN" &>/dev/null; then - EXEC_CMD_BIN="$(type -P "$EXEC_CMD_BIN")" -fi -if type -P "$EXEC_PRE_SCRIPT" &>/dev/null; then - EXEC_PRE_SCRIPT="$(type -P "$EXEC_PRE_SCRIPT")" -fi +_resolved="$(type -P "$EXEC_CMD_BIN" 2>/dev/null)" +[ -n "$_resolved" ] && EXEC_CMD_BIN="$_resolved" +_resolved="$(type -P "$EXEC_PRE_SCRIPT" 2>/dev/null)" +[ -n "$_resolved" ] && EXEC_PRE_SCRIPT="$_resolved" +unset _resolved # - - - - - - - - - - - - - - - - - - - - - - - - - -# Only run check -if __check_service "$1"; then +# Only run check when explicitly requested +if [ "$1" = "check" ] && __check_service "$1"; then SERVICE_IS_RUNNING=yes -else +elif [ "$1" = "check" ]; then SERVICE_IS_RUNNING="no" fi # - - - - - - - - - - - - - - - - - - - - - - - - - @@ -841,14 +878,6 @@ if [ -n "$root_user_pass" ]; then echo "$root_user_pass" >"${ROOT_FILE_PREFIX}/${SERVICE_NAME}_pass" fi # - - - - - - - - - - - - - - - - - - - - - - - - - -# create needed dirs -if [ ! -d "$LOG_DIR" ]; then - mkdir -p "$LOG_DIR" -fi -if [ ! -d "$RUN_DIR" ]; then - mkdir -p "$RUN_DIR" -fi -# - - - - - - - - - - - - - - - - - - - - - - - - - # Allow per init script usernames and passwords if __file_exists_with_content "${USER_FILE_PREFIX}/${SERVICE_NAME}_name"; then user_name="$(<"${USER_FILE_PREFIX}/${SERVICE_NAME}_name")" @@ -934,7 +963,7 @@ __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=$? +errorCode=${PIPESTATUS[0]} if [ -n "$EXEC_CMD_BIN" ]; then if [ "$errorCode" -eq 0 ]; then SERVICE_EXIT_CODE=0 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 a5f0acb..2d4a7ef 100644 --- a/rootfs/usr/local/share/template-files/config/env/default.sample +++ b/rootfs/usr/local/share/template-files/config/env/default.sample @@ -116,7 +116,7 @@ DATABASE_DIR_SUPABASE="${DATABASE_DIR_SUPABASE:-$DATABASE_BASE_DIR/supabase}" DOCKER_HOST="unix://var/run/docker.sock" # - - - - - - - - - - - - - - - - - - - - - - - - - # File locations -ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-/run/.entrypoint.pid}" +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}" 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 51b5729..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,6 +1,6 @@ # - - - - - - - - - - - - - - - - - - - - - - - - - # File locations -ENTRYPOINT_PID_FILE="${ENTRYPOINT_PID_FILE:-/run/.entrypoint.pid}" +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}"