7 Commits
9 changed files with 105 additions and 25 deletions
+3 -1
View File
@@ -13,7 +13,7 @@ endif
build: build:
mkdir -p build mkdir -p build
$(GO) build -ldflags "-w" -o build/stormfetch stormfetch $(GO) build -ldflags "-w -X 'main.systemConfigDir=$(SYSCONFDIR)'" -o build/stormfetch stormfetch
install: build/stormfetch config/ install: build/stormfetch config/
mkdir -p $(DESTDIR)$(BINDIR) mkdir -p $(DESTDIR)$(BINDIR)
@@ -34,3 +34,5 @@ run: build/stormfetch
clean: clean:
rm -r build/ rm -r build/
.PHONY: build
+1 -1
View File
@@ -20,7 +20,7 @@ Stormfetch is still in beta, so distro compatibility is limited. If you would li
- Download `make` from your package manager - Download `make` from your package manager
- Run the following command to compile the project - Run the following command to compile the project
``` ```
make make SYSCONFDIR=/etc
``` ```
- Run the following command to install stormfetch into your system. You may also append a DESTDIR variable at the end of this line if you wish to install in a different location - Run the following command to install stormfetch into your system. You may also append a DESTDIR variable at the end of this line if you wish to install in a different location
``` ```
+19
View File
@@ -0,0 +1,19 @@
#/2;36;72;15
${C2}:::::----:::::
${C2}::----------------::=
${C2}:-------------------::
${C1} : ${C2}:::. ..:-------:
${C1} =*=. ${C2}.:-----:
${C1} =****- ${C2}:-----:
${C1}=*****- ${C2}:::::: :-----:
${C1}=****+ ${C2}:--------: :----:
${C1}+****- ${C2}.----------. :----:
${C1}+****- ${C2}.----------. :-----
${C1}=****+ ${C2}:--------: :----:
${C1}=*****- ${C2}:::::: :-----:
${C1} =*****- ${C2}:----:
${C1} =*****+: ${C2}:-:
${C1} =*******=:: ::=-. ${C2}.
${C1} ==*******************-
${C1} ===****************=-
${C1} ===+=****++===
+2
View File
@@ -3,3 +3,5 @@ fetch_script: auto
ansii_colors: [] ansii_colors: []
force_config_ansii: false force_config_ansii: false
dependency_warning: true dependency_warning: true
show_fs_type: true
hidden_gpus: []
+16 -4
View File
@@ -6,18 +6,30 @@ echo -e "${C3}Kernel: ${C4}$(uname -s) $(uname -r)"
echo -e "${C3}Packages: ${C4}$(get_packages)" echo -e "${C3}Packages: ${C4}$(get_packages)"
echo -e "${C3}Shell: ${C4}${USER_SHELL}" echo -e "${C3}Shell: ${C4}${USER_SHELL}"
if [ ! -z "$CPU_MODEL" ]; then echo -e "${C3}CPU: ${C4}${CPU_MODEL} (${CPU_THREADS} threads)"; fi if [ ! -z "$CPU_MODEL" ]; then echo -e "${C3}CPU: ${C4}${CPU_MODEL} (${CPU_THREADS} threads)"; fi
if [ ! -z "$GPU_MODEL" ]; then echo -e "${C3}GPU: ${C4}${GPU_MODEL}"; fi for i in $(seq ${CONNECTED_GPUS}); do
gpu="GPU$i"
echo -e "${C3}GPU: ${C4}${!gpu}"
done
if [ ! -z "$MEM_TOTAL" ] && [ ! -z "$MEM_USED" ]; then echo -e "${C3}Memory: ${C4}${MEM_USED} MiB / ${MEM_TOTAL} MiB"; fi if [ ! -z "$MEM_TOTAL" ] && [ ! -z "$MEM_USED" ]; then echo -e "${C3}Memory: ${C4}${MEM_USED} MiB / ${MEM_TOTAL} MiB"; fi
for i in $(seq ${MOUNTED_PARTITIONS}); do for i in $(seq ${MOUNTED_PARTITIONS}); do
device="PARTITION${i}_DEVICE" device="PARTITION${i}_DEVICE"
mountpoint="PARTITION${i}_MOUNTPOINT" mountpoint="PARTITION${i}_MOUNTPOINT"
label="PARTITION${i}_LABEL" label="PARTITION${i}_LABEL"
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 "${!label}" ]; then if [ -z "${!type}" ]; then
echo -e "${C3}Partition ${!mountpoint}: ${C4}${!used}/${!total}" if [ -z "${!label}" ]; then
echo -e "${C3}Partition ${!mountpoint}: ${C4}${!used}/${!total}"
else
echo -e "${C3}Partition ${!label}: ${C4}${!used}/${!total}"
fi
else else
echo -e "${C3}Partition ${!label}: ${C4}${!used}/${!total}" 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 fi
done done
if [ ! -z "$DISPLAY_PROTOCOL" ]; then if [ ! -z "$DISPLAY_PROTOCOL" ]; then
+5 -2
View File
@@ -20,11 +20,14 @@ get_packages() {
if command_exists rpm; then if command_exists rpm; then
ARRAY+=("$(rpm -qa | wc -l) (rpm)") ARRAY+=("$(rpm -qa | wc -l) (rpm)")
fi fi
if command_exists xbps-query; then
ARRAY+=("$(xbps-query -l | wc -l) (xbps)")
fi
if command_exists bpm; then if command_exists bpm; then
ARRAY+=("$(bpm list -n) (bpm)") ARRAY+=("$(bpm list -c) (bpm)")
fi fi
if command_exists emerge; then if command_exists emerge; then
ARRAY+=("$(ls -l /var/db/pkg/ | wc -l) (emerge)") ARRAY+=("$(ls -l /var/db/pkg/* | wc -l) (emerge)")
fi fi
if command_exists flatpak; then if command_exists flatpak; then
ARRAY+=("$(flatpak list | wc -l) (flatpak)") ARRAY+=("$(flatpak list | wc -l) (flatpak)")
+27 -11
View File
@@ -13,6 +13,8 @@ import (
"strings" "strings"
) )
var systemConfigDir = "/etc/"
var configPath = "" var configPath = ""
var fetchScriptPath = "" var fetchScriptPath = ""
@@ -22,6 +24,8 @@ var config = StormfetchConfig{
AnsiiColors: make([]int, 0), AnsiiColors: make([]int, 0),
ForceConfigAnsii: false, ForceConfigAnsii: false,
DependencyWarning: true, DependencyWarning: true,
ShowFSType: false,
HiddenGPUS: make([]int, 0),
} }
type StormfetchConfig struct { type StormfetchConfig struct {
@@ -31,6 +35,8 @@ type StormfetchConfig struct {
AnsiiColors []int `yaml:"ansii_colors"` AnsiiColors []int `yaml:"ansii_colors"`
ForceConfigAnsii bool `yaml:"force_config_ansii"` ForceConfigAnsii bool `yaml:"force_config_ansii"`
DependencyWarning bool `yaml:"dependency_warning"` DependencyWarning bool `yaml:"dependency_warning"`
ShowFSType bool `yaml:"show_fs_type"`
HiddenGPUS []int `yaml:"hidden_gpus"`
} }
func main() { func main() {
@@ -42,12 +48,12 @@ func main() {
func readConfig() { func readConfig() {
// Get home directory // Get home directory
configDir, _ := os.UserConfigDir() userConfigDir, _ := os.UserConfigDir()
// Find valid config directory // Find valid config directory
if _, err := os.Stat(path.Join(configDir, "stormfetch/config.yaml")); err == nil { if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/config.yaml")); err == nil {
configPath = path.Join(configDir, "stormfetch/config.yaml") configPath = path.Join(userConfigDir, "stormfetch/config.yaml")
} else if _, err := os.Stat("/etc/stormfetch/config.yaml"); err == nil { } else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/config.yaml")); err == nil {
configPath = "/etc/stormfetch/config.yaml" configPath = path.Join(systemConfigDir, "stormfetch/config.yaml")
} else { } else {
log.Fatalf("Config file not found: %s", err.Error()) log.Fatalf("Config file not found: %s", err.Error())
} }
@@ -70,10 +76,10 @@ func readConfig() {
log.Fatalf("Fetch script path points to a directory") log.Fatalf("Fetch script path points to a directory")
} }
} }
if _, err := os.Stat(path.Join(configDir, "stormfetch/fetch_script.sh")); err == nil { if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/fetch_script.sh")); err == nil {
fetchScriptPath = path.Join(configDir, "stormfetch/fetch_script.sh") fetchScriptPath = path.Join(userConfigDir, "stormfetch/fetch_script.sh")
} else if _, err := os.Stat("/etc/stormfetch/fetch_script.sh"); err == nil { } else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/fetch_script.sh")); err == nil {
fetchScriptPath = "/etc/stormfetch/fetch_script.sh" fetchScriptPath = path.Join(systemConfigDir, "stormfetch/fetch_script.sh")
} else { } else {
log.Fatalf("Fetch script file not found: %s", err.Error()) log.Fatalf("Fetch script file not found: %s", err.Error())
} }
@@ -126,6 +132,9 @@ func SetupFetchEnv() []string {
if part.Label != "" { if part.Label != "" {
env["PARTITION"+strconv.Itoa(i+1)+"_LABEL"] = part.Label env["PARTITION"+strconv.Itoa(i+1)+"_LABEL"] = part.Label
} }
if part.Type != "" && config.ShowFSType {
env["PARTITION"+strconv.Itoa(i+1)+"_TYPE"] = part.Type
}
env["PARTITION"+strconv.Itoa(i+1)+"_TOTAL_SIZE"] = FormatBytes(part.TotalSize) env["PARTITION"+strconv.Itoa(i+1)+"_TOTAL_SIZE"] = FormatBytes(part.TotalSize)
env["PARTITION"+strconv.Itoa(i+1)+"_USED_SIZE"] = FormatBytes(part.UsedSize) env["PARTITION"+strconv.Itoa(i+1)+"_USED_SIZE"] = FormatBytes(part.UsedSize)
env["PARTITION"+strconv.Itoa(i+1)+"_FREE_SIZE"] = FormatBytes(part.FreeSize) env["PARTITION"+strconv.Itoa(i+1)+"_FREE_SIZE"] = FormatBytes(part.FreeSize)
@@ -141,8 +150,15 @@ func SetupFetchEnv() []string {
env["MONITOR"+strconv.Itoa(i+1)] = monitor env["MONITOR"+strconv.Itoa(i+1)] = monitor
} }
} }
if getGPUName() != "" { gpus := getGPUNames()
env["GPU_MODEL"] = getGPUName() if len(gpus) != 0 {
env["CONNECTED_GPUS"] = strconv.Itoa(len(gpus))
for i, gpu := range gpus {
if gpu == "" {
continue
}
env["GPU"+strconv.Itoa(i+1)] = gpu
}
} }
var ret = make([]string, len(env)) var ret = make([]string, len(env))
Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 KiB

After

Width:  |  Height:  |  Size: 121 KiB

+31 -5
View File
@@ -119,7 +119,8 @@ func getCPUThreads() int {
return int(cpu.TotalThreads) return int(cpu.TotalThreads)
} }
func getGPUName() string { func getGPUNames() []string {
var ret []string
null, _ := os.Open(os.DevNull) null, _ := os.Open(os.DevNull)
serr := os.Stderr serr := os.Stderr
os.Stderr = null os.Stderr = null
@@ -127,14 +128,17 @@ func getGPUName() string {
defer null.Close() defer null.Close()
os.Stderr = serr os.Stderr = serr
if err != nil { if err != nil {
return "" return nil
} }
for _, graphics := range gpu.GraphicsCards { for i, graphics := range gpu.GraphicsCards {
if slices.Contains(config.HiddenGPUS, i+1) {
continue
}
if graphics.DeviceInfo != nil { if graphics.DeviceInfo != nil {
return graphics.DeviceInfo.Product.Name ret = append(ret, graphics.DeviceInfo.Product.Name)
} }
} }
return "" return ret
} }
type Memory struct { type Memory struct {
@@ -315,6 +319,7 @@ type partition struct {
Device string Device string
MountPoint string MountPoint string
Label string Label string
Type string
TotalSize uint64 TotalSize uint64
UsedSize uint64 UsedSize uint64
FreeSize uint64 FreeSize uint64
@@ -324,6 +329,10 @@ func getMountedPartitions() []partition {
mounts, err := mountinfo.GetMounts(func(info *mountinfo.Info) (skip, stop bool) { mounts, err := mountinfo.GetMounts(func(info *mountinfo.Info) (skip, stop bool) {
return !strings.HasPrefix(info.Source, "/dev/"), false return !strings.HasPrefix(info.Source, "/dev/"), false
}) })
fslabels, err := os.ReadDir("/dev/disk/by-label")
if err != nil && !os.IsNotExist(err) {
return nil
}
partlabels, err := os.ReadDir("/dev/disk/by-partlabel") partlabels, err := os.ReadDir("/dev/disk/by-partlabel")
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
return nil return nil
@@ -336,16 +345,33 @@ func getMountedPartitions() []partition {
} }
labels[link] = entry.Name() labels[link] = entry.Name()
} }
for _, entry := range fslabels {
link, err := filepath.EvalSymlinks(filepath.Join("/dev/disk/by-label/", entry.Name()))
if err != nil {
continue
}
labels[link] = entry.Name()
}
var partitions []partition var partitions []partition
for _, entry := range mounts { for _, entry := range mounts {
p := partition{ p := partition{
entry.Source, entry.Source,
entry.Mountpoint, entry.Mountpoint,
"", "",
entry.FSType,
0, 0,
0, 0,
0, 0,
} }
skip := false
for _, part := range partitions {
if part.Device == p.Device {
skip = true
}
}
if skip {
continue
}
if value, ok := labels[entry.Source]; ok { if value, ok := labels[entry.Source]; ok {
p.Label = value p.Label = value
} }