#!/bin/bash

# App-specific compose tags for Pi-hole — dispatched by dockerConfigSetupFileWithData
# (containers/<app>/scripts/<app>_compose_tags.sh defining appSetupComposeTags_<app>;
# $1 = the compose file path). The CFG_* tags are filled generically; only the
# computed REV_SERVER values need this handler.
appSetupComposeTags_pihole() {
    local full_file_path="$1"
    local default_gateway network_cidr
    default_gateway=$(ip route | grep default | awk '{print $3}' | head -1)
    [[ -z "$default_gateway" ]] && default_gateway="192.168.1.1"
    network_cidr=$(ip route | grep -v default | grep -E "192\.168|10\.|172\." | awk '{print $1}' | head -1)
    [[ -z "$network_cidr" ]] && network_cidr="192.168.0.0/16"
    tagsManagerUpdateUniversalTag "$full_file_path" "PIHOLE_REV_SERVER_TARGET_TAG" "$default_gateway"
    tagsManagerUpdateUniversalTag "$full_file_path" "PIHOLE_REV_SERVER_CIDR_TAG" "$network_cidr"
}
