add subcommand that prints licenses, and link to licenses from the webadmin/webaccount/webmail interfaces

This commit is contained in:
Mechiel Lukkien
2024-10-04 09:31:31 +02:00
parent 7d3f307156
commit 8f7fc3773b
57 changed files with 1844 additions and 4 deletions

55
mox-/licenses.go Normal file
View File

@ -0,0 +1,55 @@
package mox
import (
"fmt"
"io"
"io/fs"
"strings"
)
var LicensesFsys fs.FS
// LicensesWrite writes the licenses to dst.
func LicensesWrite(dst io.Writer) error {
copyFile := func(p string) error {
f, err := LicensesFsys.Open(p)
if err != nil {
return fmt.Errorf("open license file: %v", err)
}
if _, err := io.Copy(dst, f); err != nil {
return fmt.Errorf("copy license file: %v", err)
}
if err := f.Close(); err != nil {
return fmt.Errorf("close license file: %v", err)
}
return nil
}
if _, err := fmt.Fprintf(dst, "# github.com/mjl-/mox/LICENSE\n\n"); err != nil {
return err
}
if err := copyFile("LICENSE.MIT"); err != nil {
return err
}
if _, err := fmt.Fprintf(dst, "\n\n# https://publicsuffix.org - Public Suffix List Mozilla\n\n"); err != nil {
return err
}
if err := copyFile("LICENSE.MPLv2.0"); err != nil {
return err
}
err := fs.WalkDir(LicensesFsys, "licenses", func(path string, d fs.DirEntry, err error) error {
if !d.Type().IsRegular() {
return nil
}
if _, err := fmt.Fprintf(dst, "\n\n# %s\n\n", strings.TrimPrefix(path, "licenses/")); err != nil {
return err
}
return copyFile(path)
})
if err != nil {
return fmt.Errorf("walk licenses: %v", err)
}
return nil
}