Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/Mk/Scripts/check_leftovers.sh
16462 views
1
#! /bin/sh
2
#
3
# MAINTAINER: [email protected]
4
#
5
# This script is used by poudriere and tinderbox(soon) as the source-of-truth for
6
# what should be considered a leftover and what is whitelisted.
7
#
8
# !!!! This script's input/output format must remain backwards-compatible.
9
# !!!! If you want to change it, create a new script and have the calling
10
# !!!! scripts use the new one if available.
11
#
12
# Usage: env PORTSDIR=... check_leftovers.sh category/port
13
# stdin:
14
# - missing-file
15
# + new-file
16
# M modified-file reason...
17
#
18
# stdout:
19
# same -/+/M format, but with files substituted, without approved
20
# whitelisted files, and hides any directories already in plist.
21
#
22
# The PLIST_SUB feature can be disabled by setting PLIST_SUB_SED=
23
# in environment.
24
25
set -o pipefail
26
27
[ -n "${DEBUG_MK_SCRIPTS}" -o -n "${DEBUG_MK_SCRIPTS_CHECK_LEFTOVERS}" ] && set -x
28
29
origin="$1"
30
[ $# -eq 1 ] || { echo "Must supply ORIGIN as parameter" >&2; exit 1; }
31
[ -n "${PORTSDIR}" ] || { echo "PORTSDIR must be set" >&2; exit 1; }
32
33
# May be passed in from environment if using an overlay.
34
: ${portdir:="${PORTSDIR}/${origin}"}
35
36
# PREFIX/LOCALBASE may be set in env or want default from port.
37
if [ -n "${PREFIX}" ]; then
38
PORT_FLAGS="${PORT_FLAGS} PREFIX=${PREFIX}"
39
else
40
PREFIX=$(make -C ${portdir} -VPREFIX)
41
fi
42
if [ -n "${LOCALBASE}" ]; then
43
PORT_FLAGS="${PORT_FLAGS} LOCALBASE=${LOCALBASE}"
44
else
45
LOCALBASE=$(make -C ${portdir} -VLOCALBASE)
46
fi
47
if [ -z "${CCACHE_DIR}" ]; then
48
CCACHE_DIR=$(make -C ${portdir} -VCCACHE_DIR)
49
fi
50
if [ -z "${UID_FILES}" ]; then
51
UID_FILES=$(make -C ${portdir} -VUID_FILES)
52
fi
53
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" " ")
54
plistsub_sed=$(mktemp -t plistsub_sed)
55
trap "rm -f ${plistsub_sed}" EXIT 1
56
make -C ${portdir} -VPLIST_SUB_SED | /bin/sh ${PORTSDIR}/Mk/Scripts/plist_sub_sed_sort.sh ${plistsub_sed}
57
tmpplist=$(make -C ${portdir} -VTMPPLIST)
58
59
while read -r modtype path extra; do
60
# Ignore everything from these files/directories
61
case "${path}" in
62
${CCACHE_DIR:-/nonexistent}/*|\
63
/compat/linux/proc/*|\
64
/dev/*|\
65
/etc/make.conf.bak|\
66
/proc/*|\
67
/tmp/*|\
68
/var/db/pkg/*|\
69
/var/db/ports/*|\
70
/var/log/*|\
71
/var/mail/*|\
72
/var/run/*|\
73
/var/tmp/*) continue ;;
74
# fc-cache - skip for now
75
/var/db/fontconfig/*) continue ;;
76
esac
77
78
ignore_path=0
79
sub_path=$(echo "$path" | sed -e "s|^${PREFIX}/||" -f "${plistsub_sed}")
80
orig_sub_path="${sub_path}"
81
# If this is a directory, use @dir in output
82
is_dir=0
83
if [ -d "${path}" ]; then
84
is_dir=1
85
sub_path="@dir ${sub_path}"
86
fi
87
88
# Handle PORTDOCS/PORTEXAMPLES/etc
89
case "${orig_sub_path}" in
90
%%DOCSDIR%%*) sub_path="%%PORTDOCS%%${sub_path}" ;;
91
%%EXAMPLESDIR%%*) sub_path="%%PORTEXAMPLES%%${sub_path}" ;;
92
esac
93
94
case $modtype in
95
+)
96
if [ ${is_dir} -eq 1 ]; then
97
# home directory of users created
98
case " ${homedirs} " in
99
*\ ${path}\ *) continue ;;
100
*\ ${path}/*\ *) continue ;;
101
esac
102
# Don't show dirs already in plist (due to parents)
103
grep -qE \
104
"^@(unexec rmdir \"?(%D/|${PREFIX})?${path#${PREFIX}/}[ \"]|dir(rm|rmtry)? ${path#${PREFIX}/}\$)" \
105
${tmpplist} && continue
106
fi
107
108
# Check absolute paths
109
case "${path}" in
110
# Leave qmail's queue dir alone to not cause lost mail
111
# during upgrades, just as /var/mail is left alone.
112
/var/qmail/queue/*|/var/qmail/queue) continue ;;
113
esac
114
115
# Check relative/plist paths
116
case "${sub_path}" in
117
# gconftool-2 --makefile-uninstall-rule is unpredictable
118
etc/gconf/gconf.xml.defaults/%gconf-tree*.xml) ;;
119
*) echo "+ ${sub_path}" ;;
120
esac
121
;;
122
-)
123
# Skip removal of PREFIX and PREFIX/info from
124
# bsd.port.mk for now.
125
# Skip if it is PREFIX and non-LOCALBASE. See misc/kdehier4
126
# or mail/qmail for examples
127
[ "${path}" = "${PREFIX}" -a "${LOCALBASE}" != "${PREFIX}" ] &&
128
ignore_path=1
129
130
# The removal of info may be a bug; it's part of BSD.local.dist.
131
# See ports/74691
132
133
[ "${sub_path}" = "info" -a "${LOCALBASE}" != "${PREFIX}" ] &&
134
ignore_path=1
135
136
[ $ignore_path -eq 0 ] && echo "- ${sub_path}"
137
;;
138
M)
139
# Check relative/plist paths
140
case "${sub_path}" in
141
# gconftool-2 --makefile-uninstall-rule is unpredictable
142
etc/gconf/gconf.xml.defaults/%gconf-tree*.xml) ;;
143
# removal of info files leaves entry uneasy to cleanup
144
# in info/dir
145
info/dir) ;;
146
*/info/dir) ;;
147
# The is pear database cache
148
%%PEARDIR%%/.depdb|%%PEARDIR%%/.filemap) ;;
149
#ls-R files from texmf are often regenerated
150
*/ls-R) ;;
151
# Octave packages database, blank lines can be inserted
152
# between pre-install and post-deinstall
153
share/octave/octave_packages) ;;
154
# xmlcatmgr is constantly updating catalog.ports ignore
155
# modification to that file
156
share/xml/catalog.ports) ;;
157
# Ignore common system config files
158
/etc/group|\
159
/etc/make.conf|\
160
/etc/master.passwd|\
161
/etc/passwd|\
162
/etc/pwd.db|\
163
/etc/shells|\
164
/etc/spwd.db) ;;
165
*) echo "M ${sub_path#@dir } ${extra}" ;;
166
esac
167
;;
168
esac
169
done
170
171
exit 0
172
173