summaryrefslogtreecommitdiff
path: root/java/javavmwrapper/pkg-deinstall
blob: 3075b66c5428dd9dabc23f19ecb2075492da03d2 (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
#!/bin/sh
#
# $FreeBSD$

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

# Run this script at the pre-deinstall stage
if [ "x${2}" != "xDEINSTALL" ]; then
    exit 0
fi

# The configuration file
CONF="${PKG_PREFIX}/etc/javavms"

# Ensure the configuration file exists
if [ ! -f "${CONF}" ]; then
    exit 0
fi

# Ensure the configuration file has the correct permissions
if [ ! -r "${CONF}" ]; then
    echo "error: can't read configuration file ${CONF}" 1>&2
    exit 1
fi

# Destroy the symbolic links that were created for every executable for a VM.
cat "${CONF}" | \
(
while read JAVAVM; do
    VM=`echo "${JAVAVM}" | sed -E 's|[[:space:]]*#.*||' 2>/dev/null`
    JAVA_HOME=`dirname "${VM}"`
    JAVA_HOME=`dirname "${JAVA_HOME}"`
    for exe in "${JAVA_HOME}"/bin/* "${JAVA_HOME}"/jre/bin/*; do
        exe=`basename "${exe}"`
        if [ -L "${PKG_PREFIX}/bin/${exe}" -a \
             "`ls -ld "${PKG_PREFIX}/bin/${exe}" 2>/dev/null | \
               awk '/->/{print $NF;exit 0}END{exit 1}'`" = \
             "${PKG_PREFIX}/bin/javavm" ]; then
            rm "${PKG_PREFIX}/bin/${exe}"
        fi
    done;
done;
)

exit 0