mirror of
https://github.com/casjaysdevdocker/caddy
synced 2026-06-24 08:01:08 -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
|
||||
# @@Author : CasjaysDev
|
||||
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
||||
# @@License : MIT
|
||||
# @@License : WTFPL
|
||||
# @@ReadME :
|
||||
# @@Copyright : Copyright 2023 CasjaysDev
|
||||
# @@Copyright : Copyright: (c) 2023 CasjaysDev
|
||||
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
||||
# @@File : 03-files.sh
|
||||
# @@Description : script to run files
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2016
|
||||
# shellcheck disable=SC2031
|
||||
# shellcheck disable=SC2120
|
||||
# shellcheck disable=SC2155
|
||||
# shellcheck disable=SC2199
|
||||
# shellcheck disable=SC2317
|
||||
# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
set -o pipefail
|
||||
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set env variables
|
||||
exitCode=0
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Predefined actions
|
||||
if [ -d "/tmp/bin" ]; then
|
||||
mkdir -p "/usr/local/bin"
|
||||
\mkdir -p "/usr/local/bin"
|
||||
for bin in "/tmp/bin"/*; do
|
||||
name="$(basename -- "$bin")"
|
||||
name="${bin##*/}"
|
||||
echo "Installing $name to /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
|
||||
fi
|
||||
unset bin
|
||||
if [ -d "/tmp/var" ]; then
|
||||
for var in "/tmp/var"/*; do
|
||||
name="$(basename -- "$var")"
|
||||
name="${var##*/}"
|
||||
echo "Installing $var to /var/$name"
|
||||
if [ -d "$var" ]; then
|
||||
mkdir -p "/var/$name"
|
||||
\mkdir -p "/var/$name"
|
||||
copy "$var/." "/var/$name/"
|
||||
else
|
||||
copy "$var" "/var/$name"
|
||||
@@ -52,10 +43,10 @@ fi
|
||||
unset var
|
||||
if [ -d "/tmp/etc" ]; then
|
||||
for config in "/tmp/etc"/*; do
|
||||
name="$(basename -- "$config")"
|
||||
name="${config##*/}"
|
||||
echo "Installing $config to /etc/$name"
|
||||
if [ -d "$config" ]; then
|
||||
mkdir -p "/etc/$name"
|
||||
\mkdir -p "/etc/$name"
|
||||
copy "$config/." "/etc/$name/"
|
||||
else
|
||||
copy "$config" "/etc/$name"
|
||||
@@ -65,10 +56,10 @@ fi
|
||||
unset config
|
||||
if [ -d "/tmp/usr" ]; then
|
||||
for usrpath in "/tmp/usr"/*; do
|
||||
name="$(basename -- "$usrpath")"
|
||||
name="${usrpath##*/}"
|
||||
echo "Installing $usrpath to /usr/$name"
|
||||
if [ -d "$usrpath" ]; then
|
||||
mkdir -p "/usr/$name"
|
||||
\mkdir -p "/usr/$name"
|
||||
copy "$usrpath/." "/usr/$name/"
|
||||
else
|
||||
copy "$usrpath" "/usr/$name"
|
||||
@@ -77,10 +68,7 @@ if [ -d "/tmp/usr" ]; then
|
||||
fi
|
||||
unset usrpath
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Main script
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set the exit code
|
||||
#exitCode=$?
|
||||
exitCode=$?
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
exit $exitCode
|
||||
# ex: ts=2 sw=2 et filetype=sh
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user