From 417c00609ed35921f90149dea159970679344ab6 Mon Sep 17 00:00:00 2001 From: Phil Clifford Date: Sun, 13 Mar 2022 00:50:34 +0000 Subject: [PATCH 1/2] a couple of tiny bits of English/typo/white-space fixing --- lib/set_CMDLINE.sh | 14 +++++++------- vfio-setup | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/set_CMDLINE.sh b/lib/set_CMDLINE.sh index 0a3ef0b..dd355d1 100755 --- a/lib/set_CMDLINE.sh +++ b/lib/set_CMDLINE.sh @@ -15,7 +15,7 @@ function set_KERNELSTUB () { # Check if systemd-boot already has vfio parameters from before KERNELSTUB_TEST=$(sudo kernelstub -p 2>&1 | grep "Kernel Boot Options" | perl -pe "s/.+Kernel Boot Options:\..+(vfio_pci.ids=.+ ).+/\1/") - + # If there are already vfio_pci parameters in kernelstub if [[ "$KERNELSTUB_TEST" =~ vfio_pci.ids ]] ; then @@ -60,7 +60,7 @@ function set_GRUB () { GRUB_CMDLINE_LINUX=$(cat "/etc/default/grub" | grep -P "^GRUB_CMDLINE_LINUX") perl -pi -e "s/${GRUB_CMDLINE_LINUX}/GRUB_CMDLINE_LINUX=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/$DEFAULT/grub" fi - + echo "The script will now replace your default grub file with a new one. Then attempt to update grub and generate a new grub.cfg. @@ -80,7 +80,7 @@ $SCRIPTDIR/backup/etc/default/grub fi echo "" - read -r -p "Please verify there was no errors generating the grub.cfg file, then press ENTER" + read -r -p "Please verify there were no errors generating the grub.cfg file, then press ENTER" } function show_FINISH () { @@ -107,7 +107,7 @@ function show_FINISH () { " "$CMDLINE" fi - echo "Restart your system and run + echo "Restart your system and run \"$SCRIPTDIR/vfio-verify\" to check if your GPU is properly set up. @@ -154,10 +154,10 @@ https://github.com/HikariKnight/vfio-setup-docs/wiki" } function set_CMDLINE () { - # Make a variable to tell if + # Make a variable to tell if local BOOTLOADER_AUTOCONFIG BOOTLOADER_AUTOCONFIG=0 - + # If kernelstub is detected (program to manage systemd-boot) if which kernelstub > /dev/null 2>&1 ; then @@ -180,7 +180,7 @@ function set_CMDLINE () { function main () { SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//") - + set_CMDLINE } diff --git a/vfio-setup b/vfio-setup index 7217262..34e502f 100755 --- a/vfio-setup +++ b/vfio-setup @@ -63,7 +63,7 @@ This is a list of prerequisites you will be needing before starting with VFIO: if both cards share the same device id (ex: both are identified as 1022:145c), then passthrough will not be possible unless you swap out one of the cards. * A \"ghost display\" dummy plug for your second graphic card (or having it hooked to a separate input on your monitor). -* If you are planning to use the inegrated GPU on your CPU, make sure your monitor is connected to it and working/enabled before continuing. +* If you are planning to use the integrated GPU on your CPU, make sure your monitor is connected to it and working/enabled before continuing. * Preferably a motherboard verified to work with IOMMU and with good IOMMU groups. https://reddit.com/r/vfio is a good resource for this info. (If you are unsure, you will find out while using this script) @@ -129,7 +129,7 @@ then # Create the dracut folder mkdir -p "$SCRIPTDIR/$DRACUT" # Create a dracut.conf.d file - touch "$SCRIPTDIR/$DRACUT/10-vfio.conf" + touch "$SCRIPTDIR/$DRACUT/10-vfio.conf" fi # Run ls-iommu so we can verify that IOMMU properly working 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 2/2] 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 "