Skip to content

Commit e68cdb8

Browse files
committed
src/binutils-config: fix shellcheck warnings
Fixed warnings: src/binutils-config:129:21: warning: Quote the right-hand side of != in [[ ]] to prevent glob matching. [SC2053] [...] src/binutils-config:179:22: warning: Quote the right-hand side of == in [[ ]] to prevent glob matching. [SC2053] [...] src/binutils-config:61:7: note: Double quote to prevent globbing and word splitting. [SC2086] [...] src/binutils-config:18:1: warning: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. [SC2164] src/binutils-config:323:23: warning: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a. [SC2206] [...] src/binutils-config:9:3: note: This default assignment may cause DoS due to globbing. Quote it. [SC2223] [...] src/binutils-config:306:28: note: Quote expansions in this for loop glob to prevent wordsplitting, e.g. "$dir"/*.txt . [SC2231] Disabled warnings: src/binutils-config:24:8: warning: ShellCheck can't follow non-constant source. Use a directive to specify location. [SC1090] [...] Signed-off-by: Allen-Kristjan Päll <[email protected]>
1 parent ad336e0 commit e68cdb8

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

src/binutils-config

+40-35
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66
# config-TARGET: CURRENT=version for TARGET
77
# TARGET-VER: has a TARGET and VER variable
88

9-
: ${ROOT:=/}
9+
: "${ROOT:=/}"
1010
[[ ${ROOT} != */ ]] && ROOT="${ROOT}/"
1111
[[ ${ROOT} != /* ]] && ROOT="${PWD%/}/${ROOT}"
1212
BROOT="@GENTOO_EPREFIX@"
1313
[[ ${BROOT} == @*@ ]] && BROOT=""
14-
: ${EPREFIX="${BROOT}"}
14+
: "${EPREFIX=${BROOT}}"
1515
EROOT="${ROOT%/}${EPREFIX}/"
1616
export PORTAGE_CONFIGROOT="${EROOT}"
1717

18-
cd "${BROOT}/"
18+
cd "${BROOT}/" || die "Could not cd into $BROOT"
1919

2020
trap ":" INT QUIT TSTP
2121

2222
argv0=${0##*/}
2323
FUNCTIONS_SH="${BROOT}/lib/gentoo/functions.sh"
24+
# shellcheck disable=SC1090
2425
source ${FUNCTIONS_SH} || {
2526
echo "${argv0}: Could not source ${FUNCTIONS_SH}!" 1>&2
2627
exit 1
@@ -31,7 +32,7 @@ umask 022
3132

3233
# *BSD SED does not work as-is, use GNU SED. TODO: find details.
3334
SED=$(type -P gsed)
34-
: ${SED:=$(type -P sed)}
35+
: "${SED:=$(type -P sed)}"
3536

3637
usage() {
3738
cat << USAGE_END
@@ -58,7 +59,7 @@ For example: ${BRACKET} i686-pc-linux-gnu-2.15.92.0.2${NORMAL}
5859
For more info, please see ${HILITE}binutils-config${NORMAL}(8).
5960
USAGE_END
6061

61-
exit ${1:-1}
62+
exit "${1:-1}"
6263
}
6364

6465
# Usage: version_sorted_paths <CHOST>
@@ -111,6 +112,7 @@ atomic_ln() {
111112

112113
setup_env() {
113114
unset TARGET VER LIBPATH
115+
# shellcheck disable=SC1090
114116
source "${ENV_D}/${PROFILE}"
115117
if [[ -z ${TARGET} ]] ; then
116118
eerror "${PROFILE} is invalid (no \$TARGET defined) :("
@@ -126,7 +128,7 @@ setup_env() {
126128
#
127129
BINPATH=""
128130
BINPATH_LINKS=""
129-
if [[ ${TARGET} != ${HOST} ]] ; then
131+
if [[ ${TARGET} != "${HOST}" ]] ; then
130132
#
131133
# Newer paths: /usr/${HOST}/${TARGET}/...
132134
# Older paths: /usr/${TARGET}/...
@@ -176,7 +178,7 @@ switch_profile() {
176178
for x in * ; do
177179
atomic_ln "${BINPATH}/${x}" "${ROOT}/${BINPATH_LINKS}" "${x}"
178180
atomic_ln "${BINPATH_LINKS}/${x}" "${EROOT}/usr/bin" "${TARGET}-${x}"
179-
if [[ ${TARGET} == ${HOST} ]] ; then
181+
if [[ ${TARGET} == "${HOST}" ]] ; then
180182
if [[ ${USE_NATIVE_LINKS} == yes ]]; then
181183
atomic_ln "${TARGET}-${x}" "${EROOT}/usr/bin" "${x}"
182184
else
@@ -207,9 +209,9 @@ switch_profile() {
207209
#
208210
# Generate library / ldscripts symlinks
209211
#
210-
: ${LIBPATH:=${EPREFIX}/usr/lib/binutils/${TARGET}/${VER}}
212+
: "${LIBPATH:=${EPREFIX}/usr/lib/binutils/${TARGET}/${VER}}"
211213
cd "${ROOT}/${LIBPATH}" || exit 1
212-
if [[ ${TARGET} == ${HOST} ]] ; then
214+
if [[ ${TARGET} == "${HOST}" ]] ; then
213215
dstlib=${EROOT}/usr/${HOST}/lib
214216
else
215217
dstlib=${EROOT}/usr/${HOST}/${TARGET}/lib
@@ -238,7 +240,7 @@ switch_profile() {
238240
INCPATH=${LIBPATH}/include
239241
if [[ -d ${ROOT}/${INCPATH} ]] ; then
240242
cd "${ROOT}/${INCPATH}" || exit 1
241-
if [[ ${HOST} != ${TARGET} ]] ; then
243+
if [[ ${HOST} != "${TARGET}" ]] ; then
242244
# Clean out old path -- cannot use '-exec {} +' syntax here
243245
find . -type f -exec rm -f "${EROOT}/usr/${TARGET}/usr/include/{}" \;
244246
rmdir "${EROOT}/usr/${TARGET}/usr/include" >& /dev/null
@@ -251,7 +253,7 @@ switch_profile() {
251253
# Make sure proper paths get updated
252254
#
253255
local env_update_flag="--no-ldconfig"
254-
if [[ ${TARGET} == ${HOST} ]] ; then
256+
if [[ ${TARGET} == "${HOST}" ]] ; then
255257
# Delete old config now that binutils-libs installs these files.
256258
# Note: This skips ldconfig update if env.d had LDPATH, but meh.
257259
# Most people have upgraded to ld.so.conf.d, and someone else will
@@ -281,7 +283,7 @@ switch_profile() {
281283
#
282284
# Regen env.d if need/can be
283285
#
284-
if [[ ${ROOT} == "/" ]] && [[ ${TARGET} == ${HOST} ]] ; then
286+
if [[ ${ROOT} == "/" ]] && [[ ${TARGET} == "${HOST}" ]] ; then
285287
env-update ${env_update_flag}
286288
echo
287289
ewarn "Please remember to run:"
@@ -294,24 +296,24 @@ switch_profile() {
294296
}
295297

296298
uninstall_target() {
297-
: ${TARGET:=${UARG}}
299+
: "${TARGET:=${UARG}}"
298300

299-
if [[ ${TARGET} == ${HOST} ]] ; then
301+
if [[ ${TARGET} == "${HOST}" ]] ; then
300302
die "refusing to uninstall native binutils"
301303
fi
302304

303305
shopt -s nullglob
304306
PROFILE=""
305307

306-
for PROFILE in "${ENV_D}"/${TARGET}-* ; do
308+
for PROFILE in "${ENV_D}/${TARGET}-"* ; do
307309
ewarn "Removing all signs of ${PROFILE##*/}"
308-
rm -f "${ENV_D}"/${PROFILE}
310+
rm -f "${ENV_D}/${PROFILE}"
309311
done
310312
if [[ -z ${PROFILE} ]] && [[ ! -e ${ENV_D}/config-${TARGET} ]] ; then
311313
die "no profiles exist for '${TARGET}'"
312314
fi
313315

314-
rm -f "${ENV_D}"/config-${TARGET}
316+
rm -f "${ENV_D}/config-${TARGET}"
315317

316318
local x
317319
for x in \
@@ -320,17 +322,17 @@ uninstall_target() {
320322
nm objcopy objdump ranlib readelf size strings strip
321323
do
322324
x=(
323-
"${EROOT}"/usr/bin/${TARGET}-${x}
324-
"${EROOT}"/usr/{${HOST}/,}${TARGET}/bin/${x}
325-
"${EROOT}"/usr/libexec/gcc/${TARGET}/${x}
325+
"${EROOT}/usr/bin/${TARGET}-${x}"
326+
"${EROOT}/usr/"{${HOST}/,}"${TARGET}/bin/${x}"
327+
"${EROOT}/usr/libexec/gcc/${TARGET}/${x}"
326328
)
327329
rm -f "${x[@]}"
328330
done
329331
for x in "${HEADERS[@]}" ; do
330-
rm -f "${EROOT}"/usr/{${HOST}/,}${TARGET}/{usr/,}include/${x}
332+
rm -f "${EROOT}/usr/"{"${HOST}/",}"${TARGET}/"{usr/,}"include/${x}"
331333
done
332334
for x in bfd iberty opcodes ; do
333-
rm -f "${EROOT}"/usr/${HOST}/${TARGET}/lib/lib${x}{{-*,}.so,.a,.la}
335+
rm -f "${EROOT}/usr/${HOST}/${TARGET}/lib/lib${x}"{{-*,}.so,.a,.la}
334336
done
335337
# Delete broken symlinks
336338
local destdir="${EROOT}/usr/${HOST}/${TARGET}"
@@ -339,12 +341,12 @@ uninstall_target() {
339341
rmdir \
340342
"${destdir}"/{bin,include,lib,usr} \
341343
"${destdir}" \
342-
"${EROOT}"/var/db/pkg/cross-${TARGET} \
343-
"${EROOT}"/usr/{${HOST}/,}${TARGET}/bin \
344-
"${EROOT}"/usr/libexec/gcc/${TARGET} \
344+
"${EROOT}/var/db/pkg/cross-${TARGET}" \
345+
"${EROOT}/usr/"{"${HOST}/",}"${TARGET}/bin" \
346+
"${EROOT}/usr/libexec/gcc/${TARGET}" \
345347
2>/dev/null
346348

347-
rm -f "${ENV_D}"/${TARGET}-*
349+
rm -f "${ENV_D}/${TARGET}-"*
348350
}
349351

350352
set_current_profile() {
@@ -353,6 +355,7 @@ set_current_profile() {
353355
return 1
354356
fi
355357

358+
# shellcheck disable=SC1090
356359
source "${ENV_D}/config-${TARGET}"
357360

358361
if [[ -z ${CURRENT} ]] ; then
@@ -392,17 +395,19 @@ list_profiles() {
392395
[[ -f ${x} ]] || continue
393396
[[ ${x} == */config-* ]] && continue
394397

398+
# shellcheck disable=SC1090
395399
source "${x}"
396-
if [[ ${target} != ${TARGET} ]] ; then
400+
if [[ ${target} != "${TARGET}" ]] ; then
397401
[[ -n ${target} ]] && echo
398402
target=${TARGET}
399403
fi
400404

401405
x=${x##*/}
402406
if [[ -e ${ENV_D}/config-${TARGET} ]] ; then
407+
# shellcheck disable=SC1090
403408
source "${ENV_D}/config-${TARGET}"
404-
if [[ ${VER} == ${CURRENT} ]] ; then
405-
[[ ${TARGET} == ${HOST} ]] \
409+
if [[ ${VER} == "${CURRENT}" ]] ; then
410+
[[ ${TARGET} == "${HOST}" ]] \
406411
&& x="${x} ${GOOD}*${NORMAL}" \
407412
|| x="${x} ${HILITE}*${NORMAL}"
408413
fi
@@ -425,7 +430,7 @@ list_profiles() {
425430

426431
set_HOST() {
427432
# Set HOST to CHOST if it isn't already set
428-
: ${HOST:=${CHOST:-$(portageq envvar CHOST)}}
433+
: "${HOST:=${CHOST:-$(portageq envvar CHOST)}}"
429434

430435
if [[ -z ${HOST} ]] ; then
431436
eerror "Cannot determine CHOST. Something is badly broken."
@@ -499,11 +504,11 @@ switch_profile)
499504
# decode user's profile choice
500505
x=${UARG:-$(TARGET=${HOST} set_current_profile)}
501506
PROFILE=""
502-
if [[ -z $(echo ${x} | tr -d '[:digit:]') ]] ; then
507+
if [[ -z $(echo "${x}" | tr -d '[:digit:]') ]] ; then
503508
# User gave us a profile index number from '--list-profiles'
504509
i=1
505510
for y in "${ENV_D}"/* ; do
506-
[[ ${y/config-} != ${y} ]] && continue
511+
[[ ${y/config-} != "${y}" ]] && continue
507512

508513
if [[ -f ${y} ]] && [[ ${x} -eq ${i} ]] ; then
509514
PROFILE=${y##*/}
@@ -516,9 +521,9 @@ switch_profile)
516521
if [[ -z ${PROFILE} ]] ; then
517522
# User gave us "latest" or "<CTARGET>-latest".
518523
if [[ ${x} == latest ]]; then
519-
x=$(version_sorted_paths "${ENV_D}"/${HOST}-* | tail -1)
524+
x=$(version_sorted_paths "${ENV_D}/${HOST}-"* | tail -1)
520525
elif [[ ${x} == *-latest ]]; then
521-
x=$(version_sorted_paths "${ENV_D}"/${x%-latest}-* | tail -1)
526+
x=$(version_sorted_paths "${ENV_D}/${x%-latest}-"* | tail -1)
522527
fi
523528

524529
# User gave us a full <CTARGET-version>, <CTARGET> or <version>
@@ -549,6 +554,6 @@ switch_profile)
549554
;;
550555
esac
551556

552-
eval ${DOIT}
557+
eval "${DOIT}"
553558

554559
# vim:ts=4

0 commit comments

Comments
 (0)