forked from opnsense/ports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_leftovers.sh
178 lines (163 loc) · 5.23 KB
/
check_leftovers.sh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#! /bin/sh
#
# MAINTAINER: [email protected]
#
# This script is used by poudriere and tinderbox(soon) as the source-of-truth for
# what should be considered a leftover and what is whitelisted.
#
# !!!! This script's input/output format must remain backwards-compatible.
# !!!! If you want to change it, create a new script and have the calling
# !!!! scripts use the new one if available.
#
# Usage: env PORTSDIR=... check_leftovers.sh category/port
# stdin:
# - missing-file
# + new-file
# M modified-file reason...
#
# stdout:
# same -/+/M format, but with files substituted, without approved
# whitelisted files, and hides any directories already in plist.
#
# The PLIST_SUB feature can be disabled by setting PLIST_SUB_SED=
# in environment.
set -o pipefail
[ -n "${DEBUG_MK_SCRIPTS}" -o -n "${DEBUG_MK_SCRIPTS_CHECK_LEFTOVERS}" ] && set -x
origin="$1"
[ $# -eq 1 ] || { echo "Must supply ORIGIN as parameter" >&2; exit 1; }
[ -n "${PORTSDIR}" ] || { echo "PORTSDIR must be set" >&2; exit 1; }
# May be passed in from environment if using an overlay.
: ${portdir:="${PORTSDIR}/${origin}"}
# PREFIX/LOCALBASE may be set in env or want default from port.
if [ -n "${PREFIX}" ]; then
PORT_FLAGS="${PORT_FLAGS} PREFIX=${PREFIX}"
else
PREFIX=$(make -C ${portdir} -VPREFIX)
fi
if [ -n "${LOCALBASE}" ]; then
PORT_FLAGS="${PORT_FLAGS} LOCALBASE=${LOCALBASE}"
else
LOCALBASE=$(make -C ${portdir} -VLOCALBASE)
fi
if [ -z "${CCACHE_DIR}" ]; then
CCACHE_DIR=$(make -C ${portdir} -VCCACHE_DIR)
fi
if [ -z "${UID_FILES}" ]; then
UID_FILES=$(make -C ${portdir} -VUID_FILES)
fi
homedirs=$(awk -F: -v users="$(make -C ${portdir} -V USERS|sed -e 's, ,|,g;/^$/d;s,^,^(,;s,$,)$,')" 'users && $1 ~ users {print $9}' ${UID_FILES}|sort -u|sed -e "s|/usr/local|${PREFIX}|"|tr "\n" " ")
plistsub_sed=$(mktemp -t plistsub_sed)
trap "rm -f ${plistsub_sed}" EXIT 1
make -C ${portdir} -VPLIST_SUB_SED | /bin/sh ${PORTSDIR}/Mk/Scripts/plist_sub_sed_sort.sh ${plistsub_sed}
tmpplist=$(make -C ${portdir} -VTMPPLIST)
while read -r modtype path extra; do
# Ignore everything from these files/directories
case "${path}" in
${CCACHE_DIR:-/nonexistent}/*|\
/compat/linux/proc/*|\
/dev/*|\
/etc/make.conf.bak|\
/proc/*|\
/tmp/*|\
/var/db/pkg/*|\
/var/db/ports/*|\
/var/log/*|\
/var/mail/*|\
/var/run/*|\
/var/tmp/*) continue ;;
# fc-cache - skip for now
/var/db/fontconfig/*) continue ;;
esac
ignore_path=0
sub_path=$(echo "$path" | sed -e "s|^${PREFIX}/||" -f "${plistsub_sed}")
orig_sub_path="${sub_path}"
# If this is a directory, use @dir in output
is_dir=0
if [ -d "${path}" ]; then
is_dir=1
sub_path="@dir ${sub_path}"
fi
# Handle PORTDOCS/PORTEXAMPLES/etc
case "${orig_sub_path}" in
%%DOCSDIR%%*) sub_path="%%PORTDOCS%%${sub_path}" ;;
%%EXAMPLESDIR%%*) sub_path="%%PORTEXAMPLES%%${sub_path}" ;;
esac
case $modtype in
+)
if [ ${is_dir} -eq 1 ]; then
# home directory of users created
case " ${homedirs} " in
*\ ${path}\ *) continue ;;
*\ ${path}/*\ *) continue ;;
esac
# Don't show dirs already in plist (due to parents)
grep -qE \
"^@(unexec rmdir \"?(%D/|${PREFIX})?${path#${PREFIX}/}[ \"]|dir(rm|rmtry)? ${path#${PREFIX}/}\$)" \
${tmpplist} && continue
fi
# Check absolute paths
case "${path}" in
# Leave qmail's queue dir alone to not cause lost mail
# during upgrades, just as /var/mail is left alone.
/var/qmail/queue/*|/var/qmail/queue) continue ;;
esac
# Check relative/plist paths
case "${sub_path}" in
# gconftool-2 --makefile-uninstall-rule is unpredictable
etc/gconf/gconf.xml.defaults/%gconf-tree*.xml) ;;
*) echo "+ ${sub_path}" ;;
esac
;;
-)
# Skip removal of PREFIX and PREFIX/info from
# bsd.port.mk for now.
# Skip if it is PREFIX and non-LOCALBASE. See misc/kdehier4
# or mail/qmail for examples
[ "${path}" = "${PREFIX}" -a "${LOCALBASE}" != "${PREFIX}" ] &&
ignore_path=1
# The removal of info may be a bug; it's part of BSD.local.dist.
# See ports/74691
[ "${sub_path}" = "info" -a "${LOCALBASE}" != "${PREFIX}" ] &&
ignore_path=1
[ $ignore_path -eq 0 ] && echo "- ${sub_path}"
;;
M)
# Check relative/plist paths
case "${sub_path}" in
# gconftool-2 --makefile-uninstall-rule is unpredictable
etc/gconf/gconf.xml.defaults/%gconf-tree*.xml) ;;
# This is a cache file for gio modules could be modified
# for any gio modules
lib/gio/modules/giomodule.cache) ;;
# removal of info files leaves entry uneasy to cleanup
# in info/dir
info/dir) ;;
*/info/dir) ;;
# The is pear database cache
%%PEARDIR%%/.depdb|%%PEARDIR%%/.filemap) ;;
#ls-R files from texmf are often regenerated
*/ls-R) ;;
# Octave packages database, blank lines can be inserted
# between pre-install and post-deinstall
share/octave/octave_packages) ;;
# xmlcatmgr is constantly updating catalog.ports ignore
# modification to that file
share/xml/catalog.ports) ;;
# Ignore ghc's doc index
share/doc/ghc-%%GHC_VERSION%%/*) ;;
# Ignore ghc's package conf
lib/ghc-%%GHC_VERSION%%/package.conf.d/*) ;;
# Ignore common system config files
/etc/group|\
/etc/make.conf|\
/etc/master.passwd|\
/etc/passwd|\
/etc/pwd.db|\
/etc/shells|\
/etc/spwd.db) ;;
*) echo "M ${sub_path#@dir } ${extra}" ;;
esac
;;
esac
done
exit 0