summaryrefslogtreecommitdiff
path: root/lang/perl5.14/files/use.perl.in
blob: 1a8b17ba9097b34f82fd2f65c4cf7a21801fd579 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh

# $FreeBSD$

LINK_USRBIN="%%LINK_USRBIN%%"
: ${OSVERSION:=`/sbin/sysctl -n kern.osreldate`};
PERL_VERSION="%%PERL_VERSION%%"
PERL_VER="%%PERL_VER%%"
banner="# added by use.perl $(/bin/date +'%F %T')"
special_link_list="perl perl5"

do_remove_links()
{
	for binary in ${special_link_list} ; do
		if [ -L "/usr/bin/${binary}" ] ; then
			/bin/rm -f "/usr/bin/${binary}"
		fi
	done
	bins=`/bin/ls /usr/bin/*perl*5.* ${PKG_PREFIX}/bin/*perl*5.* 2>/dev/null`
	for binary in ${bins} ; do
		if [ -L "${binary}" ] ; then
			echo "use.perl: Removing ${binary} installed by an older perl port"
			/bin/rm -f "${binary}"
		fi
	done
}

do_create_links()
{
	for binary in ${special_link_list} ; do
		if [ -f "/usr/bin/${binary}" ] ; then
			echo "use.perl: Backing up /usr/bin/${binary} as /usr/bin/${binary}.freebsd"
			/bin/mv -f "/usr/bin/${binary}" "/usr/bin/${binary}.freebsd"
		fi
		if [ -e "/usr/bin/${binary}" ] ; then
			echo "use.perl: /usr/bin/${binary} is still there, which should not happen"
		elif [ -e "${PKG_PREFIX}/bin/perl${PERL_VERSION}" ] ; then
			/bin/ln -sf "${PKG_PREFIX}/bin/perl${PERL_VERSION}" "/usr/bin/${binary}"
		else
			echo "use.perl: ${PKG_PREFIX}/bin/perl${PERL_VERSION} is not there, a symlink won't do any good"
		fi
	done
}

do_cleanup_manpath()
{
	if [ -f /etc/manpath.config ] ; then
		/bin/cp -p /etc/manpath.config /etc/manpath.config.new
		/usr/bin/awk 's=0;
			/^#.*use.perl/ { s=1; mode=1 }
			/^#/ { s=1; if (mode != 1) { mode=0 } }
			/^OPTIONAL_MANPATH.*perl5/ { s=1; if (mode == 1) { mode=2 } }
			/^$/ { s=1; if (mode != 2) { mode = 0 } }
			{ if (s != 1) { mode = 0 } if (mode == 0) print }' /etc/manpath.config >/etc/manpath.config.new
		/bin/mv /etc/manpath.config /etc/manpath.config.bak
		/bin/mv /etc/manpath.config.new /etc/manpath.config
		/bin/rm /etc/manpath.config.bak
	fi
}

do_spam_manpath()
{
	if [ -f /etc/manpath.config ] ; then
		echo "${banner}" >>/etc/manpath.config
		echo "OPTIONAL_MANPATH	${PKG_PREFIX}/lib/perl5/${PERL_VER}/man" >>/etc/manpath.config
		echo "OPTIONAL_MANPATH	${PKG_PREFIX}/lib/perl5/${PERL_VER}/perl/man" >>/etc/manpath.config
	fi
}

if [ "$2" = "POST-INSTALL" ] ; then
	if [ ${LINK_USRBIN} = yes ] ; then
		do_remove_links
		do_create_links
	fi
	if [ "${OSVERSION}" -lt 900022 ] ; then
		do_cleanup_manpath
		do_spam_manpath
	fi
elif [ "$2" = "POST-DEINSTALL" ] ; then
	[ ${LINK_USRBIN} = yes ] && do_remove_links
	[ "${OSVERSION}" -lt 900022 ] && do_cleanup_manpath
fi

exit 0