fix: publish host IP in AD DNS

This commit is contained in:
Ludwig Lehnert
2026-06-24 10:33:52 +00:00
parent 61b698890e
commit f23aa64155
5 changed files with 270 additions and 2 deletions

70
setup
View File

@@ -57,6 +57,45 @@ sanitize_sam_account_name() {
printf '%s' "${cleaned_name:0:20}"
}
parse_route_source_ip() {
local route="$1"
local previous=""
local token
for token in $route; do
if [[ "$previous" == "src" ]]; then
printf '%s\n' "$token"
return 0
fi
previous="$token"
done
return 1
}
detect_ad_dns_ip() {
local lookup_name="$1"
local target_ip=""
local route=""
if ! command -v ip >/dev/null 2>&1; then
return 1
fi
if [[ -n "$lookup_name" ]] && command -v getent >/dev/null 2>&1; then
while read -r target_ip _; do
if [[ ! "$target_ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
continue
fi
route="$(ip -o -4 route get "$target_ip" 2>/dev/null || true)"
parse_route_source_ip "$route" && return 0
done < <(getent ahostsv4 "$lookup_name" 2>/dev/null)
fi
route="$(ip -o -4 route get 1.1.1.1 2>/dev/null || true)"
parse_route_source_ip "$route"
}
prompt_value() {
local var_name="$1"
local prompt_text="$2"
@@ -92,11 +131,17 @@ write_env_file() {
local backup_retention_yearly="1"
local samba_hostname="adsambafsrv"
local netbios_name="ADSAMBAFSRV"
local ad_dns_ip=""
local ad_dns_name=""
local ad_dns_ip_auto="0"
local service_password=""
local service_account_sam=""
local fslogix_group_prompt=""
local samba_hostname_input=""
local netbios_name_input=""
local ad_dns_ip_input=""
local ad_dns_name_input=""
local detected_ad_dns_ip=""
local sanitized_netbios_name=""
prompt_value realm "REALM (e.g. EXAMPLE.COM)"
@@ -128,6 +173,25 @@ write_env_file() {
fi
netbios_name="$sanitized_netbios_name"
detected_ad_dns_ip="$(detect_ad_dns_ip "$domain" || true)"
if [[ -n "$detected_ad_dns_ip" ]]; then
read -r -p "AD_DNS_IP (host LAN IP to publish in AD DNS) [${detected_ad_dns_ip}]: " ad_dns_ip_input
if [[ -n "$ad_dns_ip_input" ]]; then
ad_dns_ip="$ad_dns_ip_input"
else
ad_dns_ip="$detected_ad_dns_ip"
ad_dns_ip_auto="1"
fi
else
prompt_value ad_dns_ip "AD_DNS_IP (host LAN IP to publish in AD DNS)"
fi
ad_dns_name="${samba_hostname}.${domain}"
read -r -p "AD_DNS_NAME [${ad_dns_name}]: " ad_dns_name_input
if [[ -n "$ad_dns_name_input" ]]; then
ad_dns_name="$ad_dns_name_input"
fi
read -r -p "BACKUP_DESTINATION (optional URL, press Enter to disable): " backup_destination
read -r -p "BACKUP_START_HOUR [2]: " backup_start_hour
backup_start_hour="${backup_start_hour:-2}"
@@ -176,6 +240,9 @@ SERVICE_ACCOUNT_PASSWORD=${service_password}
DOMAIN_USERS_SID=${domain_users_sid}
DOMAIN_ADMINS_SID=${domain_admins_sid}
FSLOGIX_GROUP_SID=${fslogix_group_sid}
AD_DNS_IP=${ad_dns_ip}
AD_DNS_NAME=${ad_dns_name}
AD_DNS_IP_AUTO=${ad_dns_ip_auto}
BACKUP_DESTINATION=${backup_destination}
BACKUP_START_HOUR=${backup_start_hour}
BACKUP_RETENTION_DAILY=${backup_retention_daily}
@@ -233,6 +300,9 @@ JOIN_PASSWORD=${service_password}
DOMAIN_USERS_SID=${domain_users_sid}
DOMAIN_ADMINS_SID=${domain_admins_sid}
FSLOGIX_GROUP_SID=${fslogix_group_sid}
AD_DNS_IP=${ad_dns_ip}
AD_DNS_NAME=${ad_dns_name}
AD_DNS_IP_AUTO=${ad_dns_ip_auto}
BACKUP_DESTINATION=${backup_destination}
BACKUP_START_HOUR=${backup_start_hour}
BACKUP_RETENTION_DAILY=${backup_retention_daily}