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