2 Commits
Author SHA1 Message Date
EnumDev c05f34eb7d Fixed minor bug and updated fetch_script.sh
Fixed bug which would cause partitions not to show up if /dev/disk/by-partlabel/ did not exist
Updated fetch_script.sh to use labels if available
2024-05-16 22:24:16 +03:00
EnumDev 39b901e6fd Added PARTITION<n>_LABEL bash variable 2024-05-16 22:05:03 +03:00
3 changed files with 32 additions and 4 deletions
+7 -2
View File
@@ -11,9 +11,14 @@ if [ ! -z "$MEM_TOTAL" ] && [ ! -z "$MEM_USED" ]; then echo -e "${C3}Memory: ${C
for i in $(seq ${MOUNTED_PARTITIONS}); do
device="PARTITION${i}_DEVICE"
mountpoint="PARTITION${i}_MOUNTPOINT"
label="PARTITION${i}_LABEL"
total="PARTITION${i}_TOTAL_SIZE"
used="PARTITION${i}_USED_SIZE"
echo -e "${C3}${!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
done
if [ ! -z "$DISPLAY_PROTOCOL" ]; then
echo -e "${C3}Display Protocol: ${C4}${DISPLAY_PROTOCOL}"
@@ -22,4 +27,4 @@ if [ ! -z "$DISPLAY_PROTOCOL" ]; then
echo -e "${C3}Screen $i: ${C4}${!monitor}"
done
fi
if [ ! -z "$DE_WM" ]; then echo -e "${C3}DE/WM: ${C4}${DE_WM}"; fi
if [ ! -z "$DE_WM" ]; then echo -e "${C3}DE/WM: ${C4}${DE_WM}"; fi
+3
View File
@@ -193,6 +193,9 @@ func SetupFetchEnv() []string {
for i, part := range partitions {
env["PARTITION"+strconv.Itoa(i+1)+"_DEVICE"] = part.Device
env["PARTITION"+strconv.Itoa(i+1)+"_MOUNTPOINT"] = part.MountPoint
if part.Label != "" {
env["PARTITION"+strconv.Itoa(i+1)+"_LABEL"] = part.Label
}
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)
+22 -2
View File
@@ -323,23 +323,39 @@ func getMonitorResolution() []string {
type partition struct {
Device string
MountPoint string
Label string
TotalSize uint64
UsedSize uint64
FreeSize uint64
}
func getMountedPartitions() []partition {
entries, err := os.ReadDir("/dev/disk/by-partuuid")
partuuids, err := os.ReadDir("/dev/disk/by-partuuid")
if err != nil {
return nil
}
partlabels, err := os.ReadDir("/dev/disk/by-partlabel")
if err != nil && !os.IsNotExist(err) {
return nil
}
labels := make(map[string]string)
for _, entry := range partlabels {
link, err := filepath.EvalSymlinks(filepath.Join("/dev/disk/by-partlabel/", entry.Name()))
if err != nil {
continue
}
labels[link] = entry.Name()
}
bytes, err := os.ReadFile("/proc/mounts")
if err != nil {
return nil
}
mountsRaw := strings.Split(string(bytes), "\n")
mounts := make(map[string]string)
for i := 0; i < len(mountsRaw); i++ {
split := strings.Split(mountsRaw[i], " ")
if len(split) <= 2 {
@@ -349,7 +365,7 @@ func getMountedPartitions() []partition {
}
var partitions []partition
for _, entry := range entries {
for _, entry := range partuuids {
link, err := filepath.EvalSymlinks(filepath.Join("/dev/disk/by-partuuid/", entry.Name()))
if err != nil {
continue
@@ -360,10 +376,14 @@ func getMountedPartitions() []partition {
p := partition{
link,
mounts[link],
"",
0,
0,
0,
}
if value, ok := labels[link]; ok {
p.Label = value
}
buf := new(syscall.Statfs_t)
err = syscall.Statfs(p.MountPoint, buf)
if err != nil {