package main import ( "io/fs" "log" "os" "path/filepath" "strings" "go.digitalxero.dev/osx/pkg" ) func main() { if len(os.Args) != 7 { log.Fatal("usage: macpack payload preinstall postinstall architecture output.pkg version") } root, prePath, postPath, architecture, output, version := os.Args[1], os.Args[2], os.Args[3], os.Args[4], os.Args[5], os.Args[6] 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(version). 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(version). 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) } }