From 667512852e35b485cc557412e58648cf70a77759 Mon Sep 17 00:00:00 2001
From: JuniorJPDJ <git@juniorjpdj.pl>
Date: Wed, 20 Jul 2022 01:23:20 +0200
Subject: [PATCH] Source entrypoint files with .envsh extension

This allows reusing variables declared between entrypoint scripts
---
 entrypoint/docker-entrypoint.sh           | 9 +++++++++
 mainline/alpine-perl/docker-entrypoint.sh | 9 +++++++++
 mainline/alpine-slim/docker-entrypoint.sh | 9 +++++++++
 mainline/alpine/docker-entrypoint.sh      | 9 +++++++++
 mainline/debian-perl/docker-entrypoint.sh | 9 +++++++++
 mainline/debian/docker-entrypoint.sh      | 9 +++++++++
 stable/alpine-perl/docker-entrypoint.sh   | 9 +++++++++
 stable/alpine-slim/docker-entrypoint.sh   | 9 +++++++++
 stable/alpine/docker-entrypoint.sh        | 9 +++++++++
 stable/debian-perl/docker-entrypoint.sh   | 9 +++++++++
 stable/debian/docker-entrypoint.sh        | 9 +++++++++
 11 files changed, 99 insertions(+)

diff --git a/entrypoint/docker-entrypoint.sh b/entrypoint/docker-entrypoint.sh
index 72d5cd9..b8b99e1 100755
--- a/entrypoint/docker-entrypoint.sh
+++ b/entrypoint/docker-entrypoint.sh
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
         echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
         find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
             case "$f" in
+                *.envsh)
+                    if [ -x "$f" ]; then
+                        echo >&3 "$0: Sourcing $f";
+                        source "$f"
+                    else
+                        # warn on shell scripts without exec bit
+                        echo >&3 "$0: Ignoring $f, not executable";
+                    fi
+                    ;;
                 *.sh)
                     if [ -x "$f" ]; then
                         echo >&3 "$0: Launching $f";
diff --git a/mainline/alpine-perl/docker-entrypoint.sh b/mainline/alpine-perl/docker-entrypoint.sh
index 72d5cd9..b8b99e1 100755
--- a/mainline/alpine-perl/docker-entrypoint.sh
+++ b/mainline/alpine-perl/docker-entrypoint.sh
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
         echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
         find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
             case "$f" in
+                *.envsh)
+                    if [ -x "$f" ]; then
+                        echo >&3 "$0: Sourcing $f";
+                        source "$f"
+                    else
+                        # warn on shell scripts without exec bit
+                        echo >&3 "$0: Ignoring $f, not executable";
+                    fi
+                    ;;
                 *.sh)
                     if [ -x "$f" ]; then
                         echo >&3 "$0: Launching $f";
diff --git a/mainline/alpine-slim/docker-entrypoint.sh b/mainline/alpine-slim/docker-entrypoint.sh
index 72d5cd9..b8b99e1 100755
--- a/mainline/alpine-slim/docker-entrypoint.sh
+++ b/mainline/alpine-slim/docker-entrypoint.sh
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
         echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
         find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
             case "$f" in
+                *.envsh)
+                    if [ -x "$f" ]; then
+                        echo >&3 "$0: Sourcing $f";
+                        source "$f"
+                    else
+                        # warn on shell scripts without exec bit
+                        echo >&3 "$0: Ignoring $f, not executable";
+                    fi
+                    ;;
                 *.sh)
                     if [ -x "$f" ]; then
                         echo >&3 "$0: Launching $f";
diff --git a/mainline/alpine/docker-entrypoint.sh b/mainline/alpine/docker-entrypoint.sh
index 72d5cd9..b8b99e1 100755
--- a/mainline/alpine/docker-entrypoint.sh
+++ b/mainline/alpine/docker-entrypoint.sh
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
         echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
         find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
             case "$f" in
+                *.envsh)
+                    if [ -x "$f" ]; then
+                        echo >&3 "$0: Sourcing $f";
+                        source "$f"
+                    else
+                        # warn on shell scripts without exec bit
+                        echo >&3 "$0: Ignoring $f, not executable";
+                    fi
+                    ;;
                 *.sh)
                     if [ -x "$f" ]; then
                         echo >&3 "$0: Launching $f";
diff --git a/mainline/debian-perl/docker-entrypoint.sh b/mainline/debian-perl/docker-entrypoint.sh
index 72d5cd9..b8b99e1 100755
--- a/mainline/debian-perl/docker-entrypoint.sh
+++ b/mainline/debian-perl/docker-entrypoint.sh
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
         echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
         find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
             case "$f" in
+                *.envsh)
+                    if [ -x "$f" ]; then
+                        echo >&3 "$0: Sourcing $f";
+                        source "$f"
+                    else
+                        # warn on shell scripts without exec bit
+                        echo >&3 "$0: Ignoring $f, not executable";
+                    fi
+                    ;;
                 *.sh)
                     if [ -x "$f" ]; then
                         echo >&3 "$0: Launching $f";
diff --git a/mainline/debian/docker-entrypoint.sh b/mainline/debian/docker-entrypoint.sh
index 72d5cd9..b8b99e1 100755
--- a/mainline/debian/docker-entrypoint.sh
+++ b/mainline/debian/docker-entrypoint.sh
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
         echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
         find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
             case "$f" in
+                *.envsh)
+                    if [ -x "$f" ]; then
+                        echo >&3 "$0: Sourcing $f";
+                        source "$f"
+                    else
+                        # warn on shell scripts without exec bit
+                        echo >&3 "$0: Ignoring $f, not executable";
+                    fi
+                    ;;
                 *.sh)
                     if [ -x "$f" ]; then
                         echo >&3 "$0: Launching $f";
diff --git a/stable/alpine-perl/docker-entrypoint.sh b/stable/alpine-perl/docker-entrypoint.sh
index 72d5cd9..b8b99e1 100755
--- a/stable/alpine-perl/docker-entrypoint.sh
+++ b/stable/alpine-perl/docker-entrypoint.sh
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
         echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
         find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
             case "$f" in
+                *.envsh)
+                    if [ -x "$f" ]; then
+                        echo >&3 "$0: Sourcing $f";
+                        source "$f"
+                    else
+                        # warn on shell scripts without exec bit
+                        echo >&3 "$0: Ignoring $f, not executable";
+                    fi
+                    ;;
                 *.sh)
                     if [ -x "$f" ]; then
                         echo >&3 "$0: Launching $f";
diff --git a/stable/alpine-slim/docker-entrypoint.sh b/stable/alpine-slim/docker-entrypoint.sh
index 72d5cd9..b8b99e1 100755
--- a/stable/alpine-slim/docker-entrypoint.sh
+++ b/stable/alpine-slim/docker-entrypoint.sh
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
         echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
         find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
             case "$f" in
+                *.envsh)
+                    if [ -x "$f" ]; then
+                        echo >&3 "$0: Sourcing $f";
+                        source "$f"
+                    else
+                        # warn on shell scripts without exec bit
+                        echo >&3 "$0: Ignoring $f, not executable";
+                    fi
+                    ;;
                 *.sh)
                     if [ -x "$f" ]; then
                         echo >&3 "$0: Launching $f";
diff --git a/stable/alpine/docker-entrypoint.sh b/stable/alpine/docker-entrypoint.sh
index 72d5cd9..b8b99e1 100755
--- a/stable/alpine/docker-entrypoint.sh
+++ b/stable/alpine/docker-entrypoint.sh
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
         echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
         find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
             case "$f" in
+                *.envsh)
+                    if [ -x "$f" ]; then
+                        echo >&3 "$0: Sourcing $f";
+                        source "$f"
+                    else
+                        # warn on shell scripts without exec bit
+                        echo >&3 "$0: Ignoring $f, not executable";
+                    fi
+                    ;;
                 *.sh)
                     if [ -x "$f" ]; then
                         echo >&3 "$0: Launching $f";
diff --git a/stable/debian-perl/docker-entrypoint.sh b/stable/debian-perl/docker-entrypoint.sh
index 72d5cd9..b8b99e1 100755
--- a/stable/debian-perl/docker-entrypoint.sh
+++ b/stable/debian-perl/docker-entrypoint.sh
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
         echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
         find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
             case "$f" in
+                *.envsh)
+                    if [ -x "$f" ]; then
+                        echo >&3 "$0: Sourcing $f";
+                        source "$f"
+                    else
+                        # warn on shell scripts without exec bit
+                        echo >&3 "$0: Ignoring $f, not executable";
+                    fi
+                    ;;
                 *.sh)
                     if [ -x "$f" ]; then
                         echo >&3 "$0: Launching $f";
diff --git a/stable/debian/docker-entrypoint.sh b/stable/debian/docker-entrypoint.sh
index 72d5cd9..b8b99e1 100755
--- a/stable/debian/docker-entrypoint.sh
+++ b/stable/debian/docker-entrypoint.sh
@@ -16,6 +16,15 @@ if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
         echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
         find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
             case "$f" in
+                *.envsh)
+                    if [ -x "$f" ]; then
+                        echo >&3 "$0: Sourcing $f";
+                        source "$f"
+                    else
+                        # warn on shell scripts without exec bit
+                        echo >&3 "$0: Ignoring $f, not executable";
+                    fi
+                    ;;
                 *.sh)
                     if [ -x "$f" ]; then
                         echo >&3 "$0: Launching $f";
-- 
GitLab