mirror of
https://github.com/casjaysdevdocker/caddy
synced 2026-06-24 14:01:04 -04:00
🎨 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:
@@ -3,46 +3,37 @@
|
|||||||
##@Version : 202606041215-git
|
##@Version : 202606041215-git
|
||||||
# @@Author : CasjaysDev
|
# @@Author : CasjaysDev
|
||||||
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
||||||
# @@License : MIT
|
# @@License : WTFPL
|
||||||
# @@ReadME :
|
# @@ReadME :
|
||||||
# @@Copyright : Copyright 2023 CasjaysDev
|
# @@Copyright : Copyright: (c) 2023 CasjaysDev
|
||||||
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
||||||
# @@File : 03-files.sh
|
# @@File : 03-files.sh
|
||||||
# @@Description : script to run files
|
# @@Description : script to run files
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329
|
||||||
# shellcheck disable=SC2031
|
|
||||||
# shellcheck disable=SC2120
|
|
||||||
# shellcheck disable=SC2155
|
|
||||||
# shellcheck disable=SC2199
|
|
||||||
# shellcheck disable=SC2317
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# Set bash options
|
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# Set env variables
|
|
||||||
exitCode=0
|
exitCode=0
|
||||||
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# Predefined actions
|
|
||||||
if [ -d "/tmp/bin" ]; then
|
if [ -d "/tmp/bin" ]; then
|
||||||
mkdir -p "/usr/local/bin"
|
\mkdir -p "/usr/local/bin"
|
||||||
for bin in "/tmp/bin"/*; do
|
for bin in "/tmp/bin"/*; do
|
||||||
name="$(basename -- "$bin")"
|
name="${bin##*/}"
|
||||||
echo "Installing $name to /usr/local/bin/$name"
|
echo "Installing $name to /usr/local/bin/$name"
|
||||||
copy "$bin" "/usr/local/bin/$name"
|
copy "$bin" "/usr/local/bin/$name"
|
||||||
chmod -f +x "/usr/local/bin/$name"
|
\chmod -f +x "/usr/local/bin/$name"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
unset bin
|
unset bin
|
||||||
if [ -d "/tmp/var" ]; then
|
if [ -d "/tmp/var" ]; then
|
||||||
for var in "/tmp/var"/*; do
|
for var in "/tmp/var"/*; do
|
||||||
name="$(basename -- "$var")"
|
name="${var##*/}"
|
||||||
echo "Installing $var to /var/$name"
|
echo "Installing $var to /var/$name"
|
||||||
if [ -d "$var" ]; then
|
if [ -d "$var" ]; then
|
||||||
mkdir -p "/var/$name"
|
\mkdir -p "/var/$name"
|
||||||
copy "$var/." "/var/$name/"
|
copy "$var/." "/var/$name/"
|
||||||
else
|
else
|
||||||
copy "$var" "/var/$name"
|
copy "$var" "/var/$name"
|
||||||
@@ -52,10 +43,10 @@ fi
|
|||||||
unset var
|
unset var
|
||||||
if [ -d "/tmp/etc" ]; then
|
if [ -d "/tmp/etc" ]; then
|
||||||
for config in "/tmp/etc"/*; do
|
for config in "/tmp/etc"/*; do
|
||||||
name="$(basename -- "$config")"
|
name="${config##*/}"
|
||||||
echo "Installing $config to /etc/$name"
|
echo "Installing $config to /etc/$name"
|
||||||
if [ -d "$config" ]; then
|
if [ -d "$config" ]; then
|
||||||
mkdir -p "/etc/$name"
|
\mkdir -p "/etc/$name"
|
||||||
copy "$config/." "/etc/$name/"
|
copy "$config/." "/etc/$name/"
|
||||||
else
|
else
|
||||||
copy "$config" "/etc/$name"
|
copy "$config" "/etc/$name"
|
||||||
@@ -65,10 +56,10 @@ fi
|
|||||||
unset config
|
unset config
|
||||||
if [ -d "/tmp/usr" ]; then
|
if [ -d "/tmp/usr" ]; then
|
||||||
for usrpath in "/tmp/usr"/*; do
|
for usrpath in "/tmp/usr"/*; do
|
||||||
name="$(basename -- "$usrpath")"
|
name="${usrpath##*/}"
|
||||||
echo "Installing $usrpath to /usr/$name"
|
echo "Installing $usrpath to /usr/$name"
|
||||||
if [ -d "$usrpath" ]; then
|
if [ -d "$usrpath" ]; then
|
||||||
mkdir -p "/usr/$name"
|
\mkdir -p "/usr/$name"
|
||||||
copy "$usrpath/." "/usr/$name/"
|
copy "$usrpath/." "/usr/$name/"
|
||||||
else
|
else
|
||||||
copy "$usrpath" "/usr/$name"
|
copy "$usrpath" "/usr/$name"
|
||||||
@@ -77,10 +68,7 @@ if [ -d "/tmp/usr" ]; then
|
|||||||
fi
|
fi
|
||||||
unset usrpath
|
unset usrpath
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# Main script
|
exitCode=$?
|
||||||
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
# Set the exit code
|
|
||||||
#exitCode=$?
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
exit $exitCode
|
exit $exitCode
|
||||||
|
# ex: ts=2 sw=2 et filetype=sh
|
||||||
|
|||||||
@@ -22,12 +22,18 @@ done
|
|||||||
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# execute command variables
|
# execute command variables
|
||||||
WORKDIR="" # set working directory
|
# Working directory for the service process
|
||||||
SERVICE_UID="0" # set the user id
|
WORKDIR=""
|
||||||
SERVICE_USER="daemon" # execute command as another user
|
# User ID to run service as
|
||||||
SERVICE_PORT="9000" # port which service is listening on
|
SERVICE_UID="0"
|
||||||
EXEC_CMD_BIN="php-fpm" # command to execute
|
# Execute command as this user
|
||||||
EXEC_CMD_ARGS="--allow-to-run-as-root --nodaemonize --fpm-config /etc/php/php-fpm.conf" # command arguments
|
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
|
# Function to exit appropriately based on context
|
||||||
__script_exit() {
|
__script_exit() {
|
||||||
local exit_code="${1:-0}"
|
local exit_code="${1:-0}"
|
||||||
@@ -40,7 +46,8 @@ __script_exit() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
PRE_EXEC_MESSAGE="" # Show message before execute
|
# Optional message to display before executing the service
|
||||||
|
PRE_EXEC_MESSAGE=""
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# Other variables that are needed
|
# Other variables that are needed
|
||||||
data_dir="/data"
|
data_dir="/data"
|
||||||
@@ -54,32 +61,32 @@ php_user="$SERVICE_USER"
|
|||||||
__update_conf_files() {
|
__update_conf_files() {
|
||||||
echo "Initializing php in $conf_dir"
|
echo "Initializing php in $conf_dir"
|
||||||
if [ -n "$php_bin" ]; then
|
if [ -n "$php_bin" ]; then
|
||||||
[ -d "/data/logs/php" ] || mkdir -p "/data/logs/php"
|
[ -d "/data/logs/php" ] || \mkdir -p "/data/logs/php"
|
||||||
chmod -Rf 777 "$data_dir/logs/php" /var/tmp
|
\chmod -Rf 777 "$data_dir/logs/php" /var/tmp
|
||||||
# Seed /config/php from discovered php etc dir on first start (copy only)
|
# Seed /config/php from discovered php etc dir on first start (copy only)
|
||||||
__init_service_conf "$conf_dir" "$etc_dir"
|
__init_service_conf "$conf_dir" "$etc_dir"
|
||||||
# Symlink /etc/php -> /config/php so /etc always reflects user config
|
# Symlink /etc/php -> /config/php so /etc always reflects user config
|
||||||
if [ ! -L "$etc_dir" ]; then
|
if [ ! -L "$etc_dir" ]; then
|
||||||
rm -rf "$etc_dir"
|
\rm -rf "$etc_dir"
|
||||||
ln -sf "$conf_dir" "$etc_dir"
|
\ln -sf "$conf_dir" "$etc_dir"
|
||||||
fi
|
fi
|
||||||
# Also normalize /etc/php if etc_dir differs (distros vary)
|
# Also normalize /etc/php if etc_dir differs (distros vary)
|
||||||
if [ "$etc_dir" != "/etc/php" ] && [ ! -L "/etc/php" ]; then
|
if [ "$etc_dir" != "/etc/php" ] && [ ! -L "/etc/php" ]; then
|
||||||
ln -sf "$conf_dir" "/etc/php"
|
\ln -sf "$conf_dir" "/etc/php"
|
||||||
fi
|
fi
|
||||||
# Flat /etc/ symlinks so /etc/php.ini, /etc/php-fpm.conf, /etc/php-fpm.d always exist
|
# 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.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.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-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
|
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
|
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|user.*=.*|user = '"$php_user"'|g' "$conf_dir"/*/www.conf
|
||||||
sed -i 's|group.*=.*|group = '"$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
|
\chown -Rf "$php_user" "$conf_dir" "$data_dir/logs/php" /var/tmp
|
||||||
else
|
else
|
||||||
echo "php can not be found"
|
echo "php can not be found"
|
||||||
[ -f "$www_dir/info.php" ] && echo "PHP support is not enabled" >"$www_dir/info.php"
|
[ -f "$www_dir/info.php" ] && echo "PHP support is not enabled" >"$www_dir/info.php"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
|
# 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
|
[ "$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"
|
export PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
|
||||||
@@ -23,11 +23,16 @@ done
|
|||||||
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# execute command variables
|
# execute command variables
|
||||||
WORKDIR="" # set working directory
|
# Working directory for the service process
|
||||||
SERVICE_UID="0" # set the user id
|
WORKDIR=""
|
||||||
SERVICE_USER="root" # execute command as another user
|
# User ID to run service as
|
||||||
SERVICE_PORT="" # port which service is listening on
|
SERVICE_UID="0"
|
||||||
EXEC_CMD_BIN="caddy" # command to execute
|
# 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
|
# Function to exit appropriately based on context
|
||||||
__script_exit() {
|
__script_exit() {
|
||||||
local exit_code="${1:-0}"
|
local exit_code="${1:-0}"
|
||||||
@@ -40,8 +45,10 @@ __script_exit() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
EXEC_CMD_ARGS="run --config /etc/caddy/Caddyfile" # command arguments
|
# Arguments to pass to caddy
|
||||||
PRE_EXEC_MESSAGE="" # Show message before execute
|
EXEC_CMD_ARGS="run --config /etc/caddy/Caddyfile"
|
||||||
|
# Optional message to display before executing the service
|
||||||
|
PRE_EXEC_MESSAGE=""
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
# Other variables that are needed
|
# Other variables that are needed
|
||||||
etc_dir="/etc/caddy"
|
etc_dir="/etc/caddy"
|
||||||
@@ -56,20 +63,20 @@ __update_conf_files() {
|
|||||||
__init_service_conf "$conf_dir" "$etc_dir"
|
__init_service_conf "$conf_dir" "$etc_dir"
|
||||||
# Symlink /etc/caddy -> /config/caddy so /etc always reflects user config
|
# Symlink /etc/caddy -> /config/caddy so /etc always reflects user config
|
||||||
if [ ! -L "$etc_dir" ]; then
|
if [ ! -L "$etc_dir" ]; then
|
||||||
rm -rf "$etc_dir"
|
\rm -rf "$etc_dir"
|
||||||
ln -sf "$conf_dir" "$etc_dir"
|
\ln -sf "$conf_dir" "$etc_dir"
|
||||||
fi
|
fi
|
||||||
#
|
#
|
||||||
[ -d "/data/logs/caddy" ] || mkdir -p "/data/logs/caddy"
|
[ -d "/data/logs/caddy" ] || \mkdir -p "/data/logs/caddy"
|
||||||
chmod -Rf 777 "/data/logs/caddy"
|
\chmod -Rf 777 "/data/logs/caddy"
|
||||||
#
|
#
|
||||||
# Seed web root from baked-in share on first start
|
# Seed web root from baked-in share on first start
|
||||||
local share_htdocs="/usr/local/share/caddy/htdocs"
|
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
|
if [ -d "$share_htdocs" ] && __is_dir_empty "$www_dir"; then
|
||||||
cp -Rf "$share_htdocs/." "$www_dir/"
|
\cp -Rf "$share_htdocs/." "$www_dir/"
|
||||||
fi
|
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.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"
|
[ -f "$www_dir/www/health/index.json" ] || echo '{ "status": "ok" }' >"$www_dir/www/health/index.json"
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user