RESOLV: finally sudo() and test ping()
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
679f11f7fa
commit
25fb41e9be
2
Makefile
2
Makefile
|
@ -40,7 +40,7 @@ gomod-init:
|
|||
gomod-clean:
|
||||
rm -f go.*
|
||||
|
||||
sudo: build
|
||||
sudo: new-build
|
||||
sudo ~/go/bin/wit-debian-gui
|
||||
|
||||
# https://golang.cafe/blog/golang-debugging-with-delve.html
|
||||
|
|
15
apt.go
15
apt.go
|
@ -1,10 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
// "log"
|
||||
|
||||
"git.wit.org/wit/gui"
|
||||
"git.wit.org/wit/shell"
|
||||
)
|
||||
|
||||
func aptGroup(tab *gui.Node) {
|
||||
|
@ -13,8 +11,17 @@ func aptGroup(tab *gui.Node) {
|
|||
n.AddButton("update apt-file", func (*gui.Node) {
|
||||
// shell.Script("apt -y install apt-file\napt-file update")
|
||||
// xterm("apt -y install apt-file; apt-file update")
|
||||
shell.Exec("apt -y install apt-file")
|
||||
shell.Exec("apt-file update")
|
||||
n.ErrorWindow("test error window", "this is the error")
|
||||
err := sudo( func() error {
|
||||
err := bash("apt install moon-buggy")
|
||||
return err
|
||||
})
|
||||
if (err != nil) {
|
||||
panic("bash failed")
|
||||
}
|
||||
err = bash("bash -x /tmp/jcarr")
|
||||
bash("apt -y install apt-file")
|
||||
bash("apt-file update")
|
||||
})
|
||||
n.AddButton("purge rc-only", func (*gui.Node) {
|
||||
xterm("dpkg -l |grep ^rc | awk '{print $2}' |xargs apt remove --purge -y")
|
||||
|
|
14
main.go
14
main.go
|
@ -33,11 +33,6 @@ var packrBox packr.Box
|
|||
func customExit(n *gui.Node) {
|
||||
origlog.Println("Should Exit Here")
|
||||
closed = true
|
||||
/*
|
||||
window := gui.Data.WindowMap["Debugging2"]
|
||||
spew.Dump(window)
|
||||
*/
|
||||
time.Sleep(3 * time.Second)
|
||||
log.Println("")
|
||||
log.Println("CLEAN EXIT")
|
||||
log.Println("")
|
||||
|
@ -55,18 +50,15 @@ func main() {
|
|||
// This directory includes the default config file if there is not already one
|
||||
packrBox = packr.NewBox("./resources")
|
||||
|
||||
filename := "ddns-tmp.conf"
|
||||
b, _ := packrBox.FindString(filename)
|
||||
log.Println(filename, "=\n\n", b)
|
||||
|
||||
// go sshClient()
|
||||
// runs the GO profiler in a goroutine
|
||||
go pprofMain()
|
||||
|
||||
// go gui.Main(dumbLoop)
|
||||
go gui.Main(initGUI)
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
gui.Queue(delayedTabs)
|
||||
go systrayMain()
|
||||
|
||||
watchWindows()
|
||||
}
|
||||
|
||||
|
|
29
os.go
29
os.go
|
@ -113,3 +113,32 @@ func packrSaveFile(packrname string, filename string) error {
|
|||
w.Flush()
|
||||
return nil
|
||||
}
|
||||
|
||||
// run something and never return from it
|
||||
// TODO: pass STDOUT, STDERR, STDIN correctly
|
||||
// TODO: figure out how to nohup the process and exit
|
||||
func bash(cmdline string) error {
|
||||
log.Println("shell.Run() START " + cmdline)
|
||||
|
||||
cmdArgs := strings.Fields(cmdline)
|
||||
|
||||
process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
|
||||
process.Stderr = os.Stderr
|
||||
process.Stdin = os.Stdin
|
||||
process.Stdout = os.Stdout
|
||||
process.Start()
|
||||
err := process.Wait()
|
||||
log.Println("shell.Exec() err =", err)
|
||||
return err
|
||||
// os.Exit(0)
|
||||
}
|
||||
|
||||
func sudo(f func() error) error {
|
||||
uid := os.Getuid()
|
||||
log.Println("You must be root to do this. uid =", uid)
|
||||
if (uid != 0) {
|
||||
return errors.New("not root")
|
||||
}
|
||||
err := f()
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -3,8 +3,12 @@ package main
|
|||
import "log"
|
||||
import "os"
|
||||
import "bufio"
|
||||
import "strings"
|
||||
import "errors"
|
||||
import "git.wit.org/wit/gui"
|
||||
|
||||
var filename string = ""
|
||||
|
||||
func resolvWindow(w *gui.Node) {
|
||||
if (w == nil) {
|
||||
gui.Config.Title = "resolv.conf Window"
|
||||
|
@ -20,38 +24,50 @@ func resolvWindow(w *gui.Node) {
|
|||
////////////// filename /////////////////////////
|
||||
gNode := tab.AddGroup("filename")
|
||||
|
||||
resolvNode := gNode.AddComboBox("resolv-1-1-1-1.conf",
|
||||
"resolv-4.2.2.2.conf",
|
||||
"resolv-8-8-8-8.conf",
|
||||
"resolv-bind.wit.org.conf",
|
||||
"resolv-ipv6-only.conf",
|
||||
"resolv-localhost.conf")
|
||||
var tmp []string
|
||||
for i, s := range packrBox.List() {
|
||||
log.Println("i, s =", i, s)
|
||||
if strings.HasPrefix(s, "resolv/") {
|
||||
tmp = append(tmp, s)
|
||||
}
|
||||
}
|
||||
// panic("junk")
|
||||
|
||||
resolvNode := gNode.AddComboBox("test", tmp...)
|
||||
|
||||
resolvNode.SetText("resolv-1-1-1-1.conf")
|
||||
resolvNode.OnChanged = func () {
|
||||
log.Println("STARTED HOSTNAME")
|
||||
filename := resolvNode.GetText()
|
||||
filename = resolvNode.GetText()
|
||||
log.Println("ENDED GetText() HOSTNAME =", filename)
|
||||
}
|
||||
|
||||
////////////// connect /////////////////////////
|
||||
gNode = tab.AddGroup("Update")
|
||||
|
||||
gNode.AddButton("/etc/resolv.conf", func (*gui.Node) {
|
||||
filename := "resolv/" + resolvNode.GetText()
|
||||
log.Println("set resolv.conf to",filename)
|
||||
b, _ := packrBox.FindString(filename)
|
||||
log.Println(filename, "=\n\n" + b)
|
||||
// spew.Dump(b)
|
||||
gNode.AddButton("Update /etc/resolv.conf", func (*gui.Node) {
|
||||
sudo( func() error {
|
||||
log.Println("set resolv.conf to",filename)
|
||||
b, _ := packrBox.FindString(filename)
|
||||
log.Println(filename, "=\n\n" + b)
|
||||
// spew.Dump(b)
|
||||
|
||||
f, err := os.Create("/etc/resolv.conf")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
w := bufio.NewWriter(f)
|
||||
n4, err := w.WriteString(b)
|
||||
log.Println("n4 =", n4)
|
||||
w.Flush()
|
||||
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
|
||||
})
|
||||
})
|
||||
gNode.AddButton("test ping ipv4", func (*gui.Node) {
|
||||
bash("ping -c 3 1.1.1.1")
|
||||
})
|
||||
gNode.AddButton("test ping ipv6", func (*gui.Node) {
|
||||
bash("ping -c 3 2001:4860:4860::6464")
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue