chore(packages): removed useless packages list hook function and debian stdlib refactoring

This commit is contained in:
Julien Dessaux 2024-03-25 10:52:45 +01:00
parent fe8d8027b3
commit d20734c275
Signed by: adyxax
GPG key ID: F92E51B86E07177E
4 changed files with 39 additions and 33 deletions

View file

@ -28,7 +28,6 @@ func Resolve() (status Status) {
case BROKEN: case BROKEN:
return BROKEN return BROKEN
case REPAIRED: case REPAIRED:
packages_list_function()
continue continue
} }
// ----- Services ---------------------------------------------- // ----- Services ----------------------------------------------

View file

@ -7,7 +7,6 @@ var packages []*PackagePromise
// packages management functions // packages management functions
var packages_install_function func([]string) (Status, []string) var packages_install_function func([]string) (Status, []string)
var packages_list_function func()
var packages_update_function *CommandPromise var packages_update_function *CommandPromise
// ----- Init ------------------------------------------------------------------ // ----- Init ------------------------------------------------------------------
@ -16,9 +15,8 @@ func init() {
} }
// ----- Public ---------------------------------------------------------------- // ----- Public ----------------------------------------------------------------
func SetPackagesConfiguration(install func([]string) (Status, []string), list func(), update *CommandPromise) { func SetPackagesConfiguration(install func([]string) (Status, []string), update *CommandPromise) {
packages_install_function = install packages_install_function = install
packages_list_function = list
packages_update_function = update packages_update_function = update
} }

View file

@ -3,14 +3,12 @@ package debian
import ( import (
"bufio" "bufio"
"bytes" "bytes"
_ "embed"
"log/slog" "log/slog"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
gonf "git.adyxax.org/adyxax/gonf/v2/pkg" gonf "git.adyxax.org/adyxax/gonf/v2/pkg"
"git.adyxax.org/adyxax/gonf/v2/stdlib/os/systemd"
) )
var packages map[string]string var packages map[string]string
@ -19,33 +17,6 @@ func init() {
packages_list() packages_list()
} }
//go:embed apt-norecommends
var apt_norecommends []byte
//go:embed sources.list
var sources_list []byte
func Promise() {
rootDir := gonf.ModeUserGroup(0755, "root", "root")
rootRO := gonf.ModeUserGroup(0444, "root", "root")
gonf.Default("debian-release", "stable")
gonf.AppendVariable("debian-extra-sources", "# Extra sources")
apt_update := gonf.Command("apt-get", "update", "-qq")
gonf.File("/etc/apt/sources.list").
Permissions(rootRO).
Template(sources_list).
Promise().
IfRepaired(apt_update)
gonf.File("/etc/apt/apt.conf.d/99_norecommends").
DirectoriesPermissions(rootDir).
Permissions(rootRO).
Template(apt_norecommends).
Promise()
gonf.SetPackagesConfiguration(packages_install, packages_list, apt_update)
gonf.Service("opensmtpd").State("enabled", "started").Promise()
systemd.Promise()
}
func packages_install(names []string) (gonf.Status, []string) { func packages_install(names []string) (gonf.Status, []string) {
gonf.FilterSlice(&names, func(n string) bool { gonf.FilterSlice(&names, func(n string) bool {
_, ok := packages[n] _, ok := packages[n]

View file

@ -0,0 +1,38 @@
package debian
import (
_ "embed"
"git.adyxax.org/adyxax/gonf/v2/pkg"
"git.adyxax.org/adyxax/gonf/v2/stdlib/os/linux"
"git.adyxax.org/adyxax/gonf/v2/stdlib/os/systemd"
)
//go:embed apt-norecommends
var apt_norecommends []byte
//go:embed sources.list
var sources_list []byte
func Promise() {
// ----- gonf --------------------------------------------------------------
apt_update := gonf.Command("apt-get", "update", "-qq")
gonf.SetPackagesConfiguration(packages_install, apt_update)
gonf.SetUsersConfiguration(linux.Useradd)
// ----- systemd -----------------------------------------------------------
systemd.Promise()
// ----- apt ---------------------------------------------------------------
rootDir := gonf.ModeUserGroup(0755, "root", "root")
rootRO := gonf.ModeUserGroup(0444, "root", "root")
gonf.Default("debian-release", "stable")
gonf.AppendVariable("debian-extra-sources", "# Extra sources")
gonf.File("/etc/apt/sources.list").
Permissions(rootRO).
Template(sources_list).
Promise().
IfRepaired(apt_update)
gonf.File("/etc/apt/apt.conf.d/99_norecommends").
DirectoriesPermissions(rootDir).
Permissions(rootRO).
Contents(apt_norecommends).
Promise()
}