cleanup of the code and add more data to config

This commit is contained in:
HikariKnight 2023-04-08 23:40:23 +02:00
parent c3be59660d
commit ef3760879b
6 changed files with 99 additions and 10 deletions

View file

@ -0,0 +1,28 @@
package configs
import (
"github.com/HikariKnight/quickpassthrough/pkg/command"
)
func getBootloader(config *Config) {
// Check what bootloader handler we are using
// Check for grub-mkconfig
_, err := command.Run("which", "grub-mkconfig")
if err == nil {
// Mark bootloader as grub2
config.bootloader = "grub2"
}
// Check for grubby (used by fedora)
_, err = command.Run("which", "grubby")
if err == nil {
// Mark it as unknown as i do not support it yet
config.bootloader = "unknown"
}
// Check for kernelstub (used by pop os)
_, err = command.Run("which", "kernelstub")
if err == nil {
config.bootloader = "kernelstub"
}
}

View file

@ -7,6 +7,7 @@ import (
"regexp"
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
"github.com/klauspost/cpuid/v2"
)
type Path struct {
@ -19,6 +20,12 @@ type Path struct {
MKINITCPIO string
}
type Config struct {
bootloader string
cpuvendor string
path *Path
}
func GetConfigPaths() *Path {
Paths := &Path{
MODPROBE: "config/etc/modprobe.d",
@ -33,14 +40,30 @@ func GetConfigPaths() *Path {
return Paths
}
func GetConfig() *Config {
config := &Config{}
config.path = GetConfigPaths()
// Set default value for bootloader
config.bootloader = "unknown"
// Detect the bootloader we are using
getBootloader(config)
// Detect the cpu vendor
config.cpuvendor = cpuid.CPU.VendorID.String()
return config
}
func InitConfigs() {
config := GetConfigPaths()
config := GetConfig()
dirs := []string{
config.MODPROBE,
config.INITRAMFS,
config.DEFAULT,
config.DRACUT,
config.path.MODPROBE,
config.path.INITRAMFS,
config.path.DEFAULT,
config.path.DRACUT,
}
// Remove old config
@ -63,9 +86,10 @@ func InitConfigs() {
}
files := []string{
config.ETCMODULES,
config.MKINITCPIO,
fmt.Sprintf("%s/modules", config.INITRAMFS),
config.path.ETCMODULES,
config.path.MKINITCPIO,
fmt.Sprintf("%s/modules", config.path.INITRAMFS),
fmt.Sprintf("%s/grub", config.path.DEFAULT),
}
for _, conffile := range files {

View file

@ -11,8 +11,6 @@ import (
func (m *model) processSelection() {
switch m.focused {
case GPUS:
configs.InitConfigs()
// Gets the selected item
selectedItem := m.lists[m.focused].SelectedItem()
@ -58,12 +56,17 @@ func (m *model) processSelection() {
m.focused++
case VBIOS:
// This is just an OK Dialog
m.focused++
case VIDEO:
// This is a YESNO Dialog
m.focused++
case INTRO:
// This is an OK Dialog
// Create the config folder and the files related to this system
configs.InitConfigs()
m.focused++
case DONE: