2023-05-18 16:07:24 +00:00
|
|
|
package distro
|
|
|
|
|
2023-05-18 21:37:07 +00:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
var mu sync.Mutex
|
|
|
|
var distros []distribution
|
|
|
|
|
|
|
|
type distribution interface {
|
2023-05-23 16:24:01 +00:00
|
|
|
Distro() Distro
|
2023-05-18 21:37:07 +00:00
|
|
|
Equal(Distro) bool
|
|
|
|
Packages() (packages []string, err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Register(d distribution) {
|
|
|
|
mu.Lock()
|
|
|
|
defer mu.Unlock()
|
|
|
|
|
|
|
|
distros = append(distros, d)
|
|
|
|
}
|
|
|
|
|
2023-05-18 22:02:41 +00:00
|
|
|
func List() (dds []Distro) {
|
|
|
|
for _, dd := range distros {
|
2023-05-23 16:24:01 +00:00
|
|
|
dds = append(dds, dd.Distro())
|
2023-05-18 22:02:41 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 16:07:24 +00:00
|
|
|
type Distro struct {
|
|
|
|
ID ID
|
|
|
|
Release string
|
|
|
|
}
|
2023-05-18 21:37:07 +00:00
|
|
|
|
|
|
|
func (d Distro) Packages() (packages []string, err error) {
|
|
|
|
for _, dd := range distros {
|
2023-05-23 16:24:01 +00:00
|
|
|
if d.ID != None && d.ID != dd.Distro().ID {
|
2023-05-18 21:37:07 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if d.Release != "" && !dd.Equal(d) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var pkgs []string
|
|
|
|
pkgs, err = dd.Packages()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
packages = append(packages, pkgs...)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|