116 lines
2.5 KiB
Go
116 lines
2.5 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"errors"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
|
|
"go.wit.com/gui"
|
|
"go.wit.com/lib/gadgets"
|
|
)
|
|
|
|
var aptWin *gadgets.BasicWindow
|
|
|
|
func aptPackagesWindow() {
|
|
var aptoutput *gui.Node
|
|
var aptNode *gui.Node
|
|
var filename string
|
|
|
|
if aptWin != nil {
|
|
aptWin.Toggle()
|
|
return
|
|
}
|
|
aptWin = gadgets.NewBasicWindow(myGui, "apt configuration and package installer")
|
|
|
|
////////////// filename /////////////////////////
|
|
gNode := aptWin.Box().NewGroup("Options")
|
|
|
|
gNode.NewButton("default packages", func() {
|
|
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.NewButton("Configure apt-file", func() {
|
|
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.NewCombobox("test")
|
|
for _, thing := range tmp {
|
|
aptNode.AddText(thing)
|
|
}
|
|
|
|
aptNode.SetText(filename)
|
|
aptNode.Custom = 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 = aptWin.Box().NewGroup("")
|
|
|
|
gNode.NewButton("Run Script", func() {
|
|
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.NewButton("set output", func() {
|
|
if aptoutput != nil {
|
|
aptoutput.SetText("wow")
|
|
aptoutput.Margin()
|
|
}
|
|
})
|
|
|
|
gNode = aptWin.Box().NewGroup("")
|
|
// aptoutput = gNode.MakeGroupEdit("script:")
|
|
// gui.Config.Stretchy = false
|
|
}
|