#! /bin/bash
SCRIPT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)

doSudo=""
if [ $(id -un) != "root" ]; then
    doSudo="/usr/bin/sudo"
fi

testuiteConf=$1
if [ -z $1 ]; then
    testuiteConf=${SCRIPT_DIR}/01-testuite.conf
fi

if ! rpm -qa | grep -q dnsmasq; then
    ${doSudo} dnf install -y dnsmasq dnsmasq-utils
fi

#if [ ! -e /etc/NetworkManager/conf.d/00-use-dnsmasq.conf ]; then
    ${doSudo} cp ${SCRIPT_DIR}/00-use-dnsmasq.conf /etc/NetworkManager/conf.d/00-use-dnsmasq.conf
#fi

#if [ ! -e /etc/NetworkManager/dnsmasq.d/01-testuite.conf ]; then
    ${doSudo} cp -r $testuiteConf /etc/NetworkManager/dnsmasq.d/
#fi

#if [ ! -e /etc/NetworkManager/dnsmasq.d/02-add-hosts.conf ]; then
    ${doSudo} cp ${SCRIPT_DIR}/02-add-hosts.conf /etc/NetworkManager/dnsmasq.d/02-add-hosts.conf
#fi

${doSudo} systemctl restart NetworkManager

