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 {
|
|
|
|
ID() ID
|
2023-05-18 22:02:41 +00:00
|
|
|
Release() string
|
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) {
|
|
|
|
mu.Lock()
|
|
|
|
defer mu.Unlock()
|
|
|
|
|
|
|
|
for _, dd := range distros {
|
|
|
|
dds = append(dds, Distro{
|
|
|
|
ID: dd.ID(),
|
|
|
|
Release: dd.Release(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
if d.ID != None && d.ID != dd.ID() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if d.Release != "" && !dd.Equal(d) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var pkgs []string
|
|
|
|
pkgs, err = dd.Packages()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
packages = append(packages, pkgs...)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|