elektrine/scripts/lib/module_selection.sh
maxfield 22a154a59d
All checks were successful
Deploy Docker Images / Build, push, and deploy (push) Successful in 20m29s
chore: remove the Uptime product
Uptime was an ops dashboard, not part of the personal internet suite.
Drop the app, route, nav item, DNS monitor hook, Oban queue, and tables.
Leftover ELEKTRINE_ENABLED_MODULES=uptime tokens are ignored so existing
hoster env files keep working.
2026-08-19 04:57:00 -04:00

128 lines
3 KiB
Bash
Executable file

#!/bin/bash
default_release_modules() {
if [[ -n "${ELEKTRINE_RELEASE_MODULES:-}" ]]; then
printf '%s' "$ELEKTRINE_RELEASE_MODULES"
elif [[ -n "${ELEKTRINE_ENABLED_MODULES:-}" ]]; then
printf '%s' "$ELEKTRINE_ENABLED_MODULES"
else
printf 'all'
fi
}
default_enabled_modules() {
if [[ -n "${ELEKTRINE_ENABLED_MODULES:-}" ]]; then
printf '%s' "$ELEKTRINE_ENABLED_MODULES"
elif [[ -n "${ELEKTRINE_RELEASE_MODULES:-}" ]]; then
printf '%s' "$ELEKTRINE_RELEASE_MODULES"
else
printf 'all'
fi
}
default_docker_profiles() {
printf '%s' "${DOCKER_PROFILES:-caddy dns email tor turn bluesky vpn}"
}
normalize_platform_modules() {
local raw="$1"
local trimmed="${raw//[[:space:]]/}"
NORMALIZED_MODULES=""
BUILD_SLUG=""
NORMALIZED_MODULE_ARRAY=()
if [[ -z "$trimmed" || "$trimmed" == "all" || "$trimmed" == "*" ]]; then
NORMALIZED_MODULES="all"
BUILD_SLUG="all"
NORMALIZED_MODULE_ARRAY=(chat social email nerve vpn dns atomine kairo)
return
fi
if [[ "$trimmed" == "none" ]]; then
NORMALIZED_MODULES="none"
BUILD_SLUG="none"
NORMALIZED_MODULE_ARRAY=()
return
fi
IFS="," read -r -a requested <<< "$trimmed"
local canonical_requested=()
local normalized=()
local token=""
append_unique_module() {
local value="$1"
local existing=""
for existing in "${canonical_requested[@]:-}"; do
if [[ "$existing" == "$value" ]]; then
return
fi
done
canonical_requested+=("$value")
}
for token in "${requested[@]}"; do
token="$(printf "%s" "$token" | tr "[:upper:]" "[:lower:]")"
case "$token" in
chat|social|email|nerve|vpn|dns|atomine|kairo)
append_unique_module "$token"
;;
uptime)
# Removed product. Ignore leftover hoster config.
;;
proofs|personhood)
append_unique_module "atomine"
;;
all|none|"")
echo "Platform module list cannot mix special values with explicit modules: $raw" >&2
return 1
;;
*)
echo "Unknown platform module: $token" >&2
return 1
;;
esac
done
local candidate=""
for candidate in chat social email nerve vpn dns atomine kairo; do
for token in "${canonical_requested[@]:-}"; do
if [[ "$token" == "$candidate" ]]; then
normalized+=("$candidate")
break
fi
done
done
if [[ "${#normalized[@]}" -eq 0 ]]; then
echo "Platform module list did not include any supported modules: $raw" >&2
return 1
fi
NORMALIZED_MODULE_ARRAY=("${normalized[@]}")
NORMALIZED_MODULES="$(IFS=,; echo "${normalized[*]}")"
if [[ "$NORMALIZED_MODULES" == "chat,social,email,nerve,vpn,dns,atomine,kairo" ]]; then
BUILD_SLUG="all"
else
BUILD_SLUG="$(IFS=-; echo "${normalized[*]}")"
fi
}
platform_module_selected() {
local wanted="$1"
local module=""
for module in "${NORMALIZED_MODULE_ARRAY[@]:-}"; do
if [[ "$module" == "$wanted" ]]; then
return 0
fi
done
return 1
}