Merge pull request #7 from HikariKnight/dev

big shellcheck cleanup
This commit is contained in:
HikariKnight 2022-03-13 13:00:40 +01:00 committed by GitHub
commit 3bf8857c65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 40 additions and 23 deletions

View file

@ -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]*)

View file

@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1091
function get_GPU_GROUP () {
clear

View file

@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1091,SC2024
function get_GPU_ROM () {
clear

View file

@ -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"

View file

@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC2034
MODPROBE="config/etc/modprobe.d"
INITRAMFS="config/etc/initramfs-tools"
ETCMODULES="config/etc/modules"

View file

@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1091
# Function to configure systemd-boot using kernelstub
function set_KERNELSTUB () {
@ -15,7 +16,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
@ -51,16 +52,16 @@ 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
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 +81,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 +108,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 +155,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 +181,7 @@ function set_CMDLINE () {
function main () {
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
set_CMDLINE
}

View file

@ -1,4 +1,6 @@
#!/bin/bash
# shellcheck disable=SC1091
function set_DRACUT () {
# Get the config paths
source "$SCRIPTDIR/lib/paths.sh"

View file

@ -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

View file

@ -1,4 +1,6 @@
#!/bin/bash
# shellcheck disable=SC1091
function set_MKINITCPIO () {
# Get the config paths
source "$SCRIPTDIR/lib/paths.sh"

View file

@ -1,4 +1,6 @@
#!/bin/bash
# shellcheck disable=SC1091
function set_MODPROBE () {
# Get the config paths
source "$SCRIPTDIR/lib/paths.sh"

View file

@ -1,4 +1,6 @@
#!/bin/bash
# shellcheck disable=SC1091
function set_VFIO () {
# Get the config paths
source "$SCRIPTDIR/lib/paths.sh"

View file

@ -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
@ -63,7 +64,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 +130,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

View file

@ -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 "