View | Details | Raw Unified | Return to bug 208916 | Differences between
and this patch

Collapse All | Expand All

(-)Mk/Scripts/check-vulnerable.sh (+37 lines)
Added Link Here
1
#!/bin/sh
2
# $FreeBSD$
3
#
4
# MAINTAINER: portmgr@FreeBSD.org
5
6
set -e
7
8
. "${dp_SCRIPTSDIR}/functions.sh"
9
10
validate_env dp_ECHO_MSG dp_PKG_BIN dp_PORTNAME
11
12
[ -n "${DEBUG_MK_SCRIPTS}" -o -n "${DEBUG_MK_SCRIPTS_CHECK_VULNERABLE}" ] && set -x
13
14
set -u
15
16
# If the package is pkg, disable these checks, it fails while
17
# upgrading when pkg is not there.
18
# FIXME: check is this is still true
19
if [ "${dp_PORTNAME}" = "pkg" ]; then
20
	exit 0
21
fi
22
23
if [ -x "${dp_PKG_BIN}" ]; then
24
	vlist=$(${dp_PKG_BIN} audit "${dp_PKGNAME}" || :)
25
	if [ "${vlist}" = "0 problem(s) in the installed packages found." ]; then
26
		vlist=""
27
	fi
28
fi
29
30
if [ -n "$vlist" ]; then
31
	${dp_ECHO_MSG} "===>  ${dp_PKGNAME} has known vulnerabilities:"
32
	${dp_ECHO_MSG} "$vlist"
33
	${dp_ECHO_MSG} "=> Please update your ports tree and try again."
34
	${dp_ECHO_MSG} "=> Note: Vulnerable ports are marked as such even if there is no update available."
35
	${dp_ECHO_MSG} "=> If you wish to ignore this vulnerability rebuild with 'make DISABLE_VULNERABILITIES=yes'"
36
	exit 1
37
fi
(-)Mk/Scripts/checksum.sh (+91 lines)
Added Link Here
1
#!/bin/sh
2
# $FreeBSD$
3
#
4
# MAINTAINER: portmgr@FreeBSD.org
5
6
set -e
7
8
. "${dp_SCRIPTSDIR}/functions.sh"
9
10
validate_env dp_CHECKSUM_ALGORITHMS dp_CURDIR dp_DISTDIR dp_DISTINFO_FILE \
11
	dp_DIST_SUBDIR dp_ECHO_MSG dp_FETCH_REGET dp_MAKE dp_MAKEFLAGS \
12
	dp_DISABLE_SIZE dp_NO_CHECKSUM
13
14
[ -n "${DEBUG_MK_SCRIPTS}" -o -n "${DEBUG_MK_SCRIPTS_CHECKSUM}" ] && set -x
15
16
set -u
17
18
check_checksum_algorithms
19
20
if [ -f "${dp_DISTINFO_FILE}" ]; then
21
	cd "${dp_DISTDIR}"
22
	OK=
23
	refetchlist=
24
	for file in "${@}"; do
25
		ignored="true"
26
		for alg in ${dp_CHECKSUM_ALGORITHMS}; do
27
			ignore="false"
28
			eval "alg_executable=\$dp_${alg}"
29
30
			if [ "$alg_executable" != "NO" ]; then
31
				MKSUM=$(eval $alg_executable \< "${file}")
32
				CKSUM=$(distinfo_data "${alg}" "${file}")
33
			else
34
				ignore="true"
35
			fi
36
37
			if [ $ignore = "false" -a -z "$CKSUM" ]; then
38
				${dp_ECHO_MSG} "=> No $alg checksum recorded for $file."
39
				ignore="true"
40
			fi
41
42
			if [ $ignore = "false" ]; then
43
				match="false"
44
				for chksum in $CKSUM; do
45
					if [ "$chksum" = "$MKSUM" ]; then
46
						match="true"
47
						break
48
					fi
49
				done
50
				if [ $match = "true" ]; then
51
					${dp_ECHO_MSG} "=> $alg Checksum OK for $file."
52
					ignored="false"
53
				else
54
					${dp_ECHO_MSG} "=> $alg Checksum mismatch for $file."
55
					refetchlist="$refetchlist $file "
56
					OK="${OK:-retry}"
57
					[ "${OK}" = "retry" -a "${dp_FETCH_REGET}" -gt 0 ] && rm -f "${file}"
58
					ignored="false"
59
				fi
60
			fi
61
		done
62
63
		if [ $ignored = "true" ]; then
64
			${dp_ECHO_MSG} "=> No suitable checksum found for $file."
65
			OK=false
66
		fi
67
	done
68
69
	if [ "${OK:=true}" = "retry" ] && [ "${dp_FETCH_REGET}" -gt 0 ]; then
70
		${dp_ECHO_MSG} "===>  Refetch for ${dp_FETCH_REGET} more times files: $refetchlist"
71
		if ${dp_MAKE} -C "${dp_CURDIR}" ${dp_MAKEFLAGS} FORCE_FETCH_LIST="$refetchlist" FETCH_REGET="$((dp_FETCH_REGET - 1))" fetch; then
72
			if ${dp_MAKE} -C "${dp_CURDIR}" ${dp_MAKEFLAGS} FETCH_REGET="$((dp_FETCH_REGET - 1))" checksum ; then
73
			OK="true"
74
			fi
75
		fi
76
	fi
77
78
	if [ "$OK" != "true" -a "${dp_FETCH_REGET}" -eq 0 ]; then
79
		${dp_ECHO_MSG} "===>  Giving up on fetching files: $refetchlist"
80
		${dp_ECHO_MSG} "Make sure the Makefile and distinfo file (${dp_DISTINFO_FILE})"
81
		${dp_ECHO_MSG} "are up to date.  If you are absolutely sure you want to override this"
82
		${dp_ECHO_MSG} "check, type \"make NO_CHECKSUM=yes [other args]\"."
83
		exit 1
84
	fi
85
	if [ "$OK" != "true" ]; then
86
		exit 1
87
	fi
88
elif [ -n "${@}" ]; then
89
	${dp_ECHO_MSG} "=> No checksum file (${DISTINFO_FILE})."
90
	exit 1
91
fi
(-)Mk/Scripts/do-fetch.sh (+174 lines)
Added Link Here
1
#!/bin/sh
2
# $FreeBSD$
3
#
4
# MAINTAINER: portmgr@FreeBSD.org
5
6
set -e
7
8
. "${dp_SCRIPTSDIR}/functions.sh"
9
10
validate_env dp_DEVELOPER dp_DISABLE_SIZE dp_DISTDIR dp_DISTINFO_FILE \
11
	dp_DIST_SUBDIR dp_ECHO_MSG dp_FETCH_AFTER_ARGS dp_FETCH_BEFORE_ARGS \
12
	dp_FETCH_CMD dp_FETCH_ENV dp_FORCE_FETCH_ALL dp_FORCE_FETCH_LIST \
13
	dp_MASTER_SITE_BACKUP dp_MASTER_SITE_OVERRIDE dp_MASTER_SORT_AWK \
14
	dp_NO_CHECKSUM dp_RANDOMIZE_SITES dp_SITE_FLAVOR dp_SCRIPTSDIR \
15
	dp_SORTED_MASTER_SITES_DEFAULT_CMD dp_SORTED_PATCH_SITES_DEFAULT_CMD \
16
	dp_TARGET
17
18
[ -n "${DEBUG_MK_SCRIPTS}" -o -n "${DEBUG_MK_SCRIPTS_DO_FETCH}" ] && set -x
19
20
set -u
21
22
mkdir -p "${dp_DISTDIR}"
23
cd "${dp_DISTDIR}"
24
25
for _file in "${@}"; do
26
	file=${_file%%:*}
27
	unescaped_file=$(unescape "${file}")
28
29
	# If this files has groups
30
	if [ "$_file" = "$file" ]; then
31
		select=''
32
	else
33
		select=$(echo "${_file##*:}" | sed -e 's/,/ /g')
34
	fi
35
36
	filebasename=${file##*/}
37
	if [ -n "${dp_FORCE_FETCH_ALL}" ]; then
38
		force_fetch=true
39
	else
40
		force_fetch=false
41
		for afile in ${dp_FORCE_FETCH_LIST}; do
42
			afile=${afile##*/}
43
			if [ "x$afile" = "x$filebasename" ]; then
44
				force_fetch=true
45
			fi
46
		done
47
	fi
48
	if [ ! -f "${unescaped_file}" -a ! -f "$filebasename" -o "$force_fetch" = "true" ]; then
49
		full_file="${dp_DIST_SUBDIR:+${dp_DIST_SUBDIR}/}${file}"
50
		if [ -L "$file" -o -L "$filebasename" ]; then
51
			${dp_ECHO_MSG} "=> ${dp_DISTDIR}/$file is a broken symlink."
52
			${dp_ECHO_MSG} "=> Perhaps a filesystem (most likely a CD) isn't mounted?"
53
			${dp_ECHO_MSG} "=> Please correct this problem and try again."
54
			exit 1
55
		fi
56
		if [ -f "${dp_DISTINFO_FILE}" -a -z "${dp_NO_CHECKSUM}" ]; then
57
			_sha256sum=$(distinfo_data SHA256 "${full_file}")
58
			if [ -z "$_sha256sum" ]; then
59
				${dp_ECHO_MSG} "=> ${dp_DIST_SUBDIR:+$dp_DIST_SUBDIR/}$file is not in ${dp_DISTINFO_FILE}."
60
				${dp_ECHO_MSG} "=> Either ${dp_DISTINFO_FILE} is out of date, or"
61
				${dp_ECHO_MSG} "=> ${dp_DIST_SUBDIR:+$dp_DIST_SUBDIR/}$file is spelled incorrectly."
62
				exit 1
63
			fi
64
		fi
65
		case ${dp_TARGET} in
66
		do-fetch|makesum)
67
			${dp_ECHO_MSG} "=> $file doesn't seem to exist in ${dp_DISTDIR}."
68
			;;
69
		esac
70
		if [ ! -w "${dp_DISTDIR}" ]; then
71
			${dp_ECHO_MSG} "=> ${dp_DISTDIR} is not writable by you; cannot fetch."
72
			exit 1
73
		fi
74
		if [ -n "$select" ] ; then
75
			__MASTER_SITES_TMP=
76
			for group in $select; do
77
				# Disable nounset for this, it may come up empty.
78
				set +u
79
				eval ___MASTER_SITES_TMP="\${_${dp_SITE_FLAVOR}_SITES_${group}}"
80
				set -u
81
				if [ -n "${___MASTER_SITES_TMP}" ] ; then
82
					__MASTER_SITES_TMP="${__MASTER_SITES_TMP} ${___MASTER_SITES_TMP}"
83
				else
84
					case ${dp_TARGET} in
85
					do-fetch|makesum)
86
						if [ -n "${dp_DEVELOPER}" ]; then
87
							${dp_ECHO_MSG} "===> /!\\ Error /!\\"
88
						else
89
							${dp_ECHO_MSG} "===> /!\\ Warning /!\\"
90
						fi
91
						${dp_ECHO_MSG} "     The :${group} group used for $file is missing"
92
						${dp_ECHO_MSG} "     from ${dp_SITE_FLAVOR}_SITES. Check for typos, or errors."
93
						if [ -n "${dp_DEVELOPER}" ]; then
94
							exit 1
95
						fi
96
						;;
97
					esac
98
99
				fi
100
			done
101
			___MASTER_SITES_TMP=
102
			SORTED_MASTER_SITES_CMD_TMP="echo ${dp_MASTER_SITE_OVERRIDE} $(echo -n "${__MASTER_SITES_TMP}" | awk "${dp_MASTER_SORT_AWK}") ${dp_MASTER_SITE_BACKUP}"
103
		else
104
			if [ ${dp_SITE_FLAVOR} = "MASTER" ]; then
105
				SORTED_MASTER_SITES_CMD_TMP="${dp_SORTED_MASTER_SITES_DEFAULT_CMD}"
106
			else
107
				SORTED_MASTER_SITES_CMD_TMP="${dp_SORTED_PATCH_SITES_DEFAULT_CMD}"
108
			fi
109
		fi
110
		case ${dp_TARGET} in
111
			fetch-list)
112
				echo -n "mkdir -p ${dp_DISTDIR} && "
113
				echo -n "cd ${dp_DISTDIR} && { "
114
				;;
115
		esac
116
		sites_remaining=0
117
		sites="$(eval "${SORTED_MASTER_SITES_CMD_TMP} ${dp_RANDOMIZE_SITES}")"
118
		for site in ${sites}; do
119
			sites_remaining=$((sites_remaining + 1))
120
		done
121
		for site in ${sites}; do
122
			sites_remaining=$((sites_remaining - 1))
123
			CKSIZE=$(distinfo_data SIZE "${full_file}")
124
			# The site may contain special shell characters, they
125
			# need to be escaped.
126
			site=$(escape "${site}")
127
			# There is a lot of escaping, but the " needs to survive echo/eval.
128
			case ${file} in
129
				*/*)
130
					mkdir -p "${file%/*}"
131
					args="-o \\\"${file}\\\" \\\"${site}${file}\\\""
132
					;;
133
				*)
134
					args="\\\"${site}${file}\\\""
135
					;;
136
			esac
137
			_fetch_cmd=$(eval "echo ${dp_FETCH_ENV} ${dp_FETCH_CMD} ${dp_FETCH_BEFORE_ARGS} ${args} ${dp_FETCH_AFTER_ARGS}")
138
			case ${dp_TARGET} in
139
			do-fetch|makesum)
140
				${dp_ECHO_MSG} "=> Attempting to fetch ${site}${file}"
141
				if eval "env ${_fetch_cmd}"; then
142
					actual_size=$(eval stat -f %z "${file}")
143
					if [ -n "${dp_DISABLE_SIZE}" ] || [ -z "${CKSIZE}" ] || [ "${actual_size}" -eq "${CKSIZE}" ]; then
144
						continue 2
145
					else
146
						${dp_ECHO_MSG} "=> Fetched file size mismatch (expected ${CKSIZE}, actual ${actual_size})"
147
						if [ ${sites_remaining} -gt 0 ]; then
148
							${dp_ECHO_MSG} "=> Trying next site"
149
							rm -f "${file}"
150
						fi
151
					fi
152
				fi
153
				;;
154
			fetch-list)
155
				echo -n "env ${_fetch_cmd} || "
156
				;;
157
			fetch-url-list-int)
158
				eval "echo $(eval "echo ${args}")"
159
				;;
160
			esac
161
		done
162
		case ${dp_TARGET} in
163
		do-fetch|makesum)
164
			${dp_ECHO_MSG} "=> Couldn't fetch it - please try to retrieve this"
165
			${dp_ECHO_MSG} "=> port manually into ${dp_DISTDIR} and try again."
166
			exit 1
167
			;;
168
		fetch-list)
169
			echo "echo ${file} not fetched; }" ; \
170
			;;
171
		esac
172
	fi
173
done
174
(-)Mk/Scripts/functions.sh (+34 lines)
Lines 216-218 export_ports_env() { Link Here
216
		fi
216
		fi
217
	done
217
	done
218
}
218
}
219
220
distinfo_data() {
221
	local alg file
222
223
	alg=$1
224
	file=$2
225
226
	if [ \( -n "${dp_DISABLE_SIZE}" -a -n "${dp_NO_CHECKSUM}" \) -o ! -f "${dp_DISTINFO_FILE}" ]; then
227
		exit
228
	fi
229
	awk -v alg="$alg" -v file="${file}" \
230
		'$1 == alg && $2 == "(" file ")" {print $4}' "${dp_DISTINFO_FILE}"
231
}
232
233
check_checksum_algorithms() {
234
	for alg in ${dp_CHECKSUM_ALGORITHMS}; do
235
		eval "alg_executable=\$dp_$alg"
236
		if [ -z "$alg_executable" ]; then
237
			${dp_ECHO_MSG} "Checksum algorithm $alg: Couldn't find the executable."
238
			${dp_ECHO_MSG} "Set $alg=/path/to/$alg in /etc/make.conf and try again."
239
			exit 1
240
		elif [ ! -x "$alg_executable" ]; then
241
			${dp_ECHO_MSG} "Checksum algorithm $alg: $alg_executable is not executable."
242
			${dp_ECHO_MSG} "Fix modes, or change $alg=$alg_executable in /etc/make.conf and try again."
243
			exit 1
244
		fi
245
	done
246
}
247
escape() {
248
	echo "$1" | sed -e 's/[&;()!#]/\\&/g'
249
}
250
unescape() {
251
	echo "$1" | sed -e 's/\\//g'
252
}
(-)Mk/Scripts/makesum.sh (+53 lines)
Added Link Here
1
#!/bin/sh
2
# $FreeBSD$
3
#
4
# MAINTAINER: portmgr@FreeBSD.org
5
6
set -e
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}
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
(-)Mk/bsd.port.mk (-471 / +150 lines)
Lines 3060-3254 check-deprecated: Link Here
3060
AUDITFILE?=		${PKG_DBDIR}/vuln.xml
3060
AUDITFILE?=		${PKG_DBDIR}/vuln.xml
3061
3061
3062
check-vulnerable:
3062
check-vulnerable:
3063
.if !defined(DISABLE_VULNERABILITIES) && !defined(PACKAGE_BUILDING)
3063
.if !defined(DISABLE_VULNERABILITIES) && !defined(PACKAGE_BUILDING) \
3064
	@if [ -f "${AUDITFILE}" ]; then \
3064
		&& exists(${AUDITFILE})
3065
		if [ -x "${PKG_BIN}" ]; then \
3065
	@${SETENV} \
3066
			vlist=`${PKG_BIN} audit "${PKGNAME}" || :`; \
3066
			dp_ECHO_MSG="${ECHO_MSG}" \
3067
			if [ "$${vlist}" = "0 problem(s) in the installed packages found." ]; then \
3067
			dp_PKG_BIN="${PKG_BIN}" \
3068
				vlist=""; \
3068
			dp_PORTNAME="${PORTNAME}" \
3069
			fi; \
3069
			dp_SCRIPTSDIR="${SCRIPTSDIR}" \
3070
		elif [ "${PORTNAME}" = "pkg" ]; then \
3070
			${SH} ${SCRIPTSDIR}/check-vulnerable.sh
3071
			vlist=""; \
3071
.endif
3072
		fi; \
3072
3073
		if [ -n "$$vlist" ]; then \
3073
# Quote simply quote all variables, except FETCH_ENV, some ports are creative
3074
			${ECHO_MSG} "===>  ${PKGNAME} has known vulnerabilities:"; \
3074
# with it, and it needs to be quoted twice to pass through the echo/eval in
3075
			${ECHO_MSG} "$$vlist"; \
3075
# do-fetch.
3076
			${ECHO_MSG} "=> Please update your ports tree and try again."; \
3076
_DO_FETCH_ENV= \
3077
			${ECHO_MSG} "=> Note: Vulnerable ports are marked as such even if there is no update available."; \
3077
			dp_DISABLE_SIZE='${DISABLE_SIZE}' \
3078
			${ECHO_MSG} "=> If you wish to ignore this vulnerability rebuild with 'make DISABLE_VULNERABILITIES=yes'"; \
3078
			dp_DISTDIR='${_DISTDIR}' \
3079
			exit 1; \
3079
			dp_DISTINFO_FILE='${DISTINFO_FILE}' \
3080
		fi; \
3080
			dp_DIST_SUBDIR='${DIST_SUBDIR}' \
3081
	fi
3081
			dp_ECHO_MSG='${ECHO_MSG}' \
3082
			dp_FETCH_AFTER_ARGS='${FETCH_AFTER_ARGS}' \
3083
			dp_FETCH_BEFORE_ARGS='${FETCH_BEFORE_ARGS}' \
3084
			dp_FETCH_CMD='${FETCH_CMD}' \
3085
			dp_FETCH_ENV=${FETCH_ENV:Q:Q} \
3086
			dp_FORCE_FETCH_ALL='${FORCE_FETCH_ALL}' \
3087
			dp_FORCE_FETCH_LIST='${FORCE_FETCH_LIST}' \
3088
			dp_MASTER_SITE_BACKUP='${_MASTER_SITE_BACKUP}' \
3089
			dp_MASTER_SITE_OVERRIDE='${_MASTER_SITE_OVERRIDE}' \
3090
			dp_MASTER_SORT_AWK='${MASTER_SORT_AWK}' \
3091
			dp_NO_CHECKSUM='${NO_CHECKSUM}' \
3092
			dp_RANDOMIZE_SITES='${_RANDOMIZE_SITES}' \
3093
			dp_SCRIPTSDIR='${SCRIPTSDIR}' \
3094
			dp_SORTED_MASTER_SITES_DEFAULT_CMD='${SORTED_MASTER_SITES_DEFAULT_CMD}' \
3095
			dp_SORTED_PATCH_SITES_DEFAULT_CMD='${SORTED_PATCH_SITES_DEFAULT_CMD}' \
3096
			dp_TARGET='${.TARGET}'
3097
.if defined(DEVELOPER)
3098
_DO_FETCH_ENV+= dp_DEVELOPER=yes
3099
.else
3100
_DO_FETCH_ENV+= dp_DEVELOPER=
3082
.endif
3101
.endif
3083
3102
3084
# set alg to any of SIZE, SHA256 (or any other checksum algorithm):
3085
DISTINFO_DATA?=	if [ \( -n "${DISABLE_SIZE}" -a -n "${NO_CHECKSUM}" \) -o ! -f "${DISTINFO_FILE}" ]; then exit; fi; \
3086
	DIR=${DIST_SUBDIR}; ${AWK} -v alg=$$alg -v file=$${DIR:+$$DIR/}$${file}	\
3087
		'$$1 == alg && $$2 == "(" file ")" {print $$4}' ${DISTINFO_FILE}
3088
3089
# Fetch
3103
# Fetch
3090
3104
3091
.if !target(do-fetch)
3105
.if !target(do-fetch)
3092
do-fetch:
3106
do-fetch:
3093
	@${MKDIR} ${_DISTDIR}
3107
.if !empty(DISTFILES)
3094
	@cd ${_DISTDIR};\
3108
	@${SETENV} \
3095
	${_MASTER_SITES_ENV} ; \
3109
			${_DO_FETCH_ENV} ${_MASTER_SITES_ENV} \
3096
	for _file in ${DISTFILES}; do \
3110
			dp_SITE_FLAVOR=MASTER \
3097
		file=$${_file%%:*}; \
3111
			${SH} ${SCRIPTSDIR}/do-fetch.sh ${DISTFILES:C/.*/'&'/}
3098
		if [ $$_file = $$file ]; then	\
3112
.endif
3099
			select='';	\
3113
.if defined(PATCHFILES) && !empty(PATCHFILES)
3100
		else	\
3114
	@${SETENV} \
3101
			select=`${ECHO_CMD} $${_file##*:} | ${SED} -e 's/,/ /g'` ;	\
3115
			${_DO_FETCH_ENV} ${_PATCH_SITES_ENV} \
3102
		fi;	\
3116
			dp_SITE_FLAVOR=PATCH \
3103
		force_fetch=false; \
3117
			${SH} ${SCRIPTSDIR}/do-fetch.sh ${PATCHFILES:C/:-p[0-9]//:C/.*/'&'/}
3104
		filebasename=$${file##*/}; \
3118
.endif
3105
		for afile in ${FORCE_FETCH}; do \
3119
.endif
3106
			afile=$${afile##*/}; \
3120
#
3107
			if [ "x$$afile" = "x$$filebasename" ]; then \
3121
# Prints out a list of files to fetch (useful to do a batch fetch)
3108
				force_fetch=true; \
3122
3109
			fi; \
3123
.if !target(fetch-list)
3110
		done; \
3124
fetch-list:
3111
		if [ ! -f $$file -a ! -f $$filebasename -o "$$force_fetch" = "true" ]; then \
3125
.if !empty(DISTFILES)
3112
			if [ -L $$file -o -L $$filebasename ]; then \
3126
	@${SETENV} \
3113
				${ECHO_MSG} "=> ${_DISTDIR}/$$file is a broken symlink."; \
3127
			${_DO_FETCH_ENV} ${_MASTER_SITES_ENV} \
3114
				${ECHO_MSG} "=> Perhaps a filesystem (most likely a CD) isn't mounted?"; \
3128
			dp_SITE_FLAVOR=MASTER \
3115
				${ECHO_MSG} "=> Please correct this problem and try again."; \
3129
			${SH} ${SCRIPTSDIR}/do-fetch.sh ${DISTFILES:C/.*/'&'/}
3116
				exit 1; \
3130
.endif
3117
			fi; \
3131
.if defined(PATCHFILES) && !empty(PATCHFILES)
3118
			if [ -f ${DISTINFO_FILE} -a "x${NO_CHECKSUM}" = "x" ]; then \
3132
	@${SETENV} \
3119
				_sha256sum=`alg=SHA256; ${DISTINFO_DATA}`; \
3133
			${_DO_FETCH_ENV} ${_PATCH_SITES_ENV} \
3120
				if [ -z "$$_sha256sum" ]; then \
3134
			dp_SITE_FLAVOR=PATCH \
3121
					${ECHO_MSG} "=> $${DIR:+$$DIR/}$$file is not in ${DISTINFO_FILE}."; \
3135
			${SH} ${SCRIPTSDIR}/do-fetch.sh ${PATCHFILES:C/:-p[0-9]//:C/.*/'&'/}
3122
					${ECHO_MSG} "=> Either ${DISTINFO_FILE} is out of date, or"; \
3123
					${ECHO_MSG} "=> $${DIR:+$$DIR/}$$file is spelled incorrectly."; \
3124
					exit 1; \
3125
				fi; \
3126
			fi; \
3127
			${ECHO_MSG} "=> $$file doesn't seem to exist in ${_DISTDIR}."; \
3128
			if [ ! -w ${_DISTDIR} ]; then \
3129
			   ${ECHO_MSG} "=> ${_DISTDIR} is not writable by you; cannot fetch."; \
3130
			   exit 1; \
3131
			fi; \
3132
			if [ ! -z "$$select" ] ; then \
3133
				__MASTER_SITES_TMP= ; \
3134
				for group in $$select; do \
3135
					if [ ! -z \$${_MASTER_SITES_$${group}} ] ; then \
3136
						eval ___MASTER_SITES_TMP="\$${_MASTER_SITES_$${group}}" ; \
3137
						__MASTER_SITES_TMP="$${__MASTER_SITES_TMP} $${___MASTER_SITES_TMP}" ; \
3138
					fi; \
3139
				done; \
3140
				___MASTER_SITES_TMP= ; \
3141
				SORTED_MASTER_SITES_CMD_TMP="${ECHO_CMD} ${_MASTER_SITE_OVERRIDE} `${ECHO_CMD} $${__MASTER_SITES_TMP} | ${AWK} '${MASTER_SORT_AWK:S|\\|\\\\|g}'` ${_MASTER_SITE_BACKUP}" ; \
3142
			else \
3143
				SORTED_MASTER_SITES_CMD_TMP="${SORTED_MASTER_SITES_DEFAULT_CMD}" ; \
3144
			fi; \
3145
			sites_remaining=0; \
3146
			sites="`eval $$SORTED_MASTER_SITES_CMD_TMP ${_RANDOMIZE_SITES}`"; \
3147
			for site in $${sites}; do \
3148
				sites_remaining=$$(($${sites_remaining} + 1)); \
3149
			done; \
3150
			for site in $${sites}; do \
3151
				sites_remaining=$$(($${sites_remaining} - 1)); \
3152
			    ${ECHO_MSG} "=> Attempting to fetch $${site}$${file}"; \
3153
				CKSIZE=`alg=SIZE; ${DISTINFO_DATA}`; \
3154
				case $${file} in \
3155
				*/*)	${MKDIR} $${file%/*}; \
3156
						args="-o $${file} $${site}$${file}";; \
3157
				*)		args=$${site}$${file};; \
3158
				esac; \
3159
				if ${SETENV} ${FETCH_ENV} ${FETCH_CMD} ${FETCH_BEFORE_ARGS} $${args} ${FETCH_AFTER_ARGS}; then \
3160
					actual_size=`stat -f %z "$${file}"`; \
3161
					if [ -n "${DISABLE_SIZE}" ] || [ -z "$${CKSIZE}" ] || [ $${actual_size} -eq $${CKSIZE} ]; then \
3162
						continue 2; \
3163
					else \
3164
						${ECHO_MSG} "=> Fetched file size mismatch (expected $${CKSIZE}, actual $${actual_size})"; \
3165
						if [ $${sites_remaining} -gt 0 ]; then \
3166
							${ECHO_MSG} "=> Trying next site"; \
3167
							${RM} -f $${file}; \
3168
						fi; \
3169
					fi; \
3170
				fi; \
3171
			done; \
3172
			${ECHO_MSG} "=> Couldn't fetch it - please try to retrieve this";\
3173
			${ECHO_MSG} "=> port manually into ${_DISTDIR} and try again."; \
3174
			exit 1; \
3175
	    fi; \
3176
	 done
3177
.if defined(PATCHFILES)
3178
	@cd ${_DISTDIR};\
3179
	${_PATCH_SITES_ENV} ; \
3180
	for _file in ${PATCHFILES}; do \
3181
		file=`${ECHO_CMD} $$_file | ${SED} -E -e 's/:[^-:][^:]*$$//'` ; \
3182
		if [ $$_file = $$file ]; then	\
3183
			select='';	\
3184
		else	\
3185
			select=`${ECHO_CMD} $${_file##*:} | ${SED} -e 's/,/ /g'` ;	\
3186
		fi;	\
3187
		file=`${ECHO_CMD} $$file | ${SED} -E -e 's/:-[^:]+$$//'` ; \
3188
		force_fetch=false; \
3189
		filebasename=$${file##*/}; \
3190
		for afile in ${FORCE_FETCH}; do \
3191
			afile=$${afile##*/}; \
3192
			if [ "x$$afile" = "x$$filebasename" ]; then \
3193
				force_fetch=true; \
3194
			fi; \
3195
		done; \
3196
		if [ ! -f $$file -a ! -f $$filebasename -o "$$force_fetch" = "true" ]; then \
3197
			if [ -L $$file -o -L $${file##*/} ]; then \
3198
				${ECHO_MSG} "=> ${_DISTDIR}/$$file is a broken symlink."; \
3199
				${ECHO_MSG} "=> Perhaps a filesystem (most likely a CD) isn't mounted?"; \
3200
				${ECHO_MSG} "=> Please correct this problem and try again."; \
3201
				exit 1; \
3202
			fi; \
3203
			${ECHO_MSG} "=> $$file doesn't seem to exist in ${_DISTDIR}."; \
3204
			if [ ! -z "$$select" ] ; then \
3205
				__PATCH_SITES_TMP= ; \
3206
				for group in $$select; do \
3207
					if [ ! -z \$${_PATCH_SITES_$${group}} ] ; then \
3208
						eval ___PATCH_SITES_TMP="\$${_PATCH_SITES_$${group}}" ; \
3209
						__PATCH_SITES_TMP="$${__PATCH_SITES_TMP} $${___PATCH_SITES_TMP}" ; \
3210
					fi; \
3211
				done; \
3212
				___PATCH_SITES_TMP= ; \
3213
				SORTED_PATCH_SITES_CMD_TMP="${ECHO_CMD} ${_MASTER_SITE_OVERRIDE} `${ECHO_CMD} $${__PATCH_SITES_TMP} | ${AWK} '${MASTER_SORT_AWK:S|\\|\\\\|g}'` ${_MASTER_SITE_BACKUP}" ; \
3214
			else \
3215
				SORTED_PATCH_SITES_CMD_TMP="${SORTED_PATCH_SITES_DEFAULT_CMD}" ; \
3216
			fi; \
3217
			sites_remaining=0; \
3218
			sites="`eval $$SORTED_PATCH_SITES_CMD_TMP`"; \
3219
			for site in $${sites}; do \
3220
				sites_remaining=$$(($${sites_remaining} + 1)); \
3221
			done; \
3222
			for site in $${sites}; do \
3223
				sites_remaining=$$(($${sites_remaining} - 1)); \
3224
			    ${ECHO_MSG} "=> Attempting to fetch $${site}$${file}"; \
3225
				CKSIZE=`alg=SIZE; ${DISTINFO_DATA}`; \
3226
				case $${file} in \
3227
				*/*)	${MKDIR} $${file%/*}; \
3228
						args="-o $${file} $${site}$${file}";; \
3229
				*)		args=$${site}$${file};; \
3230
				esac; \
3231
				if ${SETENV} ${FETCH_ENV} ${FETCH_CMD} ${FETCH_BEFORE_ARGS} $${args} ${FETCH_AFTER_ARGS}; then \
3232
					actual_size=`stat -f %z "$${file}"`; \
3233
					if [ -n "${DISABLE_SIZE}" ] || [ -z "$${CKSIZE}" ] || [ $${actual_size} -eq $${CKSIZE} ]; then \
3234
						continue 2; \
3235
					else \
3236
						${ECHO_MSG} "=> Fetched file size mismatch (expected $${CKSIZE}, actual $${actual_size})"; \
3237
						if [ $${sites_remaining} -gt 1 ]; then \
3238
							${ECHO_MSG} "=> Trying next site"; \
3239
							${RM} -f $${file}; \
3240
						fi; \
3241
					fi; \
3242
				fi; \
3243
			done; \
3244
			${ECHO_MSG} "=> Couldn't fetch it - please try to retrieve this";\
3245
			${ECHO_MSG} "=> port manually into ${_DISTDIR} and try again."; \
3246
			exit 1; \
3247
		fi; \
3248
	 done
3249
.endif
3136
.endif
3250
.endif
3137
.endif
3251
3138
3139
# Used by fetch-urlall-list and fetch-url-list
3140
3141
.if !target(fetch-url-list-int)
3142
fetch-url-list-int:
3143
.if !empty(DISTFILES)
3144
	@${SETENV} \
3145
			${_DO_FETCH_ENV} ${_MASTER_SITES_ENV} \
3146
			dp_SITE_FLAVOR=MASTER \
3147
			${SH} ${SCRIPTSDIR}/do-fetch.sh ${DISTFILES:C/.*/'&'/}
3148
.endif
3149
.if defined(PATCHFILES) && !empty(PATCHFILES)
3150
	@${SETENV} \
3151
			${_DO_FETCH_ENV} ${_PATCH_SITES_ENV} \
3152
			dp_SITE_FLAVOR=PATCH \
3153
			${SH} ${SCRIPTSDIR}/do-fetch.sh ${PATCHFILES:C/:-p[0-9]//:C/.*/'&'/}
3154
.endif
3155
.endif
3156
3157
# Prints out all the URL for all the DISTFILES and PATCHFILES.
3158
3159
.if !target(fetch-urlall-list)
3160
fetch-urlall-list:
3161
	@cd ${.CURDIR} && ${SETENV} FORCE_FETCH_ALL=yes ${MAKE} fetch-url-list-int
3162
.endif
3163
3164
# Prints the URL for all the DISTFILES and PATCHFILES that are not here
3165
3166
.if !target(fetch-url-list)
3167
fetch-url-list: fetch-url-list-int
3168
.endif
3169
3170
3252
# Extract
3171
# Extract
3253
3172
3254
clean-wrkdir:
3173
clean-wrkdir:
Lines 3966-4141 delete-distfiles-list: Link Here
3966
.endif
3885
.endif
3967
.endif
3886
.endif
3968
3887
3969
# Prints out a list of files to fetch (useful to do a batch fetch)
3970
3971
.if !target(fetch-list)
3972
fetch-list:
3973
	@${MKDIR} ${_DISTDIR}
3974
	@(cd ${_DISTDIR}; \
3975
	 ${_MASTER_SITES_ENV} ; \
3976
	 for _file in ${DISTFILES}; do \
3977
		file=`${ECHO_CMD} $$_file | ${SED} -E -e 's/:[^:]+$$//'` ; \
3978
		if [ $$_file = $$file ]; then	\
3979
			select='';	\
3980
		else	\
3981
			select=`${ECHO_CMD} $${_file##*:} | ${SED} -e 's/,/ /g'` ;	\
3982
		fi;	\
3983
		if [ ! -f $$file -a ! -f $${file##*/} ]; then \
3984
			if [ ! -z "$$select" ] ; then \
3985
				__MASTER_SITES_TMP= ; \
3986
				for group in $$select; do \
3987
					if [ ! -z \$${_MASTER_SITES_$${group}} ] ; then \
3988
						eval ___MASTER_SITES_TMP=\$${_MASTER_SITES_$${group}} ; \
3989
						__MASTER_SITES_TMP="$${__MASTER_SITES_TMP} $${___MASTER_SITES_TMP}" ; \
3990
					fi; \
3991
				done; \
3992
				___MASTER_SITES_TMP= ; \
3993
				SORTED_MASTER_SITES_CMD_TMP="${ECHO_CMD} ${_MASTER_SITE_OVERRIDE} `${ECHO_CMD} $${__MASTER_SITES_TMP} | ${AWK} '${MASTER_SORT_AWK:S|\\|\\\\|g}'` ${_MASTER_SITE_BACKUP}" ; \
3994
			else \
3995
				SORTED_MASTER_SITES_CMD_TMP="${SORTED_MASTER_SITES_DEFAULT_CMD}" ; \
3996
			fi; \
3997
			${ECHO_CMD} -n ${MKDIR} ${_DISTDIR} '&& ' ; \
3998
			${ECHO_CMD} -n cd ${_DISTDIR} '&& { ' ; \
3999
			for site in `eval $$SORTED_MASTER_SITES_CMD_TMP ${_RANDOMIZE_SITES}`; do \
4000
				if [ ! -z "`${ECHO_CMD} ${NOFETCHFILES} | ${GREP} -w $${file}`" ]; then \
4001
					if [ -z "`${ECHO_CMD} ${MASTER_SITE_OVERRIDE} | ${GREP} -w $${site}`" ]; then \
4002
						continue; \
4003
					fi; \
4004
				fi; \
4005
				CKSIZE=`alg=SIZE; ${DISTINFO_DATA}`; \
4006
				case $${file} in \
4007
				*/*)	args="-o $${file} $${site}$${file}";; \
4008
				*)		args=$${site}$${file};; \
4009
				esac; \
4010
				${ECHO_CMD} -n ${SETENV} ${FETCH_ENV} ${FETCH_CMD} ${FETCH_BEFORE_ARGS} $${args} "${FETCH_AFTER_ARGS}" '|| ' ; \
4011
			done; \
4012
			${ECHO_CMD} "${ECHO_CMD} $${file} not fetched; }" ; \
4013
		fi; \
4014
	done)
4015
.if defined(PATCHFILES)
4016
	@(cd ${_DISTDIR}; \
4017
	 ${_PATCH_SITES_ENV} ; \
4018
	 for _file in ${PATCHFILES}; do \
4019
		file=`${ECHO_CMD} $$_file | ${SED} -E -e 's/:[^-:][^:]*$$//'` ; \
4020
		if [ $$_file = $$file ]; then	\
4021
			select='';	\
4022
		else	\
4023
			select=`${ECHO_CMD} $${_file##*:} | ${SED} -e 's/,/ /g'` ;	\
4024
		fi;	\
4025
		file=`${ECHO_CMD} $$file | ${SED} -E -e 's/:-[^:]+$$//'` ; \
4026
		if [ ! -f $$file -a ! -f $${file##*/} ]; then \
4027
			if [ ! -z "$$select" ] ; then \
4028
				__PATCH_SITES_TMP= ; \
4029
				for group in $$select; do \
4030
					if [ ! -z \$${_PATCH_SITES_$${group}} ] ; then \
4031
						eval ___PATCH_SITES_TMP=\$${_PATCH_SITES_$${group}} ; \
4032
						__PATCH_SITES_TMP="$${__PATCH_SITES_TMP} $${___PATCH_SITES_TMP}" ; \
4033
				fi; \
4034
				done; \
4035
				___PATCH_SITES_TMP= ; \
4036
				SORTED_PATCH_SITES_CMD_TMP="${ECHO_CMD} ${_MASTER_SITE_OVERRIDE} `${ECHO_CMD} $${__PATCH_SITES_TMP} | ${AWK} '${MASTER_SORT_AWK:S|\\|\\\\|g}'` ${_MASTER_SITE_BACKUP}" ; \
4037
			else \
4038
				SORTED_PATCH_SITES_CMD_TMP="${SORTED_PATCH_SITES_DEFAULT_CMD}" ; \
4039
			fi; \
4040
			${ECHO_CMD} -n ${MKDIR} ${_DISTDIR} '&& ' ; \
4041
			${ECHO_CMD} -n cd ${_DISTDIR} '&& { ' ; \
4042
			for site in `eval $$SORTED_PATCH_SITES_CMD_TMP ${_RANDOMIZE_SITES}`; do \
4043
				CKSIZE=`alg=SIZE; ${DISTINFO_DATA}`; \
4044
				case $${file} in \
4045
				*/*)	args="-o $${file} $${site}$${file}";; \
4046
				*)		args=$${site}$${file};; \
4047
				esac; \
4048
				${ECHO_CMD} -n ${SETENV} ${FETCH_ENV} ${FETCH_CMD} ${FETCH_BEFORE_ARGS} $${args} "${FETCH_AFTER_ARGS}" '|| ' ; \
4049
			done; \
4050
			${ECHO_CMD} "${ECHO_CMD} $${file} not fetched; }" ; \
4051
		fi; \
4052
	 done)
4053
.endif
4054
.endif
4055
4056
.if !target(fetch-url-list-int)
4057
fetch-url-list-int:
4058
	@${MKDIR} ${_DISTDIR}
4059
	@(cd ${_DISTDIR}; \
4060
	${_MASTER_SITES_ENV}; \
4061
	for _file in ${DISTFILES}; do \
4062
		file=`${ECHO_CMD} $$_file | ${SED} -E -e 's/:[^:]+$$//'` ; \
4063
			fileptn=`${ECHO_CMD} $$file | ${SED} 's|/|\\\\/|g;s/\./\\\\./g;s/\+/\\\\+/g;s/\?/\\\\?/g'` ; \
4064
		if [ $$_file = $$file ]; then	\
4065
			select='';	\
4066
		else	\
4067
			select=`${ECHO_CMD} $${_file##*:} | ${SED} -e 's/,/ /g'` ;	\
4068
		fi;	\
4069
		if [ ! -z "${LISTALL}" -o ! -f $$file -a ! -f $${file##*/} ]; then \
4070
			if [ ! -z "$$select" ] ; then \
4071
				__MASTER_SITES_TMP= ; \
4072
				for group in $$select; do \
4073
					if [ ! -z \$${_MASTER_SITES_$${group}} ] ; then \
4074
						eval ___MASTER_SITES_TMP=\$${_MASTER_SITES_$${group}} ; \
4075
						__MASTER_SITES_TMP="$${__MASTER_SITES_TMP} $${___MASTER_SITES_TMP}" ; \
4076
					fi \
4077
				done; \
4078
				___MASTER_SITES_TMP= ; \
4079
				SORTED_MASTER_SITES_CMD_TMP="${ECHO_CMD} ${_MASTER_SITE_OVERRIDE} `${ECHO_CMD} $${__MASTER_SITES_TMP} | ${AWK} '${MASTER_SORT_AWK:S|\\|\\\\|g}'` ${_MASTER_SITE_BACKUP}" ; \
4080
			else \
4081
				SORTED_MASTER_SITES_CMD_TMP="${SORTED_MASTER_SITES_DEFAULT_CMD}" ; \
4082
			fi ; \
4083
			for site in `eval $$SORTED_MASTER_SITES_CMD_TMP ${_RANDOMIZE_SITES}`; do \
4084
				case $${file} in \
4085
				*/*)	args="-o $${file} $${site}$${file}";; \
4086
				*)		args=$${site}$${file};; \
4087
				esac; \
4088
				${ECHO_CMD} $${args} ; \
4089
			done; \
4090
		fi \
4091
	done)
4092
.if defined(PATCHFILES)
4093
	@(cd ${_DISTDIR}; \
4094
	${_PATCH_SITES_ENV} ; \
4095
	for _file in ${PATCHFILES}; do \
4096
		file=`${ECHO_CMD} $$_file | ${SED} -E -e 's/:[^-:][^:]*$$//'` ; \
4097
		if [ $$_file = $$file ]; then	\
4098
			select='';	\
4099
		else	\
4100
			select=`${ECHO_CMD} $${_file##*:} | ${SED} -e 's/,/ /g'` ;	\
4101
		fi;	\
4102
		file=`${ECHO_CMD} $$file | ${SED} -E -e 's/:-[^:]+$$//'` ; \
4103
		fileptn=`${ECHO_CMD} $$file | ${SED} 's|/|\\\\/|g;s/\./\\\\./g;s/\+/\\\\+/g;s/\?/\\\\?/g'` ; \
4104
		if [ ! -z "${LISTALL}" -o ! -f $$file -a ! -f $${file##*/} ]; then \
4105
			if [ ! -z "$$select" ] ; then \
4106
				__PATCH_SITES_TMP= ; \
4107
				for group in $$select; do \
4108
					if [ ! -z \$${_PATCH_SITES_$${group}} ] ; then \
4109
						eval ___PATCH_SITES_TMP=\$${_PATCH_SITES_$${group}} ; \
4110
						__PATCH_SITES_TMP="$${__PATCH_SITES_TMP} $${___PATCH_SITES_TMP}" ; \
4111
					fi \
4112
				done; \
4113
				___PATCH_SITES_TMP= ; \
4114
				SORTED_PATCH_SITES_CMD_TMP="${ECHO_CMD} ${_MASTER_SITE_OVERRIDE} `${ECHO_CMD} $${__PATCH_SITES_TMP} | ${AWK} '${MASTER_SORT_AWK:S|\\|\\\\|g}'` ${_MASTER_SITE_BACKUP}" ; \
4115
			else \
4116
				SORTED_PATCH_SITES_CMD_TMP="${SORTED_PATCH_SITES_DEFAULT_CMD}" ; \
4117
			fi ; \
4118
			for site in `eval $$SORTED_PATCH_SITES_CMD_TMP ${_RANDOMIZE_SITES}`; do \
4119
				case $${file} in \
4120
				*/*)	args="-o $${file} $${site}$${file}";; \
4121
				*)		args=$${site}$${file};; \
4122
				esac; \
4123
				${ECHO_CMD} $${args} ; \
4124
			done; \
4125
		fi \
4126
	 done)
4127
.endif
4128
.endif
4129
4130
.if !target(fetch-urlall-list)
4131
fetch-urlall-list:
4132
	@cd ${.CURDIR} && LISTALL=yes ${MAKE} fetch-url-list-int
4133
.endif
4134
4135
.if !target(fetch-url-list)
4136
fetch-url-list: fetch-url-list-int
4137
.endif
4138
4139
# Generates patches.
3888
# Generates patches.
4140
3889
4141
update-patches:
3890
update-patches:
Lines 4151-4282 update-patches: Link Here
4151
3900
4152
# Checksumming utilities
3901
# Checksumming utilities
4153
3902
4154
check-checksum-algorithms:
3903
# List all algorithms here, all the variables name must begin with dp_
4155
	@ \
3904
_CHECKSUM_INIT_ENV= \
4156
	${checksum_init} \
3905
	dp_SHA256=${SHA256}
4157
	\
4158
	for alg in ${CHECKSUM_ALGORITHMS:tu}; do \
4159
		eval alg_executable=\$$$$alg; \
4160
		if [ -z "$$alg_executable" ]; then \
4161
			${ECHO_MSG} "Checksum algorithm $$alg: Couldn't find the executable."; \
4162
			${ECHO_MSG} "Set $$alg=/path/to/$$alg in /etc/make.conf and try again."; \
4163
			exit 1; \
4164
		fi; \
4165
	done; \
4166
4167
checksum_init=\
4168
	SHA256=${SHA256};
4169
3906
4170
.if !target(makesum)
3907
.if !target(makesum)
4171
makesum: check-checksum-algorithms
3908
# Some port change the options with OPTIONS_*_FORCE when make(makesum) to be
4172
	@cd ${.CURDIR} && ${MAKE} fetch NO_CHECKSUM=yes \
3909
# able to add all distfiles in one go.
4173
		DISABLE_SIZE=yes
3910
# For this to work, we need to call the do-fetch script directly here so that
4174
	@if [ -f ${DISTINFO_FILE} ]; then \
3911
# the options consistent when fetching and when makesum'ing.
4175
		if ${GREP} -q "^TIMESTAMP " ${DISTINFO_FILE}; then \
3912
# As we're fetching new distfiles, that are not in the distinfo file, disable
4176
			${GREP} -v "^TIMESTAMP " ${DISTINFO_FILE} > ${DISTINFO_FILE}.sav; \
3913
# checksum and sizes checks.
4177
		fi; \
3914
makesum:
4178
	fi
3915
.if !empty(DISTFILES)
4179
	@( \
3916
	@${SETENV} \
4180
		cd ${DISTDIR}; \
3917
			${_DO_FETCH_ENV} ${_MASTER_SITES_ENV} \
4181
		\
3918
			dp_NO_CHECKSUM=yes dp_DISABLE_SIZE=yes \
4182
		${checksum_init} \
3919
			dp_SITE_FLAVOR=MASTER \
4183
		\
3920
			${SH} ${SCRIPTSDIR}/do-fetch.sh ${DISTFILES:C/.*/'&'/}
4184
		for file in ${_CKSUMFILES}; do \
3921
.endif
4185
			for alg in ${CHECKSUM_ALGORITHMS:tu}; do \
3922
.if defined(PATCHFILES) && !empty(PATCHFILES)
4186
				eval alg_executable=\$$$$alg; \
3923
	@${SETENV} \
4187
				\
3924
			${_DO_FETCH_ENV} ${_PATCH_SITES_ENV} \
4188
				if [ $$alg_executable != "NO" ]; then \
3925
			dp_NO_CHECKSUM=yes dp_DISABLE_SIZE=yes \
4189
					$$alg_executable $$file >> ${DISTINFO_FILE}.new; \
3926
			dp_SITE_FLAVOR=PATCH \
4190
				fi; \
3927
			${SH} ${SCRIPTSDIR}/do-fetch.sh ${PATCHFILES:C/:-p[0-9]//:C/.*/'&'/}
4191
			done; \
3928
.endif
4192
			${ECHO_CMD} "SIZE ($$file) = `${STAT} -f \"%z\" $$file`" >> ${DISTINFO_FILE}.new; \
3929
	@${SETENV} \
4193
		done; \
3930
			${_CHECKSUM_INIT_ENV} \
4194
		if [ ! -f ${DISTINFO_FILE}.sav ] || ! cmp -s ${DISTINFO_FILE}.sav ${DISTINFO_FILE}.new; then \
3931
			dp_CHECKSUM_ALGORITHMS='${CHECKSUM_ALGORITHMS:tu}' \
4195
			${ECHO_CMD} "TIMESTAMP = `date '+%s'`" > ${DISTINFO_FILE} ; \
3932
			dp_CKSUMFILES='${_CKSUMFILES}' \
4196
				${CAT} ${DISTINFO_FILE}.new >> ${DISTINFO_FILE} ; \
3933
			dp_DISTDIR='${DISTDIR}' \
4197
		fi ; \
3934
			dp_DISTINFO_FILE='${DISTINFO_FILE}' \
4198
		rm -f ${DISTINFO_FILE}.new ${DISTINFO_FILE}.sav ; \
3935
			dp_ECHO_MSG='${ECHO_MSG}' \
4199
	)
3936
			dp_SCRIPTSDIR='${SCRIPTSDIR}' \
3937
			${SH} ${SCRIPTSDIR}/makesum.sh ${DISTFILES:C/.*/'&'/}
4200
.endif
3938
.endif
4201
3939
4202
.if !target(checksum)
3940
.if !target(checksum)
4203
checksum: fetch check-checksum-algorithms
3941
checksum: fetch
4204
	@set -e ; \
3942
.if !empty(_CKSUMFILES)
4205
	${checksum_init} \
3943
	@${SETENV} \
4206
	if [ -f ${DISTINFO_FILE} ]; then \
3944
			${_CHECKSUM_INIT_ENV} \
4207
		cd ${DISTDIR}; OK="";\
3945
			dp_CHECKSUM_ALGORITHMS='${CHECKSUM_ALGORITHMS:tu}' \
4208
		for file in ${_CKSUMFILES}; do \
3946
			dp_CURDIR='${.CURDIR}' \
4209
			ignored="true"; \
3947
			dp_DISTDIR='${DISTDIR}' \
4210
			_file=$${file#${DIST_SUBDIR}/*};	\
3948
			dp_DISTINFO_FILE='${DISTINFO_FILE}' \
4211
			for alg in ${CHECKSUM_ALGORITHMS:tu}; do \
3949
			dp_DIST_SUBDIR='${DIST_SUBDIR}' \
4212
				ignore="false"; \
3950
			dp_ECHO_MSG='${ECHO_MSG}' \
4213
				eval alg_executable=\$$$$alg; \
3951
			dp_FETCH_REGET='${FETCH_REGET}' \
4214
				\
3952
			dp_MAKE='${MAKE}' \
4215
				if [ $$alg_executable != "NO" ]; then \
3953
			dp_MAKEFLAGS='${.MAKEFLAGS}' \
4216
					MKSUM=`$$alg_executable < $$file`; \
3954
			dp_SCRIPTSDIR='${SCRIPTSDIR}' \
4217
					CKSUM=`file=$$_file; ${DISTINFO_DATA}`; \
3955
			dp_DISABLE_SIZE='${DISABLE_SIZE}' \
4218
				else \
3956
			dp_NO_CHECKSUM='${NO_CHECKSUM}' \
4219
					ignore="true"; \
3957
			${SH} ${SCRIPTSDIR}/checksum.sh ${_CKSUMFILES:C/.*/'&'/}
4220
				fi; \
3958
.endif
4221
				\
4222
				if [ $$ignore = "false" -a -z "$$CKSUM" ]; then \
4223
					${ECHO_MSG} "=> No $$alg checksum recorded for $$file."; \
4224
					ignore="true"; \
4225
				fi; \
4226
				\
4227
				if [ $$ignore = "false" ]; then \
4228
					match="false"; \
4229
					for chksum in $$CKSUM; do \
4230
						if [ "$$chksum" = "$$MKSUM" ]; then \
4231
							match="true"; \
4232
							break; \
4233
						fi; \
4234
					done; \
4235
					if [ $$match = "true" ]; then \
4236
						${ECHO_MSG} "=> $$alg Checksum OK for $$file."; \
4237
						ignored="false"; \
4238
					else \
4239
						${ECHO_MSG} "=> $$alg Checksum mismatch for $$file."; \
4240
						refetchlist="$$refetchlist$$file "; \
4241
						OK="$${OK:-retry}"; \
4242
						[ "$${OK}" = "retry" -a ${FETCH_REGET} -gt 0 ] && ${RM} -f $${file}; \
4243
						ignored="false"; \
4244
					fi; \
4245
				fi; \
4246
			done; \
4247
			\
4248
			if [ $$ignored = "true" ]; then \
4249
				${ECHO_MSG} "=> No suitable checksum found for $$file."; \
4250
				OK="${FALSE}"; \
4251
			fi; \
4252
			\
4253
		done; \
4254
		\
4255
		if [ "$${OK:=true}" = "retry" ] && [ ${FETCH_REGET} -gt 0 ]; then \
4256
			${ECHO_MSG} "===>  Refetch for ${FETCH_REGET} more times files: $$refetchlist"; \
4257
			if ( cd ${.CURDIR} && \
4258
			    ${MAKE} ${.MAKEFLAGS} FORCE_FETCH="$$refetchlist" FETCH_REGET="`${EXPR} ${FETCH_REGET} - 1`" fetch); then \
4259
				  if ( cd ${.CURDIR} && \
4260
			        ${MAKE} ${.MAKEFLAGS} FETCH_REGET="`${EXPR} ${FETCH_REGET} - 1`" checksum ); then \
4261
				      OK="true"; \
4262
				  fi; \
4263
			fi; \
4264
		fi; \
4265
		\
4266
		if [ "$$OK" != "true" -a ${FETCH_REGET} -eq 0 ]; then \
4267
			${ECHO_MSG} "===>  Giving up on fetching files: $$refetchlist"; \
4268
			${ECHO_MSG} "Make sure the Makefile and distinfo file (${DISTINFO_FILE})"; \
4269
			${ECHO_MSG} "are up to date.  If you are absolutely sure you want to override this"; \
4270
			${ECHO_MSG} "check, type \"make NO_CHECKSUM=yes [other args]\"."; \
4271
			exit 1; \
4272
		fi; \
4273
		if [ "$$OK" != "true" ]; then \
4274
			exit 1; \
4275
		fi; \
4276
	elif [ -n "${_CKSUMFILES:M*}" ]; then \
4277
		${ECHO_MSG} "=> No checksum file (${DISTINFO_FILE})."; \
4278
		exit 1; \
4279
	fi
4280
.endif
3959
.endif
4281
3960
4282
################################################################
3961
################################################################

Return to bug 208916