xref: /freebsd/tools/build/stale-symlink-buildworld.sh (revision e9ac41698b2f322d55ccf9da50a3596edb2c1800)
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
14# check other directories as well
15: ${STALE_SYMLINK_BUILDWORLD_DIRS="/usr/obj"}
16
17trap 'rm -f $script' 0
18script=$(mktemp -t stale-symlink)
19chmod u+x $script
20
21# create a temporary shell script to check for stale symbolic links
22cat << 'EOF' > $script
23file="$1"
24
25if [ ! -e "$file" ]; then
26  echo "stale symlink detected: $(ls -ld $file)" >&2
27  exit 1
28else
29  exit 0
30fi
31EOF
32
33find -s -H \
34  /bin \
35  /boot \
36  /etc \
37  /lib \
38  /libexec \
39  /sbin \
40  /usr/bin \
41  /usr/include \
42  /usr/lib \
43  /usr/lib32 \
44  /usr/libdata \
45  /usr/libexec \
46  /usr/sbin \
47  /usr/src \
48  /usr/share \
49  $STALE_SYMLINK_BUILDWORLD_DIRS \
50  -type l \
51  -print0 | xargs -n1 -0 -P${ncpu} $script
52
53#EOF
54