59 lines
1.4 KiB
Bash
Executable File
59 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
caddy () {
|
|
|
|
if [[ ! $CADDY_HOME ]]; then
|
|
echo caddy run environment is NOT set
|
|
echo this is an error as the image build should set this
|
|
echo attempting to recover by sourcing the environment now
|
|
echo at $ENV_DIR/caddy.env
|
|
if [[ -f $ENV_DIR/caddy.env ]]; then
|
|
source $ENV_DIR/caddy.env
|
|
else
|
|
echo default environment can not be sourced at $ENV_DIR/caddy.env
|
|
return 1
|
|
fi
|
|
fi
|
|
|
|
[[ ! $CADDY_BIN ]] && CADDY_BIN is not set unable to find caddy binary
|
|
[ ! -f "$CADDY_BIN" ] && echo caddy binary file at $CADDY_BIN does not exist && return 1
|
|
[ ! -x "$CADDY_BIN" ] && echo caddy binary file $CADDY_BIN is not executable && return 1
|
|
|
|
source $LIB_DIR/caddy.lib
|
|
|
|
case "$1" in
|
|
shell)
|
|
shift 1
|
|
if [[ $# -eq 0 ]]; then
|
|
/bin/bash -l
|
|
else
|
|
/bin/bash -l -c '"$@"' "$0" "$@"
|
|
fi
|
|
;;
|
|
run)
|
|
shift 1
|
|
local conf
|
|
cd $CADDY_CONF || { echo could not enter conf directory in container; return 2; }
|
|
if [[ $1 ]];then
|
|
[[ -f $1 ]] && conf=$1 || conf=$1.conf
|
|
else
|
|
conf=Caddyfile
|
|
fi
|
|
if [[ -f $conf ]]; then
|
|
caddy_add_packages
|
|
echo running: $CADDY_BIN run --config $conf --adapter caddyfile
|
|
$CADDY_BIN run --config $conf --adapter caddyfile
|
|
else
|
|
echo no configuration file found at $conf in the container
|
|
echo make sure you have mounted one from the host into /opt/caddy/conf
|
|
fi
|
|
;;
|
|
*)
|
|
$CADDY_BIN "$@"
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
# # if script was executed then call the function
|
|
(return 0 2>/dev/null) || caddy "$@" |