mirror of
https://github.com/openziti/zrok.git
synced 2024-11-07 08:44:14 +01:00
always append common cli opts
This commit is contained in:
parent
21ede9d23b
commit
3591224560
@ -7,14 +7,19 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
share_reserved(){
|
exec_with_common_opts(){
|
||||||
|
local zrok_cmd="$* --headless ${ZROK_VERBOSE:-} ${ZROK_INSECURE:-}"
|
||||||
|
echo "INFO: running: zrok ${zrok_cmd}"
|
||||||
|
exec zrok ${zrok_cmd}
|
||||||
|
}
|
||||||
|
|
||||||
|
exec_share_reserved(){
|
||||||
local token="$1"
|
local token="$1"
|
||||||
local target="$2"
|
local target="$2"
|
||||||
shift 2
|
shift 2
|
||||||
local opts="${*:-}"
|
local opts="${*:-}"
|
||||||
local zrok_cmd="share reserved ${token} --headless ${opts} --override-endpoint ${target}"
|
local zrok_cmd="share reserved ${token} ${opts} --override-endpoint ${target}"
|
||||||
echo "INFO: running: zrok ${zrok_cmd}"
|
exec_with_common_opts ${zrok_cmd}
|
||||||
exec zrok ${zrok_cmd}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! command -v jq &>/dev/null; then
|
if ! command -v jq &>/dev/null; then
|
||||||
@ -62,9 +67,9 @@ fi
|
|||||||
# default mode is 'reserved-public', override modes are reserved-private, temp-public, temp-private.
|
# default mode is 'reserved-public', override modes are reserved-private, temp-public, temp-private.
|
||||||
: "${ZROK_FRONTEND_MODE:=reserved-public}"
|
: "${ZROK_FRONTEND_MODE:=reserved-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"
|
||||||
elif [[ "${ZROK_FRONTEND_MODE:-}" == temp-private ]]; then
|
elif [[ "${ZROK_FRONTEND_MODE:-}" == temp-private ]]; then
|
||||||
ZROK_CMD="share private --headless ${ZROK_VERBOSE:-}"
|
ZROK_CMD="share private"
|
||||||
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,9 +78,8 @@ elif [[ -s ~/.zrok/reserved.json ]]; then
|
|||||||
else
|
else
|
||||||
echo "INFO: zrok backend is already reserved: ${ZROK_RESERVED_TOKEN}"
|
echo "INFO: zrok backend is already reserved: ${ZROK_RESERVED_TOKEN}"
|
||||||
ZROK_CMD="${ZROK_RESERVED_TOKEN} ${ZROK_TARGET}"
|
ZROK_CMD="${ZROK_RESERVED_TOKEN} ${ZROK_TARGET}"
|
||||||
ZROK_CMD+=" ${ZROK_VERBOSE:-} ${ZROK_INSECURE:-}"
|
|
||||||
if [[ "${ZROK_SHARE_RESERVED}" == true ]]; then
|
if [[ "${ZROK_SHARE_RESERVED}" == true ]]; then
|
||||||
share_reserved ${ZROK_CMD}
|
exec_share_reserved ${ZROK_CMD}
|
||||||
else
|
else
|
||||||
echo "INFO: finished reserving zrok backend, continuing without sharing"
|
echo "INFO: finished reserving zrok backend, continuing without sharing"
|
||||||
exit 0
|
exit 0
|
||||||
@ -198,12 +202,10 @@ elif [[ -n "${ZROK_BASIC_AUTH:-}" ]]; then
|
|||||||
ZROK_CMD+=" --basic-auth ${ZROK_BASIC_AUTH}"
|
ZROK_CMD+=" --basic-auth ${ZROK_BASIC_AUTH}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "INFO: running: zrok ${ZROK_CMD}"
|
|
||||||
|
|
||||||
if [[ "${ZROK_FRONTEND_MODE:-}" =~ ^temp- ]]; then
|
if [[ "${ZROK_FRONTEND_MODE:-}" =~ ^temp- ]]; then
|
||||||
# frontend mode starts with 'temp-', so is temporary.
|
# frontend mode starts with 'temp-', so is temporary.
|
||||||
# share without reserving until exit.
|
# share without reserving until exit.
|
||||||
exec zrok ${ZROK_CMD}
|
exec_with_common_opts ${ZROK_CMD}
|
||||||
else
|
else
|
||||||
# reserve and continue
|
# reserve and continue
|
||||||
zrok ${ZROK_CMD} > ~/.zrok/reserved.json
|
zrok ${ZROK_CMD} > ~/.zrok/reserved.json
|
||||||
@ -228,9 +230,8 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
ZROK_CMD="${ZROK_RESERVED_TOKEN} ${ZROK_TARGET}"
|
ZROK_CMD="${ZROK_RESERVED_TOKEN} ${ZROK_TARGET}"
|
||||||
ZROK_CMD+=" ${ZROK_VERBOSE:-} ${ZROK_INSECURE:-}"
|
|
||||||
if [[ "${ZROK_SHARE_RESERVED}" == true ]]; then
|
if [[ "${ZROK_SHARE_RESERVED}" == true ]]; then
|
||||||
share_reserved ${ZROK_CMD}
|
exec_share_reserved ${ZROK_CMD}
|
||||||
else
|
else
|
||||||
echo "INFO: finished reserving zrok backend, continuing without sharing"
|
echo "INFO: finished reserving zrok backend, continuing without sharing"
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user