Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/tools/build/stale-symlink-buildworld.sh
39483 views
1
#!/bin/sh
2
# Copyright (c) Feb 2024 Wolfram Schneider <[email protected]>
3
# SPDX-License-Identifier: BSD-2-Clause
4
#
5
# stale-symlink-buildworld.sh - check for stale symlinks on a FreeBSD system
6
#
7
# The purpose of this script is to detect stale symlinks, report them to
8
# stderr and exit with a non-zero status. All other cases are ignored,
9
# such as no symlinks, missing directories, permission problems, etc.
10
#
11
# You can run the script before or after `make installworld', or any other
12
# make targets thats installs files.
13
#
14
# You can also check your local ports with:
15
#
16
# env STALE_SYMLINK_BUILDWORLD_DIRS=/usr/local ./stale-symlink-buildworld.sh
17
18
19
PATH="/bin:/usr/bin"; export PATH
20
21
: ${ncpu=$(nproc)}
22
23
obj_dir_prefix=${MAKEOBJDIRPREFIX:="/usr/obj"}
24
25
# check other directories as well
26
: ${STALE_SYMLINK_BUILDWORLD_DIRS=$obj_dir_prefix}
27
28
trap 'rm -f $script' 0
29
script=$(mktemp -t stale-symlink)
30
chmod u+x $script
31
32
# create a temporary shell script to check for stale symbolic links
33
cat << 'EOF' > $script
34
file="$1"
35
36
if [ ! -e "$file" ]; then
37
echo "stale symlink detected: $(ls -ld $file)" >&2
38
exit 1
39
else
40
exit 0
41
fi
42
EOF
43
44
find -s -H \
45
/bin \
46
/boot \
47
/etc \
48
/lib \
49
/libexec \
50
/sbin \
51
/usr/bin \
52
/usr/include \
53
/usr/lib \
54
/usr/lib32 \
55
/usr/libdata \
56
/usr/libexec \
57
/usr/sbin \
58
/usr/src \
59
/usr/share \
60
$STALE_SYMLINK_BUILDWORLD_DIRS \
61
-type l \
62
-print0 | xargs -n1 -0 -P${ncpu} $script
63
64
#EOF
65
66