1#!/bin/sh 2# Copyright (c) Feb 2024 Wolfram Schneider <wosch@FreeBSD.org> 3# SPDX-License-Identifier: BSD-2-Clause 4# 5# stale-symlink-buildworld.sh - check for stale symlinks on a FreeBSD system 6# 7# You can run the script before or after `make installworld' 8# 9 10PATH="/bin:/usr/bin"; export PATH 11 12: ${ncpu=$(nproc)} 13 14obj_dir_prefix=${MAKEOBJDIRPREFIX:="/usr/obj"} 15 16# check other directories as well 17: ${STALE_SYMLINK_BUILDWORLD_DIRS=$obj_dir_prefix} 18 19trap 'rm -f $script' 0 20script=$(mktemp -t stale-symlink) 21chmod u+x $script 22 23# create a temporary shell script to check for stale symbolic links 24cat << 'EOF' > $script 25file="$1" 26 27if [ ! -e "$file" ]; then 28 echo "stale symlink detected: $(ls -ld $file)" >&2 29 exit 1 30else 31 exit 0 32fi 33EOF 34 35find -s -H \ 36 /bin \ 37 /boot \ 38 /etc \ 39 /lib \ 40 /libexec \ 41 /sbin \ 42 /usr/bin \ 43 /usr/include \ 44 /usr/lib \ 45 /usr/lib32 \ 46 /usr/libdata \ 47 /usr/libexec \ 48 /usr/sbin \ 49 /usr/src \ 50 /usr/share \ 51 $STALE_SYMLINK_BUILDWORLD_DIRS \ 52 -type l \ 53 -print0 | xargs -n1 -0 -P${ncpu} $script 54 55#EOF 56