From edc1b4ba3908ff0068101f5be0bac7a58449fdff Mon Sep 17 00:00:00 2001 From: TheSpad Date: Fri, 2 Sep 2022 09:54:03 +0100 Subject: [PATCH 1/5] Fix custom service logic --- root/docker-mods | 51 ++++++++++++++++++++++++++ root/etc/cont-init.d/99-custom-scripts | 51 -------------------------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/root/docker-mods b/root/docker-mods index ead588e..3964dd3 100755 --- a/root/docker-mods +++ b/root/docker-mods @@ -9,6 +9,57 @@ set_legacy_executable_bits() { } set_legacy_executable_bits +# Remove all existing custom services before continuing to ensure +# we aren't running anything the user may have removed +if [[ -n "$(/bin/ls -A /etc/s6-overlay/s6-rc.d/custom-svc-* 2>/dev/null)" ]]; then + echo "[custom-init] removing existing custom services..." + rm -rf /etc/s6-overlay/s6-rc.d/custom-svc-* +fi + +if [[ -z "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]] && + [[ -z "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]]; then + echo "[custom-init] no custom services found, skipping..." +else +# Make sure custom service directory exists and has files in it +if [[ -e "${SERVICES_DIR}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]]; then + echo "[custom-init] service files found in ${SERVICES_DIR}" + for SERVICE in "${SERVICES_DIR}"/*; do + NAME="$(basename "${SERVICE}")" + if [[ -f "${SERVICE}" ]]; then + echo "[custom-init] ${NAME}: service detected, copying..." + mkdir -p /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/ + cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run + chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run + echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type + touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services + touch /etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/custom-svc-"${NAME}" + echo "[custom-init] ${NAME}: copied" + elif [[ ! -f "${SERVICE}" ]]; then + echo "[custom-init] ${NAME}: is not a file" + fi + done +fi + +if [[ -e "${SERVICES_DIR_OLD}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]]; then + echo "[custom-init] service files found in ${SERVICES_DIR_OLD}" + for SERVICE in "${SERVICES_DIR_OLD}"/*; do + NAME="$(basename "${SERVICE}")" + if [[ -f "${SERVICE}" ]]; then + echo "[custom-init] ${NAME}: service detected, copying..." + mkdir -p /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/ + cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run + chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run + echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type + touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services + touch /etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/custom-svc-"${NAME}" + echo "[custom-init] ${NAME}: copied" + elif [[ ! -f "${SERVICE}" ]]; then + echo "[custom-init] ${NAME}: is not a file" + fi + done +fi +fi + # Exit if mods is not set if [ -z ${DOCKER_MODS+x} ]; then exit 0 diff --git a/root/etc/cont-init.d/99-custom-scripts b/root/etc/cont-init.d/99-custom-scripts index bd821aa..7033953 100755 --- a/root/etc/cont-init.d/99-custom-scripts +++ b/root/etc/cont-init.d/99-custom-scripts @@ -7,57 +7,6 @@ SERVICES_DIR_OLD="/config/custom-services.d" SCRIPTS_DIR="/custom-cont-init.d" SERVICES_DIR="/custom-services.d" -# Remove all existing custom services before continuing to ensure -# we aren't running anything the user may have removed -if [[ -n "$(/bin/ls -A /etc/s6-overlay/s6-rc.d/custom-svc-* 2>/dev/null)" ]]; then - echo "[custom-init] removing existing custom services..." - rm -rf /etc/s6-overlay/s6-rc.d/custom-svc-* -fi - -if [[ -z "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]] && - [[ -z "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]]; then - echo "[custom-init] no custom services found, skipping..." -else - # Make sure custom service directory exists and has files in it - if [[ -e "${SERVICES_DIR}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]]; then - echo "[custom-init] service files found in ${SERVICES_DIR}" - for SERVICE in "${SERVICES_DIR}"/*; do - NAME="$(basename "${SERVICE}")" - if [[ -f "${SERVICE}" ]]; then - echo "[custom-init] ${NAME}: service detected, copying..." - mkdir -p /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/ - cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run - chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run - echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type - touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services - touch /etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/custom-svc-"${NAME}" - echo "[custom-init] ${NAME}: copied" - elif [[ ! -f "${SERVICE}" ]]; then - echo "[custom-init] ${NAME}: is not a file" - fi - done - fi - - if [[ -e "${SERVICES_DIR_OLD}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]]; then - echo "[custom-init] service files found in ${SERVICES_DIR_OLD}" - for SERVICE in "${SERVICES_DIR_OLD}"/*; do - NAME="$(basename "${SERVICE}")" - if [[ -f "${SERVICE}" ]]; then - echo "[custom-init] ${NAME}: service detected, copying..." - mkdir -p /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/ - cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run - chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run - echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type - touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services - touch /etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/custom-svc-"${NAME}" - echo "[custom-init] ${NAME}: copied" - elif [[ ! -f "${SERVICE}" ]]; then - echo "[custom-init] ${NAME}: is not a file" - fi - done - fi -fi - if [[ -z "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]] && [[ -z "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev/null)" ]]; then echo "[custom-init] no custom files found, skipping..." From f9f4903738e778b02055a46247b06b8a6e83e292 Mon Sep 17 00:00:00 2001 From: TheSpad Date: Fri, 2 Sep 2022 09:56:14 +0100 Subject: [PATCH 2/5] Include paths --- root/docker-mods | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/root/docker-mods b/root/docker-mods index 3964dd3..e4310bc 100755 --- a/root/docker-mods +++ b/root/docker-mods @@ -9,6 +9,10 @@ set_legacy_executable_bits() { } set_legacy_executable_bits +# Directories +SERVICES_DIR_OLD="/config/custom-services.d" +SERVICES_DIR="/custom-services.d" + # Remove all existing custom services before continuing to ensure # we aren't running anything the user may have removed if [[ -n "$(/bin/ls -A /etc/s6-overlay/s6-rc.d/custom-svc-* 2>/dev/null)" ]]; then From 4f4d9e38001c08ac4d0fae24d8879129ce89921e Mon Sep 17 00:00:00 2001 From: TheSpad Date: Fri, 2 Sep 2022 10:03:46 +0100 Subject: [PATCH 3/5] Fix script tee --- root/etc/cont-init.d/99-custom-scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/etc/cont-init.d/99-custom-scripts b/root/etc/cont-init.d/99-custom-scripts index 7033953..e800ea4 100755 --- a/root/etc/cont-init.d/99-custom-scripts +++ b/root/etc/cont-init.d/99-custom-scripts @@ -43,7 +43,7 @@ fi if [[ -n "$(/bin/ls -A "${SCRIPTS_DIR_OLD}" 2>/dev/null)" ]] || [[ -n "$(/bin/ls -A "${SERVICES_DIR_OLD}" 2>/dev/null)" ]]; then - cat <<-EOF | tee ${SCRIPTS_DIR_OLD}/README.txt,${SERVICES_DIR_OLD}/README.txt 2>/dev/null + cat << EOF | tee {${SCRIPTS_DIR_OLD}/README.txt,${SERVICES_DIR_OLD}/README.txt} 2>/dev/null ******************************************************** ******************************************************** * * From f8af24ed90b8df55567f46ce1baef089854fe473 Mon Sep 17 00:00:00 2001 From: TheSpad Date: Fri, 2 Sep 2022 10:37:36 +0100 Subject: [PATCH 4/5] Remove circular dep --- root/docker-mods | 3 --- 1 file changed, 3 deletions(-) diff --git a/root/docker-mods b/root/docker-mods index e4310bc..90ebeec 100755 --- a/root/docker-mods +++ b/root/docker-mods @@ -9,7 +9,6 @@ set_legacy_executable_bits() { } set_legacy_executable_bits -# Directories SERVICES_DIR_OLD="/config/custom-services.d" SERVICES_DIR="/custom-services.d" @@ -36,7 +35,6 @@ if [[ -e "${SERVICES_DIR}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services - touch /etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/custom-svc-"${NAME}" echo "[custom-init] ${NAME}: copied" elif [[ ! -f "${SERVICE}" ]]; then echo "[custom-init] ${NAME}: is not a file" @@ -55,7 +53,6 @@ if [[ -e "${SERVICES_DIR_OLD}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/ chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services - touch /etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/custom-svc-"${NAME}" echo "[custom-init] ${NAME}: copied" elif [[ ! -f "${SERVICE}" ]]; then echo "[custom-init] ${NAME}: is not a file" From e5eae41cea8368e441ee9794eb3368e81cb78b13 Mon Sep 17 00:00:00 2001 From: TheSpad Date: Fri, 2 Sep 2022 11:12:22 +0100 Subject: [PATCH 5/5] Fix formatting --- root/docker-mods | 72 ++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/root/docker-mods b/root/docker-mods index 90ebeec..cada155 100755 --- a/root/docker-mods +++ b/root/docker-mods @@ -23,42 +23,42 @@ if [[ -z "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]] && [[ -z "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]]; then echo "[custom-init] no custom services found, skipping..." else -# Make sure custom service directory exists and has files in it -if [[ -e "${SERVICES_DIR}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]]; then - echo "[custom-init] service files found in ${SERVICES_DIR}" - for SERVICE in "${SERVICES_DIR}"/*; do - NAME="$(basename "${SERVICE}")" - if [[ -f "${SERVICE}" ]]; then - echo "[custom-init] ${NAME}: service detected, copying..." - mkdir -p /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/ - cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run - chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run - echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type - touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services - echo "[custom-init] ${NAME}: copied" - elif [[ ! -f "${SERVICE}" ]]; then - echo "[custom-init] ${NAME}: is not a file" - fi - done -fi + # Make sure custom service directory exists and has files in it + if [[ -e "${SERVICES_DIR}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]]; then + echo "[custom-init] service files found in ${SERVICES_DIR}" + for SERVICE in "${SERVICES_DIR}"/*; do + NAME="$(basename "${SERVICE}")" + if [[ -f "${SERVICE}" ]]; then + echo "[custom-init] ${NAME}: service detected, copying..." + mkdir -p /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/ + cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run + chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run + echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type + touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services + echo "[custom-init] ${NAME}: copied" + elif [[ ! -f "${SERVICE}" ]]; then + echo "[custom-init] ${NAME}: is not a file" + fi + done + fi -if [[ -e "${SERVICES_DIR_OLD}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]]; then - echo "[custom-init] service files found in ${SERVICES_DIR_OLD}" - for SERVICE in "${SERVICES_DIR_OLD}"/*; do - NAME="$(basename "${SERVICE}")" - if [[ -f "${SERVICE}" ]]; then - echo "[custom-init] ${NAME}: service detected, copying..." - mkdir -p /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/ - cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run - chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run - echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type - touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services - echo "[custom-init] ${NAME}: copied" - elif [[ ! -f "${SERVICE}" ]]; then - echo "[custom-init] ${NAME}: is not a file" - fi - done -fi + if [[ -e "${SERVICES_DIR_OLD}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]]; then + echo "[custom-init] service files found in ${SERVICES_DIR_OLD}" + for SERVICE in "${SERVICES_DIR_OLD}"/*; do + NAME="$(basename "${SERVICE}")" + if [[ -f "${SERVICE}" ]]; then + echo "[custom-init] ${NAME}: service detected, copying..." + mkdir -p /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/ + cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run + chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run + echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type + touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services + echo "[custom-init] ${NAME}: copied" + elif [[ ! -f "${SERVICE}" ]]; then + echo "[custom-init] ${NAME}: is not a file" + fi + done + fi fi # Exit if mods is not set @@ -70,7 +70,7 @@ fi if [ ! -f /usr/bin/curl ] || [ ! -f /usr/bin/jq ]; then echo "[mod-init] Curl/JQ was not found on this system for Docker mods installing" if [ -f /usr/bin/apt ]; then - ## Ubuntu + # Ubuntu apt-get update apt-get install --no-install-recommends -y \ curl \