Merge remote-tracking branch 'origin/release-next' into ziti-edge-quicker-quickstart

This commit is contained in:
dovholuknf
2023-09-01 14:52:53 -04:00
+33 -9
View File
@@ -39,6 +39,28 @@ function _wait_for_controller {
done
}
function _wait_for_public_router {
local advertised_host_port="${ZITI_ROUTER_NAME}:${ZITI_ROUTER_PORT}"
local COUNTDOWN=10
until [[ -s "${ZITI_HOME}/${ZITI_ROUTER_NAME}.cert" ]] \
&& openssl s_client \
-connect "${advertised_host_port}" \
-servername "${ZITI_ROUTER_NAME}" \
-alpn "ziti-edge,h2,http/1.1" \
-cert "${ZITI_HOME}/${ZITI_ROUTER_NAME}.cert" \
-key "${ZITI_HOME}/${ZITI_ROUTER_NAME}.key" \
<>/dev/null 2>&1 # client cert needed for a zero exit code
do
if (( COUNTDOWN-- )); then
echo "INFO: waiting for https://${advertised_host_port}"
sleep 3
else
echo "ERROR: timed out waiting for https://${advertised_host_port}" >&2
return 1
fi
done
}
function _setup_ziti_home {
_setup_ziti_network
if [[ "${ZITI_HOME-}" == "" ]]; then export ZITI_HOME="${HOME}/.ziti/quickstart/${ZITI_NETWORK-}"; else echo "ZITI_HOME overridden: ${ZITI_HOME}"; fi
@@ -366,7 +388,7 @@ function setupEnvironment {
# Stores environment variables prefixed with ZITI_ to a .env file
function persistEnvironmentValues {
local filepath retVal envval envvar zEnvVar
local filepath tmpfilepath retVal envval envvar zEnvVar
# Get the file path
filepath="${1-}"
if [[ "" == "${filepath}" ]]; then
@@ -381,23 +403,24 @@ function persistEnvironmentValues {
fi
# Store all ZITI_ variables in the environment file, creating the directory if necessary
mkdir -p "$(dirname "${filepath}")" && echo "" > "${filepath}"
tmpfilepath="$(mktemp)"
mkdir -p "$(dirname "${filepath}")" && echo "" > "${tmpfilepath}"
for zEnvVar in $(set | grep -e "^ZITI_" | sort); do
envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)"
envval="$(echo "${zEnvVar}" | cut -d '=' -f2-1000)"
echo 'if [[ "$'${envvar}'" == "" ]]; then export '${envvar}'="'${envval}'"; else echo "NOT OVERRIDING: env var '${envvar}' already set. using existing value"; fi' >> "${filepath}"
echo 'if [[ "$'${envvar}'" == "" ]]; then export '${envvar}'="'${envval}'"; else echo "NOT OVERRIDING: env var '${envvar}' already set. using existing value"; fi' >> "${tmpfilepath}"
done
export PFXLOG_NO_JSON=true
# shellcheck disable=SC2129
echo "export PFXLOG_NO_JSON=true" >> "${filepath}"
echo "export PFXLOG_NO_JSON=true" >> "${tmpfilepath}"
echo "alias zec='ziti edge'" >> "${filepath}"
echo "alias zitiLogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:\${ZITI_CTRL_EDGE_ADVERTISED_PORT}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -y'" >> "${filepath}"
echo "alias psz='ps -ef | grep ziti'" >> "${filepath}"
echo "alias zec='ziti edge'" >> "${tmpfilepath}"
echo "alias zitiLogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:\${ZITI_CTRL_EDGE_ADVERTISED_PORT}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -y'" >> "${tmpfilepath}"
echo "alias psz='ps -ef | grep ziti'" >> "${tmpfilepath}"
#when sourcing the emitted file add the bin folder to the path
tee -a "${filepath}" > /dev/null <<'heredoc'
cat >> "${tmpfilepath}" <<'HEREDOC'
echo " "
if [[ ! "$(echo "$PATH"|grep -q "${ZITI_BIN_DIR}" && echo "yes")" == "yes" ]]; then
echo "adding ${ZITI_BIN_DIR} to the path"
@@ -407,8 +430,9 @@ echo " ziti binaries are located at: ${ZITI_BIN_DIR}"
echo -e 'add this to your path if you want by executing: export PATH=$PATH:'"${ZITI_BIN_DIR}"
echo " "
fi
heredoc
HEREDOC
mv "${tmpfilepath}" "${filepath}"
echo -e "A file with all pertinent environment values was created here: $(BLUE "${filepath}")"
echo ""
}