Initial LanUps implementation and native installers

This commit is contained in:
tongtong committed 2026-11-28 16:26:39 +08:00
commit 67a043c89b
66 files changed
+2870

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
module lan-ups-macos-packager
go 1.26.4
require go.digitalxero.dev/osx v0.3.0
+16
View File
@@ -0,0 +1,16 @@
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/github/smimesign v0.2.0 h1:Hho4YcX5N1I9XNqhq0fNx0Sts8MhLonHd+HRXVGNjvk=
github.com/github/smimesign v0.2.0/go.mod h1:iZiiwNT4HbtGRVqCQu7uJPEZCuEE5sfSSttcnePkDl4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.digitalxero.dev/osx v0.3.0 h1:PwlFuyUEcT5/4HxHAf1DjHaCRZuVcrQkC7W0yvL8k8E=
go.digitalxero.dev/osx v0.3.0/go.mod h1:RndPJgzpTmsGwHBK6mU9KmQq5F+YgPHn/FjETzvc230=
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
software.sslmate.com/src/go-pkcs12 v0.7.0 h1:Db8W44cB54TWD7stUFFSWxdfpdn6fZVcDl0w3R4RVM0=
software.sslmate.com/src/go-pkcs12 v0.7.0/go.mod h1:Qiz0EyvDRJjjxGyUQa2cCNZn/wMyzrRJ/qcDXOQazLI=
+69
View File
@@ -0,0 +1,69 @@
package main
import (
"io/fs"
"log"
"os"
"path/filepath"
"strings"
"go.digitalxero.dev/osx/pkg"
)
func main() {
if len(os.Args) != 6 {
log.Fatal("usage: macpack payload preinstall postinstall architecture output.pkg")
}
root, prePath, postPath, architecture, output := os.Args[1], os.Args[2], os.Args[3], os.Args[4], os.Args[5]
if architecture != pkg.ArchARM64 && architecture != pkg.ArchX8664 {
log.Fatal("invalid macOS architecture")
}
pre, err := os.ReadFile(prePath)
check(err)
post, err := os.ReadFile(postPath)
check(err)
component := pkg.NewPackage().WithIdentifier("local.lanups").WithName("LanUps").WithVersion("0.1.0").
WithPreInstallScript(pre).WithPostInstallScript(post)
check(filepath.WalkDir(root, func(path string, entry fs.DirEntry, err error) error {
if err != nil || entry.IsDir() {
return err
}
relative, err := filepath.Rel(root, path)
if err != nil {
return err
}
name := filepath.ToSlash(relative)
mode := fs.FileMode(0o644)
if strings.HasSuffix(name, "/LanUps.Agent") || strings.HasSuffix(name, "/LanUps.Desktop") {
mode = 0o755
}
component.WithFileFromPath("/"+name, path).WithMode(mode).Add()
return nil
}))
product, err := pkg.NewProduct().WithTitle("LanUps").WithIdentifier("local.lanups.product").WithVersion("0.1.0").
WithHostArchitectures(architecture).WithMinOSVersion("15.0").WithComponent(component).Build()
check(err)
file, err := os.Create(output)
check(err)
_, err = product.WriteTo(file)
check(err)
check(file.Close())
file, err = os.Open(output)
check(err)
defer file.Close()
info, err := file.Stat()
check(err)
archive, err := pkg.Open(file, info.Size())
check(err)
check(archive.Verify())
installed, err := archive.Component("local.lanups")
check(err)
check(installed.Verify())
}
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
+77
View File
@@ -0,0 +1,77 @@
//go:build windows
package main
import (
"archive/zip"
"fmt"
"io"
"io/fs"
"os"
"os/exec"
"path/filepath"
)
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, "LanUps installation failed:", err)
os.Exit(1)
}
}
func run() error {
self, err := os.Executable()
if err != nil {
return err
}
archive, err := zip.OpenReader(self)
if err != nil {
return err
}
defer archive.Close()
stage, err := os.MkdirTemp("", "LanUps-Setup-")
if err != nil {
return err
}
defer os.RemoveAll(stage)
for _, entry := range archive.File {
path := filepath.FromSlash(entry.Name)
if !fs.ValidPath(entry.Name) || !filepath.IsLocal(path) || !entry.Mode().IsRegular() {
return fmt.Errorf("invalid installer entry: %q", entry.Name)
}
if err := extract(filepath.Join(stage, path), entry); err != nil {
return err
}
}
if len(os.Args) == 2 && os.Args[1] == "--verify" {
fmt.Printf("Verified %d installer files\n", len(archive.File))
return nil
}
setup := filepath.Join(stage, "Setup.ps1")
args := append([]string{"-NoProfile", "-ExecutionPolicy", "Bypass", "-File", setup}, os.Args[1:]...)
powershell := filepath.Join(os.Getenv("SystemRoot"), "System32", "WindowsPowerShell", "v1.0", "powershell.exe")
command := exec.Command(powershell, args...)
command.Stdout, command.Stderr = os.Stdout, os.Stderr
return command.Run()
}
func extract(path string, entry *zip.File) error {
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
return err
}
input, err := entry.Open()
if err != nil {
return err
}
defer input.Close()
output, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o600)
if err != nil {
return err
}
_, err = io.Copy(output, input)
closeErr := output.Close()
if err != nil {
return err
}
return closeErr
}