diff --git a/www/caddy-custom/Makefile b/www/caddy-custom/Makefile new file mode 100644 index 000000000000..8b687b23f248 --- /dev/null +++ b/www/caddy-custom/Makefile @@ -0,0 +1,47 @@ +# READ pkg-descr FOR INSTRUCTIONS! +# This port will NOT build in poudriere without (simple) manual +# intervention. +# It is intentionally not hooked to package build. + +PORTNAME= caddy-custom +PORTVERSION= ${CADDY_VERSION}.${XCADDY_VERSION} +CATEGORIES= www +DISTFILES= # none + +MAINTAINER= adamw@FreeBSD.org +COMMENT= Caddy (www/caddy) with customized plugins +WWW= https://caddyserver.com + +LICENSE= APACHE20 + +BUILD_DEPENDS= xcaddy:www/xcaddy + +USES= go:no_targets + +CONFLICTS_INSTALL= caddy + +USE_RC_SUBR= caddy +SUB_FILES= caddy + +PLIST_FILES= bin/caddy + +CADDY_VERSION!= ${MAKE} -C ${.CURDIR}/../caddy -V '$${DISTVERSION}.$${PORTREVISION}' +XCADDY_VERSION!=${MAKE} -C ${.CURDIR}/../xcaddy -V '$${DISTVERSION}.$${PORTREVISION}' + +.for plugin in ${CADDY_CUSTOM_PLUGINS} +PLUGINS+= --with ${plugin} +.endfor + +XCADDY_GO_BUILD_FLAGS?= ${GO_BUILDFLAGS} + +XCADDY_ENV+= XCADDY_WHICH_GO="${GO_CMD}" \ + XCADDY_GO_BUILD_FLAGS="${XCADDY_GO_BUILD_FLAGS}" + +do-build: + ${MKDIR} ${WRKSRC} + cd ${WRKSRC} && ${XCADDY_ENV} ${LOCALBASE}/bin/xcaddy build ${PLUGINS} + +do-install: + ${INSTALL_PROGRAM} ${WRKSRC}/caddy ${STAGEDIR}${PREFIX}/bin + +.include diff --git a/www/caddy-custom/files/caddy.in b/www/caddy-custom/files/caddy.in new file mode 100644 index 000000000000..a67e3e832bbc --- /dev/null +++ b/www/caddy-custom/files/caddy.in @@ -0,0 +1,128 @@ +#!/bin/sh + +# PROVIDE: caddy +# REQUIRE: LOGIN DAEMON NETWORKING +# KEYWORD: shutdown + +# To enable caddy, add 'caddy_enable="YES"' to /etc/rc.conf or +# /etc/rc.conf.local + +# Optional settings: +# caddy_command (string): Full path to the caddy binary +# caddy_config (string): Full path to caddy config file +# (%%PREFIX%%/etc/Caddyfile) +# caddy_adapter (string): Config adapter type (caddyfile) +# caddy_directory (string): Root for caddy storage (ACME certs, etc.) +# (/var/db/caddy) +# caddy_extra_flags (string): Extra flags passed to caddy start +# caddy_logdir (string): Where caddy logs are stored +# (/var/log/caddy) +# caddy_logfile (string): Location of process log (${caddy_logdir}/caddy.log) +# This is for startup/shutdown/error messages. +# To create an access log, see: +# https://caddyserver.com/docs/caddyfile/directives/log +# caddy_user (user): User to run caddy (root) +# caddy_group (group): Group to run caddy (wheel) +# +# This script will honor XDG_CONFIG_HOME/XDG_DATA_HOME. Caddy will create a +# .../caddy subdir in each of those. By default, they are subdirs of /var/db/caddy. +# See https://caddyserver.com/docs/conventions#data-directory + +. /etc/rc.subr + +name=caddy +rcvar=caddy_enable +desc="Powerful, enterprise-ready, open source web server with automatic HTTPS written in Go" + +load_rc_config $name + +# Defaults +: ${caddy_enable:=NO} +: ${caddy_adapter:=caddyfile} +: ${caddy_config:="%%PREFIX%%/etc/Caddyfile"} +: ${caddy_command:="%%PREFIX%%/bin/${name}"} +: ${caddy_directory:=/var/db/caddy} +: ${caddy_extra_flags:=""} +: ${caddy_logdir:="/var/log/${name}"} +: ${caddy_logfile:="${caddy_logdir}/${name}.log"} +: ${caddy_user:="root"} +: ${caddy_group:="wheel"} + +# Config and base directories +: ${XDG_CONFIG_HOME:="${caddy_directory}/config"} +: ${XDG_DATA_HOME:="${caddy_directory}/data"} +export XDG_CONFIG_HOME XDG_DATA_HOME + +command="${caddy_command}" +caddy_flags="--config ${caddy_config} --adapter ${caddy_adapter}" +pidfile="/var/run/${name}/${name}.pid" + +required_files="${caddy_config} ${caddy_command}" + +start_precmd="caddy_precmd" +start_cmd="caddy_start" +stop_precmd="caddy_prestop" + +# Extra Commands +extra_commands="configtest reload" +configtest_cmd="caddy_execute validate ${caddy_flags}" +reload_cmd="caddy_execute reload ${caddy_flags}" + +caddy_execute() +{ + /usr/bin/su -m "${caddy_user}" -c "${caddy_command} $*" +} + +caddy_precmd() +{ + # Create required directories and set permissions + /usr/bin/install -d -m 755 -o "${caddy_user}" -g "${caddy_group}" ${caddy_directory} + /usr/bin/install -d -m 700 -o "${caddy_user}" -g "${caddy_group}" ${caddy_directory}/config + /usr/bin/install -d -m 700 -o "${caddy_user}" -g "${caddy_group}" ${caddy_directory}/data + /usr/bin/install -d -m 755 -o "${caddy_user}" -g "${caddy_group}" ${caddy_logdir} + /usr/bin/install -d -m 700 -o "${caddy_user}" -g "${caddy_group}" /var/run/caddy + if [ -e ${caddy_logfile} ]; then + /bin/chmod 644 ${caddy_logfile} + /usr/sbin/chown root:wheel ${caddy_logfile} + else + /usr/bin/install -m 644 -o root -g wheel /dev/null ${caddy_logfile} + fi +} + +caddy_start() +{ + echo -n "Starting caddy... " + /usr/bin/su -m ${caddy_user} -c "${caddy_command} start ${caddy_flags} \ + ${caddy_extra_flags} --pidfile ${pidfile}" >> ${caddy_logfile} 2>&1 + if [ $? -eq 0 ] && ps -ax -o pid | grep -q "$(cat ${pidfile})"; then + echo "done" + echo "Log: ${caddy_logfile}" + else + echo "Error: Caddy failed to start" + echo "Check the caddy log: ${caddy_logfile}" + fi +} + +caddy_prestop() +{ + local result + + echo -n "Stopping caddy... " + + result="$(caddy_execute stop 2>&1)" + if [ ${?} -eq 0 ]; then + echo "done" + exit 0 + else + if echo "${result}" | grep -q "connection refused"; then + echo "admin interface unavailable; using pidfile" + return 0 + else + echo "Error: Unable to stop caddy" + echo "Check the caddy log: ${caddy_logfile}" + return 1 + fi + fi +} + +run_rc_command "$1" diff --git a/www/caddy-custom/pkg-descr b/www/caddy-custom/pkg-descr new file mode 100644 index 000000000000..db3ba70aab5d --- /dev/null +++ b/www/caddy-custom/pkg-descr @@ -0,0 +1,31 @@ +This port will build a customized version of the caddy webserver +using plugins of your choice. + +Caddy is a high-performance webserver with a simple config format, +out-of-the-box HTTP/3 support, and automatica transparent ACME +certificate provisioning. + +NOTE: THIS PORT BYPASSES EVERY SINGLE ONE OF FREEBSD'S CHECKSUM- +BASED DISTFILE TAMPERING DETECTION MECHANISMS. USE THIS AT YOUR +OWN PERIL (though the peril is exactly the same as using the +xcaddy port). + +To make this work: + +1) In /usr/local/etc/poudriere.conf, add the following: + + ALLOW_NETWORKING_PACKAGES="caddy-custom" + + You can skip this step if you're not building in poudriere. + +2) Put your plugin list into make.conf (or + /usr/local/etc/poudriere.conf/make.conf): + + .if ${.CURDIR:M*/www/caddy-custom*} + CADDY_CUSTOM_PLUGINS= github.com/caddy-dns/rfc2136 github.com/greenpau/caddy-security + .endif + + If you have any other xcaddy build flags you want to set, put + them in XCADDY_ENV. + +3) Profit