files
This commit is contained in:
parent
de91b8313e
commit
7b41b2ee83
1
.gitignore
vendored
1
.gitignore
vendored
@ -0,0 +1 @@
|
|||||||
|
./main
|
||||||
10
.idea/.gitignore
vendored
Normal file
10
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Ignored default folder with query files
|
||||||
|
/queries/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
9
.idea/awesomeProject.iml
Normal file
9
.idea/awesomeProject.iml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
10
.idea/go.imports.xml
Normal file
10
.idea/go.imports.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GoImports">
|
||||||
|
<option name="excludedPackages">
|
||||||
|
<array>
|
||||||
|
<option value="golang.org/x/net/context" />
|
||||||
|
</array>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/awesomeProject.iml" filepath="$PROJECT_DIR$/.idea/awesomeProject.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
ascii/arch.txt
Normal file
6
ascii/arch.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
_ _ _
|
||||||
|
/\ | | | | (_)
|
||||||
|
/ \ _ __ ___| |__ | | _ _ __ _ ___ __
|
||||||
|
/ /\ \ | '__/ __| '_ \ | | | | '_ \| | | \ \/ /
|
||||||
|
/ ____ \| | | (__| | | | | |____| | | | | |_| |> <
|
||||||
|
/_/ \_\_| \___|_| |_| |______|_|_| |_|\__,_/_/\_\
|
||||||
6
ascii/debian.txt
Normal file
6
ascii/debian.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
_____ _ _
|
||||||
|
| __ \ | | (_)
|
||||||
|
| | | | ___ | |__ _ __ _ _ __
|
||||||
|
| | | | / _ \ | '_ \ | | / _` | | '_ \
|
||||||
|
| |__| | | __/ | |_) | | | | (_| | | | | |
|
||||||
|
|_____/ \___| |_.__/ |_| \__,_| |_| |_|
|
||||||
6
ascii/nix.txt
Normal file
6
ascii/nix.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
_ _ _ ____ _____
|
||||||
|
| \ | (_) / __ \ / ____|
|
||||||
|
| \| |___ _| | | | (___
|
||||||
|
| . ` | \ \/ / | | |\___ \
|
||||||
|
| |\ | |> <| |__| |____) |
|
||||||
|
|_| \_|_/_/\_\\____/|_____/
|
||||||
210
main.go
Normal file
210
main.go
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
Reset = "\033[0m"
|
||||||
|
GreenBold = "\033[1;32m"
|
||||||
|
BlueBright = "\033[94m"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getDist() string {
|
||||||
|
f, _ := os.Open("/etc/os-release")
|
||||||
|
defer func(f *os.File) {
|
||||||
|
err := f.Close()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error closing file:", err)
|
||||||
|
}
|
||||||
|
}(f)
|
||||||
|
s := bufio.NewScanner(f)
|
||||||
|
var dist string
|
||||||
|
for s.Scan() {
|
||||||
|
t := s.Text()
|
||||||
|
if strings.HasPrefix(t, "PRETTY_NAME") {
|
||||||
|
distro := strings.TrimPrefix(t, "PRETTY_NAME=")
|
||||||
|
dist = strings.Trim(distro, "\"")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dist = strings.TrimSpace(dist)
|
||||||
|
return dist
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRam() string {
|
||||||
|
f, err := os.Open("/proc/meminfo")
|
||||||
|
if err != nil {
|
||||||
|
return "error"
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
var total, available int
|
||||||
|
s := bufio.NewScanner(f)
|
||||||
|
for s.Scan() {
|
||||||
|
line := s.Text()
|
||||||
|
if strings.HasPrefix(line, "MemTotal:") {
|
||||||
|
fmt.Sscanf(line, "MemTotal: %d kB", &total)
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(line, "MemAvailable:") {
|
||||||
|
fmt.Sscanf(line, "MemAvailable: %d kB", &available)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalMB := total / 1024
|
||||||
|
availableMB := available / 1024
|
||||||
|
usedMB := totalMB - availableMB
|
||||||
|
|
||||||
|
ram := fmt.Sprintf("%d / %d MiB (%d MiB available)", usedMB, totalMB, availableMB)
|
||||||
|
ram = strings.TrimSpace(ram)
|
||||||
|
return ram
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCpu() string {
|
||||||
|
f, err := os.Open("/proc/cpuinfo")
|
||||||
|
if err != nil {
|
||||||
|
return "error"
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
var cpu string
|
||||||
|
s := bufio.NewScanner(f)
|
||||||
|
for s.Scan() {
|
||||||
|
line := s.Text()
|
||||||
|
if strings.HasPrefix(line, "model name") {
|
||||||
|
parts := strings.SplitN(line, ":", 2)
|
||||||
|
if len(parts) > 1 {
|
||||||
|
cpu := strings.TrimSpace(parts[1])
|
||||||
|
return cpu
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu = fmt.Sprintf(cpu)
|
||||||
|
cpu = strings.TrimSpace(cpu)
|
||||||
|
return cpu
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGpu() string {
|
||||||
|
out, err := exec.Command("sh", "-c", "lspci | grep -E 'VGA|3D'").Output()
|
||||||
|
if err != nil {
|
||||||
|
return "Unknown GPU"
|
||||||
|
}
|
||||||
|
line := string(out)
|
||||||
|
parts := strings.Split(line, ": ")
|
||||||
|
if len(parts) > 1 {
|
||||||
|
return cleanGpuString(parts[1])
|
||||||
|
}
|
||||||
|
return "GPU not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanGpuString(raw string) string {
|
||||||
|
re := regexp.MustCompile(`\(.*\)`)
|
||||||
|
res := re.ReplaceAllString(raw, "")
|
||||||
|
res = strings.ReplaceAll(res, "Corporation", "")
|
||||||
|
res = strings.ReplaceAll(res, "[", "")
|
||||||
|
res = strings.ReplaceAll(res, "]", "")
|
||||||
|
return strings.Join(strings.Fields(res), " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getKernel() string {
|
||||||
|
out, err := exec.Command("sh", "-c", "uname -r").Output()
|
||||||
|
if err != nil {
|
||||||
|
return "Error getting kernel, how did we get there?"
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(string(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHostname() string {
|
||||||
|
hostname, err := exec.Command("sh", "-c", "uname -n").Output()
|
||||||
|
if err != nil {
|
||||||
|
return "Error getting hostname, awful"
|
||||||
|
}
|
||||||
|
username, errUser := exec.Command("sh", "-c", "whoami").Output()
|
||||||
|
if errUser != nil {
|
||||||
|
return "Error getting username, nobody here but us chickens!"
|
||||||
|
}
|
||||||
|
fullHostname := fmt.Sprintf("%s@%s", strings.TrimSpace(string(username)), strings.TrimSpace(string(hostname)))
|
||||||
|
return fullHostname
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPkgs() string {
|
||||||
|
var pkgs string
|
||||||
|
if strings.HasPrefix(getDist(), "Arch") {
|
||||||
|
out, _ := exec.Command("sh", "-c", "pacman -Qq | wc -l").Output()
|
||||||
|
pkgs = strings.TrimSpace(string(out)) + " (pacman)"
|
||||||
|
return pkgs
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(getDist(), "Debian") {
|
||||||
|
out, _ := exec.Command("sh", "-c", "dpkg -l | grep ^ii | wc -l").Output()
|
||||||
|
pkgs = strings.TrimSpace(string(out)) + " (apt)"
|
||||||
|
return pkgs
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(getDist(), "NixOS") {
|
||||||
|
out, _ := exec.Command("sh", "-c", "nix-env -qa --installed | wc -l").Output()
|
||||||
|
pkgs = strings.TrimSpace(string(out)) + " (nix)"
|
||||||
|
return pkgs
|
||||||
|
}
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAscii() string {
|
||||||
|
var ascii string
|
||||||
|
if strings.HasPrefix(getDist(), "Arch") {
|
||||||
|
content, err := os.ReadFile("ascii/arch.txt")
|
||||||
|
if err != nil {
|
||||||
|
return "no ascii, but thats arch btw\n"
|
||||||
|
}
|
||||||
|
ascii = fmt.Sprintf(string(content))
|
||||||
|
return ascii
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(getDist(), "Debian") {
|
||||||
|
content, err := os.ReadFile("ascii/debian.txt")
|
||||||
|
if err != nil {
|
||||||
|
return "no ascii, but thats necrokall\n"
|
||||||
|
}
|
||||||
|
ascii = fmt.Sprintf(string(content))
|
||||||
|
return ascii
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(getDist(), "NixOS") {
|
||||||
|
content, err := os.ReadFile("ascii/nix.txt")
|
||||||
|
if err != nil {
|
||||||
|
return "no ascii, but thats NIX POBEDA\n"
|
||||||
|
}
|
||||||
|
ascii = fmt.Sprintf(string(content))
|
||||||
|
return ascii
|
||||||
|
}
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type Info struct {
|
||||||
|
Label string
|
||||||
|
Value string
|
||||||
|
}
|
||||||
|
|
||||||
|
stats := []Info{
|
||||||
|
{"distro", getDist()},
|
||||||
|
{"packages", getPkgs()},
|
||||||
|
{"kernel", getKernel()},
|
||||||
|
{"hostname", getHostname()},
|
||||||
|
{"memory", getRam()},
|
||||||
|
{"cpu", getCpu()},
|
||||||
|
{"gpu", getGpu()},
|
||||||
|
}
|
||||||
|
fmt.Print(BlueBright)
|
||||||
|
fmt.Printf(getAscii())
|
||||||
|
fmt.Print(Reset)
|
||||||
|
fmt.Printf("\n")
|
||||||
|
fmt.Println("---------------------------")
|
||||||
|
|
||||||
|
for _, s := range stats {
|
||||||
|
fmt.Printf("> %s%s%s: %s\n", GreenBold, s.Label, Reset, s.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user