115 lines
2.5 KiB
Go
115 lines
2.5 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"errors"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
|
|
"git.wit.org/wit/gui"
|
|
)
|
|
|
|
func aptPackagesWindow(w *gui.Node) {
|
|
var aptoutput *gui.Node
|
|
var aptNode *gui.Node
|
|
var filename string
|
|
|
|
if w == nil {
|
|
gui.Config.Title = "apt configuration and package installer"
|
|
gui.Config.Width = 1600
|
|
gui.Config.Height = 800
|
|
gui.Config.Exit = nil
|
|
w = gui.NewWindow()
|
|
}
|
|
|
|
tab := w.AddTab("apt", nil)
|
|
// populateNEW(tab, "new")
|
|
|
|
////////////// filename /////////////////////////
|
|
gNode := tab.AddGroup("Options")
|
|
|
|
gNode.AddButton("default packages", func(*gui.Node) {
|
|
log.Println("STARTED HOSTNAME")
|
|
aptNode.SetText("bin/install-default-packages.sh")
|
|
filename = "bin/install-default-packages.sh"
|
|
b, _ := packrBox.FindString(filename)
|
|
if aptoutput != nil {
|
|
aptoutput.SetText(b)
|
|
}
|
|
log.Println("ENDED GetText() HOSTNAME =", filename)
|
|
})
|
|
|
|
gNode.CreateFontButton("fonts")
|
|
|
|
gNode.AddButton("Configure apt-file", func(*gui.Node) {
|
|
log.Println("STARTED HOSTNAME")
|
|
aptNode.SetText("bin/apt-file.sh")
|
|
filename = "bin/apt-file.sh"
|
|
b, _ := packrBox.FindString(filename)
|
|
if aptoutput != nil {
|
|
aptoutput.SetText(b)
|
|
}
|
|
log.Println("ENDED GetText() HOSTNAME =", filename)
|
|
})
|
|
|
|
var tmp []string
|
|
for i, s := range packrBox.List() {
|
|
log.Println("i, s =", i, s)
|
|
if strings.HasPrefix(s, "bin/") {
|
|
tmp = append(tmp, s)
|
|
}
|
|
}
|
|
// panic("junk")
|
|
|
|
aptNode = gNode.AddComboBox("test", tmp...)
|
|
|
|
aptNode.SetText(filename)
|
|
aptNode.OnChanged = func() {
|
|
log.Println("STARTED HOSTNAME")
|
|
filename = aptNode.GetText()
|
|
b, _ := packrBox.FindString(filename)
|
|
if aptoutput != nil {
|
|
aptoutput.SetText(b)
|
|
}
|
|
log.Println("ENDED GetText() HOSTNAME =", filename)
|
|
}
|
|
|
|
////////////// connect /////////////////////////
|
|
gNode = tab.AddGroup("")
|
|
|
|
gNode.AddButton("Run Script", func(*gui.Node) {
|
|
sudo(func() error {
|
|
log.Println("set resolv.conf to", filename)
|
|
b, _ := packrBox.FindString(filename)
|
|
// spew.Dump(b)
|
|
b = aptoutput.GetText()
|
|
|
|
log.Println("Setting /etc/resolv.conf to:\n\n" + b)
|
|
|
|
f, err := os.Create("/etc/resolv.conf")
|
|
if err != nil {
|
|
return errors.New("os.Create() /etc/resolv.conf failed")
|
|
}
|
|
defer f.Close()
|
|
w := bufio.NewWriter(f)
|
|
n4, err := w.WriteString(b)
|
|
log.Println("n4 =", n4)
|
|
w.Flush()
|
|
return nil
|
|
})
|
|
})
|
|
|
|
gui.Config.Stretchy = true
|
|
gNode.AddButton("set output", func(*gui.Node) {
|
|
if aptoutput != nil {
|
|
aptoutput.SetText("wow")
|
|
aptoutput.SetMargined(false)
|
|
}
|
|
})
|
|
|
|
gNode = tab.AddGroup("")
|
|
aptoutput = gNode.MakeGroupEdit("script:")
|
|
gui.Config.Stretchy = false
|
|
}
|