Added PARTITION<n>_LABEL bash variable
This commit is contained in:
parent
2af3ab1156
commit
39b901e6fd
3
main.go
3
main.go
@ -193,6 +193,9 @@ func SetupFetchEnv() []string {
|
|||||||
for i, part := range partitions {
|
for i, part := range partitions {
|
||||||
env["PARTITION"+strconv.Itoa(i+1)+"_DEVICE"] = part.Device
|
env["PARTITION"+strconv.Itoa(i+1)+"_DEVICE"] = part.Device
|
||||||
env["PARTITION"+strconv.Itoa(i+1)+"_MOUNTPOINT"] = part.MountPoint
|
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)+"_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)
|
||||||
|
24
utils.go
24
utils.go
@ -323,23 +323,39 @@ func getMonitorResolution() []string {
|
|||||||
type partition struct {
|
type partition struct {
|
||||||
Device string
|
Device string
|
||||||
MountPoint string
|
MountPoint string
|
||||||
|
Label string
|
||||||
TotalSize uint64
|
TotalSize uint64
|
||||||
UsedSize uint64
|
UsedSize uint64
|
||||||
FreeSize uint64
|
FreeSize uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMountedPartitions() []partition {
|
func getMountedPartitions() []partition {
|
||||||
entries, err := os.ReadDir("/dev/disk/by-partuuid")
|
partuuids, err := os.ReadDir("/dev/disk/by-partuuid")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partlabels, err := os.ReadDir("/dev/disk/by-partlabel")
|
||||||
|
if err != nil {
|
||||||
|
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")
|
bytes, err := os.ReadFile("/proc/mounts")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mountsRaw := strings.Split(string(bytes), "\n")
|
mountsRaw := strings.Split(string(bytes), "\n")
|
||||||
mounts := make(map[string]string)
|
mounts := make(map[string]string)
|
||||||
|
|
||||||
for i := 0; i < len(mountsRaw); i++ {
|
for i := 0; i < len(mountsRaw); i++ {
|
||||||
split := strings.Split(mountsRaw[i], " ")
|
split := strings.Split(mountsRaw[i], " ")
|
||||||
if len(split) <= 2 {
|
if len(split) <= 2 {
|
||||||
@ -349,7 +365,7 @@ func getMountedPartitions() []partition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var partitions []partition
|
var partitions []partition
|
||||||
for _, entry := range entries {
|
for _, entry := range partuuids {
|
||||||
link, err := filepath.EvalSymlinks(filepath.Join("/dev/disk/by-partuuid/", entry.Name()))
|
link, err := filepath.EvalSymlinks(filepath.Join("/dev/disk/by-partuuid/", entry.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
@ -360,10 +376,14 @@ func getMountedPartitions() []partition {
|
|||||||
p := partition{
|
p := partition{
|
||||||
link,
|
link,
|
||||||
mounts[link],
|
mounts[link],
|
||||||
|
"",
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
}
|
}
|
||||||
|
if value, ok := labels[link]; ok {
|
||||||
|
p.Label = value
|
||||||
|
}
|
||||||
buf := new(syscall.Statfs_t)
|
buf := new(syscall.Statfs_t)
|
||||||
err = syscall.Statfs(p.MountPoint, buf)
|
err = syscall.Statfs(p.MountPoint, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user