1#
2# -- START --
3# postinstall.freebsd.sh,v 1.1 2001/08/21 20:33:16 root Exp
4#
5#  If you are building a PORT, see the
6#  DISTRIBUTIONS/Freebsd directory for a complete port
7#  building package.
8# 
9# This is the shell script that does the postinstall
10# dynamic fixup
11#  It needs to be massaged with the information for
12#  various paths.
13# If you are building a package,  then you do NOT want
14#  to have this executed - it will put the sample files
15#  in place.  You need to do this during the postinstall
16#  step in the package installation.
17#
18echo RUNNING postinstall.freebsd.sh parms "'$0 $@'" MAKEPACKAGE="$MAKEPACKAGE" MAKEINSTALL="$MAKEINSTALL" PREFIX="$PREFIX" INIT="$INIT" cwd `pwd`
19if [ "$VERBOSE_INSTALL" != "" ] ; then set -x; fi
20fix () {
21    v=`echo $1 | sed -e 's/[:;].*//'`;
22    p=`echo $2 | sed -e 's/:.*//'`; d=`dirname $p`;
23    if expr "$p" : "\|" >/dev/null ; then
24        echo "$v is a filter '$p'" 
25        return 0
26    fi
27    echo "Putting $p in $d, using $v.sample"
28    if [ ! -d "$d" ] ; then
29        echo "Directory $d does not exist!"
30        mkdir -p $d
31    fi
32    if [ -f $v.sample ] ; then
33        if [ $v.sample != $p.sample ] ; then ${INSTALL} $v.sample $p.sample; fi
34    elif [ -f $v ] ; then
35        if [ $v != $p.sample ] ; then ${INSTALL} $v $p.sample; fi
36    else
37        echo "Do not have $v.sample or $v"
38    fi
39    if [ ! -f $p.sample ] ; then
40        echo "Do not have $p.sample"
41    elif [ ! -f $p ] ; then
42        ${INSTALL} -m 644 $p.sample $p;
43    fi;
44}
45# we use the /usr/local/etc/rc.d method to start
46# lpd
47# we have to take them from one place and put in another
48if [ "X$MAKEPACKAGE" = "XYES" ] ; then
49    hold=${DESTDIR}${PREFIX}/etc/lpd
50    echo "Setting up configuration files path for package" ${hold}
51    # we put files into the destination
52    if [ ! -d ${hold} ] ; then mkdir -p ${hold} ; fi;
53    ${INSTALL} lpd.perms ${hold}/lpd.perms.sample
54    ${INSTALL} lpd.conf ${hold}/lpd.conf.sample
55    ${INSTALL} printcap ${hold}/printcap.sample
56    if [ "$INIT" != no ] ; then
57        ${INSTALL} -m 755 init.freebsd ${hold}/lprng.sh
58    fi
59elif [ "X$MAKEINSTALL" = XYES ] ; then
60	# we have the port pre-install operation
61	if [ "$MANDIR" = "/usr/man" -a ! -d ${DESTDIR}/usr/man ] ; then
62		# we have the dreaded standard installation
63		# try to make a symbolic link to 
64		echo "Creating symbolic link from /usr/man to /usr/share/man"
65		v=`ln -s ${DESTDIR}/usr/share/man ${DESTDIR}/usr/man`;
66	fi
67    hold=${DESTDIR}${PREFIX}/etc/lpd
68    echo "Setting up configuration files path for installation" ${hold}
69    if [ ! -d ${hold} ] ; then mkdir -p ${hold} ; fi;
70    ${INSTALL} lpd.perms ${hold}/lpd.perms.sample
71    ${INSTALL} lpd.conf ${hold}/lpd.conf.sample
72    ${INSTALL} printcap ${hold}/printcap.sample
73
74    fix ${hold}/lpd.perms "${DESTDIR}${LPD_PERMS_PATH}"
75    fix ${hold}/lpd.conf "${DESTDIR}${LPD_CONF_PATH}"
76    fix ${hold}/printcap "${DESTDIR}${PRINTCAP_PATH}"
77
78    if [ "$INIT" != no ] ; then
79		if [ -f /etc/rc.conf ] ; then
80			perl -spi.bak -e 's/^lpd_enable/#lpd_enable/;' ${DESTDIR}/etc/rc.conf 
81		fi
82		${INSTALL} -m 755 init.freebsd ${hold}/lprng.sh
83		init=${DESTDIR}/usr/local/etc/rc.d/lprng.sh
84		echo "Setting up init script $init using init.freebsd"
85		if [ ! -d `dirname $init` ] ; then mkdir -p `dirname $init ` ; fi;
86		rm -f $init
87		${INSTALL} -m 755 init.freebsd $init
88
89		echo "Stopping LPD"
90		kill -INT `ps ${PSHOWALL} | awk '/lpd/{ print $1;}'` >/dev/null 2>&1
91		sleep 2;
92		# check the printcap information
93		echo "Checking Printcap Info and fixing permissions"
94		${SBINDIR}/checkpc -f
95		# restart the server
96		echo "Restarting server"
97		sh $init start
98    fi
99elif [ "X$2" = "XPOST-INSTALL" ] ; then
100    # when doing an install from a package we get the file from the package
101    hold=etc/lpd
102    if [ -f ${hold}/lpd.perms.sample ] ; then
103        fix ${hold}/lpd.perms "${LPD_PERMS_PATH}"
104        fix ${hold}/lpd.conf "${LPD_CONF_PATH}"
105        fix ${hold}/printcap "${PRINTCAP_PATH}"
106		if [ "$INIT" != no ] ; then
107			init=/usr/local/etc/rc.d/lprng.sh
108			${INSTALL} -m 755 ${hold}/lprng.sh $init;
109			if [ -f /etc/rc.conf ] ; then
110				perl -spi.bak -e 's/^lpd_enable/#lpd_enable/;' /etc/rc.conf 
111			fi
112		fi
113    else
114        echo "WARNING: configuration files missing from package! CWD " `pwd`
115        ls
116        exit 1
117    fi
118elif [ "X$2" = "XPRE-INSTALL" ] ; then
119	# we have the port pre-install operation
120	if [ "$MANDIR" = "/usr/man" -a ! -d /usr/man ] ; then
121		# we have the dreaded standard installation
122		# try to make a symbolic link to 
123		echo "Creating symbolic link from /usr/man to /usr/share/man"
124		v=`ln -s /usr/share/man /usr/man`;
125	fi
126fi
127exit 0
128