🎨 Apply script conventions to caddy setup and init.d scripts 🎨

Fix violations of script_conventions.md in the three scripts edited
during the /config/ architecture migration.
- rootfs/root/docker/setup/03-files.sh: collapse multiple shellcheck disable lines into single canonical line; remove commented-out exitCode line; add
This commit is contained in:
2026-06-04 12:59:46 -04:00
parent a31c2542bd
commit f319a21ab9
3 changed files with 63 additions and 61 deletions
@@ -22,12 +22,18 @@ done
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# execute command variables
WORKDIR="" # set working directory
SERVICE_UID="0" # set the user id
SERVICE_USER="daemon" # execute command as another user
SERVICE_PORT="9000" # port which service is listening on
EXEC_CMD_BIN="php-fpm" # command to execute
EXEC_CMD_ARGS="--allow-to-run-as-root --nodaemonize --fpm-config /etc/php/php-fpm.conf" # command arguments
# Working directory for the service process
WORKDIR=""
# User ID to run service as
SERVICE_UID="0"
# Execute command as this user
SERVICE_USER="daemon"
# Port the service listens on
SERVICE_PORT="9000"
# Binary to execute
EXEC_CMD_BIN="php-fpm"
# Arguments to pass to php-fpm
EXEC_CMD_ARGS="--allow-to-run-as-root --nodaemonize --fpm-config /etc/php/php-fpm.conf"
# Function to exit appropriately based on context
__script_exit() {
local exit_code="${1:-0}"
@@ -40,7 +46,8 @@ __script_exit() {
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PRE_EXEC_MESSAGE="" # Show message before execute
# Optional message to display before executing the service
PRE_EXEC_MESSAGE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Other variables that are needed
data_dir="/data"
@@ -54,32 +61,32 @@ php_user="$SERVICE_USER"
__update_conf_files() {
echo "Initializing php in $conf_dir"
if [ -n "$php_bin" ]; then
[ -d "/data/logs/php" ] || mkdir -p "/data/logs/php"
chmod -Rf 777 "$data_dir/logs/php" /var/tmp
[ -d "/data/logs/php" ] || \mkdir -p "/data/logs/php"
\chmod -Rf 777 "$data_dir/logs/php" /var/tmp
# Seed /config/php from discovered php etc dir on first start (copy only)
__init_service_conf "$conf_dir" "$etc_dir"
# Symlink /etc/php -> /config/php so /etc always reflects user config
if [ ! -L "$etc_dir" ]; then
rm -rf "$etc_dir"
ln -sf "$conf_dir" "$etc_dir"
\rm -rf "$etc_dir"
\ln -sf "$conf_dir" "$etc_dir"
fi
# Also normalize /etc/php if etc_dir differs (distros vary)
if [ "$etc_dir" != "/etc/php" ] && [ ! -L "/etc/php" ]; then
ln -sf "$conf_dir" "/etc/php"
\ln -sf "$conf_dir" "/etc/php"
fi
# Flat /etc/ symlinks so /etc/php.ini, /etc/php-fpm.conf, /etc/php-fpm.d always exist
[ -L "/etc/php.ini" ] || [ -e "/etc/php.ini" ] || ln -sf "/etc/php/php.ini" "/etc/php.ini"
[ -L "/etc/php-fpm.conf" ] || [ -e "/etc/php-fpm.conf" ] || ln -sf "/etc/php/php-fpm.conf" "/etc/php-fpm.conf"
[ -L "/etc/php-fpm.d" ] || [ -e "/etc/php-fpm.d" ] || ln -sf "/etc/php/php-fpm.d" "/etc/php-fpm.d"
[ -L "/etc/php.ini" ] || [ -e "/etc/php.ini" ] || \ln -sf "/etc/php/php.ini" "/etc/php.ini"
[ -L "/etc/php-fpm.conf" ] || [ -e "/etc/php-fpm.conf" ] || \ln -sf "/etc/php/php-fpm.conf" "/etc/php-fpm.conf"
[ -L "/etc/php-fpm.d" ] || [ -e "/etc/php-fpm.d" ] || \ln -sf "/etc/php/php-fpm.d" "/etc/php-fpm.d"
#
if [ -f "$www_dir/www/index.html" ] && [ -f "$www_dir/www/index.php" ]; then
rm -Rf "$www_dir/www/index.html"
\rm -Rf "$www_dir/www/index.html"
fi
chmod -Rf 777 "/data/logs/php"
\chmod -Rf 777 "/data/logs/php"
#
sed -i 's|user.*=.*|user = '"$php_user"'|g' "$conf_dir"/*/www.conf
sed -i 's|group.*=.*|group = '"$php_user"'|g' "$conf_dir"/*/www.conf
chown -Rf "$php_user" "$conf_dir" "$data_dir/logs/php" /var/tmp
\sed -i 's|user.*=.*|user = '"$php_user"'|g' "$conf_dir"/*/www.conf
\sed -i 's|group.*=.*|group = '"$php_user"'|g' "$conf_dir"/*/www.conf
\chown -Rf "$php_user" "$conf_dir" "$data_dir/logs/php" /var/tmp
else
echo "php can not be found"
[ -f "$www_dir/info.php" ] && echo "PHP support is not enabled" >"$www_dir/info.php"
+22 -15
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
SCRIPT_NAME="$(basename "$0" 2>/dev/null)"
SCRIPT_NAME="${0##*/}"
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -o pipefail -x$DEBUGGER_OPTIONS || set -o pipefail
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
@@ -23,11 +23,16 @@ done
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# execute command variables
WORKDIR="" # set working directory
SERVICE_UID="0" # set the user id
SERVICE_USER="root" # execute command as another user
SERVICE_PORT="" # port which service is listening on
EXEC_CMD_BIN="caddy" # command to execute
# Working directory for the service process
WORKDIR=""
# User ID to run service as
SERVICE_UID="0"
# Execute command as this user
SERVICE_USER="root"
# Port the service listens on
SERVICE_PORT=""
# Binary to execute
EXEC_CMD_BIN="caddy"
# Function to exit appropriately based on context
__script_exit() {
local exit_code="${1:-0}"
@@ -40,8 +45,10 @@ __script_exit() {
fi
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EXEC_CMD_ARGS="run --config /etc/caddy/Caddyfile" # command arguments
PRE_EXEC_MESSAGE="" # Show message before execute
# Arguments to pass to caddy
EXEC_CMD_ARGS="run --config /etc/caddy/Caddyfile"
# Optional message to display before executing the service
PRE_EXEC_MESSAGE=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Other variables that are needed
etc_dir="/etc/caddy"
@@ -56,20 +63,20 @@ __update_conf_files() {
__init_service_conf "$conf_dir" "$etc_dir"
# Symlink /etc/caddy -> /config/caddy so /etc always reflects user config
if [ ! -L "$etc_dir" ]; then
rm -rf "$etc_dir"
ln -sf "$conf_dir" "$etc_dir"
\rm -rf "$etc_dir"
\ln -sf "$conf_dir" "$etc_dir"
fi
#
[ -d "/data/logs/caddy" ] || mkdir -p "/data/logs/caddy"
chmod -Rf 777 "/data/logs/caddy"
[ -d "/data/logs/caddy" ] || \mkdir -p "/data/logs/caddy"
\chmod -Rf 777 "/data/logs/caddy"
#
# Seed web root from baked-in share on first start
local share_htdocs="/usr/local/share/caddy/htdocs"
[ -d "$www_dir" ] || mkdir -p "$www_dir"
[ -d "$www_dir" ] || \mkdir -p "$www_dir"
if [ -d "$share_htdocs" ] && __is_dir_empty "$www_dir"; then
cp -Rf "$share_htdocs/." "$www_dir/"
\cp -Rf "$share_htdocs/." "$www_dir/"
fi
[ -d "$www_dir/www/health" ] || mkdir -p "$www_dir/www/health"
[ -d "$www_dir/www/health" ] || \mkdir -p "$www_dir/www/health"
[ -f "$www_dir/www/health/index.txt" ] || echo 'ok' >"$www_dir/www/health/index.txt"
[ -f "$www_dir/www/health/index.json" ] || echo '{ "status": "ok" }' >"$www_dir/www/health/index.json"
#