Path: blob/main/tools/build/stale-symlink-buildworld.sh
39483 views
#!/bin/sh1# Copyright (c) Feb 2024 Wolfram Schneider <[email protected]>2# SPDX-License-Identifier: BSD-2-Clause3#4# stale-symlink-buildworld.sh - check for stale symlinks on a FreeBSD system5#6# The purpose of this script is to detect stale symlinks, report them to7# stderr and exit with a non-zero status. All other cases are ignored,8# such as no symlinks, missing directories, permission problems, etc.9#10# You can run the script before or after `make installworld', or any other11# make targets thats installs files.12#13# You can also check your local ports with:14#15# env STALE_SYMLINK_BUILDWORLD_DIRS=/usr/local ./stale-symlink-buildworld.sh161718PATH="/bin:/usr/bin"; export PATH1920: ${ncpu=$(nproc)}2122obj_dir_prefix=${MAKEOBJDIRPREFIX:="/usr/obj"}2324# check other directories as well25: ${STALE_SYMLINK_BUILDWORLD_DIRS=$obj_dir_prefix}2627trap 'rm -f $script' 028script=$(mktemp -t stale-symlink)29chmod u+x $script3031# create a temporary shell script to check for stale symbolic links32cat << 'EOF' > $script33file="$1"3435if [ ! -e "$file" ]; then36echo "stale symlink detected: $(ls -ld $file)" >&237exit 138else39exit 040fi41EOF4243find -s -H \44/bin \45/boot \46/etc \47/lib \48/libexec \49/sbin \50/usr/bin \51/usr/include \52/usr/lib \53/usr/lib32 \54/usr/libdata \55/usr/libexec \56/usr/sbin \57/usr/src \58/usr/share \59$STALE_SYMLINK_BUILDWORLD_DIRS \60-type l \61-print0 | xargs -n1 -0 -P${ncpu} $script6263#EOF646566