diff --git a/README.md b/README.md index 2177737..e1eb704 100644 --- a/README.md +++ b/README.md @@ -143,9 +143,12 @@ The tracked example contains only: ```dotenv TAPM_BROKER_URL=https://tapm.example.com +GITEA_DOMAIN=git.example.com ``` Replace it with the deployed HTTPS origin, without an API path. There is no hard-coded operational broker URL; authorization fails with a configuration -message when the variable is missing or invalid. Repository updates do not +message when the variable is missing or invalid. `GITEA_DOMAIN` is a hostname, +without `https://` or a path, and controls Gitea connectivity plus restoration +of the `voltron/iDS-Defaults.git` repository. Repository updates do not overwrite the system configuration file. diff --git a/config.env.example b/config.env.example index 1e8f1d9..1248320 100644 --- a/config.env.example +++ b/config.env.example @@ -1,2 +1,3 @@ # Copy to /etc/ta-proxmenu/config.env and replace with the deployed broker. TAPM_BROKER_URL=https://tapm.example.com +GITEA_DOMAIN=git.example.com diff --git a/defaults.inc b/defaults.inc index 8ef37e1..504e104 100755 --- a/defaults.inc +++ b/defaults.inc @@ -20,19 +20,29 @@ PULSE_RELEASE='v6.1.1' PULSE_PORT='7655' TAPM_CONFIG_FILE='/etc/ta-proxmenu/config.env' -if [[ -z "${TAPM_BROKER_URL:-}" && -r "$TAPM_CONFIG_FILE" ]]; then - TAPM_BROKER_URL="$( - sed -n 's/^[[:space:]]*TAPM_BROKER_URL[[:space:]]*=[[:space:]]*//p' \ - "$TAPM_CONFIG_FILE" | - tail -n 1 - )" - TAPM_BROKER_URL="${TAPM_BROKER_URL#\"}" - TAPM_BROKER_URL="${TAPM_BROKER_URL%\"}" - TAPM_BROKER_URL="${TAPM_BROKER_URL#\'}" - TAPM_BROKER_URL="${TAPM_BROKER_URL%\'}" -fi +for config_key in TAPM_BROKER_URL GITEA_DOMAIN; do + if [[ -z "${!config_key:-}" && -r "$TAPM_CONFIG_FILE" ]]; then + config_value="$( + sed -n "s/^[[:space:]]*${config_key}[[:space:]]*=[[:space:]]*//p" \ + "$TAPM_CONFIG_FILE" | + tail -n 1 + )" + config_value="${config_value#\"}" + config_value="${config_value%\"}" + config_value="${config_value#\'}" + config_value="${config_value%\'}" + printf -v "$config_key" '%s' "$config_value" + fi +done +unset config_key config_value TAPM_BROKER_URL="${TAPM_BROKER_URL:-}" TAPM_BROKER_URL="${TAPM_BROKER_URL%/}" +GITEA_DOMAIN="${GITEA_DOMAIN:-}" +if [[ "$GITEA_DOMAIN" =~ ^[A-Za-z0-9.-]+(:[0-9]+)?$ ]]; then + GITEA_URL="https://${GITEA_DOMAIN}" +else + GITEA_URL='' +fi S1_BROKER_PACKAGE='sentinelone-linux' S1_PACKAGE='tapm-sentinelone.deb' diff --git a/run.sh b/run.sh index babff3c..bdd1fae 100755 --- a/run.sh +++ b/run.sh @@ -5,6 +5,26 @@ DEFAULTS_REPOSITORY='/opt/idssys/defaults' DEFAULTS_CACHE_DIR='/var/cache/ta-proxmenu' DEFAULTS_CHECK_FILE="${DEFAULTS_CACHE_DIR}/defaults-last-check" DEFAULTS_CHECK_SECONDS=14400 +TAPM_CONFIG_FILE='/etc/ta-proxmenu/config.env' + +if [[ -z "${GITEA_DOMAIN:-}" && -r "$TAPM_CONFIG_FILE" ]]; then + GITEA_DOMAIN="$( + sed -n 's/^[[:space:]]*GITEA_DOMAIN[[:space:]]*=[[:space:]]*//p' \ + "$TAPM_CONFIG_FILE" | + tail -n 1 + )" + GITEA_DOMAIN="${GITEA_DOMAIN#\"}" + GITEA_DOMAIN="${GITEA_DOMAIN%\"}" + GITEA_DOMAIN="${GITEA_DOMAIN#\'}" + GITEA_DOMAIN="${GITEA_DOMAIN%\'}" +fi +if [[ "${GITEA_DOMAIN:-}" =~ ^[A-Za-z0-9.-]+(:[0-9]+)?$ ]]; then + GITEA_URL="https://${GITEA_DOMAIN}" + DEFAULTS_REPOSITORY_URL="${GITEA_URL}/voltron/iDS-Defaults.git" +else + GITEA_URL='' + DEFAULTS_REPOSITORY_URL='' +fi source /opt/idssys/ta-proxmenu/inc/git-update.inc @@ -36,9 +56,13 @@ AUTO_UPDATE_DEFAULTS() { if [[ ! -d "${DEFAULTS_REPOSITORY}/.git" ]]; then echo "iDSSYS Defaults is missing; restoring it from origin..." + if [[ -z "$DEFAULTS_REPOSITORY_URL" ]]; then + echo "WARNING: GITEA_DOMAIN is not configured; unable to restore iDSSYS Defaults." >&2 + return + fi mkdir -p /opt/idssys if ! timeout 60 git clone \ - https://git.scity.us/voltron/iDS-Defaults.git "$DEFAULTS_REPOSITORY"; then + "$DEFAULTS_REPOSITORY_URL" "$DEFAULTS_REPOSITORY"; then echo "WARNING: Unable to restore iDSSYS Defaults." >&2 return fi @@ -234,9 +258,13 @@ INSTALL_UPDATES() { local update_failed=0 echo -e "${idsCL[LightCyan]}Checking for updates...${idsCL[Default]}" + if [[ -z "$GITEA_URL" ]]; then + echo -e "${idsCL[Red]}GITEA_DOMAIN is not configured in ${TAPM_CONFIG_FILE}.${idsCL[Default]}" + return 1 + fi if ! curl --fail --silent --show-error --head \ - --connect-timeout 3 --max-time 10 https://git.scity.us >/dev/null; then - echo -e "${idsCL[Red]}Could not connect to git.scity.us${idsCL[Default]}" + --connect-timeout 3 --max-time 10 "$GITEA_URL" >/dev/null; then + echo -e "${idsCL[Red]}Could not connect to ${GITEA_DOMAIN}${idsCL[Default]}" return 1 fi