LibrePortal/scripts/network/ip/ip_is_available.sh
librelad 875a60f90f LibrePortal v0.1.0 — initial release
A free, open, self-hosted app platform (GNU AGPLv3): one-click app deploys,
Traefik reverse proxy with automatic SSL, rootless Docker support, gluetun
VPN routing, and a web dashboard to manage it all.

Free & open forever to self-host; optional paid hosted services fund it.
See PROMISE.md.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-21 20:37:54 +01:00

24 lines
850 B
Bash
Executable File

#!/bin/bash
# Check if IP is available
ipIsAvailable()
{
local test_ip="$1"
# Validate IP format using regex (same pattern as scanning function)
if [[ ! "$test_ip" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
ip_available=""
elif [[ -z "$test_ip" ]]; then
ip_available=""
else
local existing=$(sqlite3 "$docker_dir/$db_file" "SELECT resource_value FROM network_resources WHERE resource_type = 'ip' AND resource_value = '$test_ip' AND status = 'active';" 2>/dev/null)
if [[ -n "$existing" ]]; then
ip_available=""
elif docker network inspect $CFG_NETWORK_NAME --format '{{range .Containers}}{{.IPv4Address}} {{end}}' 2>/dev/null | grep -q "$test_ip"; then
ip_available=""
else
ip_available="$test_ip"
fi
fi
}