#!/bin/bash
################################################################################
#
# make_managed_mount - postinstall/preremove steps for installed managed mounts
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006, 2007, 2008 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_managed_mount 4155 2008-08-07 04:58:41Z yselkowitz $
#
################################################################################
set -e

for d
do
	if [ ! -d ${D}${d} ]
	then
		error "directory ${d} does not exist"
	fi

	dodir /etc/postinstall /etc/preremove

	d_="${d//\//_}"

	cd ${D}${d}
	tar jcf ${D}/etc/postinstall/${PN}-${d_}.tar.bz2 *

	cd ${D}
	rm -fr ${D}${d}

	cat >> ${D}/etc/postinstall/${PN}.sh <<-_EOF
		if [ ! -d ${d} ]
		then
		    mkdir -p ${d}
		    mount -o managed \$(cygpath -w ${d}) ${d}
		    tar jxf /etc/postinstall/${PN}-${d_}.tar.bz2 -C ${d}
		fi

		_EOF

	cat >> ${D}/etc/preremove/${PN}.sh <<-_EOF
		rm -fr ${d}/*
		sleep 1
		umount ${d}
		rmdir ${d}
		
		_EOF
done
