From 59069d7be5342c45d161709cec4ad87473138ece Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Thu, 10 Mar 2022 16:13:33 +0100 Subject: [PATCH] Add script to copy files to the system and update initramfs --- lib/apply_CHANGES.sh | 76 ++++++++++++++++++++++++++++++++++++++++ lib/apply_changes.sh | 26 -------------- lib/get_USB_CTL_GROUP.sh | 2 +- 3 files changed, 77 insertions(+), 27 deletions(-) create mode 100644 lib/apply_CHANGES.sh delete mode 100644 lib/apply_changes.sh diff --git a/lib/apply_CHANGES.sh b/lib/apply_CHANGES.sh new file mode 100644 index 0000000..920969b --- /dev/null +++ b/lib/apply_CHANGES.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +function make_BACKUP () { + local BACKUPDIR + BACKUPDIR="$SCRIPTDIR/config/backup" + + if [ ! -d "$BACKUPDIR" ]; + then + mkdir -p "$BACKUPDIR/etc/initramfs-tools" + mkdir -p "$BACKUPDIR/etc/modprobe.d" + + sudo cp -v "/etc/modules" "$BACKUPDIR/etc/modules" + sudo cp -v "/etc/initramfs-tools/modules" "$BACKUPDIR/etc/initramfs-rools/modules" + + if [ -f "/etc/modprobe.d/vfio.conf" ]; + then + sudo cp -v "/etc/modprobe.d/vfio.conf" "$BACKUPDIR/etc/modprobe.d/vfio.conf" + fi + + echo "Backup completed!" + + else + echo "A backup already exists! +backup skipped." + fi +} + +function copy_FILES () { + echo "Starting copying files to the system!" + sudo cp -v "$SCRIPTDIR/$MODULES" "/etc/modules" + sudo cp -v "$SCRIPTDIR/$INITRAMFS/modules" "/etc/initramfs-tools/modules" + sudo cp -v "$SCRIPTDIR/$MODPROBE/vfio.conf" "/etc/modprobe.d/vfio.conf" + + echo "" + echo "Rebuilding initramfs" + sudo update-initramfs -u +} + +function apply_CHANGES () { + clear + # Get the config paths + source "$SCRIPTDIR/lib/paths.sh" + + echo "Configuration is now complete and these files have been generated for your system: +$SCRIPTDIR/$MODULES +$SCRIPTDIR/$INITRAMFS/modules +$SCRIPTDIR/$MODPROBE/vfio.conf + +By proceeding, a backup of your system's version of these files will be placed in +$SCRIPTDIR/config/backup +unless a backup already exist. + +Then the files above will be copied to your system followed by running \"update-initramfs -u\" +to build your new initrd image (all of this will require sudo permissions!)" + + read -p "Do you want to proceed with the installation of the files? [Y/n]: " YESNO + + case "${YESNO}" in + [Yy]*) + make_BACKUP + copy_FILES + exec "$SCRIPTDIR/lib/set_CMDLINE.sh" + ;; + *) + exit 1 + ;; + esac +} + + +function main () { + SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//") + apply_CHANGES +} + +main diff --git a/lib/apply_changes.sh b/lib/apply_changes.sh deleted file mode 100644 index d9c1f41..0000000 --- a/lib/apply_changes.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -function apply_CHANGES () { - clear - # Get the config paths - source "$SCRIPTDIR/lib/paths.sh" - - read -p "Do you want to proceed with the installation of the files? [y/N]: " YESNO - - case "${YESNO}" in - [Yy]*) - echo "" - ;; - *) - exit 1 - ;; - esac -} - - -function main () { - SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//") - apply_CHANGES -} - -main diff --git a/lib/get_USB_CTL_GROUP.sh b/lib/get_USB_CTL_GROUP.sh index ea7e59f..311c044 100755 --- a/lib/get_USB_CTL_GROUP.sh +++ b/lib/get_USB_CTL_GROUP.sh @@ -29,7 +29,7 @@ To return to the previous page just press ENTER. # 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" - exec "$SCRIPTDIR/lib/set_CMDLINE.sh" + exec "$SCRIPTDIR/lib/apply_CHANGES.sh" ;; *) exec "$SCRIPTDIR/lib/get_USB_CTL.sh"