Compare commits

..

4 Commits

Author SHA1 Message Date
Jeff Carr 406472ecb2 move this code to go.wit.com/lib/hostname 2025-03-23 10:18:04 -05:00
Jeff Carr 3185270746 use go-cmd/cmd 2024-11-08 06:43:57 -06:00
Jeff Carr 7e1460f9f6 getDomainname()
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-11-01 21:41:46 -05:00
Jeff Carr 40e811b3b3 Init() is a better function name here 2024-02-25 18:39:27 -06:00
7 changed files with 52 additions and 12 deletions

View File

@ -1,8 +1,7 @@
all:
@echo
@echo Run: make redomod
@echo
@# ./myrepos >/tmp/myrepos.stderr 2>&1
all: goimports vet
vet:
GO111MODULE=off go vet
goimports:
goimports -w *.go
@ -13,3 +12,6 @@ redomod:
GO111MODULE= go mod init
GO111MODULE= go mod tidy
clean:
-rm -f go.*
-go-mod-clean --purge

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# linuxstatus
this is being moved to go.wit.com/lib/hostname

View File

@ -3,8 +3,11 @@
package linuxstatus
import (
"fmt"
"io/ioutil"
"strings"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
// will try to get this hosts FQDN
@ -80,6 +83,17 @@ func (ls *LinuxStatus) setHostShort() {
}
}
// getDomainName extracts the domain name from a given hostname
func getDomainName(hostname string) (string, error) {
parts := strings.Split(hostname, ".")
if len(parts) < 3 {
return "", fmt.Errorf("hostname '%s' is too short to extract a domain name", hostname)
}
// Join all parts except the first one, which is assumed to be a subdomain
domain := strings.Join(parts[1:], ".")
return domain, nil
}
func lookupHostname() {
if !me.Ready() {
return
@ -107,6 +121,27 @@ func lookupHostname() {
if hostfqdn != hostname {
log.Log(WARN, "hostname", hostname, "does not equal fqdn.FqdnHostname()", hostfqdn)
// TODO: figure out what is wrong
if dn == "(none)" {
realdn, err := getDomainName(hostfqdn)
if err == nil {
log.Log(WARN, "need to run: 'domainname", realdn, "' here")
me.changed = true
me.hostnameStatus.SetText("FIXING")
shell.Run([]string{"domainname", realdn})
return
} else {
log.Log(WARN, "getDomainName() err =", err)
log.Log(WARN, "/etc/hostname is too short. let the user set the name here.")
// me.changed = true
me.hostnameStatus.SetText("INVALID DOMAIN NAME")
// return
}
}
log.Log(WARN, "don't know what to do here with domainname")
log.Log(WARN, "check that /etc/hostname is valid?")
// me.changed = true
me.hostnameStatus.SetText("UNKNOWN")
// return
}
var test string

View File

@ -44,7 +44,7 @@ func linuxLoop() {
sort.Strings(a)
tmp := strings.Join(a, "\n")
if tmp != me.workingIPv4.String() {
log.Log(CHANGE, "realAAAA() your real IPv6 addresses changed")
log.Log(CHANGE, "realA() your real IPv6 addresses changed")
me.changed = true
me.workingIPv4.SetText(tmp)
}

2
net.go
View File

@ -101,7 +101,7 @@ func realA() []string {
return a
}
func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
func checkDNSOld() (map[string]*IPtype, map[string]*IPtype) {
var ipv4s map[string]*IPtype
var ipv6s map[string]*IPtype

6
new.go
View File

@ -2,13 +2,12 @@
package linuxstatus
import (
"go.wit.com/gui"
"go.wit.com/log"
"go.wit.com/lib/gadgets"
)
func NewLinuxStatus(parent *gui.Node) *LinuxStatus {
func InitLinuxStatus() *LinuxStatus {
if me != nil {
log.Log(WARN, "You have done New() twice. You can only do this once")
return me
@ -21,10 +20,9 @@ func NewLinuxStatus(parent *gui.Node) *LinuxStatus {
me.ipmap = make(map[string]*IPtype)
log.Log(WARN, "Creating the Window")
me.window = gadgets.NewBasicWindow(parent, "OS Hostname Details")
me.window = gadgets.RawBasicWindow("OS Hostname Details")
me.window.Make()
draw(me)
me.window.Draw()
me.ready = true
return me

View File

@ -9,7 +9,9 @@ import (
)
func (ls *LinuxStatus) Update() {
if ls == nil { return }
if ls == nil {
return
}
if !ls.Ready() {
log.Log(WARN, "can't update yet. ready is false")
log.Error(errors.New("Update() is not ready yet"))