mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-16 07:56:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed45b739a5 | ||
|
|
8c380dbec4 | ||
|
|
7c493dc9f9 |
@@ -13,7 +13,7 @@ endif
|
||||
|
||||
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/
|
||||
mkdir -p $(DESTDIR)$(BINDIR)
|
||||
|
||||
@@ -20,7 +20,7 @@ Stormfetch is still in beta, so distro compatibility is limited. If you would li
|
||||
- Download `make` from your package manager
|
||||
- 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
|
||||
```
|
||||
|
||||
@@ -3,4 +3,5 @@ fetch_script: auto
|
||||
ansii_colors: []
|
||||
force_config_ansii: false
|
||||
dependency_warning: true
|
||||
show_fs_type: true
|
||||
hidden_gpus: []
|
||||
|
||||
@@ -15,13 +15,22 @@ for i in $(seq ${MOUNTED_PARTITIONS}); do
|
||||
device="PARTITION${i}_DEVICE"
|
||||
mountpoint="PARTITION${i}_MOUNTPOINT"
|
||||
label="PARTITION${i}_LABEL"
|
||||
type="PARTITION${i}_TYPE"
|
||||
total="PARTITION${i}_TOTAL_SIZE"
|
||||
used="PARTITION${i}_USED_SIZE"
|
||||
if [ -z "${!type}" ]; then
|
||||
if [ -z "${!label}" ]; then
|
||||
echo -e "${C3}Partition ${!mountpoint}: ${C4}${!used}/${!total}"
|
||||
else
|
||||
echo -e "${C3}Partition ${!label}: ${C4}${!used}/${!total}"
|
||||
fi
|
||||
else
|
||||
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
|
||||
if [ ! -z "$DISPLAY_PROTOCOL" ]; then
|
||||
echo -e "${C3}Display Protocol: ${C4}${DISPLAY_PROTOCOL}"
|
||||
|
||||
@@ -24,7 +24,7 @@ get_packages() {
|
||||
ARRAY+=("$(xbps-query -l | wc -l) (xbps)")
|
||||
fi
|
||||
if command_exists bpm; then
|
||||
ARRAY+=("$(bpm list -n) (bpm)")
|
||||
ARRAY+=("$(bpm list -c) (bpm)")
|
||||
fi
|
||||
if command_exists emerge; then
|
||||
ARRAY+=("$(ls -l /var/db/pkg/* | wc -l) (emerge)")
|
||||
|
||||
@@ -13,6 +13,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var systemConfigDir = "/etc/"
|
||||
|
||||
var configPath = ""
|
||||
var fetchScriptPath = ""
|
||||
|
||||
@@ -22,6 +24,7 @@ var config = StormfetchConfig{
|
||||
AnsiiColors: make([]int, 0),
|
||||
ForceConfigAnsii: false,
|
||||
DependencyWarning: true,
|
||||
ShowFSType: false,
|
||||
HiddenGPUS: make([]int, 0),
|
||||
}
|
||||
|
||||
@@ -32,6 +35,7 @@ type StormfetchConfig struct {
|
||||
AnsiiColors []int `yaml:"ansii_colors"`
|
||||
ForceConfigAnsii bool `yaml:"force_config_ansii"`
|
||||
DependencyWarning bool `yaml:"dependency_warning"`
|
||||
ShowFSType bool `yaml:"show_fs_type"`
|
||||
HiddenGPUS []int `yaml:"hidden_gpus"`
|
||||
}
|
||||
|
||||
@@ -44,12 +48,12 @@ func main() {
|
||||
|
||||
func readConfig() {
|
||||
// Get home directory
|
||||
configDir, _ := os.UserConfigDir()
|
||||
userConfigDir, _ := os.UserConfigDir()
|
||||
// Find valid config directory
|
||||
if _, err := os.Stat(path.Join(configDir, "stormfetch/config.yaml")); err == nil {
|
||||
configPath = path.Join(configDir, "stormfetch/config.yaml")
|
||||
} else if _, err := os.Stat("/etc/stormfetch/config.yaml"); err == nil {
|
||||
configPath = "/etc/stormfetch/config.yaml"
|
||||
if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/config.yaml")); err == nil {
|
||||
configPath = path.Join(userConfigDir, "stormfetch/config.yaml")
|
||||
} else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/config.yaml")); err == nil {
|
||||
configPath = path.Join(systemConfigDir, "stormfetch/config.yaml")
|
||||
} else {
|
||||
log.Fatalf("Config file not found: %s", err.Error())
|
||||
}
|
||||
@@ -72,10 +76,10 @@ func readConfig() {
|
||||
log.Fatalf("Fetch script path points to a directory")
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(path.Join(configDir, "stormfetch/fetch_script.sh")); err == nil {
|
||||
fetchScriptPath = path.Join(configDir, "stormfetch/fetch_script.sh")
|
||||
} else if _, err := os.Stat("/etc/stormfetch/fetch_script.sh"); err == nil {
|
||||
fetchScriptPath = "/etc/stormfetch/fetch_script.sh"
|
||||
if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/fetch_script.sh")); err == nil {
|
||||
fetchScriptPath = path.Join(userConfigDir, "stormfetch/fetch_script.sh")
|
||||
} else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/fetch_script.sh")); err == nil {
|
||||
fetchScriptPath = path.Join(systemConfigDir, "stormfetch/fetch_script.sh")
|
||||
} else {
|
||||
log.Fatalf("Fetch script file not found: %s", err.Error())
|
||||
}
|
||||
@@ -128,6 +132,9 @@ func SetupFetchEnv() []string {
|
||||
if 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)+"_USED_SIZE"] = FormatBytes(part.UsedSize)
|
||||
env["PARTITION"+strconv.Itoa(i+1)+"_FREE_SIZE"] = FormatBytes(part.FreeSize)
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 163 KiB After Width: | Height: | Size: 121 KiB |
@@ -319,6 +319,7 @@ type partition struct {
|
||||
Device string
|
||||
MountPoint string
|
||||
Label string
|
||||
Type string
|
||||
TotalSize uint64
|
||||
UsedSize uint64
|
||||
FreeSize uint64
|
||||
@@ -328,6 +329,10 @@ func getMountedPartitions() []partition {
|
||||
mounts, err := mountinfo.GetMounts(func(info *mountinfo.Info) (skip, stop bool) {
|
||||
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")
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return nil
|
||||
@@ -340,16 +345,33 @@ func getMountedPartitions() []partition {
|
||||
}
|
||||
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
|
||||
for _, entry := range mounts {
|
||||
p := partition{
|
||||
entry.Source,
|
||||
entry.Mountpoint,
|
||||
"",
|
||||
entry.FSType,
|
||||
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 {
|
||||
p.Label = value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user