Path: blob/main/Mk/Scripts/check_leftovers.sh
16462 views
#! /bin/sh1#2# MAINTAINER: [email protected]3#4# This script is used by poudriere and tinderbox(soon) as the source-of-truth for5# what should be considered a leftover and what is whitelisted.6#7# !!!! This script's input/output format must remain backwards-compatible.8# !!!! If you want to change it, create a new script and have the calling9# !!!! scripts use the new one if available.10#11# Usage: env PORTSDIR=... check_leftovers.sh category/port12# stdin:13# - missing-file14# + new-file15# M modified-file reason...16#17# stdout:18# same -/+/M format, but with files substituted, without approved19# whitelisted files, and hides any directories already in plist.20#21# The PLIST_SUB feature can be disabled by setting PLIST_SUB_SED=22# in environment.2324set -o pipefail2526[ -n "${DEBUG_MK_SCRIPTS}" -o -n "${DEBUG_MK_SCRIPTS_CHECK_LEFTOVERS}" ] && set -x2728origin="$1"29[ $# -eq 1 ] || { echo "Must supply ORIGIN as parameter" >&2; exit 1; }30[ -n "${PORTSDIR}" ] || { echo "PORTSDIR must be set" >&2; exit 1; }3132# May be passed in from environment if using an overlay.33: ${portdir:="${PORTSDIR}/${origin}"}3435# PREFIX/LOCALBASE may be set in env or want default from port.36if [ -n "${PREFIX}" ]; then37PORT_FLAGS="${PORT_FLAGS} PREFIX=${PREFIX}"38else39PREFIX=$(make -C ${portdir} -VPREFIX)40fi41if [ -n "${LOCALBASE}" ]; then42PORT_FLAGS="${PORT_FLAGS} LOCALBASE=${LOCALBASE}"43else44LOCALBASE=$(make -C ${portdir} -VLOCALBASE)45fi46if [ -z "${CCACHE_DIR}" ]; then47CCACHE_DIR=$(make -C ${portdir} -VCCACHE_DIR)48fi49if [ -z "${UID_FILES}" ]; then50UID_FILES=$(make -C ${portdir} -VUID_FILES)51fi52homedirs=$(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" " ")53plistsub_sed=$(mktemp -t plistsub_sed)54trap "rm -f ${plistsub_sed}" EXIT 155make -C ${portdir} -VPLIST_SUB_SED | /bin/sh ${PORTSDIR}/Mk/Scripts/plist_sub_sed_sort.sh ${plistsub_sed}56tmpplist=$(make -C ${portdir} -VTMPPLIST)5758while read -r modtype path extra; do59# Ignore everything from these files/directories60case "${path}" in61${CCACHE_DIR:-/nonexistent}/*|\62/compat/linux/proc/*|\63/dev/*|\64/etc/make.conf.bak|\65/proc/*|\66/tmp/*|\67/var/db/pkg/*|\68/var/db/ports/*|\69/var/log/*|\70/var/mail/*|\71/var/run/*|\72/var/tmp/*) continue ;;73# fc-cache - skip for now74/var/db/fontconfig/*) continue ;;75esac7677ignore_path=078sub_path=$(echo "$path" | sed -e "s|^${PREFIX}/||" -f "${plistsub_sed}")79orig_sub_path="${sub_path}"80# If this is a directory, use @dir in output81is_dir=082if [ -d "${path}" ]; then83is_dir=184sub_path="@dir ${sub_path}"85fi8687# Handle PORTDOCS/PORTEXAMPLES/etc88case "${orig_sub_path}" in89%%DOCSDIR%%*) sub_path="%%PORTDOCS%%${sub_path}" ;;90%%EXAMPLESDIR%%*) sub_path="%%PORTEXAMPLES%%${sub_path}" ;;91esac9293case $modtype in94+)95if [ ${is_dir} -eq 1 ]; then96# home directory of users created97case " ${homedirs} " in98*\ ${path}\ *) continue ;;99*\ ${path}/*\ *) continue ;;100esac101# Don't show dirs already in plist (due to parents)102grep -qE \103"^@(unexec rmdir \"?(%D/|${PREFIX})?${path#${PREFIX}/}[ \"]|dir(rm|rmtry)? ${path#${PREFIX}/}\$)" \104${tmpplist} && continue105fi106107# Check absolute paths108case "${path}" in109# Leave qmail's queue dir alone to not cause lost mail110# during upgrades, just as /var/mail is left alone.111/var/qmail/queue/*|/var/qmail/queue) continue ;;112esac113114# Check relative/plist paths115case "${sub_path}" in116# gconftool-2 --makefile-uninstall-rule is unpredictable117etc/gconf/gconf.xml.defaults/%gconf-tree*.xml) ;;118*) echo "+ ${sub_path}" ;;119esac120;;121-)122# Skip removal of PREFIX and PREFIX/info from123# bsd.port.mk for now.124# Skip if it is PREFIX and non-LOCALBASE. See misc/kdehier4125# or mail/qmail for examples126[ "${path}" = "${PREFIX}" -a "${LOCALBASE}" != "${PREFIX}" ] &&127ignore_path=1128129# The removal of info may be a bug; it's part of BSD.local.dist.130# See ports/74691131132[ "${sub_path}" = "info" -a "${LOCALBASE}" != "${PREFIX}" ] &&133ignore_path=1134135[ $ignore_path -eq 0 ] && echo "- ${sub_path}"136;;137M)138# Check relative/plist paths139case "${sub_path}" in140# gconftool-2 --makefile-uninstall-rule is unpredictable141etc/gconf/gconf.xml.defaults/%gconf-tree*.xml) ;;142# removal of info files leaves entry uneasy to cleanup143# in info/dir144info/dir) ;;145*/info/dir) ;;146# The is pear database cache147%%PEARDIR%%/.depdb|%%PEARDIR%%/.filemap) ;;148#ls-R files from texmf are often regenerated149*/ls-R) ;;150# Octave packages database, blank lines can be inserted151# between pre-install and post-deinstall152share/octave/octave_packages) ;;153# xmlcatmgr is constantly updating catalog.ports ignore154# modification to that file155share/xml/catalog.ports) ;;156# Ignore common system config files157/etc/group|\158/etc/make.conf|\159/etc/master.passwd|\160/etc/passwd|\161/etc/pwd.db|\162/etc/shells|\163/etc/spwd.db) ;;164*) echo "M ${sub_path#@dir } ${extra}" ;;165esac166;;167esac168done169170exit 0171172173