happyDomain/hadmin.sh
Pierre-Olivier Mercier c22cdc91e8
All checks were successful
continuous-integration/drone/push Build is passing
hadmin: use HAPPYDOMAIN_ADMIN_BIND and handle TCP addresses
Replace the non-standard HAPPYDOMAIN_SOCKET variable with
HAPPYDOMAIN_ADMIN_BIND, matching the config env var. Handle TCP bind
addresses (:8080, 0.0.0.0:8080, [::]:8080) in addition to Unix sockets.
2026-05-25 23:39:19 +08:00

30 lines
692 B
Bash
Executable file

#!/bin/sh
[ -z "${HAPPYDOMAIN_ADMIN_BIND}" ] &&
DEST="./happydomain.sock" ||
DEST="${HAPPYDOMAIN_ADMIN_BIND}"
if [ -S "${DEST}" ]; then
DEST="--unix-socket $DEST http://localhost"
elif echo "$DEST" | grep -q ":"; then
case "$DEST" in
:*) DEST="http://localhost${DEST}" ;;
0.0.0.0:*) DEST="http://localhost${DEST#0.0.0.0}" ;;
\[::\]:*) DEST="http://localhost:${DEST##*:}" ;;
*) DEST="http://${DEST}" ;;
esac
fi
RET=$(curl -s ${DEST}"$@")
CODE=$?
if [ -t 1 ]
then
which jq > /dev/null 2> /dev/null &&
echo "${RET}" | jq . 2> /dev/null ||
echo "$RET"
else
echo "$RET"
fi
exit $CODE