mirror of
https://github.com/HikariKnight/quickpassthrough.git
synced 2025-05-13 14:44:45 -04:00
implement backup system
This commit is contained in:
parent
7eb7e2fa1c
commit
300ca653cc
6 changed files with 88 additions and 6 deletions
|
@ -29,4 +29,7 @@ func Set_Dracut() {
|
||||||
|
|
||||||
// Add to our kernel arguments file that vfio_pci should load early (dracut does this using kernel arguments)
|
// Add to our kernel arguments file that vfio_pci should load early (dracut does this using kernel arguments)
|
||||||
fileio.AppendContent(" rd.driver.pre=vfio_pci", config.Path.CMDLINE)
|
fileio.AppendContent(" rd.driver.pre=vfio_pci", config.Path.CMDLINE)
|
||||||
|
|
||||||
|
// Make a backup of dracutConf if there is one there
|
||||||
|
backupFile(strings.Replace(dracutConf, "config", "", 1))
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,4 +60,7 @@ func Set_Modprobe(gpu_IDs []string) {
|
||||||
content,
|
content,
|
||||||
conffile,
|
conffile,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Make a backup of dracutConf if there is one there
|
||||||
|
backupFile(strings.Replace(conffile, "config", "", 1))
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,9 @@ func InitConfigs() {
|
||||||
confpath,
|
confpath,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Make a backup directory
|
||||||
|
makeBackupDir(syspath)
|
||||||
|
|
||||||
// Create the directories for our configs
|
// Create the directories for our configs
|
||||||
err := os.MkdirAll(confpath, os.ModePerm)
|
err := os.MkdirAll(confpath, os.ModePerm)
|
||||||
errorcheck.ErrorCheck(err)
|
errorcheck.ErrorCheck(err)
|
||||||
|
@ -128,6 +131,9 @@ func InitConfigs() {
|
||||||
errorcheck.ErrorCheck(err)
|
errorcheck.ErrorCheck(err)
|
||||||
// Close the file so we can edit it
|
// Close the file so we can edit it
|
||||||
file.Close()
|
file.Close()
|
||||||
|
|
||||||
|
// Backup the sysfile if we do not have a backup
|
||||||
|
backupFile(sysfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we now have a config that exists
|
// If we now have a config that exists
|
||||||
|
@ -179,3 +185,36 @@ func vfio_modules() []string {
|
||||||
// Return the modules
|
// Return the modules
|
||||||
return modules
|
return modules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func backupFile(source string) {
|
||||||
|
// Make a destination path
|
||||||
|
dest := fmt.Sprintf("backup%s", source)
|
||||||
|
|
||||||
|
// If the file exists in the config but not on the system it is a file we make
|
||||||
|
if fileio.FileExist(fmt.Sprintf("config%s", source)) && !fileio.FileExist(source) {
|
||||||
|
// Create the blank file so that a copy of the backup folder to /etc
|
||||||
|
file, err := os.Create(dest)
|
||||||
|
errorcheck.ErrorCheck(err, "Error creating file %s", dest)
|
||||||
|
file.Close()
|
||||||
|
} else if !fileio.FileExist(dest) {
|
||||||
|
// If a backup of the file does not exist
|
||||||
|
// Write to the logger
|
||||||
|
logger.Printf("No first time backup of %s detected.\nCreating a backup at %s", source, dest)
|
||||||
|
|
||||||
|
// Copy the file
|
||||||
|
fileio.FileCopy(source, dest)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeBackupDir(dest string) {
|
||||||
|
// If a backup directory does not exist
|
||||||
|
if !fileio.FileExist("backup/") {
|
||||||
|
// Write to the logger
|
||||||
|
logger.Printf("Backup directory does not exist!\nCreating backup directory for first run backup")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the empty directories
|
||||||
|
err := os.MkdirAll(fmt.Sprintf("backup/%s", dest), os.ModePerm)
|
||||||
|
errorcheck.ErrorCheck(err, "Error making backup/ folder")
|
||||||
|
}
|
||||||
|
|
|
@ -27,9 +27,6 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
if m.focused > 0 && m.focused != DONE {
|
if m.focused > 0 && m.focused != DONE {
|
||||||
m.focused--
|
m.focused--
|
||||||
return m, nil
|
return m, nil
|
||||||
} else if m.focused == DONE {
|
|
||||||
// Since we have no QuickEmu support, skip the usb controller configuration
|
|
||||||
m.focused = VIDEO
|
|
||||||
} else {
|
} else {
|
||||||
// If we are at the beginning, just exit
|
// If we are at the beginning, just exit
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
@ -39,6 +36,10 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
// If we are done then handle keybindings a bit differently
|
// If we are done then handle keybindings a bit differently
|
||||||
// Setup keybindings for authDialog
|
// Setup keybindings for authDialog
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
|
case "ctrl+z":
|
||||||
|
// Since we have no QuickEmu support, skip the usb controller configuration
|
||||||
|
m.focused = VIDEO
|
||||||
|
|
||||||
case "ctrl+c":
|
case "ctrl+c":
|
||||||
// Exit when user presses CTRL+C
|
// Exit when user presses CTRL+C
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
|
|
@ -125,9 +125,14 @@ func (m model) View() string {
|
||||||
"* The \"quickemu\" folder contains files that might be\n useable for quickemu in the future\n",
|
"* The \"quickemu\" folder contains files that might be\n useable for quickemu in the future\n",
|
||||||
"* The files inside the \"etc\" folder must be copied to your system.\n",
|
"* The files inside the \"etc\" folder must be copied to your system.\n",
|
||||||
" NOTE: Verify that these files are correctly formated/edited!\n",
|
" NOTE: Verify that these files are correctly formated/edited!\n",
|
||||||
|
"* Once all files have been copied, you need to update your bootloader and rebuild\n",
|
||||||
|
" your initramfs using the tools to do so by your system.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"A script file named \"install.sh\" has been generated,\n",
|
"This program can do this for you, however the program will have to\n",
|
||||||
"run it to copy the files to your system and make a backup of your old files.",
|
"type your password to sudo using STDIN, to avoid using STDIN press CTRL+C\n",
|
||||||
|
"and copy the files, update your bootloader and rebuild your initramfs manually.\n",
|
||||||
|
"If you want to go back and change something, press CTRL+Z\n",
|
||||||
|
"\nNOTE: A backup of the original files from the first run can be found in the backup folder",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,17 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This just implements repetetive tasks I have to do with files
|
/*
|
||||||
|
* This just implements repetetive tasks I have to do with files
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Creates a file and appends the content to the file (ending newline must be supplied with content string)
|
||||||
func AppendContent(content string, fileName string) {
|
func AppendContent(content string, fileName string) {
|
||||||
// Open the file
|
// Open the file
|
||||||
f, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_WRONLY, os.ModePerm)
|
f, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_WRONLY, os.ModePerm)
|
||||||
|
@ -22,6 +26,7 @@ func AppendContent(content string, fileName string) {
|
||||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Error writing to %s", fileName))
|
errorcheck.ErrorCheck(err, fmt.Sprintf("Error writing to %s", fileName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reads the file and returns a stringlist with each line
|
||||||
func ReadLines(fileName string) []string {
|
func ReadLines(fileName string) []string {
|
||||||
content, err := os.Open(fileName)
|
content, err := os.Open(fileName)
|
||||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Error reading file %s", fileName))
|
errorcheck.ErrorCheck(err, fmt.Sprintf("Error reading file %s", fileName))
|
||||||
|
@ -41,6 +46,7 @@ func ReadLines(fileName string) []string {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reads a file and returns all the content as a string
|
||||||
func ReadFile(fileName string) string {
|
func ReadFile(fileName string) string {
|
||||||
// Read the whole file
|
// Read the whole file
|
||||||
content, err := os.ReadFile(fileName)
|
content, err := os.ReadFile(fileName)
|
||||||
|
@ -51,6 +57,7 @@ func ReadFile(fileName string) string {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if a file exists and returns a bool
|
||||||
func FileExist(fileName string) bool {
|
func FileExist(fileName string) bool {
|
||||||
var exist bool
|
var exist bool
|
||||||
|
|
||||||
|
@ -66,3 +73,27 @@ func FileExist(fileName string) bool {
|
||||||
// Return if the file exists
|
// Return if the file exists
|
||||||
return exist
|
return exist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copies a FILE from source to dest
|
||||||
|
func FileCopy(sourceFile, destFile string) {
|
||||||
|
// Get the file info
|
||||||
|
filestat, err := os.Stat(sourceFile)
|
||||||
|
errorcheck.ErrorCheck(err, "Error getting fileinfo of: %s", sourceFile)
|
||||||
|
|
||||||
|
// If the file is a regular file
|
||||||
|
if filestat.Mode().IsRegular() {
|
||||||
|
// Open the source file for reading
|
||||||
|
source, err := os.Open(sourceFile)
|
||||||
|
errorcheck.ErrorCheck(err, "Error opening %s for copying", sourceFile)
|
||||||
|
defer source.Close()
|
||||||
|
|
||||||
|
// Create the destination file
|
||||||
|
dest, err := os.Create(destFile)
|
||||||
|
errorcheck.ErrorCheck(err, "Error creating %s", destFile)
|
||||||
|
defer dest.Close()
|
||||||
|
|
||||||
|
// Copy the contents of source to dest using io
|
||||||
|
_, err = io.Copy(dest, source)
|
||||||
|
errorcheck.ErrorCheck(err, "Failed to copy \"%s\" to \"%s\"", sourceFile, destFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue