f69efb67ad
- Tauri desktop app (apps/desktop) - Python Django API service (services/api) - Deployment scripts and docs
70 lines
2.0 KiB
Bash
70 lines
2.0 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
BASE_DOMAIN="${NETMAKER_BASE_DOMAIN:-nm.101-96-214-81.nip.io}"
|
|
ENV_FILE="${NETMAKER_ENV_FILE:-/root/netmaker/netmaker.env}"
|
|
NETWORK_ID="${NETMAKER_NETWORK_ID:-homevpn}"
|
|
NETWORK_RANGE="${NETMAKER_NETWORK_RANGE:-100.88.0.0/24}"
|
|
|
|
if [[ ! -f "${ENV_FILE}" ]]; then
|
|
echo "[AbyssInfo] Missing ${ENV_FILE}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
set -a
|
|
# shellcheck source=/dev/null
|
|
. "${ENV_FILE}"
|
|
set +a
|
|
|
|
if [[ -z "${MASTER_KEY:-}" ]]; then
|
|
echo "[AbyssInfo] MASTER_KEY is missing in ${ENV_FILE}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
api_url="https://api.${BASE_DOMAIN}"
|
|
auth_header="Authorization: Bearer ${MASTER_KEY}"
|
|
|
|
echo "[AbyssInfo] Checking Netmaker network: ${NETWORK_ID}"
|
|
networks_json="$(curl -ksS -H "${auth_header}" "${api_url}/api/networks")"
|
|
if echo "${networks_json}" | jq -e --arg id "${NETWORK_ID}" '.[]? | select(.netid == $id)' >/dev/null; then
|
|
echo "[AbyssInfo] Network already exists: ${NETWORK_ID}"
|
|
else
|
|
echo "[AbyssInfo] Creating Netmaker network: ${NETWORK_ID} (${NETWORK_RANGE})"
|
|
payload="$(jq -n \
|
|
--arg netid "${NETWORK_ID}" \
|
|
--arg addressrange "${NETWORK_RANGE}" \
|
|
'{
|
|
netid: $netid,
|
|
addressrange: $addressrange,
|
|
defaultacl: "yes",
|
|
defaultmtu: 1420,
|
|
defaultlistenport: 51821,
|
|
defaultkeepalive: 20,
|
|
auto_join: true
|
|
}')"
|
|
|
|
response_file="$(mktemp)"
|
|
code="$(curl -ksS -o "${response_file}" -w "%{http_code}" \
|
|
-X POST "${api_url}/api/networks" \
|
|
-H "${auth_header}" \
|
|
-H "Content-Type: application/json" \
|
|
--data "${payload}" || true)"
|
|
|
|
if [[ "${code}" -lt 200 || "${code}" -ge 300 ]]; then
|
|
echo "[AbyssInfo] Failed to create network. HTTP ${code}" >&2
|
|
head -c 500 "${response_file}" >&2 || true
|
|
echo >&2
|
|
rm -f "${response_file}"
|
|
exit 1
|
|
fi
|
|
rm -f "${response_file}"
|
|
fi
|
|
|
|
echo "[AbyssInfo] Current networks:"
|
|
curl -ksS -H "${auth_header}" "${api_url}/api/networks" \
|
|
| jq -r '.[] | "- \(.netid) \(.addressrange // "")"'
|
|
|
|
echo "[AbyssInfo] Backend config:"
|
|
echo "NETMAKER_BASE_URL=${api_url}"
|
|
echo "NETMAKER_NETWORK_ID=${NETWORK_ID}"
|