parent
3337efcb8f
commit
395f5ab6bc
13 changed files with 115 additions and 78 deletions
|
@ -1,5 +1,44 @@
|
|||
package common
|
||||
|
||||
const PermissionNotice = "\nPermissions error occured during file operation.\n" +
|
||||
"This could mean you initially ran QuickPassthrough as root or with sudo, but are now running it as a normal user. " +
|
||||
"Please try running QuickPassthrough as root/with sudo again."
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
"github.com/gookit/color"
|
||||
)
|
||||
|
||||
const PermissionNotice = `
|
||||
<yellowB>Permissions error occured during file operations.</>
|
||||
|
||||
<blue_b>Hint</>:
|
||||
|
||||
If you initially ran QuickPassthrough as root or using sudo,
|
||||
but are now running it as a normal user, this is expected behavior.
|
||||
|
||||
<us>Try running QuickPassthrough as root or using sudo if so.</>
|
||||
|
||||
If this does not work, double check your filesystem's permissions,
|
||||
and be sure to check the debug log for more information.`
|
||||
|
||||
// ErrorCheck serves as a wrapper for HikariKnight/ls-iommu/pkg/common.ErrorCheck that allows for visibile error messages
|
||||
func ErrorCheck(err error, msg ...string) {
|
||||
_, _ = os.Stdout.WriteString("\033[H\033[2J") // clear the screen
|
||||
oneMsg := ""
|
||||
if err != nil {
|
||||
if len(msg) < 1 {
|
||||
oneMsg = ""
|
||||
} else {
|
||||
for _, v := range msg {
|
||||
oneMsg += v + "\n"
|
||||
}
|
||||
}
|
||||
color.Printf("\n<red_b>FATAL</>: %s\n%s\nAborting", err.Error(), oneMsg)
|
||||
for i := 0; i < 10; i++ {
|
||||
time.Sleep(1 * time.Second)
|
||||
print(".")
|
||||
}
|
||||
print("\n")
|
||||
errorcheck.ErrorCheck(err, msg...)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
"github.com/klauspost/cpuid/v2"
|
||||
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/logger"
|
||||
"github.com/HikariKnight/quickpassthrough/pkg/command"
|
||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||
|
@ -82,7 +82,7 @@ func Set_KernelStub(isRoot bool) {
|
|||
kernel_args := fileio.ReadFile(config.Path.CMDLINE)
|
||||
|
||||
// Run and log, check for errors
|
||||
errorcheck.ErrorCheck(command.ExecAndLogSudo(isRoot, true,
|
||||
common.ErrorCheck(command.ExecAndLogSudo(isRoot, true,
|
||||
"kernelstub -a "+kernel_args,
|
||||
),
|
||||
"Error, kernelstub command returned exit code 1",
|
||||
|
@ -99,7 +99,7 @@ func Set_Grubby(isRoot bool) string {
|
|||
|
||||
// Run and log, check for errors
|
||||
err := command.ExecAndLogSudo(isRoot, true, "grubby --update-kernel=ALL "+fmt.Sprintf("--args=%s", kernel_args))
|
||||
errorcheck.ErrorCheck(err, "Error, grubby command returned exit code 1")
|
||||
common.ErrorCheck(err, "Error, grubby command returned exit code 1")
|
||||
|
||||
// Return what we did
|
||||
return fmt.Sprintf("Executed: sudo grubby --update-kernel=ALL --args=\"%s\"", kernel_args)
|
||||
|
@ -233,11 +233,11 @@ func Set_Grub2(isRoot bool) error {
|
|||
}
|
||||
if lpErr == nil {
|
||||
// we know mkconfig is empty despite no error;
|
||||
// so set an error for [errorcheck.ErrorCheck].
|
||||
// so set an error for [common.ErrorCheck].
|
||||
lpErr = errors.New("neither grub-mkconfig or grub2-mkconfig found")
|
||||
}
|
||||
errorcheck.ErrorCheck(lpErr, lpErr.Error()+"\n")
|
||||
return lpErr // note: unreachable as [errorcheck.ErrorCheck] calls fatal
|
||||
common.ErrorCheck(lpErr, lpErr.Error()+"\n")
|
||||
return lpErr // note: unreachable as [common.ErrorCheck] calls fatal
|
||||
default:
|
||||
}
|
||||
|
||||
|
@ -245,9 +245,9 @@ func Set_Grub2(isRoot bool) error {
|
|||
|
||||
// tabulate the output, [command.RunErrSudo] logged the execution.
|
||||
logger.Printf("\t" + strings.Join(mklog, "\n\t"))
|
||||
errorcheck.ErrorCheck(err, "Failed to update /boot/grub/grub.cfg")
|
||||
common.ErrorCheck(err, "Failed to update /boot/grub/grub.cfg")
|
||||
|
||||
// always returns nil as [errorcheck.ErrorCheck] calls fatal
|
||||
// always returns nil as [common.ErrorCheck] calls fatal
|
||||
// keeping the ret signature, as we should consider passing down errors
|
||||
// but that's a massive rabbit hole to go down for this codebase as a whole
|
||||
return err
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||
)
|
||||
|
||||
|
@ -15,7 +15,7 @@ import (
|
|||
func initramfs_readHeader(lines int, fileName string) string {
|
||||
// Open the file
|
||||
f, err := os.Open(fileName)
|
||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Error opening %s", fileName))
|
||||
common.ErrorCheck(err, fmt.Sprintf("Error opening %s", fileName))
|
||||
defer f.Close()
|
||||
|
||||
header_re := regexp.MustCompile(`^#`)
|
||||
|
@ -50,7 +50,7 @@ func initramfs_addModules(conffile string) {
|
|||
|
||||
// Open the system file for reading
|
||||
sysfile, err := os.Open(syspath)
|
||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Error opening file for reading %s", syspath))
|
||||
common.ErrorCheck(err, fmt.Sprintf("Error opening file for reading %s", syspath))
|
||||
defer sysfile.Close()
|
||||
|
||||
// Check if user has vendor-reset installed/enabled and make sure that is first
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/logger"
|
||||
)
|
||||
|
||||
|
@ -55,12 +55,12 @@ func GenerateVBIOSDumper(vbios_path string) {
|
|||
|
||||
// Make the script file
|
||||
scriptfile, err := os.Create("utils/dump_vbios.sh")
|
||||
errorcheck.ErrorCheck(err, "Cannot create file \"utils/dump_vbios.sh\"")
|
||||
common.ErrorCheck(err, "Cannot create file \"utils/dump_vbios.sh\"")
|
||||
defer scriptfile.Close()
|
||||
|
||||
// Make the script executable
|
||||
scriptfile.Chmod(0775)
|
||||
errorcheck.ErrorCheck(err, "Could not change permissions of \"utils/dump_vbios.sh\"")
|
||||
common.ErrorCheck(err, "Could not change permissions of \"utils/dump_vbios.sh\"")
|
||||
|
||||
// Write to logger
|
||||
logger.Printf("Writing utils/dump_vbios.sh\n")
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/logger"
|
||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||
)
|
||||
|
@ -26,7 +26,7 @@ func DisableVFIOVideo(i int) {
|
|||
if strings.Contains(kernel_args, "vfio_pci.disable_vga") {
|
||||
// Remove the old file
|
||||
err := os.Remove(config.Path.CMDLINE)
|
||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Could not rewrite %s", config.Path.CMDLINE))
|
||||
common.ErrorCheck(err, fmt.Sprintf("Could not rewrite %s", config.Path.CMDLINE))
|
||||
|
||||
// Enable or disable the VGA based on our given value
|
||||
if i == 0 {
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"os"
|
||||
"regexp"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
"github.com/klauspost/cpuid/v2"
|
||||
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
|
@ -83,21 +82,21 @@ func InitConfigs() {
|
|||
// Remove old config
|
||||
if err := os.RemoveAll("config"); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
errorcheck.ErrorCheck(err, common.PermissionNotice)
|
||||
common.ErrorCheck(err, common.PermissionNotice)
|
||||
return // note: unreachable due to ErrorCheck calling fatal
|
||||
}
|
||||
// won't be called if the error is ErrNotExist
|
||||
errorcheck.ErrorCheck(err, "\nError removing old config")
|
||||
common.ErrorCheck(err, "\nError removing old config")
|
||||
}
|
||||
|
||||
// Make the config folder
|
||||
if err := os.Mkdir("config", os.ModePerm); err != nil && !errors.Is(err, os.ErrExist) {
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
errorcheck.ErrorCheck(err, common.PermissionNotice)
|
||||
common.ErrorCheck(err, common.PermissionNotice)
|
||||
return // note: unreachable due to ErrorCheck calling fatal
|
||||
}
|
||||
// won't be called if the error is ErrExist
|
||||
errorcheck.ErrorCheck(err, "\nError making config folder")
|
||||
common.ErrorCheck(err, "\nError making config folder")
|
||||
}
|
||||
|
||||
// Make a regex to get the system path instead of the config path
|
||||
|
@ -113,10 +112,10 @@ func InitConfigs() {
|
|||
// If we received an error that is not ErrNotExist
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
errorcheck.ErrorCheck(err, common.PermissionNotice)
|
||||
common.ErrorCheck(err, common.PermissionNotice)
|
||||
return // note: unreachable due to ErrorCheck calling fatal
|
||||
}
|
||||
errorcheck.ErrorCheck(err, "\nError checking for directory: "+syspath)
|
||||
common.ErrorCheck(err, "\nError checking for directory: "+syspath)
|
||||
continue // note: also unreachable
|
||||
}
|
||||
|
||||
|
@ -136,10 +135,10 @@ func InitConfigs() {
|
|||
// Create the directories for our configs
|
||||
if err = os.MkdirAll(confpath, os.ModePerm); err != nil && !errors.Is(err, os.ErrExist) {
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
errorcheck.ErrorCheck(err, common.PermissionNotice)
|
||||
common.ErrorCheck(err, common.PermissionNotice)
|
||||
return // note: unreachable due to ErrorCheck calling fatal
|
||||
}
|
||||
errorcheck.ErrorCheck(err, "\nError making directory: "+confpath)
|
||||
common.ErrorCheck(err, "\nError making directory: "+confpath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -168,10 +167,10 @@ func InitConfigs() {
|
|||
// If we received an error that is not ErrNotExist
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
errorcheck.ErrorCheck(err, common.PermissionNotice)
|
||||
common.ErrorCheck(err, common.PermissionNotice)
|
||||
return // note: unreachable due to ErrorCheck calling fatal
|
||||
}
|
||||
errorcheck.ErrorCheck(err, "\nError checking for file: "+sysfile)
|
||||
common.ErrorCheck(err, "\nError checking for file: "+sysfile)
|
||||
continue // note: also unreachable
|
||||
}
|
||||
|
||||
|
@ -186,7 +185,7 @@ func InitConfigs() {
|
|||
|
||||
// Create the directories for our configs
|
||||
file, err := os.Create(conffile)
|
||||
errorcheck.ErrorCheck(err)
|
||||
common.ErrorCheck(err)
|
||||
// Close the file so we can edit it
|
||||
_ = file.Close()
|
||||
|
||||
|
@ -197,10 +196,10 @@ func InitConfigs() {
|
|||
exists, err = fileio.FileExist(conffile)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
errorcheck.ErrorCheck(err, common.PermissionNotice)
|
||||
common.ErrorCheck(err, common.PermissionNotice)
|
||||
return // note: unreachable due to ErrorCheck calling fatal
|
||||
}
|
||||
errorcheck.ErrorCheck(err, "\nError checking for file: "+conffile)
|
||||
common.ErrorCheck(err, "\nError checking for file: "+conffile)
|
||||
continue // note: also unreachable
|
||||
}
|
||||
|
||||
|
@ -269,10 +268,10 @@ func backupFile(source string) {
|
|||
for _, err := range []error{configFileError, sysFileError, destFileError} {
|
||||
if err != nil {
|
||||
if errors.Is(configFileError, os.ErrPermission) {
|
||||
errorcheck.ErrorCheck(configFileError, common.PermissionNotice)
|
||||
common.ErrorCheck(configFileError, common.PermissionNotice)
|
||||
return // note: unreachable due to ErrorCheck calling fatal
|
||||
}
|
||||
errorcheck.ErrorCheck(configFileError, "\nError checking for file: "+source)
|
||||
common.ErrorCheck(configFileError, "\nError checking for file: "+source)
|
||||
return // note: also unreachable
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +281,7 @@ func backupFile(source string) {
|
|||
case configExists && !sysExists:
|
||||
// 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\n", dest)
|
||||
common.ErrorCheck(err, "Error creating file %s\n", dest)
|
||||
_ = file.Close()
|
||||
|
||||
// If a backup of the file does not exist
|
||||
|
@ -302,10 +301,10 @@ func makeBackupDir(dest string) {
|
|||
if err != nil {
|
||||
// If we received an error that is not ErrNotExist
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
errorcheck.ErrorCheck(err, common.PermissionNotice)
|
||||
common.ErrorCheck(err, common.PermissionNotice)
|
||||
return // note: unreachable due to ErrorCheck calling fatal
|
||||
}
|
||||
errorcheck.ErrorCheck(err, "Error checking for backup/ folder")
|
||||
common.ErrorCheck(err, "Error checking for backup/ folder")
|
||||
return // note: also unreachable
|
||||
}
|
||||
|
||||
|
@ -319,10 +318,10 @@ func makeBackupDir(dest string) {
|
|||
err = nil
|
||||
}
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
errorcheck.ErrorCheck(err, common.PermissionNotice)
|
||||
common.ErrorCheck(err, common.PermissionNotice)
|
||||
return // note: unreachable due to ErrorCheck calling fatal
|
||||
}
|
||||
errorcheck.ErrorCheck(err, "Error making backup/ folder")
|
||||
common.ErrorCheck(err, "Error making backup/ folder")
|
||||
}
|
||||
|
||||
// CopyToSystem copies a file to the system.
|
||||
|
@ -334,7 +333,7 @@ func CopyToSystem(isRoot bool, conffile, sysfile string) {
|
|||
fmt.Printf("Copying: %s to %s\n", conffile, sysfile)
|
||||
|
||||
// [command.ExecAndLogSudo] will log the command's output
|
||||
errorcheck.ErrorCheck(command.ExecAndLogSudo(isRoot, false,
|
||||
common.ErrorCheck(command.ExecAndLogSudo(isRoot, false,
|
||||
fmt.Sprintf("cp -v \"%s\" %s", conffile, sysfile),
|
||||
), // if error, log and exit
|
||||
fmt.Sprintf("Failed to copy %s to %s", conffile, sysfile),
|
||||
|
@ -342,7 +341,7 @@ func CopyToSystem(isRoot bool, conffile, sysfile string) {
|
|||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// note that if we failed the error check, the following will not appear in the log!
|
||||
// this is because the [errorcheck.ErrorCheck] function will call [log.Fatalf] and exit
|
||||
// this is because the [common.ErrorCheck] function will call [log.Fatalf] and exit
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
||||
logger.Printf("Copied %s to %s\n", conffile, sysfile)
|
||||
|
|
|
@ -12,9 +12,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
"github.com/cavaliergopher/grab/v3"
|
||||
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||
"github.com/HikariKnight/quickpassthrough/pkg/untar"
|
||||
)
|
||||
|
@ -96,14 +96,14 @@ type Response struct {
|
|||
func CheckLsIOMMU() {
|
||||
// Check the API for releases
|
||||
resp, err := http.Get("https://api.github.com/repos/hikariknight/ls-iommu/releases/latest")
|
||||
errorcheck.ErrorCheck(err)
|
||||
common.ErrorCheck(err)
|
||||
|
||||
// Close the response when function ends
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Get the response body
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
errorcheck.ErrorCheck(err)
|
||||
common.ErrorCheck(err)
|
||||
|
||||
var result Response
|
||||
if err := json.Unmarshal(body, &result); err != nil {
|
||||
|
@ -114,7 +114,7 @@ func CheckLsIOMMU() {
|
|||
path := "utils"
|
||||
if exists, _ := fileio.FileExist(path); !exists {
|
||||
err := os.Mkdir(path, os.ModePerm)
|
||||
errorcheck.ErrorCheck(err)
|
||||
common.ErrorCheck(err)
|
||||
}
|
||||
|
||||
// Generate the download url
|
||||
|
@ -134,30 +134,30 @@ func CheckLsIOMMU() {
|
|||
|
||||
// Get the checksum data
|
||||
checksums, err := http.Get(checkSumsUrl)
|
||||
errorcheck.ErrorCheck(err)
|
||||
common.ErrorCheck(err)
|
||||
defer checksums.Body.Close()
|
||||
checksums_txt, err := io.ReadAll(checksums.Body)
|
||||
errorcheck.ErrorCheck(err)
|
||||
common.ErrorCheck(err)
|
||||
|
||||
// Check if the tar.gz exists
|
||||
if exists, _ := fileio.FileExist(fileName); !exists {
|
||||
downloadNewVersion(path, fileName, downloadUrl)
|
||||
if checkSum(string(checksums_txt), fileName) {
|
||||
err = untar.Untar(fmt.Sprintf("%s/", path), fileName)
|
||||
errorcheck.ErrorCheck(err)
|
||||
common.ErrorCheck(err)
|
||||
}
|
||||
} else {
|
||||
if !checkSum(string(checksums_txt), fileName) {
|
||||
downloadNewVersion(path, fileName, downloadUrl)
|
||||
err = untar.Untar(fmt.Sprintf("%s/", path), fileName)
|
||||
errorcheck.ErrorCheck(err)
|
||||
common.ErrorCheck(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkSum(checksums string, fileName string) bool {
|
||||
r, err := os.Open(fileName)
|
||||
errorcheck.ErrorCheck(err)
|
||||
common.ErrorCheck(err)
|
||||
defer r.Close()
|
||||
|
||||
hasher := sha256.New()
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
"github.com/gookit/color"
|
||||
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/configs"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/lsiommu"
|
||||
"github.com/HikariKnight/quickpassthrough/pkg/command"
|
||||
|
@ -98,7 +98,7 @@ func viewGPU(config *configs.Config, ext ...int) {
|
|||
if exists, _ := fileio.FileExist(config.Path.CMDLINE); exists {
|
||||
// Delete it as we will have to make a new one anyway
|
||||
err := os.Remove(config.Path.CMDLINE)
|
||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Could not remove %s", config.Path.CMDLINE))
|
||||
common.ErrorCheck(err, fmt.Sprintf("Could not remove %s", config.Path.CMDLINE))
|
||||
}
|
||||
|
||||
// Write initial kernel_arg file
|
||||
|
@ -118,7 +118,7 @@ func viewGPU(config *configs.Config, ext ...int) {
|
|||
if exists, _ := fileio.FileExist(config.Path.CMDLINE); exists {
|
||||
// Delete it as we will have to make a new one anyway
|
||||
err := os.Remove(config.Path.CMDLINE)
|
||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Could not remove %s", config.Path.CMDLINE))
|
||||
common.ErrorCheck(err, fmt.Sprintf("Could not remove %s", config.Path.CMDLINE))
|
||||
}
|
||||
|
||||
// Write initial kernel_arg file
|
||||
|
|
|
@ -6,9 +6,10 @@ package internal
|
|||
import (
|
||||
"os"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/pages"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/pages"
|
||||
)
|
||||
|
||||
// This is where we build everything
|
||||
|
@ -16,7 +17,7 @@ func Tui() {
|
|||
// Log all errors to a new logfile (super useful feature of BubbleTea!)
|
||||
_ = os.Rename("quickpassthrough_debug.log", "quickpassthrough_debug_old.log")
|
||||
logfile, err := tea.LogToFile("quickpassthrough_debug.log", "")
|
||||
errorcheck.ErrorCheck(err, "Error creating log file")
|
||||
common.ErrorCheck(err, "Error creating log file")
|
||||
defer logfile.Close()
|
||||
|
||||
// New WIP Tui
|
||||
|
|
|
@ -10,8 +10,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/logger"
|
||||
)
|
||||
|
||||
|
@ -85,16 +84,16 @@ func Elevate(password string) {
|
|||
|
||||
// Open STDIN
|
||||
stdin, err := cmd.StdinPipe()
|
||||
errorcheck.ErrorCheck(err, "\nFailed to get sudo STDIN")
|
||||
common.ErrorCheck(err, "\nFailed to get sudo STDIN")
|
||||
|
||||
// Start the authentication
|
||||
err = cmd.Start()
|
||||
errorcheck.ErrorCheck(err, "\nFailed to start sudo command")
|
||||
common.ErrorCheck(err, "\nFailed to start sudo command")
|
||||
|
||||
// Get the passed password
|
||||
pw, _ := base64.StdEncoding.DecodeString(password)
|
||||
_, err = stdin.Write([]byte(string(pw) + "\n"))
|
||||
errorcheck.ErrorCheck(err, "\nFailed at typing to STDIN")
|
||||
common.ErrorCheck(err, "\nFailed at typing to STDIN")
|
||||
// Clear the password
|
||||
pw = nil
|
||||
password = ""
|
||||
|
@ -103,7 +102,7 @@ func Elevate(password string) {
|
|||
|
||||
// Wait for the sudo prompt (If the correct password was given, it will not stay behind)
|
||||
err = cmd.Wait()
|
||||
errorcheck.ErrorCheck(err, "\nError, password given was wrong")
|
||||
common.ErrorCheck(err, "\nError, password given was wrong")
|
||||
}
|
||||
|
||||
// Clear clears the terminal.
|
||||
|
|
|
@ -7,8 +7,6 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
)
|
||||
|
||||
|
@ -22,18 +20,18 @@ func AppendContent(content string, fileName string) {
|
|||
// Open the file
|
||||
f, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_WRONLY, os.ModePerm)
|
||||
|
||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Error opening \"%s\" for writing", fileName))
|
||||
common.ErrorCheck(err, fmt.Sprintf("Error opening \"%s\" for writing", fileName))
|
||||
defer f.Close()
|
||||
|
||||
// Write the content
|
||||
_, err = f.WriteString(content)
|
||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Error writing to %s", fileName))
|
||||
common.ErrorCheck(err, fmt.Sprintf("Error writing to %s", fileName))
|
||||
}
|
||||
|
||||
// ReadLines reads the file and returns a stringlist with each line.
|
||||
func ReadLines(fileName string) []string {
|
||||
content, err := os.Open(fileName)
|
||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Error reading file %s", fileName))
|
||||
common.ErrorCheck(err, fmt.Sprintf("Error reading file %s", fileName))
|
||||
defer content.Close()
|
||||
|
||||
// Make a list of lines
|
||||
|
@ -55,10 +53,10 @@ func ReadFile(fileName string) string {
|
|||
// Read the whole file
|
||||
content, err := os.ReadFile(fileName)
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
errorcheck.ErrorCheck(err, common.PermissionNotice)
|
||||
common.ErrorCheck(err, common.PermissionNotice)
|
||||
return "" // note: unreachable due to ErrorCheck calling fatal
|
||||
}
|
||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Failed to ReadFile on %s", fileName))
|
||||
common.ErrorCheck(err, fmt.Sprintf("Failed to ReadFile on %s", fileName))
|
||||
|
||||
// Return all the lines as one string
|
||||
return string(content)
|
||||
|
@ -87,22 +85,22 @@ func FileExist(fileName string) (bool, error) {
|
|||
func FileCopy(sourceFile, destFile string) {
|
||||
// Get the file info
|
||||
filestat, err := os.Stat(sourceFile)
|
||||
errorcheck.ErrorCheck(err, "Error getting fileinfo of: %s", sourceFile)
|
||||
common.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)
|
||||
common.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)
|
||||
common.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)
|
||||
common.ErrorCheck(err, "Failed to copy \"%s\" to \"%s\"", sourceFile, destFile)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
"github.com/gookit/color"
|
||||
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
)
|
||||
|
||||
func ManualInput(msg string, format string) []string {
|
||||
|
@ -18,7 +19,7 @@ func ManualInput(msg string, format string) []string {
|
|||
// Get the user input
|
||||
var input string
|
||||
_, err := fmt.Scan(&input)
|
||||
errorcheck.ErrorCheck(err)
|
||||
common.ErrorCheck(err)
|
||||
|
||||
input_list := strings.Split(input, ",")
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||
"github.com/HikariKnight/quickpassthrough/internal/common"
|
||||
)
|
||||
|
||||
// Slightly modified from source: https://medium.com/@skdomino/taring-untaring-files-in-go-6b07cf56bc07
|
||||
|
@ -17,7 +17,7 @@ import (
|
|||
// creating the file structure at 'dst' along the way, and writing any files
|
||||
func Untar(dst string, fileName string) error {
|
||||
r, err := os.Open(fileName)
|
||||
errorcheck.ErrorCheck(err, fmt.Sprintf("Failed to open: %s", fileName))
|
||||
common.ErrorCheck(err, fmt.Sprintf("Failed to open: %s", fileName))
|
||||
defer r.Close()
|
||||
|
||||
gzr, err := gzip.NewReader(r)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue