fix: portage count and distro detection

This commit is contained in:
nekohepott 2026-06-17 04:16:35 +03:00
parent 3387e2916e
commit abc4ea7369
No known key found for this signature in database
3 changed files with 24 additions and 3 deletions

View File

@ -12,7 +12,7 @@ build:
install:
@if [ "$$(id -u)" -ne 0 ] && [ -z "$(DESTDIR)" ]; then \
echo "Error: root privileges required. Run with sudo."; \
echo "Error: root privileges required. Run with sudo or doas."; \
exit 1; \
fi
@echo "Installing $(BINARY_NAME) to $(PREFIX)/bin..."

View File

@ -39,6 +39,25 @@ func getPmPackages(packagerName string, packagerPath string) string {
return fmt.Sprintf("%d (apk)", pkgCount)
}
if packagerName == "emerge" {
count := 0
for _, cat := range pkgs {
if !cat.IsDir() || strings.HasPrefix(cat.Name(), ".") {
continue
}
catPath := packagerPath + "/" + cat.Name()
subdirs, err := os.ReadDir(catPath)
if err != nil {
continue
}
for _, sub := range subdirs {
if sub.IsDir() && !strings.HasPrefix(sub.Name(), ".") {
count++
}
}
}
return strconv.Itoa(count) + " (emerge)"
}
return strconv.Itoa(len(pkgs)) + " (" + packagerName + ")"
}
return ""
@ -55,7 +74,7 @@ func GetPkgs() string {
{"dnf", "/var/lib/dnf"},
{"zypper", "/var/lib/zypp"},
{"xbps", "/var/db/xbps"},
{"emerge", "/var/lib/portage"},
{"emerge", "/var/db/pkg"},
{"apk", "/etc/apk/"},
{"flatpak", "/var/lib/flatpak/app"},
}

View File

@ -31,10 +31,12 @@ func GetDist() (string, string) {
if strings.HasPrefix(t, "ID=") {
id = strings.TrimPrefix(t, "ID=")
id = strings.Trim(id, "\"")
id = strings.ReplaceAll(id, "'", "")
}
if strings.HasPrefix(t, "PRETTY_NAME=") {
prettyName = strings.TrimPrefix(t, "PRETTY_NAME=")
prettyName = strings.Trim(prettyName, "\"")
prettyName = strings.ReplaceAll(prettyName, "'", "")
}
}
if id == "" && prettyName == "" {
@ -194,7 +196,7 @@ func GetKernel() string {
}
func GetHostname() string {
hostname, err := os.ReadFile("/etc/hostname")
hostname, err := os.ReadFile("/proc/sys/kernel/hostname")
if err != nil {
return "unknown"
}