cleanup of the code and add more data to config
This commit is contained in:
parent
c3be59660d
commit
ef3760879b
6 changed files with 99 additions and 10 deletions
1
go.mod
1
go.mod
|
@ -9,6 +9,7 @@ require (
|
|||
github.com/charmbracelet/bubbles v0.15.0
|
||||
github.com/charmbracelet/bubbletea v0.23.2
|
||||
github.com/charmbracelet/lipgloss v0.7.1
|
||||
github.com/klauspost/cpuid/v2 v2.2.4
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
3
go.sum
3
go.sum
|
@ -21,6 +21,8 @@ github.com/charmbracelet/lipgloss v0.7.1 h1:17WMwi7N1b1rVWOjMT+rCh7sQkvDU75B2hbZ
|
|||
github.com/charmbracelet/lipgloss v0.7.1/go.mod h1:yG0k3giv8Qj8edTCbbg6AlQ5e8KNWpFujkNawKNhE2c=
|
||||
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
|
||||
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
|
||||
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
|
||||
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
|
@ -62,6 +64,7 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
||||
|
|
28
internal/configs/config_inits.go
Normal file
28
internal/configs/config_inits.go
Normal 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"
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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:
|
||||
|
|
30
pkg/command/command.go
Normal file
30
pkg/command/command.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func Run(binary string, args ...string) ([]string, error) {
|
||||
var stdout, stderr bytes.Buffer
|
||||
|
||||
// Configure the ls-iommu c--ommand
|
||||
cmd := exec.Command(binary, args...)
|
||||
cmd.Stderr = &stderr
|
||||
cmd.Stdout = &stdout
|
||||
|
||||
// Execute the command
|
||||
err := cmd.Run()
|
||||
|
||||
// Read the output
|
||||
output, _ := io.ReadAll(&stdout)
|
||||
outerr, _ := io.ReadAll(&stderr)
|
||||
|
||||
outputs := []string{}
|
||||
outputs = append(outputs, string(output))
|
||||
outputs = append(outputs, string(outerr))
|
||||
|
||||
// Return our list of items
|
||||
return outputs, err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue