Sun Jan 2 16:15:55 2022 UTC ()
Don't just remove a symlink on removal, ensure that it points
to an expected name before doing so.  Should prevent removal of
required symlinks which might otherwise happen when this package
by accident is instsalled and subsequently de-installed on
9.0 - 9.2 or other netbsd-9 variants.
Parts of fix for PR#56597.


(he)
diff -r1.2 -r1.3 pkgsrc/emulators/compat_netbsd/INSTALL.ELF

cvs diff -r1.2 -r1.3 pkgsrc/emulators/compat_netbsd/INSTALL.ELF (expand / switch to unified diff)

--- pkgsrc/emulators/compat_netbsd/INSTALL.ELF 2013/02/17 10:34:31 1.2
+++ pkgsrc/emulators/compat_netbsd/INSTALL.ELF 2022/01/02 16:15:55 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: INSTALL.ELF,v 1.2 2013/02/17 10:34:31 spz Exp $ 1# $NetBSD: INSTALL.ELF,v 1.3 2022/01/02 16:15:55 he Exp $
2 2
3# Generate a +ROOT_ACTIONS script that runs certain actions that require 3# Generate a +ROOT_ACTIONS script that runs certain actions that require
4# superuser privileges. 4# superuser privileges.
5# 5#
6case "${STAGE},$1" in 6case "${STAGE},$1" in
7UNPACK,|UNPACK,+ROOT_ACTIONS) 7UNPACK,|UNPACK,+ROOT_ACTIONS)
8 ${CAT} > ./+ROOT_ACTIONS << 'EOF' 8 ${CAT} > ./+ROOT_ACTIONS << 'EOF'
9#!@SH@ 9#!@SH@
10# 10#
11# +ROOT_ACTIONS - run actions requiring superuser privileges 11# +ROOT_ACTIONS - run actions requiring superuser privileges
12# 12#
13# Usage: ./+ROOT_ACTIONS ADD|REMOVE [metadatadir] 13# Usage: ./+ROOT_ACTIONS ADD|REMOVE [metadatadir]
14# 14#
@@ -73,28 +73,35 @@ ADD,0) @@ -73,28 +73,35 @@ ADD,0)
73 73
74REMOVE,0) 74REMOVE,0)
75 ${SED} -n "/^\# SYMLINK: /{s/^\# SYMLINK: //;p;}" ${SELF} | 75 ${SED} -n "/^\# SYMLINK: /{s/^\# SYMLINK: //;p;}" ${SELF} |
76 while read src dst; do 76 while read src dst; do
77 case $src in 77 case $src in
78 "") continue ;; 78 "") continue ;;
79 esac 79 esac
80 case $dst in 80 case $dst in
81 "") continue ;; 81 "") continue ;;
82 [!/]*) dst="${PKG_PREFIX}/$dst" ;; 82 [!/]*) dst="${PKG_PREFIX}/$dst" ;;
83 esac 83 esac
84 84
85 if ${TEST} -h "$dst"; then 85 if ${TEST} -h "$dst"; then
86 ${ECHO} "${PKGNAME}: removing $dst" 86 lsrc=$(readlink $dst)
87 ${RM} -f "$dst" 87 if [ "$lsrc" = ${PKG_PREFIX}/$src -o \
 88 "$lsrc" = $src ]
 89 then
 90 ${ECHO} "${PKGNAME}: removing $dst"
 91 ${RM} -f "$dst"
 92 else
 93 ${ECHO} "${PKGNAME}: mismatched symlink, skipping removal of $dst"
 94 fi
88 fi 95 fi
89 done 96 done
90 ${RM} -f ${ROOT_ACTIONS_COOKIE} 97 ${RM} -f ${ROOT_ACTIONS_COOKIE}
91 ;; 98 ;;
92 99
93ADD,*) 100ADD,*)
94 if ${TEST} ! -f ${ROOT_ACTIONS_COOKIE}; then 101 if ${TEST} ! -f ${ROOT_ACTIONS_COOKIE}; then
95 ${CAT} << EOM 102 ${CAT} << EOM
96============================================================================== 103==============================================================================
97Please run the following command with superuser privileges to complete 104Please run the following command with superuser privileges to complete
98the installation of ${PKGNAME}: 105the installation of ${PKGNAME}:
99 106
100 cd ${PKG_METADATA_DIR} && ${SELF} ADD 107 cd ${PKG_METADATA_DIR} && ${SELF} ADD