commands that require a parameter now prompt user for input when argument not provided

added console outputs when a command is executed successfully (stopZitiController, stopAllEdgeRouters)
Added a single checkEnvVariable function so it can be used repeatedly for consistent output
All functions that create a file now output the file location
This commit is contained in:
gberl002
2021-12-09 09:25:26 -05:00
parent 4b9972530c
commit 7dff2dee0f
+330 -188
View File
@@ -45,13 +45,11 @@ function zitiLogin {
"${ZITI_BIN_DIR-}/ziti" edge login "${ZITI_EDGE_CONTROLLER_API}" -u "${ZITI_USER-}" -p "${ZITI_PWD}" -c "${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert"
}
function cleanZitiController {
ziti_home="${ZITI_HOME-}"
if [[ "${ziti_home}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_HOME is not set") "
if [ "$(checkEnvVariable ZITI_HOME)" ]; then
return 1
fi
rm -rf "${ziti_home}/db"
mkdir "${ziti_home}/db"
rm -rf "${ZITI_HOME}/db"
mkdir "${ZITI_HOME}/db"
initializeController
}
function initializeController {
@@ -65,18 +63,26 @@ function startZitiController {
echo -e "ziti-controller started as process id: $pid. log located at: $(BLUE "${ZITI_HOME-}/ziti-edge-controller.log")"
return $pid
}
function stopZitiController {
killall ziti-controller
# shellcheck disable=SC2181
if [[ $? == 0 ]]; then echo "Controller stopped."; fi
}
function startExpressEdgeRouter {
"${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" > "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.log" 2>&1 &
pid=$!
echo -e "Express Edge Router started as process id: $pid. log located at: $(BLUE "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.log")"
return $pid
}
function stopAllEdgeRouters {
killall ziti-router
killall ziti-controller
# shellcheck disable=SC2181
if [[ $? == 0 ]]; then echo "Router(s) stopped."; fi
}
function checkHostsFile {
ctrlexists=$(grep -c "${ZITI_CONTROLLER_HOSTNAME}" /etc/hosts)
edgectrlexists=$(grep -c "${ZITI_EDGE_CONTROLLER_HOSTNAME}" /etc/hosts)
@@ -111,6 +117,8 @@ function checkHostsFile {
echo " "
echo "add these entries to your hosts file, and rerun the script when ready"
return 1
else
echo -e "$(GREEN "Hosts file looks good")"
fi
}
@@ -140,8 +148,7 @@ function getLatestZitiVersion {
function getLatestZiti {
setupZitiHome
if [[ "${ZITI_HOME-}" == "" ]]; then
echo "ERROR: ZITI_HOME is not set!"
if [ "$(checkEnvVariable ZITI_HOME)" ]; then
return 1
fi
@@ -157,12 +164,7 @@ function getLatestZiti {
return 1
fi
ziti_bin_ver="${ZITI_BINARIES_VERSION-}"
if [[ "${ziti_bin_ver}" == "" ]]; then
echo "ERROR: ZITI_BINARIES_VERSION is not set!"
return 1
fi
export ZITI_BIN_DIR="${ziti_bin_root}/ziti-${ziti_bin_ver}"
export ZITI_BIN_DIR="${ziti_bin_root}/ziti-${ZITI_BINARIES_VERSION}"
ZITI_BINARIES_FILE_ABSPATH="${ZITI_HOME-}/ziti-bin/${ZITI_BINARIES_FILE}"
if ! test -f "${ZITI_BINARIES_FILE_ABSPATH}"; then
@@ -220,10 +222,9 @@ function checkPrereqs {
echo " "
echo " "
return 1
else
echo -e "$(GREEN "Prerequisites confirmed")"
fi
echo "Let's get started creating your local development network!"
echo ""
echo ""
}
function checkControllerName {
@@ -235,7 +236,12 @@ function checkControllerName {
}
function unsetZitiEnv {
for zEnvVar in $(set | grep -e "^ZITI_" | sort); do envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)"; echo unsetting "[${envvar}]${zEnvVar}"; unset "${envvar}"; done
if [[ "${1-}" == "-s" ]]; then
# Silent...
for zEnvVar in $(set | grep -e "^ZITI_" | sort); do envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)"; unset "${envvar}"; done
else
for zEnvVar in $(set | grep -e "^ZITI_" | sort); do envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)"; echo unsetting "[${envvar}]${zEnvVar}"; unset "${envvar}"; done
fi
unset ZITIx_EXPRESS_COMPLETE
}
@@ -290,7 +296,7 @@ function setupZitiNetwork {
function setupZitiHome {
if [[ "${ZITI_HOME-}" == "" ]]; then
export ZITI_HOME="${HOME}/.ziti/quickstart/${ZITI_NETWORK-}"
echo "using default ZITI_HOME: ${ZITI_HOME}"
echo -e "using default ZITI_HOME: $(BLUE "${ZITI_HOME}")"
fi
}
@@ -318,7 +324,7 @@ function generateEnvFile {
export ENV_FILE="${ZITI_HOME-}/${ZITI_NETWORK-}.env"
echo -e "environment file created and sourced from: $(BLUE "${ENV_FILE}")"
echo -e "environment file sourced from: $(BLUE "${ENV_FILE}")"
}
function ziti_expressConfiguration {
@@ -326,10 +332,10 @@ function ziti_expressConfiguration {
echo -e "$(RED " --- It looks like you've run an express install in this shell already. ---")"
echo -en "Would you like to clear existing Ziti variables and continue (y/N)? "
read -r
echo
echo " "
if [[ "${REPLY}" =~ [Yy]$ ]]; then
echo -e "$(GREEN "Clearing existing Ziti variables and continuing with express install")"
unsetZitiEnv
unsetZitiEnv "-s"
else
echo -e "$(RED " --- Exiting express install ---")"
return 1
@@ -356,6 +362,9 @@ function ziti_expressConfiguration {
if [[ "${ZITI_EDGE_ROUTER_HOSTNAME-}" != "" ]]; then echo "ZITI_EDGE_ROUTER_HOSTNAME OVERIDDEN: $ZITI_EDGE_ROUTER_HOSTNAME"; fi
if [[ "${ZITI_EDGE_ROUTER_PORT-}" != "" ]]; then echo "ZITI_EDGE_ROUTER_PORT OVERIDDEN: $ZITI_EDGE_ROUTER_PORT"; fi
echo " "
echo " "
echo -e "******** Setting Up Environment ********"
if [[ "${1-}" == "" ]]; then
nw="$(hostname)"
else
@@ -364,7 +373,7 @@ function ziti_expressConfiguration {
setupZitiNetwork "${nw}"
setupZitiHome
echo "ZITI HOME SET TO: ${ZITI_HOME}"
echo "ZITI HOME SET TO: $(BLUE "${ZITI_HOME}")"
if ! getLatestZiti "no"; then
echo -e "$(RED "getLatestZiti failed")"
@@ -376,9 +385,16 @@ function ziti_expressConfiguration {
fi
#checkHostsFile
echo " "
echo " "
echo -e "******** Setting Up Public Key Infrastructure ********"
createPki
createControllerConfig
#createControllerSystemdFile
echo " "
echo " "
echo -e "******** Setting Up Controller ********"
createControllerConfig "controller"
#createControllerSystemdFile controller
initializeController
startZitiController
echo "waiting for the controller to come online to allow the edge router to enroll"
@@ -386,6 +402,9 @@ function ziti_expressConfiguration {
zitiLogin
echo " "
echo " "
echo -e "******** Setting Up Edge Routers ********"
echo -e "---------- Creating an edge router policy allowing all identities to connect to routers with a $(GREEN "#public") attribute"
"${ZITI_BIN_DIR-}/ziti" edge delete edge-router-policy allEdgeRouters > /dev/null
"${ZITI_BIN_DIR-}/ziti" edge create edge-router-policy allEdgeRouters --edge-router-roles '#public' --identity-roles '#all' > /dev/null
@@ -402,12 +421,12 @@ function ziti_expressConfiguration {
"${ZITI_BIN_DIR-}/ziti" edge delete edge-router "${ZITI_EDGE_ROUTER_RAWNAME}" > /dev/null
"${ZITI_BIN_DIR-}/ziti" edge create edge-router "${ZITI_EDGE_ROUTER_RAWNAME}" -o "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.jwt" -t -a "public"> /dev/null
sleep 1
echo "---------- Enrolling edge-router ${ZITI_EDGE_ROUTER_RAWNAME}...."
echo "---------- Enrolling edge-router ${ZITI_EDGE_ROUTER_RAWNAME}...."
"${ZITI_BIN_DIR-}/ziti-router" enroll "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" --jwt "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.jwt" &> "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.enrollment.log"
echo ""
killall ziti-controller
stopZitiController
echo "Edge Router enrolled. Controller stopped."
echo ""
@@ -490,6 +509,10 @@ function expressInstall {
#make sure the user has all the necessary commands to be successful
checkPrereqs
echo "Let's get started creating your local development network!"
echo ""
echo ""
#prompt the user for input and do what they want/need
decideOperation 1 "${1-}"
}
@@ -550,13 +573,11 @@ function pki_create_intermediate {
fi
echo " "
}
function printUsage()
{
function printUsage() {
echo "Usage: ${1-} [cert to test] [ca pool to use]"
}
function verifyCertAgainstPool()
{
function verifyCertAgainstPool() {
if [[ "" == "${1-}" ]]
then
printUsage "verifyCertAgainstPool"
@@ -585,8 +606,7 @@ function verifyCertAgainstPool()
fi
}
function showIssuerAndSubjectForPEM()
{
function showIssuerAndSubjectForPEM() {
echo "Displaying Issuer and Subject for cert pool:"
echo " ${1-}"
openssl crl2pkcs7 -nocrl -certfile "${1-}" | openssl pkcs7 -print_certs -text -noout | grep -E "(Subject|Issuer)"
@@ -597,18 +617,29 @@ function createRouterPki {
}
function createPrivateRouterConfig {
# Allow router name to be passed in as arg
router_name="${1-}"
if [[ "${router_name}" == "" ]]; then
echo -e " * ERROR: $(RED "createPrivateRouterConfig requires a parameter to be supplied") "
# If router name is not passed as arg, prompt user for input
echo -e "$(YELLOW "createPrivateRouterConfig requires a router name to be supplied") "
default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}"
echo -en "Enter router name (${default_router_name}):"
read -r router_name
# Accept the default if no name provided
if [[ "${router_name}" == "" ]]; then
router_name="${default_router_name}"
fi
fi
# Make sure necessary env variables are set
if [ "$(checkEnvVariable ZITI_HOME ZITI_BIN_DIR)" ]; then
return 1
fi
ziti_home="${ZITI_HOME-}"
if [[ "${ziti_home}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_HOME is not set") "
return 1
fi
cat > "${ZITI_HOME-}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" <<HereDocForEdgeRouter
output_file="${ZITI_HOME-}/${router_name}.yaml"
cat > "${output_file}" <<HereDocForEdgeRouter
v: 3
identity:
@@ -676,6 +707,8 @@ forwarder:
linkDialQueueLength: 1000
linkDialWorkerCount: 10
HereDocForEdgeRouter
echo "Controller configuration file written to: $(BLUE "${output_file}")"
}
function createPki {
@@ -710,16 +743,24 @@ function createPki {
function createFabricRouterConfig {
router_name="${1-}"
if [[ "${router_name}" == "" ]]; then
echo -e " * ERROR: $(RED "createFabricRouterConfig requires a parameter to be supplied") "
# If router name is not passed as arg, prompt user for input
echo -e "$(YELLOW "createFabricRouterConfig requires a router name to be supplied") "
echo -en "Enter router name:"
read -r router_name
# Accept the default if no name provided
if [[ "${router_name}" == "" ]]; then
echo -e " * ERROR: $(RED "createFabricRouterConfig requires a parameter [router_name] to be supplied") "
return 1
fi
fi
if [ "$(checkEnvVariable ZITI_HOME)" ]; then
return 1
fi
ziti_home="${ZITI_HOME-}"
if [[ "${ziti_home}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_HOME is not set") "
return 1
fi
cat > "${ZITI_HOME}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" <<HereDocForEdgeRouter
output_file="${ZITI_HOME}/${router_name}.yaml"
cat > "${output_file}" <<HereDocForEdgeRouter
v: 3
identity:
@@ -787,22 +828,34 @@ forwarder:
linkDialQueueLength: 1000
linkDialWorkerCount: 10
HereDocForEdgeRouter
echo "Fabric router configuration file written to: $(BLUE "${output_file}")"
}
function createEdgeRouterWssConfig {
# Allow router name to be passed in as arg
router_name="${1-}"
if [[ "${router_name}" == "" ]]; then
echo -e " * ERROR: $(RED "createEdgeRouterWssConfig requires a parameter to be supplied") "
# If router name is not passed as arg, prompt user for input
echo -e "$(YELLOW "createEdgeRouterWssConfig requires a router name to be supplied") "
default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}"
echo -en "Enter router name (${default_router_name}):"
read -r router_name
# Accept the default if no name provided
if [[ "${router_name}" == "" ]]; then
router_name="${default_router_name}"
fi
fi
# Make sure necessary env variables are set
if [ "$(checkEnvVariable ZITI_HOME ZITI_BIN_DIR)" ]; then
return 1
fi
ziti_home="${ZITI_HOME-}"
if [[ "${ziti_home}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_HOME is not set") "
return 1
fi
cat > "${ZITI_HOME-}/${router_name}.yaml" <<HereDocForEdgeRouter
output_file="${ZITI_HOME-}/${router_name}.yaml"
cat > "${output_file}" <<HereDocForEdgeRouter
v: 3
identity:
@@ -870,23 +923,35 @@ forwarder:
linkDialQueueLength: 1000
linkDialWorkerCount: 10
HereDocForEdgeRouter
echo "Edge router wss configuration file written to: $(BLUE "${output_file}")"
}
# shellcheck disable=SC2120
function createEdgeRouterConfig {
# Allow router name to be passed in as arg
router_name="${1-}"
if [[ "${router_name}" == "" ]]; then
echo -e " * ERROR: $(RED "createEdgeRouterConfig requires a parameter to be supplied") "
# If router name is not passed as arg, prompt user for input
echo -e "$(YELLOW "createEdgeRouterConfig requires a router name to be supplied") "
default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}"
echo -en "Enter router name (${default_router_name}):"
read -r router_name
# Accept the default if no name provided
if [[ "${router_name}" == "" ]]; then
router_name="${default_router_name}"
fi
fi
# Make sure necessary env variables are set
if [ "$(checkEnvVariable ZITI_HOME ZITI_BIN_DIR)" ]; then
return 1
fi
ziti_home="${ZITI_HOME-}"
if [[ "${ziti_home}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_HOME is not set") "
return 1
fi
cat > "${ziti_home}/${router_name}.yaml" <<HereDocForEdgeRouter
output_file="${ZITI_HOME}/${router_name}.yaml"
cat > "${output_file}" <<HereDocForEdgeRouter
v: 3
identity:
@@ -954,10 +1019,13 @@ forwarder:
linkDialQueueLength: 1000
linkDialWorkerCount: 10
HereDocForEdgeRouter
echo "edge router configuration file written to: $(BLUE "${output_file}")"
}
function createFabricIdentity {
cat > "${ZITI_HOME}/identities.yml" <<IdentitiesJsonHereDoc
output_file="${ZITI_HOME}/identities.yaml"
cat > "${output_file}" <<IdentitiesJsonHereDoc
---
default:
caCert: "${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_CONTROLLER_HOSTNAME}-server.chain.pem"
@@ -965,20 +1033,38 @@ default:
key: "${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/keys/${ZITI_NETWORK-}-dotzeet.key"
endpoint: tls:${ZITI_CONTROLLER_HOSTNAME}:${ZITI_FAB_MGMT_PORT}
IdentitiesJsonHereDoc
echo "identities file written to: $(BLUE "${output_file}")"
}
function createControllerConfig {
ziti_home="${ZITI_HOME-}"
if [[ "${ziti_home}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_HOME is not set") "
# Allow controller name to be passed in as arg
controller_name="${1-}"
if [[ "${controller_name}" == "" ]]; then
# If controller name is not passed as arg, prompt user for input
echo -e "$(YELLOW "createControllerConfig requires a controller name to be supplied") "
default_controller_name="controller"
echo -en "Enter controller name (${default_controller_name}):"
read -r controller_name
# Accept the default if no name provided
if [[ "${controller_name}" == "" ]]; then
controller_name="${default_controller_name}"
fi
fi
# Make sure necessary env variables are set
if [ "$(checkEnvVariable ZITI_HOME )" ]; then
return 1
fi
cat "${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_CONTROLLER_HOSTNAME}-server.chain.pem" > "${ZITI_PKI_OS_SPECIFIC}/cas.pem"
cat "${ZITI_PKI_OS_SPECIFIC}/${ZITI_SIGNING_INTERMEDIATE_NAME}/certs/${ZITI_SIGNING_INTERMEDIATE_NAME}.cert" >> "${ZITI_PKI_OS_SPECIFIC}/cas.pem"
echo "wrote CA file to: ${ZITI_PKI_OS_SPECIFIC}/cas.pem"
echo "wrote CA file to: $(BLUE "${ZITI_PKI_OS_SPECIFIC}/cas.pem")"
cat > "${ziti_home}/controller.yaml" <<HereDocForEdgeConfiguration
output_file="${ZITI_HOME}/${controller_name}.yaml"
cat > "${output_file}" <<HereDocForEdgeConfiguration
v: 3
#trace:
@@ -1115,7 +1201,7 @@ web:
# - edge-client
# - fabric-management
- binding: edge-management
# options - variable optional/required
# options - arg optional/required
# This section is used to define values that are specified by the API they are associated with.
# These settings are per API. The example below is for the 'edge-api' and contains both optional values and
# required values.
@@ -1125,14 +1211,12 @@ web:
HereDocForEdgeConfiguration
echo "controller configuration file written to: ${ziti_home}/controller.yaml"
echo "Controller configuration file written to: $(BLUE "${output_file}")"
}
# shellcheck disable=SC2120
function ziti_createEnvFile {
ziti_home="${ZITI_HOME-}"
if [[ "${ziti_home}" == "" ]]; then
echo -e "$(RED "ERROR: ZITI_HOME HAS NOT BEEN DECLARED!")"
if [ "$(checkEnvVariable ZITI_HOME)" ]; then
if decideToUseDefaultZitiHome; then
# shellcheck disable=SC2155
export ZITI_NETWORK="$(hostname)"
@@ -1144,16 +1228,14 @@ function ziti_createEnvFile {
export ZITI_HOME="${ziti_home}"
if [[ "${ZITI_OSTYPE}" == "windows" ]]; then
export ZITI_HOME_OS_SPECIFIC="$(cygpath -m ${ZITI_HOME})"
export ZITI_HOME_OS_SPECIFIC="$(cygpath -m "${ZITI_HOME}")"
else
export ZITI_HOME_OS_SPECIFIC="${ZITI_HOME}"
fi
export ENV_FILE="${ZITI_HOME}/${ZITI_NETWORK}.env"
export ZITI_SHARED="${ZITI_HOME}"
if [[ "${ENV_FILE}" == "" ]]; then
echo -e "$(RED "ERROR: ENV_FILE HAS NOT BEEN DECLARED!")"
echo " "
if [ "$(checkEnvVariable ENV_FILE)" ]; then
return 1
fi
@@ -1177,7 +1259,7 @@ function ziti_createEnvFile {
if [[ "${ZITI_USER-}" == "" ]]; then export ZITI_USER="admin"; fi
if [[ "${ZITI_PWD-}" == "" ]]; then export ZITI_PWD="admin"; fi
if [[ "${ZITI_DOMAIN_SUFFIX-}" == "" ]]; then export ZITI_DOMAIN_SUFFIX=""; fi
if [[ "${ZITI_ID-}" == "" ]]; then export ZITI_ID="${ZITI_HOME}/identities.yml"; fi
if [[ "${ZITI_ID-}" == "" ]]; then export ZITI_ID="${ZITI_HOME}/identities.yaml"; fi
if [[ "${ZITI_FAB_MGMT_PORT-}" == "" ]]; then export ZITI_FAB_MGMT_PORT="10000"; fi
if [[ "${ZITI_FAB_CTRL_PORT-}" == "" ]]; then export ZITI_FAB_CTRL_PORT="6262"; fi
@@ -1186,7 +1268,7 @@ function ziti_createEnvFile {
export ZITI_PKI="${ZITI_SHARED}/pki"
if [[ "${ZITI_OSTYPE}" == "windows" ]]; then
export ZITI_PKI_OS_SPECIFIC="$(cygpath -m ${ZITI_PKI})"
export ZITI_PKI_OS_SPECIFIC="$(cygpath -m "${ZITI_PKI}")"
else
export ZITI_PKI_OS_SPECIFIC="${ZITI_PKI}"
fi
@@ -1239,6 +1321,7 @@ echo " "
fi
heredoc
echo "env file written to: $(BLUE "${ENV_FILE}")"
}
function waitForController {
@@ -1258,34 +1341,36 @@ function waitForController {
}
function createControllerSystemdFile {
ziti_home="${ZITI_HOME-}"
if [[ "${ziti_home}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_HOME is not set") "
# Allow controller name to be passed in as arg
controller_name="${1-}"
if [[ "${controller_name}" == "" ]]; then
# If controller name is not passed as arg, prompt user for input
echo -e "$(YELLOW "createRouterSystemdFile requires a controller name to be supplied") "
default_controller_name="controller"
echo -en "Enter controller name (${default_controller_name}):"
read -r controller_name
# Accept the default if no name provided
if [[ "${controller_name}" == "" ]]; then
controller_name=default_controller_name
fi
fi
# Make sure necessary env variables are set
if [ "$(checkEnvVariable ZITI_HOME ZITI_BIN_DIR)" ]; then
return 1
fi
ziti_bin_dir="${ZITI_BIN_DIR-}"
if [[ "${ziti_bin_dir}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_BIN_DIR is not set") "
return 1
fi
ziti_ctrl_name="${ZITI_CONTROLLER_RAWNAME-}"
if [[ "${ziti_ctrl_name}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_CONTROLLER_RAWNAME is not set") "
return 1
fi
systemd_file="${ziti_home}/ziti-controller.service"
cat > "${systemd_file}" <<HeredocForSystemd
output_file="${ZITI_HOME}/ziti-controller.service"
cat > "${output_file}" <<HeredocForSystemd
[Unit]
Description=Ziti-Controller
After=network.target
[Service]
User=root
WorkingDirectory=${ziti_home}
ExecStart="${ziti_bin_dir}/ziti-controller" run "${ziti_home}/controller.yaml"
WorkingDirectory=${ZITI_HOME}
ExecStart="${ZITI_BIN_DIR}/ziti-controller" run "${ZITI_HOME}/${controller_name}.yaml"
Restart=always
RestartSec=2
LimitNOFILE=65535
@@ -1294,37 +1379,40 @@ LimitNOFILE=65535
WantedBy=multi-user.target
HeredocForSystemd
echo "Controller systemd file written to: ${systemd_file}"
echo "Controller systemd file written to: $(BLUE "${output_file}")"
}
function createRouterSystemdFile {
# Allow router name to be passed in as arg
router_name="${1-}"
if [[ "${router_name}" == "" ]]; then
echo -e " * ERROR: $(RED "createRouterSystemdFile requires parameter [router_name] to be supplied") "
# If router name is not passed as arg, prompt user for input
echo -e "$(YELLOW "createRouterSystemdFile requires a router name to be supplied") "
default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}"
echo -en "Enter router name (${default_router_name}):"
read -r router_name
# Accept the default if no name provided
if [[ "${router_name}" == "" ]]; then
router_name="${default_router_name}"
fi
fi
if [ "$(checkEnvVariable ZITI_HOME ZITI_BIN_DIR )" ]; then
return 1
fi
ziti_home="${ZITI_HOME-}"
if [[ "${ziti_home}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_HOME is not set") "
return 1
fi
ziti_bin_dir="${ZITI_BIN_DIR-}"
if [[ "${ziti_bin_dir}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_BIN_DIR is not set") "
return 1
fi
systemd_file="${ziti_home}/ziti-router-${router_name}.service"
cat > "${systemd_file}" <<HeredocForSystemd
output_file="${ZITI_HOME}/ziti-router-${router_name}.service"
cat > "${output_file}" <<HeredocForSystemd
[Unit]
Description=Ziti-Router for ${router_name}
After=network.target
[Service]
User=root
WorkingDirectory=${ziti_home}
ExecStart="${ziti_bin_dir}/ziti-router" run "${ziti_home}/${router_name}.yaml"
WorkingDirectory=${ZITI_HOME}
ExecStart="${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME}/${router_name}.yaml"
Restart=always
RestartSec=2
LimitNOFILE=65536
@@ -1333,73 +1421,44 @@ LimitNOFILE=65536
WantedBy=multi-user.target
HeredocForSystemd
echo "Router systemd file written to: ${systemd_file}"
echo "Router systemd file written to: $(BLUE "${output_file}")"
}
function createControllerLaunchdFile {
launchd_file="${ziti_home}/ziti-router-${router_name}.launchd"
cat > "${launchd_file}" <<HeredocForLaunchd
# Allow controller name to be passed in as arg
controller_name="${1-}"
if [[ "${controller_name}" == "" ]]; then
# If controller name is not passed as arg, prompt user for input
echo -e "$(YELLOW "createRouterLaunchdFile requires a controller name to be supplied") "
default_controller_name="controller"
echo -en "Enter controller name (${default_controller_name}):"
read -r controller_name
# Accept the default if no name provided
if [[ "${controller_name}" == "" ]]; then
controller_name="${default_controller_name}"
fi
fi
# Make sure necessary env variables are set
if [ "$(checkEnvVariable ZITI_HOME ZITI_BIN_DIR)" ]; then
return 1
fi
output_file="${ZITI_HOME}/ziti-controller-${controller_name}.plist"
cat > "${output_file}" <<HeredocForLaunchd
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>ziti-controller-${ZITI_BINARIES_VERSION}</string>
<string>ziti-controller-${controller_name}</string>
<key>ProgramArguments</key>
<array>
<string>./ziti-controller</string>
<!--string>--verbose</string-->
<string>$ZITI_BIN_DIR/ziti-controller</string>
<string>run</string>
<string>./ctrl.with.edge.yml</string>
</array>
<key>WorkingDirectory</key>
<string>${ZITI_HOME}</string>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>StandardOutPath</key>
<string>/Users/scarey/Library/Logs/ziti-controller-0.22.9.log</string>
<key>StandardErrorPath</key>
<string>/Users/scarey/Library/Logs/ziti-controller-0.22.9.log</string>
</dict>
</plist>
HeredocForLaunchd
echo "Router launchd file written to: ${launchd_file}"
}
function createRouterLaunchdFile {
router_name="${1-}"
if [[ "${router_name}" == "" ]]; then
echo -e " * ERROR: $(RED "createRouterLaunchdFile requires parameter [router_name] to be supplied") "
return 1
fi
ziti_home="${ZITI_HOME-}"
if [[ "${ziti_home}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_HOME is not set") "
return 1
fi
ziti_bin_dir="${ZITI_BIN_DIR-}"
if [[ "${ziti_bin_dir}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_BIN_DIR is not set") "
return 1
fi
launchd_file="${ziti_home}/ziti-router-${router_name}.launchd"
cat > "${launchd_file}" <<HeredocForLaunchd
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>ziti-controller-0.22.9</string>
<key>ProgramArguments</key>
<array>
<string>./ziti-controller</string>
<!--string>--verbose</string-->
<string>run</string>
<string>./ctrl.with.edge.yml</string>
<string>$ZITI_HOME/${controller_name}.yaml</string>
</array>
<key>WorkingDirectory</key>
<string>${ZITI_HOME}</string>
@@ -1412,38 +1471,99 @@ cat > "${launchd_file}" <<HeredocForLaunchd
</dict>
</dict>
<key>StandardOutPath</key>
<string>/Users/scarey/Library/Logs/ziti-controller-0.22.9.log</string>
<string>${ZITI_HOME}/Logs/ziti-router-$ZITI_BINARIES_VERSION.log</string>
<key>StandardErrorPath</key>
<string>/Users/scarey/Library/Logs/ziti-controller-0.22.9.log</string>
<string>${ZITI_HOME}/Logs/ziti-router-$ZITI_BINARIES_VERSION.log</string>
</dict>
</plist>
HeredocForLaunchd
echo "Router launchd file written to: ${launchd_file}"
echo "Controller launchd file written to: $(BLUE "${output_file}")"
showLaunchdMessage
}
function createRouterLaunchdFile {
# Allow router name to be passed in as arg
router_name="${1-}"
if [[ "${router_name}" == "" ]]; then
# If router name is not passed as arg, prompt user for input
echo -e "$(YELLOW "createRouterLaunchdFile requires a router name to be supplied") "
default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}"
echo -en "Enter router name (${default_router_name}):"
read -r router_name
# Accept the default if no name provided
if [[ "${router_name}" == "" ]]; then
router_name="${default_router_name}"
fi
fi
# Make sure necessary env variables are set
if [ "$(checkEnvVariable ZITI_HOME ZITI_BIN_DIR)" ]; then
return 1
fi
output_file="${ziti_home}/ziti-router-${router_name}.plist"
cat > "${output_file}" <<HeredocForLaunchd
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>ziti-router-$router_name</string>
<key>ProgramArguments</key>
<array>
<string>$ZITI_BIN_DIR/ziti-router</string>
<string>run</string>
<string>$ZITI_HOME/ctrl.with.edge.yml</string>
</array>
<key>WorkingDirectory</key>
<string>${ZITI_HOME}</string>
<key>KeepAlive</key>
<true/>
<dict>
<key>PathState</key>
<dict>
<key>${ZITI_HOME}/launchd-enabled</key>
<true/>
</dict>
</dict>
<key>StandardOutPath</key>
<string>${ZITI_HOME}/Logs/ziti-router-$ZITI_BINARIES_VERSION.log</string>
<key>StandardErrorPath</key>
<string>${ZITI_HOME}/Logs/ziti-router-$ZITI_BINARIES_VERSION.log</string>
</dict>
</plist>
HeredocForLaunchd
echo "Router launchd file written to: $(BLUE "${output_file}")"
showLaunchdMessage
}
function showLaunchdMessage {
echo -e " "
echo -e "$(YELLOW "The generated launchd file is designed to keep the service alive while the file")"
echo -e "$(BLUE "${ZITI_HOME}/launchd-enabled") $(YELLOW "remains present.")"
echo -e "$(YELLOW "If this file is not present, the service will end")"
}
function createZacSystemdFile {
ziti_home="${ZITI_HOME-}"
if [[ "${ziti_home}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_HOME is not set") "
if [ "$(checkEnvVariable ZITI_HOME )" ]; then
return 1
fi
ziti_bin_dir="${ZITI_BIN_DIR-}"
if [[ "${ziti_bin_dir}" == "" ]]; then
echo -e " * ERROR: $(RED "ZITI_BIN_DIR is not set") "
return 1
fi
systemd_file="${ziti_home}/ziti-console.service"
cat > "${systemd_file}" <<HeredocForSystemd
output_file="${ZITI_HOME}/ziti-console.service"
cat > "${output_file}" <<HeredocForSystemd
[Unit]
Description=Ziti-Console
After=network.target
[Service]
User=root
WorkingDirectory=${ziti_home}/ziti-console
ExecStart=node "${ziti_home}/ziti-console/server.js"
WorkingDirectory=${ZITI_HOME}/ziti-console
ExecStart=node "${ZITI_HOME}/ziti-console/server.js"
Restart=always
RestartSec=2
LimitNOFILE=65536
@@ -1452,7 +1572,7 @@ LimitNOFILE=65536
WantedBy=multi-user.target
HeredocForSystemd
echo "ziti-console systemd file written to: ${systemd_file}"
echo "ziti-console systemd file written to: $(BLUE "${output_file}")"
}
function setOs {
@@ -1480,5 +1600,27 @@ function setOs {
return 0
}
function checkEnvVariable() {
for arg
do
# Parameter expansion is different between shells
if [ -n "$ZSH_VERSION" ]; then
if [ -z "${(P)arg}" ]; then
echo -e " * ERROR: $(RED "${arg} is not set") "
return 1
fi
elif [ -n "$BASH_VERSION" ]; then
if [ -z "${!arg}" ]; then
echo -e " * ERROR: $(RED "${arg} is not set") "
return 1
fi
else
echo -e " * $(RED "Unsupported shell, supply a PR or log an issue on https://github.com/openziti/ziti") "
return 1
fi
done
return 0
}
set +uo pipefail