From 388ba638bd1c75e3a426494b29ca2f6f6500d0ad Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Sun, 9 Apr 2023 16:21:27 +0200 Subject: [PATCH] add cmdline to config and fix fileio append --- internal/configs/config_bootloaders.go | 14 ++++++++++++++ internal/configs/configs.go | 11 +++++++++-- pkg/fileio/fileio.go | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/internal/configs/config_bootloaders.go b/internal/configs/config_bootloaders.go index 0e2b6c5..d5a1642 100644 --- a/internal/configs/config_bootloaders.go +++ b/internal/configs/config_bootloaders.go @@ -2,6 +2,8 @@ package configs import ( "github.com/HikariKnight/quickpassthrough/pkg/command" + "github.com/HikariKnight/quickpassthrough/pkg/fileio" + "github.com/klauspost/cpuid/v2" ) func getBootloader(config *Config) { @@ -26,3 +28,15 @@ func getBootloader(config *Config) { config.bootloader = "kernelstub" } } + +func set_Cmdline() { + // Get the system info + cpuinfo := cpuid.CPU + + // Get the configs + config := GetConfig() + + // Write test file + fileio.AppendContent(cpuinfo.VendorString, config.path.CMDLINE) + fileio.AppendContent(cpuinfo.VendorString, config.path.CMDLINE) +} diff --git a/internal/configs/configs.go b/internal/configs/configs.go index e874a7a..d933ece 100644 --- a/internal/configs/configs.go +++ b/internal/configs/configs.go @@ -12,6 +12,7 @@ import ( ) type Path struct { + CMDLINE string MODPROBE string INITRAMFS string ETCMODULES string @@ -29,6 +30,7 @@ type Config struct { func GetConfigPaths() *Path { Paths := &Path{ + CMDLINE: "config/cmdline", MODPROBE: "config/etc/modprobe.d", INITRAMFS: "config/etc/initramfs-tools", ETCMODULES: "config/etc/modules", @@ -52,7 +54,7 @@ func GetConfig() *Config { getBootloader(config) // Detect the cpu vendor - config.cpuvendor = cpuid.CPU.VendorID.String() + config.cpuvendor = cpuid.CPU.VendorString return config } @@ -71,6 +73,12 @@ func InitConfigs() { // Remove old config os.RemoveAll("config") + // Make the config folder + os.Mkdir("config", os.ModePerm) + + // Generate the kernel arguments + set_Cmdline() + // Make a regex to get the system path instead of the config path syspath_re := regexp.MustCompile(`^config`) @@ -126,7 +134,6 @@ func InitConfigs() { // Add the modules to the config file initramfs_addModules(conffile) } - } } } diff --git a/pkg/fileio/fileio.go b/pkg/fileio/fileio.go index 05ca533..4a24a47 100644 --- a/pkg/fileio/fileio.go +++ b/pkg/fileio/fileio.go @@ -12,7 +12,7 @@ import ( func AppendContent(content string, fileName string) { // Open the file - f, err := os.OpenFile(fileName, os.O_APPEND|os.O_WRONLY, os.ModePerm) + 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)) defer f.Close()