nfpm: Modified zrok-share to cater for private temporary and reserved shares, controlled by ZROK_FRONTEND_MODE; Modified env file with additional variable ZROK_FRONTEND_MODE;

This commit is contained in:
Stefan Adelbert 2024-06-07 15:04:48 +10:00 committed by Kenneth Bingham
parent 6b4c6d4713
commit e5479e84fe
No known key found for this signature in database
GPG Key ID: 31709281860130B6
2 changed files with 20 additions and 7 deletions

View File

@ -54,9 +54,12 @@ fi
exit 1 exit 1
} }
# default mode is reserved (public), override mode is temp-public, i.e., "share public" without a reserved subdomain # default mode is 'temp-public' (unreserved), override modes are temp-private, reserver-public, reserved-private.
: "${ZROK_FRONTEND_MODE:-temp-public}"
if [[ "${ZROK_FRONTEND_MODE:-}" == temp-public ]]; then if [[ "${ZROK_FRONTEND_MODE:-}" == temp-public ]]; then
ZROK_CMD="share public --headless ${ZROK_VERBOSE:-}" ZROK_CMD="share public --headless ${ZROK_VERBOSE:-}"
elif [[ "${ZROK_FRONTEND_MODE:-}" == temp-private ]]; then
ZROK_CMD="share private --headless ${ZROK_VERBOSE:-}"
elif [[ -s ~/.zrok/reserved.json ]]; then elif [[ -s ~/.zrok/reserved.json ]]; then
ZROK_RESERVED_TOKEN="$(jq -r '.token' ~/.zrok/reserved.json 2>/dev/null)" ZROK_RESERVED_TOKEN="$(jq -r '.token' ~/.zrok/reserved.json 2>/dev/null)"
if [[ -z "${ZROK_RESERVED_TOKEN}" || "${ZROK_RESERVED_TOKEN}" == null ]]; then if [[ -z "${ZROK_RESERVED_TOKEN}" || "${ZROK_RESERVED_TOKEN}" == null ]]; then
@ -73,8 +76,13 @@ elif [[ -s ~/.zrok/reserved.json ]]; then
exit 0 exit 0
fi fi
fi fi
else elif [[ "${ZROK_FRONTEND_MODE:-}" == reserved-public ]]; then
ZROK_CMD="reserve public --json-output ${ZROK_VERBOSE:-}" ZROK_CMD="reserve public --json-output ${ZROK_VERBOSE:-}"
elif [[ "${ZROK_FRONTEND_MODE:-}" == reserved-private ]]; then
ZROK_CMD="reserve private --json-output ${ZROK_VERBOSE:-}"
else
echo "ERROR: invalid value for ZROK_FRONTEND_MODE '${ZROK_FRONTEND_MODE}'" >&2
exit 1
fi fi
[[ -n "${ZROK_BACKEND_MODE:-}" ]] || { [[ -n "${ZROK_BACKEND_MODE:-}" ]] || {
@ -88,12 +96,12 @@ case "${ZROK_BACKEND_MODE}" in
echo "ERROR: ZROK_TARGET='${ZROK_TARGET}' is not an HTTP URL" >&2 echo "ERROR: ZROK_TARGET='${ZROK_TARGET}' is not an HTTP URL" >&2
exit 1 exit 1
else else
echo "INFO: validated backend mode ${ZROK_BACKEND_MODE} and target ${ZROK_TARGET}" echo "INFO: validated backend mode '${ZROK_BACKEND_MODE}' and target '${ZROK_TARGET}'"
fi fi
;; ;;
caddy) caddy)
if ! [[ "${ZROK_TARGET}" =~ ^/ ]]; then if ! [[ "${ZROK_TARGET}" =~ ^/ ]]; then
echo "ERROR: ZROK_TARGET='${ZROK_TARGET}' is not an absolute filesystem path." >&2 echo "ERROR: ZROK_TARGET='${ZROK_TARGET}' is not an absolute filesystem path" >&2
exit 1 exit 1
elif ! [[ -f "${ZROK_TARGET}" && -r "${ZROK_TARGET}" ]]; then elif ! [[ -f "${ZROK_TARGET}" && -r "${ZROK_TARGET}" ]]; then
echo "ERROR: ZROK_TARGET='${ZROK_TARGET}' is not a readable regular file" >&2 echo "ERROR: ZROK_TARGET='${ZROK_TARGET}' is not a readable regular file" >&2
@ -104,7 +112,7 @@ case "${ZROK_BACKEND_MODE}" in
;; ;;
web|drive) web|drive)
if ! [[ "${ZROK_TARGET}" =~ ^/ ]]; then if ! [[ "${ZROK_TARGET}" =~ ^/ ]]; then
echo "ERROR: ZROK_TARGET='${ZROK_TARGET}' is not an absolute filesystem path." >&2 echo "ERROR: ZROK_TARGET='${ZROK_TARGET}' is not an absolute filesystem path" >&2
exit 1 exit 1
elif ! [[ -d "${ZROK_TARGET}" && -r "${ZROK_TARGET}" ]]; then elif ! [[ -d "${ZROK_TARGET}" && -r "${ZROK_TARGET}" ]]; then
echo "ERROR: ZROK_TARGET='${ZROK_TARGET}' is not a readable directory" >&2 echo "ERROR: ZROK_TARGET='${ZROK_TARGET}' is not a readable directory" >&2
@ -142,8 +150,9 @@ fi
echo "INFO: running: zrok ${ZROK_CMD}" echo "INFO: running: zrok ${ZROK_CMD}"
if [[ "${ZROK_FRONTEND_MODE:-}" == temp-public ]]; then if [[ "${ZROK_FRONTEND_MODE:-}" =~ ^temp- ]]; then
# share until exit # frontend mode starts with 'temp-', so is temporary.
# share without reserving until exit.
exec zrok ${ZROK_CMD} exec zrok ${ZROK_CMD}
else else
# reserve and continue # reserve and continue

View File

@ -86,3 +86,7 @@ ZROK_SHARE_OPTS=""
# set if self-hosting zrok and not using only the default frontend name 'public'; must be a space-separated list # set if self-hosting zrok and not using only the default frontend name 'public'; must be a space-separated list
# WARNING: changes take effect the next time the frontend URL is reserved # WARNING: changes take effect the next time the frontend URL is reserved
#ZROK_FRONTENDS="public" #ZROK_FRONTENDS="public"
# you MAY set to change the frontend mode: temp-public (default), temp-private, reserved-public, reserved-private
# WARNING: changes take effect the next time the frontend URL is reserved
#ZROK_FRONTEND_MODE="temp-public"