quickpassthrough/lib/apply_CHANGES.sh
2022-03-12 15:39:09 +01:00

82 lines
2.2 KiB
Bash
Executable file

#!/bin/bash
function make_BACKUP () {
local BACKUPDIR
BACKUPDIR="$SCRIPTDIR/backup"
if [ ! -d "$BACKUPDIR" ];
then
# Make the backup directories
mkdir -p "$BACKUPDIR/etc/initramfs-tools"
mkdir -p "$BACKUPDIR/etc/modprobe.d"
mkdir -p "$BACKUPDIR/etc/default"
# Backup system files
sudo cp -v "/etc/modules" "$BACKUPDIR/etc/modules"
sudo cp -v "/etc/initramfs-tools/modules" "$BACKUPDIR/etc/initramfs-tools/modules"
sudp cp -v "/etc/default/grub" "$BACKUPDIR/etc/default/grub"
# If a vfio.conf file exists, backup that too
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/$ETCMODULES" "/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/$ETCMODULES
$SCRIPTDIR/$INITRAMFS/modules
$SCRIPTDIR/$MODPROBE/vfio.conf
By proceeding, a backup of your system's version of these files will be placed in
$SCRIPTDIR/backup
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
case "${YESNO}" in
[Yy]*)
make_BACKUP
copy_FILES
exec "$SCRIPTDIR/lib/set_CMDLINE.sh"
;;
*)
exit 1
;;
esac
}
function main () {
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
apply_CHANGES
}
main