From f4df3572d5e2fd7cf1698522abcc260a5acdca88 Mon Sep 17 00:00:00 2001 From: casjay Date: Tue, 26 May 2026 18:25:35 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20printf=20%q=20empty-var=20?= =?UTF-8?q?bug;=20sync=20Dockerfile;=20update=20README=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three fixes in this commit: 1. printf '%q' empty-variable bug — all 7 init.d service scripts: printf '%q ' $su_exec/\$args/\$extra_env with an unset/empty variable calls printf with no vararg, causing bash to format the empty string as '' (two single-quotes), which gets written into the generated exec script and makes the container fail to start. Fixed with ${var:+...} parameter expansion so an empty variable produces an empty string. 2. Dockerfile — sync to template 202605261603 (structural changes: blank line after $SHELL_OPTS in apk-repos block, un-indented echo "" in Custom Settings and Custom Applications stubs); preserve all tor-specific values (IMAGE_NAME, PHP_SERVER, BUILD_DATE, SERVICE_PORT, EXPOSE_PORTS, PHP_VERSION, IMAGE_REPO, CONTAINER_VERSION, PULL_URL, PACK_LIST, HOSTNAME, OCI labels). 3. README.md — add the full EXPOSE_PORTS list to the docker run command and docker-compose ports section (privoxy 8118, SOCKS5 9050, DNS 9053 TCP+UDP, web 9080, bridge range 57000-57007). - Dockerfile: sync structural template changes; update BUILD_DATE to 202605261603 - README.md: add -p 8118:8118 9050:9050 9053:9053 9053/udp 9080:9080 57000-57007 ports - rootfs/usr/local/etc/docker/init.d/01-tor-server.sh: fix _q_su/_q_args/_q_extra printf %q guard - rootfs/usr/local/etc/docker/init.d/02-tor-bridge.sh: fix _q_su/_q_args/_q_extra printf %q guard - rootfs/usr/local/etc/docker/init.d/03-tor-relay.sh: fix _q_su/_q_args/_q_extra printf %q guard - rootfs/usr/local/etc/docker/init.d/04-tor-exit.sh: fix _q_su/_q_args/_q_extra printf %q guard - rootfs/usr/local/etc/docker/init.d/09-unbound.sh: fix _q_su/_q_args/_q_extra printf %q guard - rootfs/usr/local/etc/docker/init.d/98-privoxy.sh: fix _q_su/_q_args/_q_extra printf %q guard - rootfs/usr/local/etc/docker/init.d/zz-nginx.sh: fix _q_su/_q_args/_q_extra printf %q guard Dockerfile README.md rootfs/usr/local/etc/docker/init.d/01-tor-server.sh rootfs/usr/local/etc/docker/init.d/02-tor-bridge.sh rootfs/usr/local/etc/docker/init.d/03-tor-relay.sh rootfs/usr/local/etc/docker/init.d/04-tor-exit.sh rootfs/usr/local/etc/docker/init.d/09-unbound.sh rootfs/usr/local/etc/docker/init.d/98-privoxy.sh rootfs/usr/local/etc/docker/init.d/zz-nginx.sh --- Dockerfile | 7 ++++--- README.md | 12 ++++++++++++ rootfs/usr/local/etc/docker/init.d/01-tor-server.sh | 10 +++++----- rootfs/usr/local/etc/docker/init.d/02-tor-bridge.sh | 10 +++++----- rootfs/usr/local/etc/docker/init.d/03-tor-relay.sh | 10 +++++----- rootfs/usr/local/etc/docker/init.d/04-tor-exit.sh | 10 +++++----- rootfs/usr/local/etc/docker/init.d/09-unbound.sh | 10 +++++----- rootfs/usr/local/etc/docker/init.d/98-privoxy.sh | 10 +++++----- rootfs/usr/local/etc/docker/init.d/zz-nginx.sh | 10 +++++----- 9 files changed, 51 insertions(+), 38 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1ec4edb..c778c45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Docker image for tor using the alpine template ARG IMAGE_NAME="tor" ARG PHP_SERVER="tor" -ARG BUILD_DATE="202510220838" +ARG BUILD_DATE="202605261603" ARG LANGUAGE="en_US.UTF-8" ARG TIMEZONE="America/New_York" ARG WWW_ROOT_DIR="/usr/local/share/httpd/default" @@ -97,6 +97,7 @@ RUN echo "Initializing the system"; \ RUN echo "Creating and editing system files "; \ $SHELL_OPTS; \ + rm -Rf "/etc/apk/repositories"; \ [ "$DISTRO_VERSION" = "latest" ] && DISTRO_VERSION="edge";[ "$DISTRO_VERSION" = "edge" ] || DISTRO_VERSION="v${DISTRO_VERSION}"; \ echo "http://dl-cdn.alpinelinux.org/alpine/${DISTRO_VERSION}/main" >>"/etc/apk/repositories"; \ @@ -146,7 +147,7 @@ RUN echo "Updating system files "; \ RUN echo "Custom Settings"; \ $SHELL_OPTS; \ - echo "" +echo "" RUN echo "Setting up users and scripts "; \ $SHELL_OPTS; \ @@ -163,7 +164,7 @@ RUN echo "Setting OS Settings "; \ RUN echo "Custom Applications"; \ $SHELL_OPTS; \ - echo "" +echo "" RUN echo "Running custom commands"; \ if [ -f "/root/docker/setup/05-custom.sh" ];then echo "Running the custom script";/root/docker/setup/05-custom.sh||{ echo "Failed to execute /root/docker/setup/05-custom.sh" && exit 10; };echo "Done running the custom script";fi; \ diff --git a/README.md b/README.md index 5488c9f..fa20ff3 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,12 @@ docker run -d \ -v "$dockerHome/data:/data:z" \ -v "$dockerHome/config:/config:z" \ -p 80:80 \ +-p 8118:8118 \ +-p 9050:9050 \ +-p 9053:9053 \ +-p 9053:9053/udp \ +-p 9080:9080 \ +-p 57000-57007:57000-57007 \ casjaysdevdocker/tor:latest ``` @@ -50,6 +56,12 @@ services: - "/var/lib/srv/$USER/docker/casjaysdevdocker/tor/latest/volumes/config:/config:z" ports: - 80:80 + - 8118:8118 + - 9050:9050 + - 9053:9053 + - 9053:9053/udp + - 9080:9080 + - 57000-57007:57000-57007 restart: always ``` diff --git a/rootfs/usr/local/etc/docker/init.d/01-tor-server.sh b/rootfs/usr/local/etc/docker/init.d/01-tor-server.sh index 3a7ccfb..0a3eb5d 100755 --- a/rootfs/usr/local/etc/docker/init.d/01-tor-server.sh +++ b/rootfs/usr/local/etc/docker/init.d/01-tor-server.sh @@ -704,10 +704,10 @@ __run_start_script() { _q_path=$(printf '%q' "$path") _q_sysname=$(printf '%q' "$sysname") _q_svcuser=$(printf '%q' "${SERVICE_USER:-$RUNAS_USER}") - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) - _q_extra=$(printf '%q ' $extra_env) + _q_args=${args:+$(printf '%q ' $args)} + _q_extra=${extra_env:+$(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" @@ -736,9 +736,9 @@ __run_start_script() { else if [ ! -f "$START_SCRIPT" ]; then local _q_su _q_cmd _q_args - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) + _q_args=${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" diff --git a/rootfs/usr/local/etc/docker/init.d/02-tor-bridge.sh b/rootfs/usr/local/etc/docker/init.d/02-tor-bridge.sh index b78897c..b5ce539 100755 --- a/rootfs/usr/local/etc/docker/init.d/02-tor-bridge.sh +++ b/rootfs/usr/local/etc/docker/init.d/02-tor-bridge.sh @@ -630,10 +630,10 @@ __run_start_script() { _q_path=$(printf '%q' "$path") _q_sysname=$(printf '%q' "$sysname") _q_svcuser=$(printf '%q' "${SERVICE_USER:-$RUNAS_USER}") - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) - _q_extra=$(printf '%q ' $extra_env) + _q_args=${args:+$(printf '%q ' $args)} + _q_extra=${extra_env:+$(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" @@ -662,9 +662,9 @@ __run_start_script() { else if [ ! -f "$START_SCRIPT" ]; then local _q_su _q_cmd _q_args - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) + _q_args=${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" diff --git a/rootfs/usr/local/etc/docker/init.d/03-tor-relay.sh b/rootfs/usr/local/etc/docker/init.d/03-tor-relay.sh index 35ca204..b9c6be4 100755 --- a/rootfs/usr/local/etc/docker/init.d/03-tor-relay.sh +++ b/rootfs/usr/local/etc/docker/init.d/03-tor-relay.sh @@ -636,10 +636,10 @@ __run_start_script() { _q_path=$(printf '%q' "$path") _q_sysname=$(printf '%q' "$sysname") _q_svcuser=$(printf '%q' "${SERVICE_USER:-$RUNAS_USER}") - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) - _q_extra=$(printf '%q ' $extra_env) + _q_args=${args:+$(printf '%q ' $args)} + _q_extra=${extra_env:+$(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" @@ -668,9 +668,9 @@ __run_start_script() { else if [ ! -f "$START_SCRIPT" ]; then local _q_su _q_cmd _q_args - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) + _q_args=${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" diff --git a/rootfs/usr/local/etc/docker/init.d/04-tor-exit.sh b/rootfs/usr/local/etc/docker/init.d/04-tor-exit.sh index b055a99..75ae4f1 100755 --- a/rootfs/usr/local/etc/docker/init.d/04-tor-exit.sh +++ b/rootfs/usr/local/etc/docker/init.d/04-tor-exit.sh @@ -681,10 +681,10 @@ __run_start_script() { _q_path=$(printf '%q' "$path") _q_sysname=$(printf '%q' "$sysname") _q_svcuser=$(printf '%q' "${SERVICE_USER:-$RUNAS_USER}") - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) - _q_extra=$(printf '%q ' $extra_env) + _q_args=${args:+$(printf '%q ' $args)} + _q_extra=${extra_env:+$(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" @@ -713,9 +713,9 @@ __run_start_script() { else if [ ! -f "$START_SCRIPT" ]; then local _q_su _q_cmd _q_args - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) + _q_args=${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" diff --git a/rootfs/usr/local/etc/docker/init.d/09-unbound.sh b/rootfs/usr/local/etc/docker/init.d/09-unbound.sh index e965529..f5f0dd1 100755 --- a/rootfs/usr/local/etc/docker/init.d/09-unbound.sh +++ b/rootfs/usr/local/etc/docker/init.d/09-unbound.sh @@ -550,10 +550,10 @@ __run_start_script() { _q_path=$(printf '%q' "$path") _q_sysname=$(printf '%q' "$sysname") _q_svcuser=$(printf '%q' "${SERVICE_USER:-$RUNAS_USER}") - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) - _q_extra=$(printf '%q ' $extra_env) + _q_args=${args:+$(printf '%q ' $args)} + _q_extra=${extra_env:+$(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" @@ -582,9 +582,9 @@ __run_start_script() { else if [ ! -f "$START_SCRIPT" ]; then local _q_su _q_cmd _q_args - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) + _q_args=${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" diff --git a/rootfs/usr/local/etc/docker/init.d/98-privoxy.sh b/rootfs/usr/local/etc/docker/init.d/98-privoxy.sh index d7b4361..872547a 100755 --- a/rootfs/usr/local/etc/docker/init.d/98-privoxy.sh +++ b/rootfs/usr/local/etc/docker/init.d/98-privoxy.sh @@ -550,10 +550,10 @@ __run_start_script() { _q_path=$(printf '%q' "$path") _q_sysname=$(printf '%q' "$sysname") _q_svcuser=$(printf '%q' "${SERVICE_USER:-$RUNAS_USER}") - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) - _q_extra=$(printf '%q ' $extra_env) + _q_args=${args:+$(printf '%q ' $args)} + _q_extra=${extra_env:+$(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" @@ -582,9 +582,9 @@ __run_start_script() { else if [ ! -f "$START_SCRIPT" ]; then local _q_su _q_cmd _q_args - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) + _q_args=${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" diff --git a/rootfs/usr/local/etc/docker/init.d/zz-nginx.sh b/rootfs/usr/local/etc/docker/init.d/zz-nginx.sh index 3ae32e9..d40e326 100755 --- a/rootfs/usr/local/etc/docker/init.d/zz-nginx.sh +++ b/rootfs/usr/local/etc/docker/init.d/zz-nginx.sh @@ -605,10 +605,10 @@ __run_start_script() { _q_path=$(printf '%q' "$path") _q_sysname=$(printf '%q' "$sysname") _q_svcuser=$(printf '%q' "${SERVICE_USER:-$RUNAS_USER}") - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) - _q_extra=$(printf '%q ' $extra_env) + _q_args=${args:+$(printf '%q ' $args)} + _q_extra=${extra_env:+$(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" @@ -637,9 +637,9 @@ __run_start_script() { else if [ ! -f "$START_SCRIPT" ]; then local _q_su _q_cmd _q_args - _q_su=$(printf '%q ' $su_exec) + _q_su=${su_exec:+$(printf '%q ' $su_exec)} _q_cmd=$(printf '%q' "$cmd") - _q_args=$(printf '%q ' $args) + _q_args=${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"