From c22a447a344d608bcbf3a15e9dd5a5ec0c15f3ae Mon Sep 17 00:00:00 2001
From: Franco Fichtner <franco@opnsense.org>
Date: Sat, 2 Jun 2018 10:23:46 +0200
Subject: [PATCH] Framework: sync with upstream

Taken from: HardenedBSD
---
 MOVED                                | 12 ++++++++++++
 Mk/Scripts/actual-package-depends.sh |  2 +-
 Mk/Scripts/check_leftovers.sh        |  2 --
 Mk/Scripts/checksum.sh               |  2 +-
 Mk/Scripts/create-manifest.sh        |  4 ++--
 Mk/Scripts/depends-list.sh           |  4 ++++
 Mk/Scripts/find-lib.sh               |  4 ++--
 Mk/Scripts/functions.sh              | 16 +++++++++-------
 Mk/Scripts/generate-symbols.sh       |  2 +-
 Mk/Scripts/qa.sh                     | 23 +++++++++++++----------
 Mk/Scripts/smart_makepatch.sh        |  3 ++-
 Tools/scripts/portsvar.sh            |  2 +-
 12 files changed, 48 insertions(+), 28 deletions(-)

diff --git a/MOVED b/MOVED
index 3230c9961685..29435f1b224e 100644
--- a/MOVED
+++ b/MOVED
@@ -10210,3 +10210,15 @@ devel/hs-text||2018-05-25|Removed, no longer supported
 science/hs-bio||2018-05-25|Removed, no longer supported
 textproc/hs-parsec||2018-05-25|Removed, no longer supported
 audio/calf|audio/calf-lv2|2018-05-27|Added -lv2 suffix: the port mostly provides LV2 plugins
+net/rubygem-gitaly-proto083|net/rubygem-gitaly-proto|2018-06-01|Has expired: Obsoleted by update of www/gitlab. Please use net/rubygem-gitaly-proto instead.
+net/rubygem-gitaly-proto084|net/rubygem-gitaly-proto|2018-06-01|Has expired: Obsoleted by update of www/gitlab. Please use net/rubygem-gitaly-proto instead
+textproc/rubygem-github-linguist47|textproc/rubygem-github-linguist|2018-06-01|Has expired: Obsoleted by update of www/gitlab. Please use textproc/rubygem-github-linguist instead
+textproc/rubygem-loofah20|textproc/rubygem-loofah|2018-06-01|Has expired: Obsoleted by update of www/gitlab. Please use textproc/rubygem-loofah instead.
+www/npm-node4|www/npm|2018-06-01|Has expired: Use www/npm instead
+emulators/qemu-launcher||2018-06-01|Has expired: Upstream is gone
+textproc/kibana3||2018-06-01|Has expired: End of Life was 2015-11-15, depends on expired www/node4
+textproc/kibana41||2018-06-01|Has expired: End of Life was 2016-11-10, depends on expired www/node4
+textproc/kibana43||2018-06-01|Has expired: End of Life was 2017-05-24, depends on expired www/node4
+textproc/kibana44||2018-06-01|Has expired: End of Life was 2017-08-02, depends on expired www/node4
+textproc/kibana45||2018-06-01|Has expired: End of Life was 2017-09-30, depends on expired www/node4
+www/node4|www/node|2018-06-01|Has expired: Node.js v4.x reaches end-of-life on 2018-04-30, see https://github.com/nodejs/Release
diff --git a/Mk/Scripts/actual-package-depends.sh b/Mk/Scripts/actual-package-depends.sh
index 18af33e57d39..d773efa96a84 100644
--- a/Mk/Scripts/actual-package-depends.sh
+++ b/Mk/Scripts/actual-package-depends.sh
@@ -17,7 +17,7 @@ resolv_symlink() {
 		return
 	fi
 
-	tgt=`readlink ${file}`
+	tgt=$(readlink ${file})
 	case $tgt in
 	/*)
 		echo $tgt
diff --git a/Mk/Scripts/check_leftovers.sh b/Mk/Scripts/check_leftovers.sh
index c7d00121006e..9e4afd1ca670 100644
--- a/Mk/Scripts/check_leftovers.sh
+++ b/Mk/Scripts/check_leftovers.sh
@@ -152,10 +152,8 @@ while read modtype path extra; do
 			share/xml/catalog.ports) ;;
 			# Ignore ghc's doc index
 			share/doc/ghc-%%GHC_VERSION%%/*) ;;
-			share/doc/ghc-%%GHC_VERSION%%/html/libraries/%%PORTNAME%%-%%PORTVERSION%%/html) ;;
 			# Ignore ghc's package conf
 			lib/ghc-%%GHC_VERSION%%/package.conf.d/*) ;;
-			lib/ghc-%%GHC_VERSION%%/package.conf.d/%%PORTNAME%%-%%PORTVERSION%%.conf) ;;
 			# Ignore common system config files
 			/etc/group|\
 			/etc/make.conf|\
diff --git a/Mk/Scripts/checksum.sh b/Mk/Scripts/checksum.sh
index 7a0872209575..cde14a831999 100644
--- a/Mk/Scripts/checksum.sh
+++ b/Mk/Scripts/checksum.sh
@@ -87,7 +87,7 @@ if [ -f "${dp_DISTINFO_FILE}" ]; then
 	if [ "$OK" != "true" ]; then
 		exit 1
 	fi
-elif [ -n "${@}" ]; then
+elif [ -n "${*}" ]; then
 	${dp_ECHO_MSG} "=> No checksum file (${dp_DISTINFO_FILE})."
 	exit 1
 fi
diff --git a/Mk/Scripts/create-manifest.sh b/Mk/Scripts/create-manifest.sh
index 25f9c999c636..974198cf7928 100644
--- a/Mk/Scripts/create-manifest.sh
+++ b/Mk/Scripts/create-manifest.sh
@@ -57,8 +57,8 @@ EOT
 [ -z "${dp_LICENSE}" ] || echo "licenses: [ ${dp_LICENSE} ]"
 [ -z "${dp_USERS}" ] || echo "users: [ ${dp_USERS} ]"
 [ -z "${dp_GROUPS}" ] || echo "groups: [ ${dp_GROUPS} ]"
-[ -n "${dp_NO_ARCH}" ] && echo "arch : `${dp_PKG_BIN} config abi | tr '[:upper:]' '[:lower:]' | cut -d: -f1,2`:*"
-[ -n "${dp_NO_ARCH}" ] && echo "abi : `${dp_PKG_BIN} config abi | cut -d: -f1,2`:*"
+[ -n "${dp_NO_ARCH}" ] && echo "arch : $(${dp_PKG_BIN} config abi | tr '[:upper:]' '[:lower:]' | cut -d: -f1,2):*"
+[ -n "${dp_NO_ARCH}" ] && echo "abi : $(${dp_PKG_BIN} config abi | cut -d: -f1,2):*"
 
 # Then the key/values sections
 echo "deps: { "
diff --git a/Mk/Scripts/depends-list.sh b/Mk/Scripts/depends-list.sh
index 39a0c5656f50..91d95d136e7e 100644
--- a/Mk/Scripts/depends-list.sh
+++ b/Mk/Scripts/depends-list.sh
@@ -115,10 +115,14 @@ check_dep() {
 		fi
 		[ ${show_dep} -eq 1 ] && echo "${port_display}"
 		if [ ${recursive} -eq 1 -o ${requires_wrkdir} -eq 1 -a ${show_dep} -eq 1 ]; then
+			# shellcheck disable=SC2068
+			# Do not add quotes, we want to split the string here.
 			check_dep $@
 		fi
 	done
 }
 
 checked=
+# shellcheck disable=SC2068
+# Do not add quotes, we want to split the string here.
 check_dep $@
diff --git a/Mk/Scripts/find-lib.sh b/Mk/Scripts/find-lib.sh
index e442bcb7f2e9..80c830ac14fa 100644
--- a/Mk/Scripts/find-lib.sh
+++ b/Mk/Scripts/find-lib.sh
@@ -22,12 +22,12 @@ if [ $# -ne 1 ]; then
 fi
 
 lib=$1
-dirs="${LIB_DIRS} `cat ${LOCALBASE}/libdata/ldconfig/* 2>/dev/null || :`"
+dirs="${LIB_DIRS} $(cat ${LOCALBASE}/libdata/ldconfig/* 2>/dev/null || :)"
 
 for libdir in ${dirs} ; do
 	test -f ${libdir}/${lib} || continue
 	libfile=${libdir}/${lib}
-	[ `file -b -L --mime-type ${libfile}` = "application/x-sharedlib" ] || continue
+	[ $(file -b -L --mime-type ${libfile}) = "application/x-sharedlib" ] || continue
 	echo $libfile
 	break
 done
diff --git a/Mk/Scripts/functions.sh b/Mk/Scripts/functions.sh
index 6a360abf21c7..72ee5c3fe69e 100644
--- a/Mk/Scripts/functions.sh
+++ b/Mk/Scripts/functions.sh
@@ -74,9 +74,9 @@ parse_plist() {
 		@info\ *|@shell\ *|@xmlcatmgr\ *)
 			set -- $line
 			shift
-			case "$@" in
-			/*) echo "${comment}$@" ;;
-			*) echo "${comment}${cwd}/$@" ;;
+			case "$*" in
+			/*) echo "${comment}$*" ;;
+			*) echo "${comment}${cwd}/$*" ;;
 			esac
 		;;
 		@sample\ *)
@@ -103,12 +103,12 @@ parse_plist() {
 		@fc\ *|@fcfontsdir\ *|@fontsdir\ *)
 			set -- $line
 			shift
-			case "$@" in
+			case "$*" in
 			/*)
-			echo >&3 "${comment}$@"
+			echo >&3 "${comment}$*"
 			;;
 			*)
-			echo >&3 "${comment}${cwd}/$@"
+			echo >&3 "${comment}${cwd}/$*"
 			;;
 			esac
 		;;
@@ -160,7 +160,7 @@ validate_env() {
 }
 
 export_ports_env() {
-	local export_vars make_cmd make_env var results value uses
+	local export_vars make_cmd make_env var value uses
 
 	if [ -n "${HAVE_PORTS_ENV:-}" ]; then
 		return 0
@@ -197,6 +197,8 @@ export_ports_env() {
 		value="$(eval echo \$${var})"
 
 		if [ -n "${value}" ]; then
+			# shellcheck disable=SC2163
+			# We want to export the variable which name is in var.
 			export ${var}
 			echo "export ${var}=\"${value}\""
 		fi
diff --git a/Mk/Scripts/generate-symbols.sh b/Mk/Scripts/generate-symbols.sh
index cdad53635f93..6d490e86c999 100644
--- a/Mk/Scripts/generate-symbols.sh
+++ b/Mk/Scripts/generate-symbols.sh
@@ -3,7 +3,7 @@
 # Maintainer: portmgr@FreeBSD.org
 
 msg() {
-        echo "====> $@"
+        echo "====> $*"
 }
 
 msg "Finding symbols"
diff --git a/Mk/Scripts/qa.sh b/Mk/Scripts/qa.sh
index 9ef94484a728..7b4c25122839 100644
--- a/Mk/Scripts/qa.sh
+++ b/Mk/Scripts/qa.sh
@@ -13,15 +13,15 @@ LF=$(printf '\nX')
 LF=${LF%X}
 
 notice() {
-	echo "Notice: $@" >&2
+	echo "Notice: $*" >&2
 }
 
 warn() {
-	echo "Warning: $@" >&2
+	echo "Warning: $*" >&2
 }
 
 err() {
-	echo "Error: $@" >&2
+	echo "Error: $*" >&2
 }
 
 list_stagedir_elfs() {
@@ -31,7 +31,7 @@ list_stagedir_elfs() {
 shebangonefile() {
 	local f interp interparg badinterp rc
 
-	f="$@"
+	f="$*"
 	rc=0
 
 	# whitelist some files
@@ -248,9 +248,9 @@ sharedmimeinfo() {
 suidfiles() {
 	local filelist
 
-	filelist=`find ${STAGEDIR} -type f \
+	filelist=$(find ${STAGEDIR} -type f \
 		\( -perm -u+x -or -perm -g+x -or -perm -o+x \) \
-		\( -perm -u+s -or -perm -g+s \)`
+		\( -perm -u+s -or -perm -g+s \))
 	if [ -n "${filelist}" ]; then
 		warn "setuid files in the stage directory (are these necessary?):"
 		ls -liTd ${filelist}
@@ -278,12 +278,12 @@ libperl() {
 			# No results presents a blank line from heredoc.
 			[ -z "${f}" ] && continue
 			files=$((files+1))
-			found=`readelf -d ${f} | awk "BEGIN {libperl=1; rpath=10; runpath=100}
+			found=$(readelf -d ${f} | awk "BEGIN {libperl=1; rpath=10; runpath=100}
 				/NEEDED.*${LIBPERL}/  { libperl = 0 }
 				/RPATH.*perl.*CORE/   { rpath   = 0 }
 				/RUNPATH.*perl.*CORE/ { runpath = 0 }
 				END {print libperl+rpath+runpath}
-				"`
+				")
 			case "${found}" in
 				*1)
 					warn "${f} is not linked with ${LIBPERL}, not respecting lddlflags?"
@@ -657,7 +657,7 @@ proxydeps() {
 			if listcontains ${dep_file} "${already}"; then
 				continue
 			fi
-			if $(pkg which -q ${dep_file} > /dev/null 2>&1); then
+			if pkg which -q ${dep_file} > /dev/null 2>&1; then
 				dep_file_pkg=$(pkg which -qo ${dep_file})
 
 				# Check that the .so we need has a SONAME
@@ -818,6 +818,9 @@ gemdeps()
 {
 	rc=0
 	if [ "${PKGBASE%%-*}" = "rubygem" ]; then
+		# shellcheck disable=SC2153
+		# In the heredoc, ${PORTNAME} comes from the environment, not
+		# to be confused with ${portname}
 		while read -r l; do
 			if [ -n "${l}" ]; then
 				name=${l%% *}
@@ -917,7 +920,7 @@ checks="$checks suidfiles libtool libperl prefixvar baselibs terminfo"
 checks="$checks proxydeps sonames perlcore no_arch gemdeps gemfiledeps flavors"
 
 ret=0
-cd ${STAGEDIR}
+cd ${STAGEDIR} || exit 1
 for check in ${checks}; do
 	${check} || ret=1
 done
diff --git a/Mk/Scripts/smart_makepatch.sh b/Mk/Scripts/smart_makepatch.sh
index 41f96e5e6399..b594e4590a4c 100644
--- a/Mk/Scripts/smart_makepatch.sh
+++ b/Mk/Scripts/smart_makepatch.sh
@@ -276,7 +276,8 @@ conserve_old_patches() {
 }
 
 install_regenerated_patches() {
-	local testdir=$(find ${DESTDIR} -empty)
+	local testdir
+	testdir=$(find ${DESTDIR} -empty)
 	if [ -z "${testdir}" ]; then
 		mkdir -p ${PATCHDIR}
 		find ${DESTDIR} -type f -exec mv {} ${PATCHDIR}/ \;
diff --git a/Tools/scripts/portsvar.sh b/Tools/scripts/portsvar.sh
index a30b2d1290dc..bd579714d677 100755
--- a/Tools/scripts/portsvar.sh
+++ b/Tools/scripts/portsvar.sh
@@ -29,7 +29,7 @@
 #
 # $FreeBSD$
 #
-# MAINTAINER= daichi@FreeBSD.org
+# MAINTAINER= ports@FreeBSD.org
 
 usage_msg="usage:
     portsvar.sh [-a] [-e] [-w target] [-h] [var=val ...] var1 [var2 ...]