Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/Mk/Scripts/makesum.sh
16462 views
1
#!/bin/sh
2
#
3
# MAINTAINER: [email protected]
4
5
set -e
6
set -o pipefail
7
8
. "${dp_SCRIPTSDIR}/functions.sh"
9
10
validate_env dp_CHECKSUM_ALGORITHMS dp_CKSUMFILES dp_DISTDIR dp_DISTINFO_FILE \
11
dp_ECHO_MSG
12
13
[ -n "${DEBUG_MK_SCRIPTS}" -o -n "${DEBUG_MK_SCRIPTS_MAKESUM}" ] && set -x
14
15
set -u
16
17
DISTINFO_OLD=$(mktemp -t makesum-old)
18
DISTINFO_NEW=$(mktemp -t makesum-new)
19
20
trap 'rm -f ${DISTINFO_OLD} ${DISTINFO_NEW}' EXIT INT TERM
21
22
check_checksum_algorithms
23
24
cd "${dp_DISTDIR}"
25
26
# Running `make makesum` a twice should not change the timestamp generated from
27
# the first run.
28
# So, we extract the content of the distinfo file minus the TIMESTAMP, if it
29
# contains a TIMESTAMP.
30
if [ -f "${dp_DISTINFO_FILE}" ] && grep -q "^TIMESTAMP " ${dp_DISTINFO_FILE}; then
31
grep -v "^TIMESTAMP " ${dp_DISTINFO_FILE} > ${DISTINFO_OLD} || true
32
fi
33
34
for file in ${dp_CKSUMFILES}; do
35
for alg in ${dp_CHECKSUM_ALGORITHMS}; do
36
eval "alg_executable=\$dp_$alg"
37
38
if [ "$alg_executable" != "NO" ]; then
39
$alg_executable "$file" >> "${DISTINFO_NEW}"
40
fi
41
done
42
echo "SIZE ($file) = $(stat -f %z "$file")" >> "${DISTINFO_NEW}"
43
done
44
45
# Now, we generate the distinfo file in two cases:
46
# - If the saved file is empty, it means there was no TIMESTAMP in it, so we
47
# need to add one.
48
# - If the old and new distinfo content minus the TIMESTAMP differ, it means
49
# something was updated or changed, it is time to generate a new timestamp.
50
if [ ! -s ${DISTINFO_OLD} ] || ! cmp -s ${DISTINFO_OLD} ${DISTINFO_NEW}; then
51
echo "TIMESTAMP = $(date '+%s')" > ${dp_DISTINFO_FILE}
52
cat ${DISTINFO_NEW} >> ${dp_DISTINFO_FILE}
53
fi
54
55