#!/bin/bash
# $Id: domain_check.bash 2 2023-09-15 09:19:17Z bertrand $
# Ce script permet de vérifier que les domaines sur le serveur de page 
# parking ont une configuration cohérente.
apache_path="/etc/apache2"
apache_domain_list="$apache_path/domain.list"
apache_sites_folder="$apache_path/sites-available"
index=1
amtl_ref=4
while read domain; do
	#echo "[$domain]"
	readarray -td\; domain_parts <<< "$domain"; declare -p domain_parts > /dev/null
	#echo "($domain_parts)"
	domain_name=${domain_parts[0]}
	domain_tldr=${domain_parts[1]}
	#domain_tld=${domain_tldr%%*( )}
	domain_tld=`echo $domain_tldr | sed 's/ *$//g'`
	echo -n "[$domain_name.$domain_tld] = "
	prefix=$(printf "%03d" $index)
	config_file="$apache_sites_folder/$prefix-$domain_name-$domain_tld.conf"
	#echo $config_file
	amtl=$(cat $config_file | grep "$domain_name" | wc -l)
	if [[ $amtl -eq $amtl_ref ]]; then
		echo "OK"
	else
		echo "ERR ($amtl lines found)"
	fi
	((index=index+1))
done < $apache_domain_list
