diff options
author | Viorel Munteanu <ceamac.paragon@gmail.com> | 2022-05-21 18:14:40 +0300 |
---|---|---|
committer | Sam James <sam@gentoo.org> | 2022-06-30 21:40:16 +0000 |
commit | aefd51cd66b73a46463563aa2a11410a93061b0d (patch) | |
tree | b37e5d4bd5f22697c502a39cbf2b2b1877df0edf /sys-apps/busybox | |
parent | sys-apps/busybox: Fix warning with USE -selinux (diff) | |
download | gentoo-aefd51cd66b73a46463563aa2a11410a93061b0d.tar.gz gentoo-aefd51cd66b73a46463563aa2a11410a93061b0d.tar.bz2 gentoo-aefd51cd66b73a46463563aa2a11410a93061b0d.zip |
sys-apps/busybox: fix bugs reported by shellcheck
Closes: https://bugs.gentoo.org/839171
Signed-off-by: Viorel Munteanu <ceamac.paragon@gmail.com>
Closes: https://github.com/gentoo/gentoo/pull/25062
Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'sys-apps/busybox')
-rw-r--r-- | sys-apps/busybox/files/mdev/dvbdev | 8 | ||||
-rw-r--r-- | sys-apps/busybox/files/mdev/ide_links | 20 | ||||
-rw-r--r-- | sys-apps/busybox/files/mdev/usbdev | 42 | ||||
-rw-r--r-- | sys-apps/busybox/files/mdev/usbdisk_link | 36 |
4 files changed, 55 insertions, 51 deletions
diff --git a/sys-apps/busybox/files/mdev/dvbdev b/sys-apps/busybox/files/mdev/dvbdev index f0186c176cd8..971b0efc9096 100644 --- a/sys-apps/busybox/files/mdev/dvbdev +++ b/sys-apps/busybox/files/mdev/dvbdev @@ -8,11 +8,11 @@ DVB_DEV=${MDEV#*.} case "$ACTION" in add|"") - mkdir -p dvb/adapter${N} - mv ${MDEV} dvb/adapter${N}/${DVB_DEV} + mkdir -p "dvb/adapter${N}" + mv "${MDEV}" "dvb/adapter${N}/${DVB_DEV}" ;; remove) - rm -f dvb/adapter${N}/${DVB_DEV} - rmdir dvb/adapter${N} 2>/dev/null + rm -f "dvb/adapter${N}/${DVB_DEV}" + rmdir "dvb/adapter${N}" 2>/dev/null rmdir dvb/ 2>/dev/null esac diff --git a/sys-apps/busybox/files/mdev/ide_links b/sys-apps/busybox/files/mdev/ide_links index be0c95aa9c0e..dfb7c9cb46d5 100644 --- a/sys-apps/busybox/files/mdev/ide_links +++ b/sys-apps/busybox/files/mdev/ide_links @@ -1,23 +1,23 @@ #!/bin/sh -[ -f /proc/ide/$MDEV/media ] || exit +[ -f /proc/ide/"${MDEV}"/media ] || exit -media=`cat /proc/ide/$MDEV/media` -for i in $media $media[0-9]* ; do - if [ "`readlink $i 2>/dev/null`" = $MDEV ] ; then - LINK=$i +media=$(cat /proc/ide/"${MDEV}"/media) +for i in "${media}" "${media}"[0-9]* ; do + if [ "$(readlink "$i" 2>/dev/null)" = "${MDEV}" ] ; then + LINK="$i" break fi done # link exist, remove if necessary and exit -if [ "$LINK" ] ; then - [ "$ACTION" = remove ] && rm $LINK +if [ "${LINK}" ] ; then + [ "${ACTION}" = remove ] && rm "${LINK}" exit fi # create a link -num=`ls $media[0-9]* 2>/dev/null | wc -l` -ln -sf $MDEV "$media`echo $num`" -[ -e "$media" ] || ln -sf $MDEV "$media" +num=$(ls "${media}"[0-9]* 2>/dev/null | wc -l) +ln -sf "${MDEV}" "${media}${num}" +[ -e "${media}" ] || ln -sf "${MDEV}" "${media}" diff --git a/sys-apps/busybox/files/mdev/usbdev b/sys-apps/busybox/files/mdev/usbdev index ea5b9155736c..eda3825df287 100644 --- a/sys-apps/busybox/files/mdev/usbdev +++ b/sys-apps/busybox/files/mdev/usbdev @@ -5,7 +5,7 @@ # add zeros to device or bus add_zeros () { - case "$(echo $1 | wc -L)" in + case "$(echo "$1" | wc -L)" in 1) echo "00$1" ;; 2) echo "0$1" ;; *) echo "$1" @@ -15,48 +15,48 @@ add_zeros () { # bus and device dirs in /sys -USB_PATH=$(echo $MDEV | sed -e 's/usbdev\([0-9]\).[0-9]/usb\1/') -USB_PATH=$(find /sys/devices -type d -name "$USB_PATH") -USB_DEV_DIR=$(echo $MDEV | sed -e 's/usbdev\([0-9]\).\([0-9]\)/\1-\2/') +USB_PATH=$(echo "${MDEV}" | sed -e 's/usbdev\([0-9]\).[0-9]/usb\1/') +USB_PATH=$(find /sys/devices -type d -name "${USB_PATH}") +USB_DEV_DIR=$(echo "${MDEV}" | sed -e 's/usbdev\([0-9]\).\([0-9]\)/\1-\2/') # dir names in /dev -BUS=$(add_zeros $(echo $MDEV | sed -e 's/^usbdev\([0-9]\).[0-9]/\1/')) -USB_DEV=$(add_zeros $(echo $MDEV | sed -e 's/^usbdev[0-9].\([0-9]\)/\1/')) +BUS=$(add_zeros "$(echo "${MDEV}" | sed -e 's/^usbdev\([0-9]\).[0-9]/\1/')") +USB_DEV=$(add_zeros "$(echo "${MDEV}" | sed -e 's/^usbdev[0-9].\([0-9]\)/\1/')") # try to load the proper driver for usb devices -case "$ACTION" in +case "${ACTION}" in add|"") # load usb bus driver - for i in $USB_PATH/*/modalias ; do - modprobe `cat $i` 2>/dev/null + for i in "${USB_PATH}"/*/modalias ; do + modprobe "$(cat "$i")" 2>/dev/null done # load usb device driver if existent - if [ -d $USB_PATH/$USB_DEV_DIR ]; then - for i in $USB_PATH/$USB_DEV_DIR/*/modalias ; do - modprobe `cat $i` 2>/dev/null + if [ -d "${USB_PATH}/${USB_DEV_DIR}" ]; then + for i in "${USB_PATH}/${USB_DEV_DIR}"/*/modalias ; do + modprobe "$(cat "$i")" 2>/dev/null done fi # move usb device file - mkdir -p bus/usb/$BUS - mv $MDEV bus/usb/$BUS/$USB_DEV + mkdir -p "bus/usb/${BUS}" + mv "${MDEV}" "bus/usb/${BUS}/${USB_DEV}" ;; remove) # unload device driver, if device dir is existent - if [ -d $USB_PATH/$USB_DEV_DIR ]; then - for i in $USB_PATH/$USB_DEV_DIR/*/modalias ; do - modprobe -r `cat $i` 2>/dev/null + if [ -d "${USB_PATH}/${USB_DEV_DIR}" ]; then + for i in "${USB_PATH}/${USB_DEV_DIR}"/*/modalias ; do + modprobe -r "$(cat "$i")" 2>/dev/null done fi # unload usb bus driver. Does this make sense? # what happens, if two usb devices are plugged in # and one is removed? - for i in $USB_PATH/*/modalias ; do - modprobe -r `cat $i` 2>/dev/null + for i in "${USB_PATH}"/*/modalias ; do + modprobe -r "$(cat "$i")" 2>/dev/null done # remove device file and possible empty dirs - rm -f bus/usb/$BUS/$USB_DEV - rmdir bus/usb/$BUS/ 2>/dev/null + rm -f "bus/usb/${BUS}/${USB_DEV}" + rmdir "bus/usb/${BUS}/" 2>/dev/null rmdir bus/usb/ 2>/dev/null rmdir bus/ 2>/dev/null esac diff --git a/sys-apps/busybox/files/mdev/usbdisk_link b/sys-apps/busybox/files/mdev/usbdisk_link index 6bb069243f4c..e42cc8bc9085 100644 --- a/sys-apps/busybox/files/mdev/usbdisk_link +++ b/sys-apps/busybox/files/mdev/usbdisk_link @@ -4,31 +4,35 @@ current=$(readlink usbdisk) -if [ "$current" = "$MDEV" ] && [ "$ACTION" = "remove" ]; then +if [ "${current}" = "${MDEV}" ] && [ "${ACTION}" = "remove" ]; then rm -f usbdisk usba1 fi -[ -n "$current" ] && exit +[ -n "${current}" ] && exit -if [ -e /sys/block/$MDEV ]; then - SYSDEV=$(readlink -f /sys/block/$MDEV/device) +if [ -e /sys/block/"${MDEV}" ]; then + SYSDEV=$(readlink -f /sys/block/"${MDEV}"/device) # if /sys device path contains '/usb[0-9]' then we assume its usb # also, if it's a usb without partitions we require FAT - if [ "${SYSDEV##*/usb[0-9]}" != "$SYSDEV" ]; then + if [ "${SYSDEV##*/usb[0-9]}" != "${SYSDEV}" ]; then # do not create link if there is not FAT - dd if=/dev/$MDEV bs=512 count=1 2>/dev/null | strings | grep FAT >/dev/null || exit 0 + dd if=/dev/"${MDEV}" bs=512 count=1 2>/dev/null | strings | grep FAT >/dev/null || exit 0 - ln -sf $MDEV usbdisk + ln -sf "${MDEV}" usbdisk # keep this for compat. people have it in fstab - ln -sf $MDEV usba1 + ln -sf "${MDEV}" usba1 fi -elif [ -e /sys/block/*/$MDEV ] ; then - PARENT=$(dirname /sys/block/*/$MDEV) - SYSDEV=$(readlink -f $PARENT/device) - if [ "${SYSDEV##*/usb[0-9]}" != "$SYSDEV" ]; then - ln -sf $MDEV usbdisk - # keep this for compat. people have it in fstab - ln -sf $MDEV usba1 - fi +else + for i in /sys/block/*/"${MDEV}"; do + if [ -e "$i" ]; then + PARENT=$(dirname "$i") + SYSDEV=$(readlink -f "${PARENT}"/device) + if [ "${SYSDEV##*/usb[0-9]}" != "${SYSDEV}" ]; then + ln -sf "${MDEV}" usbdisk + # keep this for compat. people have it in fstab + ln -sf "${MDEV}" usba1 + fi + fi + done fi |