From 6e0fd90dd7b40deb7ee6d9c965e7728727b41e1c Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Sun, 13 Mar 2022 12:53:13 +0100 Subject: [PATCH] big shellcheck cleanup and disabling the shellchecks we will ignore --- lib/apply_CHANGES.sh | 3 ++- lib/get_GPU_GROUP.sh | 1 + lib/get_GPU_ROM.sh | 1 + lib/get_USB_CTL_GROUP.sh | 3 ++- lib/paths.sh | 1 + lib/set_CMDLINE.sh | 9 +++++---- lib/set_DRACUT.sh | 2 ++ lib/set_INITRAMFSTOOLS.sh | 5 +++-- lib/set_MKINITCPIO.sh | 2 ++ lib/set_MODPROBE.sh | 2 ++ lib/set_VFIO.sh | 2 ++ vfio-setup | 5 +++-- vfio-verify | 9 +++++---- 13 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh index 14f01e1..7e6f175 100755 --- a/lib/apply_CHANGES.sh +++ b/lib/apply_CHANGES.sh @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck disable=SC1091 function make_BACKUP () { local BACKUPDIR @@ -127,7 +128,7 @@ unless a backup already exist. Then the files above will be copied to your system followed by running followed by updating your initramfs and then attempt adding new kernel arguments to your bootloader." - read -p "Do you want to proceed with the installation of the files? (no=quit) [Y/n]: " YESNO + read -r -p "Do you want to proceed with the installation of the files? (no=quit) [Y/n]: " YESNO case "${YESNO}" in [Nn]*) diff --git a/lib/get_GPU_GROUP.sh b/lib/get_GPU_GROUP.sh index 208408a..57b9e6f 100755 --- a/lib/get_GPU_GROUP.sh +++ b/lib/get_GPU_GROUP.sh @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck disable=SC1091 function get_GPU_GROUP () { clear diff --git a/lib/get_GPU_ROM.sh b/lib/get_GPU_ROM.sh index 568d2af..0105559 100755 --- a/lib/get_GPU_ROM.sh +++ b/lib/get_GPU_ROM.sh @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck disable=SC1091,SC2024 function get_GPU_ROM () { clear diff --git a/lib/get_USB_CTL_GROUP.sh b/lib/get_USB_CTL_GROUP.sh index 956e9bb..54b75fb 100755 --- a/lib/get_USB_CTL_GROUP.sh +++ b/lib/get_USB_CTL_GROUP.sh @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck disable=SC1091 function get_USB_CTL_GROUP () { clear @@ -26,7 +27,7 @@ To return to the previous page just press ENTER. [Yy]*) # Get the PCI ids local PCI_ID - PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | cut -d " " -f 4 | perl -pe "s/([0-9a-f]{2}:[0-9a-f]{2}.[0-9a-f]{1})\n/\"\1\" /" | perl -pe "s/\s$//") + PCI_ID=$("$SCRIPTDIR/utils/ls-iommu" | grep -i "group $1" | cut -d " " -f 4 | perl -pe "s/([0-9a-f]{2}:[0-9a-f]{2}.[0-9a-f]{1})\n/\"\1\" /" | perl -pe "s/\s$//") # Replace the blank USB_CTL_ID with the PCI_ID for the usb controller the user wants to pass through perl -pi -e "s/USB_CTL_ID=\(\)/USB_CTL_ID=\($PCI_ID\)/" "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf" diff --git a/lib/paths.sh b/lib/paths.sh index fb632ea..efc5734 100755 --- a/lib/paths.sh +++ b/lib/paths.sh @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck disable=SC2034 MODPROBE="config/etc/modprobe.d" INITRAMFS="config/etc/initramfs-tools" ETCMODULES="config/etc/modules" diff --git a/lib/set_CMDLINE.sh b/lib/set_CMDLINE.sh index 0a3ef0b..30851a6 100755 --- a/lib/set_CMDLINE.sh +++ b/lib/set_CMDLINE.sh @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck disable=SC1091 # Function to configure systemd-boot using kernelstub function set_KERNELSTUB () { @@ -51,13 +52,13 @@ function set_GRUB () { if grep -q "GRUB_CMDLINE_LINUX_DEFAULT=" "$SCRIPTDIR/$DEFAULT/grub" ; then # Update the GRUB_CMDLINE_LINUX_DEFAULT line - GRUB_CMDLINE=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX_DEFAULT" | perl -pe "s/GRUB_CMDLINE_LINUX_DEFAULT=\"(.+)\"/\1/" | perl -pe "s/iommu=(pt|on)|amd_iommu=on|vfio_pci.ids=.+|vfio_pci.disable_vga=\d{1}//g" | perl -pe "s/(^\s+|\s+$)//g") - GRUB_CMDLINE_LINUX=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX_DEFAULT") + GRUB_CMDLINE=$(grep -P "^GRUB_CMDLINE_LINUX_DEFAULT" "/etc/default/grub" | perl -pe "s/GRUB_CMDLINE_LINUX_DEFAULT=\"(.+)\"/\1/" | perl -pe "s/iommu=(pt|on)|amd_iommu=on|vfio_pci.ids=.+|vfio_pci.disable_vga=\d{1}//g" | perl -pe "s/(^\s+|\s+$)//g") + GRUB_CMDLINE_LINUX=$(grep -P "^GRUB_CMDLINE_LINUX_DEFAULT" "/etc/default/grub") perl -pi -e "s/${GRUB_CMDLINE_LINUX}/GRUB_CMDLINE_LINUX_DEFAULT=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/$DEFAULT/grub" else # Update the GRUB_CMDLINE_LINUX line - GRUB_CMDLINE=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX" | perl -pe "s/GRUB_CMDLINE_LINUX=\"(.+)\"/\1/" | perl -pe "s/iommu=(pt|on)|amd_iommu=on|vfio_pci.ids=.+|vfio_pci.disable_vga=\d{1}//g" | perl -pe "s/(^\s+|\s+$)//g") - GRUB_CMDLINE_LINUX=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX") + GRUB_CMDLINE=$(grep -P "^GRUB_CMDLINE_LINUX" "/etc/default/grub" | perl -pe "s/GRUB_CMDLINE_LINUX=\"(.+)\"/\1/" | perl -pe "s/iommu=(pt|on)|amd_iommu=on|vfio_pci.ids=.+|vfio_pci.disable_vga=\d{1}//g" | perl -pe "s/(^\s+|\s+$)//g") + GRUB_CMDLINE_LINUX=$(grep -P "^GRUB_CMDLINE_LINUX" "/etc/default/grub") perl -pi -e "s/${GRUB_CMDLINE_LINUX}/GRUB_CMDLINE_LINUX=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/$DEFAULT/grub" fi diff --git a/lib/set_DRACUT.sh b/lib/set_DRACUT.sh index 4989f9a..4dc0270 100755 --- a/lib/set_DRACUT.sh +++ b/lib/set_DRACUT.sh @@ -1,4 +1,6 @@ #!/bin/bash +# shellcheck disable=SC1091 + function set_DRACUT () { # Get the config paths source "$SCRIPTDIR/lib/paths.sh" diff --git a/lib/set_INITRAMFSTOOLS.sh b/lib/set_INITRAMFSTOOLS.sh index 6210112..2eea550 100755 --- a/lib/set_INITRAMFSTOOLS.sh +++ b/lib/set_INITRAMFSTOOLS.sh @@ -1,12 +1,13 @@ #!/bin/bash +# shellcheck disable=SC1091 function insert_INITRAMFSTOOLS() { # Get the header and enabled modules separately from the /etc/modules file local MODULES_HEADER local MODULES_ENABLED local VENDOR_RESET - MODULES_HEADER=$(head -n $1 "$2" | grep -P "^#" | grep -v "# Added by quickpassthrough") - MODULES_ENABLED=$(cat "$2" | grep -vP "^#" | grep -v "vendor-reset") + MODULES_HEADER=$(head -n "$1" "$2" | grep -P "^#" | grep -v "# Added by quickpassthrough") + MODULES_ENABLED=$(grep -vP "^#" "$2" | grep -v "vendor-reset" | perl -pe "s/^\n//") VENDOR_RESET=0 # If vendor-reset is present diff --git a/lib/set_MKINITCPIO.sh b/lib/set_MKINITCPIO.sh index 2a584ec..34ea8b4 100755 --- a/lib/set_MKINITCPIO.sh +++ b/lib/set_MKINITCPIO.sh @@ -1,4 +1,6 @@ #!/bin/bash +# shellcheck disable=SC1091 + function set_MKINITCPIO () { # Get the config paths source "$SCRIPTDIR/lib/paths.sh" diff --git a/lib/set_MODPROBE.sh b/lib/set_MODPROBE.sh index 1c54229..6858bed 100755 --- a/lib/set_MODPROBE.sh +++ b/lib/set_MODPROBE.sh @@ -1,4 +1,6 @@ #!/bin/bash +# shellcheck disable=SC1091 + function set_MODPROBE () { # Get the config paths source "$SCRIPTDIR/lib/paths.sh" diff --git a/lib/set_VFIO.sh b/lib/set_VFIO.sh index 18da794..7960f21 100755 --- a/lib/set_VFIO.sh +++ b/lib/set_VFIO.sh @@ -1,4 +1,6 @@ #!/bin/bash +# shellcheck disable=SC1091 + function set_VFIO () { # Get the config paths source "$SCRIPTDIR/lib/paths.sh" diff --git a/vfio-setup b/vfio-setup index 7217262..272a808 100755 --- a/vfio-setup +++ b/vfio-setup @@ -1,14 +1,15 @@ #!/bin/bash +# shellcheck disable=SC1091 # Get the scripts directory SCRIPTDIR=$(dirname "$(realpath "$0")") -cd "$SCRIPTDIR" +cd "$SCRIPTDIR" || exit # Get the config paths source "$SCRIPTDIR/lib/paths.sh" # Get the CPU Vendor -CPU_VENDOR=$(cat /proc/cpuinfo | grep vendor | head -1 | cut -f 2 | cut -d " " -f 2) +CPU_VENDOR=$(grep "vendor_id" /proc/cpuinfo | head -1 | cut -f 2 | cut -d " " -f 2) CMDLINE="iommu=pt" # Adjust our kernel_args based on cpu vendor diff --git a/vfio-verify b/vfio-verify index 275d44f..2130a93 100755 --- a/vfio-verify +++ b/vfio-verify @@ -1,18 +1,19 @@ #!/bin/bash +# shellcheck disable=SC2002,SC2164 # Get the scripts directory -SCRIPTDIR=$(dirname "$(which $0)") +SCRIPTDIR=$(dirname "$(which "$0")") cd "$SCRIPTDIR" # If there is a config generated, then $SCRIPTDIR/config/kernel_args # should exist, which contains all the info we need -if [ -f $SCRIPTDIR/config/kernel_args ]; +if [ -f "$SCRIPTDIR/config/kernel_args" ]; then # Fetch part of the device id we need - DEVID=$(cat $SCRIPTDIR/config/kernel_args | cut -d " " -f 3 | cut -d "=" -f 2 | perl -pe "s/^([0-9a-f]{4}:).*/\1/") + DEVID=$(cat "$SCRIPTDIR/config/kernel_args" | cut -d " " -f 3 | cut -d "=" -f 2 | perl -pe "s/^([0-9a-f]{4}:).*/\1/") echo "#------------------------------------------#" # List info about the vfio gpu and what kernel driver is being used - lspci -d $DEVID -v | grep -iP "kernel driver|amd|radeon|nvidia|nouveau" | grep -vi "kernel modules" + lspci -d "$DEVID" -v | grep -iP "kernel driver|amd|radeon|nvidia|nouveau" | grep -vi "kernel modules" echo "#------------------------------------------#" printf "