12 Commits
7 changed files with 102 additions and 56 deletions
+3 -1
View File
@@ -1,3 +1,5 @@
SHELL := /bin/bash
ifeq ($(PREFIX),) ifeq ($(PREFIX),)
PREFIX := /usr/local PREFIX := /usr/local
endif endif
@@ -35,4 +37,4 @@ run: build/stormfetch
clean: clean:
rm -r build/ rm -r build/
.PHONY: build .PHONY: build
+1 -1
View File
@@ -3,7 +3,7 @@
## A simple linux fetch program written in go and bash ## A simple linux fetch program written in go and bash
### Developers: ### Developers:
- [CapCreeperGR ](https://gitlab.com/CapCreeperGR) - [EnumDev](https://gitlab.com/EnumDev)
### Project Information ### Project Information
Stormfetch is a program that can read your system's information and display it in the terminal along with the ASCII art of the Linux distribution you are running. Stormfetch is a program that can read your system's information and display it in the terminal along with the ASCII art of the Linux distribution you are running.
+29 -25
View File
@@ -7,38 +7,42 @@ echo -e "${C3}Packages: ${C4}$(get_packages)"
echo -e "${C3}Shell: ${C4}${USER_SHELL}" echo -e "${C3}Shell: ${C4}${USER_SHELL}"
echo -e "${C3}Init: ${C4}${INIT_SYSTEM}" echo -e "${C3}Init: ${C4}${INIT_SYSTEM}"
echo -e "${C3}Libc: ${C4}${LIBC}" echo -e "${C3}Libc: ${C4}${LIBC}"
if [ ! -z "$CPU_MODEL" ]; then echo -e "${C3}CPU: ${C4}${CPU_MODEL} (${CPU_THREADS} threads)"; fi [ -n "$MOTHERBOARD" ] && echo -e "${C3}Motherboard: ${C4}${MOTHERBOARD}"
for i in $(seq ${CONNECTED_GPUS}); do [ -n "$CPU_MODEL" ] && echo -e "${C3}CPU: ${C4}${CPU_MODEL} (${CPU_THREADS} threads)"
for i in $(seq "${CONNECTED_GPUS}"); do
gpu="GPU$i" gpu="GPU$i"
echo -e "${C3}GPU: ${C4}${!gpu}" echo -e "${C3}GPU: ${C4}${!gpu}"
done done
if [ ! -z "$MEM_TOTAL" ] && [ ! -z "$MEM_USED" ]; then echo -e "${C3}Memory: ${C4}${MEM_USED} MiB / ${MEM_TOTAL} MiB"; fi [ -n "$MEM_TOTAL" ] && [ -n "$MEM_USED" ] && echo -e "${C3}Memory: ${C4}${MEM_USED} MiB / ${MEM_TOTAL} MiB"
for i in $(seq ${MOUNTED_PARTITIONS}); do for i in $(seq "${MOUNTED_PARTITIONS}"); do
device="PARTITION${i}_DEVICE" mountpoint="PARTITION${i}_MOUNTPOINT"
mountpoint="PARTITION${i}_MOUNTPOINT" label="PARTITION${i}_LABEL"
label="PARTITION${i}_LABEL" type="PARTITION${i}_TYPE"
type="PARTITION${i}_TYPE" total="PARTITION${i}_TOTAL_SIZE"
total="PARTITION${i}_TOTAL_SIZE" used="PARTITION${i}_USED_SIZE"
used="PARTITION${i}_USED_SIZE" if [ -z "${!type}" ]; then
if [ -z "${!type}" ]; then if [ -z "${!label}" ]; then
if [ -z "${!label}" ]; then echo -e "${C3}Partition ${!mountpoint}: ${C4}${!used}/${!total}"
echo -e "${C3}Partition ${!mountpoint}: ${C4}${!used}/${!total}"
else
echo -e "${C3}Partition ${!label}: ${C4}${!used}/${!total}"
fi
else else
if [ -z "${!label}" ]; then echo -e "${C3}Partition ${!label}: ${C4}${!used}/${!total}"
echo -e "${C3}Partition ${!mountpoint} (${!type}): ${C4}${!used}/${!total}"
else
echo -e "${C3}Partition ${!label} (${!type}): ${C4}${!used}/${!total}"
fi
fi fi
done else
if [ ! -z "$DISPLAY_PROTOCOL" ]; then if [ -z "${!label}" ]; then
echo -e "${C3}Partition ${!mountpoint} (${!type}): ${C4}${!used}/${!total}"
else
echo -e "${C3}Partition ${!label} (${!type}): ${C4}${!used}/${!total}"
fi
fi
done
[ -n "$LOCAL_IPV4" ] && echo -e "${C3}Local IPv4 Address: ${C4}${LOCAL_IPV4}"
if [ -n "$DISPLAY_PROTOCOL" ]; then
echo -e "${C3}Display Protocol: ${C4}${DISPLAY_PROTOCOL}" echo -e "${C3}Display Protocol: ${C4}${DISPLAY_PROTOCOL}"
for i in $(seq ${CONNECTED_MONITORS}); do for i in $(seq "${CONNECTED_MONITORS}"); do
monitor="MONITOR$i" monitor="MONITOR$i"
echo -e "${C3}Screen $i: ${C4}${!monitor}" echo -e "${C3}Screen $i: ${C4}${!monitor}"
done done
fi fi
if [ ! -z "$DE_WM" ]; then echo -e "${C3}DE/WM: ${C4}${DE_WM}"; fi [ -n "$DE_WM" ] && echo -e "${C3}DE/WM: ${C4}${DE_WM}"
# Exiting with error code 0 in case the condition above returns 1
exit 0
+1
View File
@@ -10,6 +10,7 @@ require (
) )
require ( require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-ole/go-ole v1.2.6 // indirect
github.com/jackmordaunt/pcidb v1.0.1 // indirect github.com/jackmordaunt/pcidb v1.0.1 // indirect
github.com/jackmordaunt/wmi v1.2.4 // indirect github.com/jackmordaunt/wmi v1.2.4 // indirect
+2
View File
@@ -1,5 +1,7 @@
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc h1:7D+Bh06CRPCJO3gr2F7h1sriovOZ8BMhca2Rg85c2nk= github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc h1:7D+Bh06CRPCJO3gr2F7h1sriovOZ8BMhca2Rg85c2nk=
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/jackmordaunt/ghw v1.0.4 h1:as+COFuPuXaNQC3WqzoHS/E2JYWZU7gN8ompNTUxNxs= github.com/jackmordaunt/ghw v1.0.4 h1:as+COFuPuXaNQC3WqzoHS/E2JYWZU7gN8ompNTUxNxs=
+3 -1
View File
@@ -128,6 +128,7 @@ func SetupFetchEnv(showTimeTaken bool) []string {
setVariable("DISTRO_LONG_NAME", func() string { return getDistroInfo().LongName }) setVariable("DISTRO_LONG_NAME", func() string { return getDistroInfo().LongName })
setVariable("DISTRO_SHORT_NAME", func() string { return getDistroInfo().ShortName }) setVariable("DISTRO_SHORT_NAME", func() string { return getDistroInfo().ShortName })
setVariable("CPU_MODEL", func() string { return getCPUName() }) setVariable("CPU_MODEL", func() string { return getCPUName() })
setVariable("MOTHERBOARD", func() string { return getMotherboardModel() })
setVariable("CPU_THREADS", func() string { return strconv.Itoa(getCPUThreads()) }) setVariable("CPU_THREADS", func() string { return strconv.Itoa(getCPUThreads()) })
start := time.Now().UnixMilli() start := time.Now().UnixMilli()
memory := GetMemoryInfo() memory := GetMemoryInfo()
@@ -167,6 +168,7 @@ func SetupFetchEnv(showTimeTaken bool) []string {
setVariable("DISPLAY_PROTOCOL", func() string { return GetDisplayProtocol() }) setVariable("DISPLAY_PROTOCOL", func() string { return GetDisplayProtocol() })
setVariable("LIBC", func() string { return GetLibc() }) setVariable("LIBC", func() string { return GetLibc() })
setVariable("INIT_SYSTEM", func() string { return GetInitSystem() }) setVariable("INIT_SYSTEM", func() string { return GetInitSystem() })
setVariable("LOCAL_IPV4", func() string { return GetLocalIP() })
start = time.Now().UnixMilli() start = time.Now().UnixMilli()
monitors := getMonitorResolution() monitors := getMonitorResolution()
end = time.Now().UnixMilli() end = time.Now().UnixMilli()
@@ -258,7 +260,7 @@ func runStormfetch() {
} }
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { if err != nil {
log.Fatal(err) log.Fatalf("Error: Could not run fetch script: %s", err)
} }
// Print Distro Information // Print Distro Information
maxWidth := 0 maxWidth := 0
+63 -28
View File
@@ -3,13 +3,13 @@ package main
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/BurntSushi/xgb" "github.com/go-gl/glfw/v3.3/glfw"
"github.com/BurntSushi/xgb/xinerama"
"github.com/jackmordaunt/ghw" "github.com/jackmordaunt/ghw"
"github.com/mitchellh/go-ps" "github.com/mitchellh/go-ps"
"github.com/moby/sys/mountinfo" "github.com/moby/sys/mountinfo"
"log" "log"
"math" "math"
"net"
"os" "os"
"os/exec" "os/exec"
"path" "path"
@@ -73,8 +73,8 @@ func getDistroAsciiArt() string {
} }
userConfDir, err := os.UserConfigDir() userConfDir, err := os.UserConfigDir()
if err != nil { if err != nil {
if _, err := os.Stat(path.Join("/etc/stormfetch/ascii/", id)); err == nil { if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/ascii/", id)); err == nil {
bytes, err := os.ReadFile(path.Join("/etc/stormfetch/ascii/", id)) bytes, err := os.ReadFile(path.Join(systemConfigDir, "stormfetch/ascii/", id))
if err != nil { if err != nil {
return defaultAscii return defaultAscii
} }
@@ -89,8 +89,8 @@ func getDistroAsciiArt() string {
return defaultAscii return defaultAscii
} }
return string(bytes) return string(bytes)
} else if _, err := os.Stat(path.Join("/etc/stormfetch/ascii/", id)); err == nil { } else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/ascii/", id)); err == nil {
bytes, err := os.ReadFile(path.Join("/etc/stormfetch/ascii/", id)) bytes, err := os.ReadFile(path.Join(systemConfigDir, "stormfetch/ascii/", id))
if err != nil { if err != nil {
return defaultAscii return defaultAscii
} }
@@ -100,6 +100,14 @@ func getDistroAsciiArt() string {
} }
} }
func getMotherboardModel() string {
bytes, err := os.ReadFile("/sys/devices/virtual/dmi/id/board_name")
if err != nil {
return ""
}
return strings.TrimSpace(string(bytes))
}
func getCPUName() string { func getCPUName() string {
cpu, err := ghw.CPU() cpu, err := ghw.CPU()
if err != nil { if err != nil {
@@ -236,7 +244,7 @@ func GetShell() string {
func GetDEWM() string { func GetDEWM() string {
processes, err := ps.Processes() processes, err := ps.Processes()
if err != nil { if err != nil {
log.Fatal(err) log.Fatalf("Error: could not get processes: %s", err)
} }
var executables []string var executables []string
for _, process := range processes { for _, process := range processes {
@@ -265,17 +273,25 @@ func GetDEWM() string {
} else if processExists("gnome-session") { } else if processExists("gnome-session") {
return "Gnome " + runCommand("gnome-shell --version | awk '{print $3}'") return "Gnome " + runCommand("gnome-shell --version | awk '{print $3}'")
} else if processExists("xfce4-session") { } else if processExists("xfce4-session") {
return "XFCE " + runCommand("xfce4-session --version | grep xfce4-session | awk '{print $2}'") return "XFCE " + runCommand("xfce4-session --version | head -n1 | awk '{print $2}'")
} else if processExists("cinnamon") { } else if processExists("cinnamon") {
return "Cinnamon " + runCommand("cinnamon --version | awk '{print $3}'") return "Cinnamon " + runCommand("cinnamon --version | awk '{print $3}'")
} else if processExists("mate-panel") { } else if processExists("mate-panel") {
return "MATE " + runCommand("mate-about --version | awk '{print $4}'") return "MATE " + runCommand("mate-about --version | awk '{print $4}'")
} else if processExists("lxsession") { } else if processExists("lxsession") {
return "LXDE" return "LXDE"
} else if processExists("i3") {
return "i3 " + runCommand("i3 --version | awk '{print $3}'")
} else if processExists("sway") { } else if processExists("sway") {
return "Sway " + runCommand("sway --version | awk '{print $3}'") if runCommand("sway --version | awk '{print $1}'") == "swayfx" {
return "SwayFX " + runCommand("sway --version | awk '{print $3}'")
} else {
return "Sway " + runCommand("sway --version | awk '{print $3}'")
}
} else if processExists("bspwm") { } else if processExists("bspwm") {
return "Bspwm " + runCommand("bspwm -v") return "Bspwm " + runCommand("bspwm -v")
} else if processExists("Hyprland") {
return "Hyprland " + runCommand("hyprctl version | sed -n 3p | awk '{print $2}' | tr -d 'v,'")
} else if processExists("icewm-session") { } else if processExists("icewm-session") {
return "IceWM " + runCommand("icewm --version | awk '{print $2}'") return "IceWM " + runCommand("icewm --version | awk '{print $2}'")
} }
@@ -294,20 +310,16 @@ func GetDisplayProtocol() string {
func getMonitorResolution() []string { func getMonitorResolution() []string {
var monitors []string var monitors []string
if GetDisplayProtocol() == "X11" { if GetDisplayProtocol() != "" {
conn, err := xgb.NewConn() err := glfw.Init()
if err != nil { if err != nil {
return nil panic(err)
} }
err = xinerama.Init(conn) for _, monitor := range glfw.GetMonitors() {
if err != nil { mode := monitor.GetVideoMode()
return nil monitors = append(monitors, fmt.Sprintf("%dx%d %dHz", mode.Width, mode.Height, mode.RefreshRate))
}
reply, _ := xinerama.QueryScreens(conn).Reply()
conn.Close()
for _, screen := range reply.ScreenInfo {
monitors = append(monitors, strconv.Itoa(int(screen.Width))+"x"+strconv.Itoa(int(screen.Height)))
} }
defer glfw.Terminate()
} }
return monitors return monitors
} }
@@ -407,18 +419,29 @@ func GetInitSystem() string {
return strings.TrimSpace(string(out)) return strings.TrimSpace(string(out))
} }
link, err := os.Readlink("/sbin/init") process, err := ps.FindProcess(1)
if err != nil { if err != nil {
return "Unknown" return ""
} }
if path.Base(link) == "systemd" {
return "Systemd " + runCommand("systemctl --version | head -1 | awk '{print $2}'") // Special cases
} else if path.Base(link) == "openrc-init" { // OpenRC check
if _, err := os.Stat("/usr/sbin/openrc"); err == nil {
return "OpenRC " + runCommand("openrc --version | awk '{print $3}'") return "OpenRC " + runCommand("openrc --version | awk '{print $3}'")
} else if path.Base(link) == "runit-init" { }
// Default PID 1 process name checking
switch process.Executable() {
case "systemd":
return "Systemd " + runCommand("systemctl --version | head -n1 | awk '{print $2}'")
case "runit":
return "Runit" return "Runit"
} else { case "dinit":
return "Unknown" return "Dinit " + runCommand("dinit --version | head -n1 | awk '{print substr($3, 1, length($3)-1)}'")
case "enit":
return "Enit " + runCommand("enit --version | awk '{print $3}'")
default:
return process.Executable()
} }
} }
@@ -440,6 +463,18 @@ func GetLibc() string {
return "Musl " + strings.TrimSpace(string(bytes)) return "Musl " + strings.TrimSpace(string(bytes))
} }
func GetLocalIP() string {
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
return ""
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP.String()
}
func FormatBytes(bytes uint64) string { func FormatBytes(bytes uint64) string {
var suffixes [6]string var suffixes [6]string
suffixes[0] = "B" suffixes[0] = "B"