diff --git a/cmd/enit/main.go b/cmd/enit/main.go index ba107e0..5cdd46f 100644 --- a/cmd/enit/main.go +++ b/cmd/enit/main.go @@ -9,6 +9,7 @@ import ( "os/exec" "os/signal" "path" + "strings" "syscall" "time" ) @@ -41,6 +42,8 @@ func main() { mountVirtualFilesystems() // Mount filesystems in fstab mountFilesystems() + // Set hostname + setHostname() // Start service manager startServiceManager() @@ -168,6 +171,25 @@ func stopServiceManager() { fmt.Println("Done.") } +func setHostname() { + fmt.Print("Setting hostname... ") + + bytes, err := os.ReadFile("/etc/hostname") + if err != nil { + log.Println("Could not set hostname!") + return + } + + hostname := strings.TrimSpace(string(bytes)) + + if err := syscall.Sethostname([]byte(hostname)); err != nil { + log.Println("Could not set hostname!") + return + } + + fmt.Println("Done.") +} + func waitZombieProcesses() { for { if wpid, _ := syscall.Wait4(-1, nil, syscall.WNOHANG, nil); wpid <= 0 {