add cmdline to config and fix fileio append

This commit is contained in:
HikariKnight 2023-04-09 16:21:27 +02:00
parent f5116648e6
commit 388ba638bd
3 changed files with 24 additions and 3 deletions

View file

@ -2,6 +2,8 @@ package configs
import ( import (
"github.com/HikariKnight/quickpassthrough/pkg/command" "github.com/HikariKnight/quickpassthrough/pkg/command"
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
"github.com/klauspost/cpuid/v2"
) )
func getBootloader(config *Config) { func getBootloader(config *Config) {
@ -26,3 +28,15 @@ func getBootloader(config *Config) {
config.bootloader = "kernelstub" 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)
}

View file

@ -12,6 +12,7 @@ import (
) )
type Path struct { type Path struct {
CMDLINE string
MODPROBE string MODPROBE string
INITRAMFS string INITRAMFS string
ETCMODULES string ETCMODULES string
@ -29,6 +30,7 @@ type Config struct {
func GetConfigPaths() *Path { func GetConfigPaths() *Path {
Paths := &Path{ Paths := &Path{
CMDLINE: "config/cmdline",
MODPROBE: "config/etc/modprobe.d", MODPROBE: "config/etc/modprobe.d",
INITRAMFS: "config/etc/initramfs-tools", INITRAMFS: "config/etc/initramfs-tools",
ETCMODULES: "config/etc/modules", ETCMODULES: "config/etc/modules",
@ -52,7 +54,7 @@ func GetConfig() *Config {
getBootloader(config) getBootloader(config)
// Detect the cpu vendor // Detect the cpu vendor
config.cpuvendor = cpuid.CPU.VendorID.String() config.cpuvendor = cpuid.CPU.VendorString
return config return config
} }
@ -71,6 +73,12 @@ func InitConfigs() {
// Remove old config // Remove old config
os.RemoveAll("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 // Make a regex to get the system path instead of the config path
syspath_re := regexp.MustCompile(`^config`) syspath_re := regexp.MustCompile(`^config`)
@ -126,7 +134,6 @@ func InitConfigs() {
// Add the modules to the config file // Add the modules to the config file
initramfs_addModules(conffile) initramfs_addModules(conffile)
} }
} }
} }
} }

View file

@ -12,7 +12,7 @@ import (
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_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)) errorcheck.ErrorCheck(err, fmt.Sprintf("Error opening \"%s\" for writing", fileName))
defer f.Close() defer f.Close()