Index: Mk/Scripts/actual-package-depends.sh =================================================================== --- Mk/Scripts/actual-package-depends.sh +++ Mk/Scripts/actual-package-depends.sh @@ -17,7 +17,7 @@ return fi - tgt=`readlink ${file}` + tgt=$(readlink ${file}) case $tgt in /*) echo $tgt Index: Mk/Scripts/check-stagedir.sh =================================================================== --- Mk/Scripts/check-stagedir.sh +++ Mk/Scripts/check-stagedir.sh @@ -62,9 +62,9 @@ } >${WRKDIR}/.mtree } -# Sort a directory list by the order of the dfs-sorted file (from find -ds) +# Sort a directory list by the order of the dfs-sorted file (from find -d -s) sort_dfs() { - while read dir; do + while read -r dir; do grep "^[0-9]* ${dir}$" ${WRKDIR}/.staged-dirs-dfs-sorted done | sort -n | cut -d ' ' -f2- } @@ -122,14 +122,14 @@ | sort -u >${WRKDIR}/.traced-dirs find ${STAGEDIR} -type d | sed -e "s,^${STAGEDIR},,;/^$/d" | sort \ >${WRKDIR}/.staged-dirrms-sorted - find -sd ${STAGEDIR}${PREFIX} -type d -empty | sed -e "s,^${STAGEDIR},,;\,^${PREFIX}$,d;/^$/d" \ + find -s -d ${STAGEDIR}${PREFIX} -type d -empty | sed -e "s,^${STAGEDIR},,;\,^${PREFIX}$,d;/^$/d" \ >${WRKDIR}/.staged-dirs-dfs - find -sd ${STAGEDIR} -type d ! -path "${STAGEDIR}${PREFIX}/*" | sed -e "s,^${STAGEDIR},,;\,^${PREFIX}$,d;/^$/d" \ + find -s -d ${STAGEDIR} -type d ! -path "${STAGEDIR}${PREFIX}/*" | sed -e "s,^${STAGEDIR},,;\,^${PREFIX}$,d;/^$/d" \ >>${WRKDIR}/.staged-dirs-dfs sort ${WRKDIR}/.staged-dirs-dfs >${WRKDIR}/.staged-dirs-sorted awk '{print FNR, $0}' ${WRKDIR}/.staged-dirs-dfs \ >${WRKDIR}/.staged-dirs-dfs-sorted - # Find all staged dirs and then sort them by depth-first (find -ds) + # Find all staged dirs and then sort them by depth-first (find -d -s) comm -13 ${WRKDIR}/.traced-dirs ${WRKDIR}/.staged-dirs-sorted \ | sort_dfs | sed "${sed_dirs_gen}" \ >>${WRKDIR}/.staged-plist || : @@ -141,7 +141,7 @@ echo "===> Checking for items in STAGEDIR missing from pkg-plist" # Handle whitelisting - while read path; do + while read -r path; do case "${path}" in *.bak) ;; *.orig) ;; @@ -199,16 +199,16 @@ sed -e "s,^,${WRKDIR}/.missing-dirs," \ -e 's,^\(.*\)$,"\1",' \ ${WRKDIR}/.missing-plist-dirs | xargs mkdir -p - find -ds ${WRKDIR}/.missing-dirs | \ + find -d -s ${WRKDIR}/.missing-dirs | \ sed -e "s,^${WRKDIR}/.missing-dirs,," | \ - while read dir; do \ + while read -r dir; do \ grep -x "${dir}" ${WRKDIR}/.missing-plist-dirs || :; done | \ sed "${sed_dirs}" \ >>${WRKDIR}/.invalid-plist-missing || : rm -rf ${WRKDIR}/.missing-dirs if [ -s "${WRKDIR}/.invalid-plist-missing" ]; then ret=1 - while read line; do + while read -r line; do echo "Error: Missing: ${line}" >&2 done < ${WRKDIR}/.invalid-plist-missing fi Index: Mk/Scripts/check_leftovers.sh =================================================================== --- Mk/Scripts/check_leftovers.sh +++ Mk/Scripts/check_leftovers.sh @@ -45,11 +45,11 @@ if [ -z "${CCACHE_DIR}" ]; then CCACHE_DIR=$(make -C ${portdir} -VCCACHE_DIR) fi -homedirs=$(awk -F: -v users=$(make -C ${portdir} -V USERS|sed -e 's, ,|,g;/^$/d;s,^,^(,;s,$,)$,') 'users && $1 ~ users {print $9}' ${PORTSDIR}/UIDs|sort -u|sed -e "s|/usr/local|${PREFIX}|"|tr "\n" " ") +homedirs=$(awk -F: -v users="$(make -C ${portdir} -V USERS|sed -e 's, ,|,g;/^$/d;s,^,^(,;s,$,)$,')" 'users && $1 ~ users {print $9}' ${PORTSDIR}/UIDs|sort -u|sed -e "s|/usr/local|${PREFIX}|"|tr "\n" " ") plistsub_sed=$(make -C ${portdir} -VPLIST_SUB_SED | /bin/sh ${PORTSDIR}/Mk/Scripts/plist_sub_sed_sort.sh) tmpplist=$(make -C ${portdir} -VTMPPLIST) -while read modtype path extra; do +while read -r modtype path extra; do # Ignore everything from these files/directories case "${path}" in ${CCACHE_DIR}/*|\ @@ -152,10 +152,8 @@ 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|\ Index: Mk/Scripts/checksum.sh =================================================================== --- Mk/Scripts/checksum.sh +++ Mk/Scripts/checksum.sh @@ -87,7 +87,7 @@ 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 Index: Mk/Scripts/create-manifest.sh =================================================================== --- Mk/Scripts/create-manifest.sh +++ Mk/Scripts/create-manifest.sh @@ -57,8 +57,8 @@ [ -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: { " Index: Mk/Scripts/depends-list.sh =================================================================== --- Mk/Scripts/depends-list.sh +++ Mk/Scripts/depends-list.sh @@ -92,10 +92,14 @@ # Grab any needed vars from the port. if [ ${requires_wrkdir} -eq 1 ]; then + # shellcheck disable=SC2046 + # We want word splitting here. set -- $(${dp_MAKE} -C ${d} -VWRKDIR -V_UNIFIED_DEPENDS) wrkdir="$1" shift elif [ ${recursive} -eq 1 ]; then + # shellcheck disable=SC2046 + # We want word splitting here. set -- $(${dp_MAKE} -C ${d} -V_UNIFIED_DEPENDS) fi @@ -106,10 +110,14 @@ fi [ ${show_dep} -eq 1 ] && echo ${d} 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 $@ Index: Mk/Scripts/find-lib.sh =================================================================== --- Mk/Scripts/find-lib.sh +++ Mk/Scripts/find-lib.sh @@ -22,12 +22,12 @@ 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 Index: Mk/Scripts/functions.sh =================================================================== --- Mk/Scripts/functions.sh +++ Mk/Scripts/functions.sh @@ -74,9 +74,9 @@ @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 @@ @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 @@ } export_ports_env() { - local export_vars make_cmd make_env var results value uses + local export_vars make_cmd make_env var value uses validate_env MAKE PORTSDIR @@ -201,8 +201,8 @@ done # Bring in all the vars, but not empty ones. - eval $(${MAKE} -f ${PORTSDIR}/Mk/bsd.port.mk ${make_cmd} \ - USES="${uses}" | grep -v '=$' | sed -e 's,\\ $,,') + eval "$(${MAKE} -f ${PORTSDIR}/Mk/bsd.port.mk ${make_cmd} \ + USES="${uses}" | grep -v '=$' | sed -e 's,\\ $,,')" for var in ${export_vars}; do # Export and display non-empty ones. This is not redundant # with above since we're looping on all vars here; do not @@ -210,6 +210,8 @@ 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 Index: Mk/Scripts/generate-symbols.sh =================================================================== --- Mk/Scripts/generate-symbols.sh +++ Mk/Scripts/generate-symbols.sh @@ -3,7 +3,7 @@ # Maintainer: portmgr@FreeBSD.org msg() { - echo "====> $@" + echo "====> $*" } msg "Finding symbols" @@ -13,8 +13,8 @@ LF=$(printf '\nX') LF=${LF%X} find ${STAGEDIR} -type f \ - -exec /usr/bin/file -nNF "${LF}" {} + | while read f; do - read output + -exec /usr/bin/file -nNF "${LF}" {} + | while read -r f; do + read -r output case "${output}" in ELF\ *\ executable,\ *FreeBSD*,\ not\ stripped*|\ ELF\ *\ shared\ object,\ *FreeBSD*,\ not\ stripped*) @@ -28,7 +28,7 @@ sed -e "s,^${STAGEDIR}${PREFIX}/,${lib_dir}/," -e 's,/[^/]*$,,' \ ${ELF_FILES} | sort -u | xargs mkdir -p -while read staged_elf_file; do +while read -r staged_elf_file; do elf_file_name="${staged_elf_file##*/}" lib_dir_dest="${lib_dir}/${staged_elf_file#${STAGEDIR}${PREFIX}/}" # Strip off filename Index: Mk/Scripts/plist_sub_sed_sort.sh =================================================================== --- Mk/Scripts/plist_sub_sed_sort.sh +++ Mk/Scripts/plist_sub_sed_sort.sh @@ -5,7 +5,7 @@ # # PLIST_SUB_SED helper to sort by longest value first. -exec awk '{ +awk '{ while (match($0, /s![^!]*![^!]*!g;/)) { sedp=substr($0, RSTART, RLENGTH) $0=substr($0, RSTART+RLENGTH) Index: Mk/Scripts/qa.sh =================================================================== --- Mk/Scripts/qa.sh +++ Mk/Scripts/qa.sh @@ -13,15 +13,15 @@ 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 @@ shebangonefile() { local f interp interparg badinterp rc - f="$@" + f="$*" rc=0 # whitelist some files @@ -95,7 +95,7 @@ rc=0 - while read f; do + while read -r f; do # No results presents a blank line from heredoc. [ -z "${f}" ] && continue shebangonefile "${f}" || rc=1 @@ -113,7 +113,7 @@ local found_openssl local file [ "${PKGBASE}" = "pkg" -o "${PKGBASE}" = "pkg-devel" ] && return - while read f; do + while read -r f; do case ${f} in File:\ .*) file=${f#File: .} @@ -148,10 +148,10 @@ # Split stat(1) result into 2 lines and read each line separately to # retain spaces in filenames. - while read l; do + while read -r l; do # No results presents a blank line from heredoc. [ -z "${l}" ] && continue - read link + read -r link case "${link}" in ${STAGEDIR}*) err "Bad symlink '${l#${STAGEDIR}${PREFIX}/}' pointing inside the stage directory" @@ -181,7 +181,7 @@ rc=0 - while read f; do + while read -r f; do # No results presents a blank line from heredoc. [ -z "${f}" ] && continue # Ignore false-positive/harmless files @@ -208,10 +208,10 @@ # files with spaces are kept intact. # Using readelf -h ... /ELF Header:/ will match on all ELF files. find ${STAGEDIR} -type f ! -name '*.a' ! -name '*.o' \ - -exec readelf -S {} + 2>/dev/null | awk '\ - /File:/ {sub(/File: /, "", $0); file=$0} \ + -exec readelf -S {} + 2>/dev/null | awk ' + /File:/ {sub(/File: /, "", $0); file=$0} /SYMTAB/ {print file}' | - while read f; do + while read -r f; do warn "'${f#${STAGEDIR}${PREFIX}/}' is not stripped consider trying INSTALL_TARGET=install-strip or using \${STRIP_CMD}" done } @@ -248,9 +248,9 @@ 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} @@ -260,10 +260,11 @@ libtool() { if [ -z "${USESLIBTOOL}" ]; then - find ${STAGEDIR} -name '*.la' | while read f; do - grep -q 'libtool library' "${f}" && - err ".la libraries found, port needs USES=libtool" && - return 1 || true + find ${STAGEDIR} -name '*.la' | while read -r f; do + if grep -q 'libtool library' "${f}"; then + err ".la libraries found, port needs USES=libtool" + return 1 + fi done # The return above continues here. fi @@ -274,16 +275,16 @@ if [ -n "${SITE_ARCH_REL}" -a -d "${STAGEDIR}${PREFIX}/${SITE_ARCH_REL}" ]; then has_some_libperl_so=0 files=0 - while read f; do + while read -r f; do # 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?" @@ -645,17 +646,17 @@ # Check all dynamicaly linked ELF files # Some .so are not executable, but we want to check them too. - while read file; do + while read -r file; do # No results presents a blank line from heredoc. [ -z "${file}" ] && continue - while read dep_file; do + while read -r dep_file; do # No results presents a blank line from heredoc. [ -z "${dep_file}" ] && continue # Skip files we already checked. 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 @@ -678,9 +679,9 @@ already="${already} ${dep_file}" done <<-EOT $(env LD_LIBMAP_DISABLE=1 ldd -a "${STAGEDIR}${file}" | \ - awk '\ - BEGIN {section=0}\ - /^\// {section++}\ + awk ' + BEGIN {section=0} + /^\// {section++} !/^\// && section<=1 && ($3 ~ "^'${PREFIX}'" || $3 ~ "^'${LOCALBASE}'") {print $3}') EOT done <<-EOT @@ -698,7 +699,7 @@ sonames() { [ ! -d ${STAGEDIR}${PREFIX}/lib -o -n "${BUNDLE_LIBS}" ] && return 0 - while read f; do + while read -r f; do # No results presents a blank line from heredoc. [ -z "${f}" ] && continue # Ignore symlinks @@ -746,7 +747,7 @@ module=$(perlcore_port_module_mapping "${portname}") version=$(expr "${dep}" : ".*>=*\([^:<]*\)") - while read l; do + while read -r l; do case "${l}" in *was\ not\ in\ CORE*) # This never was with Perl @@ -783,7 +784,7 @@ no_arch() { [ -z "$NO_ARCH" ] && return rc=0 - while read f; do + while read -r f; do [ -z "$f" ] && continue if [ -n "$NO_ARCH_IGNORE" ]; then skip= @@ -809,6 +810,9 @@ { 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%% *} @@ -863,7 +867,7 @@ checks="$checks proxydeps sonames perlcore no_arch gemdeps flavors" ret=0 -cd ${STAGEDIR} +cd ${STAGEDIR} || exit 1 for check in ${checks}; do ${check} || ret=1 done Index: Mk/Scripts/smart_makepatch.sh =================================================================== --- Mk/Scripts/smart_makepatch.sh +++ Mk/Scripts/smart_makepatch.sh @@ -51,9 +51,9 @@ echo ${raw_name} else echo ${raw_name} | awk -v sc=${STRIP_COMPONENTS} -F "/" \ - '{ for (x = sc + 1; x <= NF; x++) { \ - slash = (x>sc+1) ? "/" : ""; \ - printf ("%s%s", slash, $x); \ + '{ for (x = sc + 1; x <= NF; x++) { + slash = (x>sc+1) ? "/" : ""; + printf ("%s%s", slash, $x); }}' fi } @@ -63,13 +63,15 @@ local raw_name sans_cwd=$(echo $1 | sed 's|^\.\/||') raw_name=$(strip_path ${sans_cwd}) - echo patch-$(echo ${raw_name} | sed -e 's|_|&&|g; s|/|_|g') + echo "patch-$(echo ${raw_name} | sed -e 's|_|&&|g; s|/|_|g')" } patchdir_files_list() { if [ -d "${PATCHDIR}" ]; then + # shellcheck disable=SC2035 + # -f already makes sure what follows is not a flag (cd ${PATCHDIR} && \ - find * -type f -name "patch-*" -maxdepth 0 \ + find -f * -type f -name "patch-*" -maxdepth 0 \ 2>/dev/null | sed -e '/\.orig$/d' ) fi; @@ -135,33 +137,33 @@ rawname=$(grep "^+++ " ${existing_patch} | \ awk -v num=${num} '{x++; if (x==num) print $2}') fname=$(std_patch_filename $rawname) - awk -v num=${num} '\ - BEGIN { done=0; x=0; hunk=0; looking=(num==1) } \ - { \ - if (!done) { \ - if ($1 == "@@") { \ - split ($2,a,","); \ - split ($3,b,","); \ + awk -v num=${num} ' + BEGIN { done=0; x=0; hunk=0; looking=(num==1) } + { + if (!done) { + if ($1 == "@@") { + split ($2,a,","); + split ($3,b,","); hca = a[2]; hcb = a[3]; hunk = 1; - } else if (hunk) { \ - first=substr($1,1,1); \ - if (first == "-") { hca-- } \ - else if (first == "+") { hcb-- } \ - else {hca--; hcb--} \ - if (hca == 0 && hcb == 0) {hunk = 0} \ - } \ - if ($1 == "---") { \ - x++; \ - if (x == num) { done = 1 } \ - if (x + 1 == num) { looking = 1 } \ - } else if (!hunk && looking) { \ - if ($1!="diff" && $1!="index" && $1!="+++") {\ - print $0 \ - } \ - } \ - } \ + } else if (hunk) { + first=substr($1,1,1); + if (first == "-") { hca-- } + else if (first == "+") { hcb-- } + else {hca--; hcb--} + if (hca == 0 && hcb == 0) {hunk = 0} + } + if ($1 == "---") { + x++; + if (x == num) { done = 1 } + if (x + 1 == num) { looking = 1 } + } else if (!hunk && looking) { + if ($1!="diff" && $1!="index" && $1!="+++") { + print $0 + } + } + } }' ${existing_patch} > ${COMMENTS}/${fname} done } @@ -185,8 +187,10 @@ local OUT local ORIG local new_list + # shellcheck disable=SC2035 + # -f already makes sure what follows is not a flag new_list=$(cd "${PATCH_WRKSRC}" && \ - find -s * -type f -name '*.orig' 2>/dev/null) + find -s -f * -type f -name '*.orig' 2>/dev/null) (cd "${PATCH_WRKSRC}" && for F in ${new_list}; do ORIG=${F#./} NEW=${ORIG%.orig} @@ -200,13 +204,13 @@ } get_patch_name() { - awk -v name=$1 '\ - { if ($2 == name) \ - { \ - if (!done) { print $1 }; \ - done = 1; \ - } \ - } \ + awk -v name=$1 ' + { if ($2 == name) + { + if (!done) { print $1 }; + done = 1; + } + } END { if (!done) print name }' ${PATCHMAP} } @@ -216,7 +220,9 @@ local P local name local patch_list - patch_list=$(cd ${REGENNED} && find * -name "patch-*" 2>/dev/null) + # shellcheck disable=SC2035 + # -f already makes sure what follows is not a flag + patch_list=$(cd ${REGENNED} && find -f * -name "patch-*" 2>/dev/null) for P in ${patch_list}; do name=$(get_patch_name ${P}) [ -e ${COMMENTS}/${P} ] && cat ${COMMENTS}/${P} \ @@ -244,7 +250,8 @@ } 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}/ \;