#!/bin/bash
################################################################################
#
# prep_etc_defaults - postinstall steps for /etc/defaults config files
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006, 2007, 2009 Yaakov Selkowitz
# Provided by the Cygwin Ports project <http://cygwinports.dotsrc.org/>
#
# cygport 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.
#
# cygport 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 cygport.  If not, see <http://www.gnu.org/licenses/>.
#
# $Id: make_etc_defaults 6004 2009-03-12 04:33:40Z yselkowitz $
#
################################################################################
set -e

for etc
do
	if [ ! -f ${D}${etc} ]
	then
		error "file ${etc} does not exist"
	fi

	dodir /etc/defaults${etc%/*}
	/bin/mv ${D}${etc} ${D}/etc/defaults${etc}

	dodir /etc/postinstall
	cat >> ${D}/etc/postinstall/${PN}.sh <<-_EOF
		if [ ! -f ${etc} ]
		then
		    /bin/cp /etc/defaults${etc} ${etc}
		fi
		
		_EOF

	dodir /etc/preremove
	cat >> ${D}/etc/preremove/${PN}.sh <<-_EOF
		if [ -f ${etc} ] && cmp -s /etc/defaults${etc} ${etc}
		then
		    rm ${etc}
		fi
		
		_EOF
done
