Skip to content

Commit 58f57d4

Browse files
committed
src/binutils-config: fix shellcheck warnings
Signed-off-by: Allen-Kristjan Päll <[email protected]>
1 parent bf4b9fc commit 58f57d4

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
@@ -56,7 +57,7 @@ For example: ${BRACKET}i686-pc-linux-gnu-2.15.92.0.2${NORMAL}
5657
For more info, please see ${HILITE}binutils-config${NORMAL}(8).
5758
USAGE_END
5859

59-
exit ${1:-1}
60+
exit "${1:-1}"
6061
}
6162

6263
# Usage: version_sorted_paths <CHOST>
@@ -109,6 +110,7 @@ atomic_ln() {
109110

110111
setup_env() {
111112
unset TARGET VER LIBPATH
113+
# shellcheck disable=SC1090
112114
source "${ENV_D}/${PROFILE}"
113115
if [[ -z ${TARGET} ]] ; then
114116
eerror "${PROFILE} is invalid (no \$TARGET defined) :("
@@ -124,7 +126,7 @@ setup_env() {
124126
#
125127
BINPATH=""
126128
BINPATH_LINKS=""
127-
if [[ ${TARGET} != ${HOST} ]] ; then
129+
if [[ ${TARGET} != "${HOST}" ]] ; then
128130
#
129131
# Newer paths: /usr/${HOST}/${TARGET}/...
130132
# Older paths: /usr/${TARGET}/...
@@ -174,7 +176,7 @@ switch_profile() {
174176
for x in * ; do
175177
atomic_ln "${BINPATH}/${x}" "${ROOT}/${BINPATH_LINKS}" "${x}"
176178
atomic_ln "${BINPATH_LINKS}/${x}" "${EROOT}/usr/bin" "${TARGET}-${x}"
177-
if [[ ${TARGET} == ${HOST} ]] ; then
179+
if [[ ${TARGET} == "${HOST}" ]] ; then
178180
if [[ ${USE_NATIVE_LINKS} == yes ]]; then
179181
atomic_ln "${TARGET}-${x}" "${EROOT}/usr/bin" "${x}"
180182
else
@@ -205,9 +207,9 @@ switch_profile() {
205207
#
206208
# Generate library / ldscripts symlinks
207209
#
208-
: ${LIBPATH:=${EPREFIX}/usr/lib/binutils/${TARGET}/${VER}}
210+
: "${LIBPATH:=${EPREFIX}/usr/lib/binutils/${TARGET}/${VER}}"
209211
cd "${ROOT}/${LIBPATH}" || exit 1
210-
if [[ ${TARGET} == ${HOST} ]] ; then
212+
if [[ ${TARGET} == "${HOST}" ]] ; then
211213
dstlib=${EROOT}/usr/${HOST}/lib
212214
else
213215
dstlib=${EROOT}/usr/${HOST}/${TARGET}/lib
@@ -236,7 +238,7 @@ switch_profile() {
236238
INCPATH=${LIBPATH}/include
237239
if [[ -d ${ROOT}/${INCPATH} ]] ; then
238240
cd "${ROOT}/${INCPATH}" || exit 1
239-
if [[ ${HOST} != ${TARGET} ]] ; then
241+
if [[ ${HOST} != "${TARGET}" ]] ; then
240242
# Clean out old path -- cannot use '-exec {} +' syntax here
241243
find . -type f -exec rm -f "${EROOT}/usr/${TARGET}/usr/include/{}" \;
242244
rmdir "${EROOT}/usr/${TARGET}/usr/include" >& /dev/null
@@ -249,7 +251,7 @@ switch_profile() {
249251
# Make sure proper paths get updated
250252
#
251253
local env_update_flag="--no-ldconfig"
252-
if [[ ${TARGET} == ${HOST} ]] ; then
254+
if [[ ${TARGET} == "${HOST}" ]] ; then
253255
# Delete old config now that binutils-libs installs these files.
254256
# Note: This skips ldconfig update if env.d had LDPATH, but meh.
255257
# Most people have upgraded to ld.so.conf.d, and someone else will
@@ -279,7 +281,7 @@ switch_profile() {
279281
#
280282
# Regen env.d if need/can be
281283
#
282-
if [[ ${ROOT} == "/" ]] && [[ ${TARGET} == ${HOST} ]] ; then
284+
if [[ ${ROOT} == "/" ]] && [[ ${TARGET} == "${HOST}" ]] ; then
283285
env-update ${env_update_flag}
284286
echo
285287
ewarn "Please remember to run:"
@@ -292,24 +294,24 @@ switch_profile() {
292294
}
293295

294296
uninstall_target() {
295-
: ${TARGET:=${UARG}}
297+
: "${TARGET:=${UARG}}"
296298

297-
if [[ ${TARGET} == ${HOST} ]] ; then
299+
if [[ ${TARGET} == "${HOST}" ]] ; then
298300
die "refusing to uninstall native binutils"
299301
fi
300302

301303
shopt -s nullglob
302304
PROFILE=""
303305

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

312-
rm -f "${ENV_D}"/config-${TARGET}
314+
rm -f "${ENV_D}"/config-"${TARGET}"
313315

314316
local x
315317
for x in \
@@ -318,17 +320,17 @@ uninstall_target() {
318320
nm objcopy objdump ranlib readelf size strings strip
319321
do
320322
x=(
321-
"${EROOT}"/usr/bin/${TARGET}-${x}
322-
"${EROOT}"/usr/{${HOST}/,}${TARGET}/bin/${x}
323-
"${EROOT}"/usr/libexec/gcc/${TARGET}/${x}
323+
"${EROOT}"/usr/bin/"${TARGET}"-"${x}"
324+
"${EROOT}"/usr/{${HOST}/,}"${TARGET}"/bin/"${x}"
325+
"${EROOT}"/usr/libexec/gcc/"${TARGET}"/"${x}"
324326
)
325327
rm -f "${x[@]}"
326328
done
327329
for x in "${HEADERS[@]}" ; do
328-
rm -f "${EROOT}"/usr/{${HOST}/,}${TARGET}/{usr/,}include/${x}
330+
rm -f "${EROOT}"/usr/{"${HOST}"/,}"${TARGET}"/{usr/,}include/"${x}"
329331
done
330332
for x in bfd iberty opcodes ; do
331-
rm -f "${EROOT}"/usr/${HOST}/${TARGET}/lib/lib${x}{{-*,}.so,.a,.la}
333+
rm -f "${EROOT}"/usr/"${HOST}"/"${TARGET}"/lib/lib"${x}"{{-*,}.so,.a,.la}
332334
done
333335
# Delete broken symlinks
334336
local destdir="${EROOT}/usr/${HOST}/${TARGET}"
@@ -337,12 +339,12 @@ uninstall_target() {
337339
rmdir \
338340
"${destdir}"/{bin,include,lib,usr} \
339341
"${destdir}" \
340-
"${EROOT}"/var/db/pkg/cross-${TARGET} \
341-
"${EROOT}"/usr/{${HOST}/,}${TARGET}/bin \
342-
"${EROOT}"/usr/libexec/gcc/${TARGET} \
342+
"${EROOT}"/var/db/pkg/cross-"${TARGET}" \
343+
"${EROOT}"/usr/{"${HOST}"/,}"${TARGET}"/bin \
344+
"${EROOT}"/usr/libexec/gcc/"${TARGET}" \
343345
2>/dev/null
344346

345-
rm -f "${ENV_D}"/${TARGET}-*
347+
rm -f "${ENV_D}"/"${TARGET}"-*
346348
}
347349

348350
set_current_profile() {
@@ -351,6 +353,7 @@ set_current_profile() {
351353
return 1
352354
fi
353355

356+
# shellcheck disable=SC1090
354357
source "${ENV_D}/config-${TARGET}"
355358

356359
if [[ -z ${CURRENT} ]] ; then
@@ -390,17 +393,19 @@ list_profiles() {
390393
[[ -f ${x} ]] || continue
391394
[[ ${x} == */config-* ]] && continue
392395

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

399403
x=${x##*/}
400404
if [[ -e ${ENV_D}/config-${TARGET} ]] ; then
405+
# shellcheck disable=SC1090
401406
source "${ENV_D}/config-${TARGET}"
402-
if [[ ${VER} == ${CURRENT} ]] ; then
403-
[[ ${TARGET} == ${HOST} ]] \
407+
if [[ ${VER} == "${CURRENT}" ]] ; then
408+
[[ ${TARGET} == "${HOST}" ]] \
404409
&& x="${x} ${GOOD}*${NORMAL}" \
405410
|| x="${x} ${HILITE}*${NORMAL}"
406411
fi
@@ -423,7 +428,7 @@ list_profiles() {
423428

424429
set_HOST() {
425430
# Set HOST to CHOST if it isn't already set
426-
: ${HOST:=${CHOST:-$(portageq envvar CHOST)}}
431+
: "${HOST:=${CHOST:-$(portageq envvar CHOST)}}"
427432

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

506511
if [[ -f ${y} ]] && [[ ${x} -eq ${i} ]] ; then
507512
PROFILE=${y##*/}
@@ -514,9 +519,9 @@ switch_profile)
514519
if [[ -z ${PROFILE} ]] ; then
515520
# User gave us "latest" or "<CTARGET>-latest".
516521
if [[ ${x} == latest ]]; then
517-
x=$(version_sorted_paths "${ENV_D}"/${HOST}-* | tail -1)
522+
x=$(version_sorted_paths "${ENV_D}"/"${HOST}"-* | tail -1)
518523
elif [[ ${x} == *-latest ]]; then
519-
x=$(version_sorted_paths "${ENV_D}"/${x%-latest}-* | tail -1)
524+
x=$(version_sorted_paths "${ENV_D}"/"${x%-latest}"-* | tail -1)
520525
fi
521526

522527
# User gave us a full <CTARGET-version>, <CTARGET> or <version>
@@ -547,6 +552,6 @@ switch_profile)
547552
;;
548553
esac
549554

550-
eval ${DOIT}
555+
eval "${DOIT}"
551556

552557
# vim:ts=4

0 commit comments

Comments
 (0)