#!/bin/sh

# Copyright (c) 2022 SUSE Software Solutions ltd
#
# This file is part of cloud-netconfig.
#
# cloud-netconfig is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cloud-netconfig is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cloud-netconfig.  If not, see <http://www.gnu.org/licenses/>.


test -z "$INTERFACE" && exit 1
ifcfg="/etc/sysconfig/network/ifcfg-${INTERFACE}"

if [[ -f $ifcfg ]]; then
    if grep -q -E "^CLOUD_NETCONFIG_MANAGE=[\'\"]?yes" $ifcfg ; then
        logger -t cloud-netconfig "ifcfg file for $INTERFACE seems stale, deleting"
        rm "/etc/sysconfig/network/ifcfg-${INTERFACE}"
    fi
fi
