1#!/bin/sh
2#
3# Copyright (c) 2007 Chris Reinhardt. All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# 1. Redistributions of source code must retain the above copyright notice
10#    this list of conditions and the following disclaimer.
11#
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
17# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# $MidnightBSD: mports/Tools/scripts/chkfake,v 1.5 2007/11/14 18:51:17 ctriv Exp $
28#
29# MAINTAINER=   ctriv@MidnightBSD.org
30#
31# Check a fake install for errors.
32#
33# usage:  cd $port && make MPORT_MAINTAINER_MODE=yes fake
34#
35
36IFS="
37"
38
39PLIST=$1
40DESTDIR=$2
41PREFIX=$3
42CWD=$PREFIX
43
44if [ ! -z "$4" -a "$4" = '-s' ]; then
45	SKIP=`echo $5 | sed -E 's/ /\\|/g'`
46fi
47
48EXIT=0
49
50echo "Checking $DESTDIR"
51
52for _ENTRY in `cat $PLIST | grep -e '^[^@]\|^@cw\?d'`; do
53	ENTRY=`echo $_ENTRY | sed -E 's/[ 	]*$//'`
54	if echo $ENTRY | grep -e '^@cw\?d' > /dev/null; then
55		CWD=`echo $ENTRY | sed -E 's/^@cw?d[ \t]*([^\n]*)/\1/'`;
56		if [ ! -n "$CWD" ]; then
57			CWD=$PREFIX;
58		fi
59		continue;
60	fi
61	if [ -L $DESTDIR$CWD/$ENTRY ]; then
62		continue;
63	fi
64	if [ -e $DESTDIR$CWD/$ENTRY ]; then
65		if echo $ENTRY | grep -e "^$SKIP$" > /dev/null; then
66			continue;
67		fi
68
69		if grep $DESTDIR $DESTDIR$CWD/$ENTRY >/dev/null; then
70			EXIT=1
71			echo "    $ENTRY contains the fake destdir."
72		fi
73		continue;
74	fi
75	EXIT=1
76	if [ -e $CWD/$ENTRY ]; then
77		echo "    $ENTRY installed in $CWD"
78	else
79		echo "    $ENTRY not installed."
80	fi
81done
82
83if [ $EXIT -eq 0 ]; then
84	echo "Fake succeeded."
85else
86	echo "Fake failed."
87fi
88
89exit $EXIT
90
91