2021-02-08 23:55:36 +00:00
|
|
|
// package packaging provides tools for buildin Orbit installation packages.
|
|
|
|
package packaging
|
|
|
|
|
2021-02-17 02:05:18 +00:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2021-02-25 20:38:21 +00:00
|
|
|
"github.com/fleetdm/orbit/pkg/update"
|
|
|
|
"github.com/fleetdm/orbit/pkg/update/filestore"
|
2021-02-17 02:05:18 +00:00
|
|
|
"github.com/pkg/errors"
|
2021-02-25 20:38:21 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2021-02-17 02:05:18 +00:00
|
|
|
)
|
|
|
|
|
2021-02-08 23:55:36 +00:00
|
|
|
// Options are the configurable options provided for the package.
|
|
|
|
type Options struct {
|
|
|
|
// FleetURL is the URL to the Fleet server.
|
|
|
|
FleetURL string
|
|
|
|
// EnrollSecret is the enroll secret used to authenticate to the Fleet
|
|
|
|
// server.
|
|
|
|
EnrollSecret string
|
2021-02-09 03:23:50 +00:00
|
|
|
// Version is the version number for this package.
|
|
|
|
Version string
|
|
|
|
// Identifier is the identifier (eg. com.fleetdm.orbit) for the package product.
|
|
|
|
Identifier string
|
2021-02-08 23:55:36 +00:00
|
|
|
// StartService is a boolean indicating whether to start a system-specific
|
|
|
|
// background service.
|
|
|
|
StartService bool
|
|
|
|
// Insecure enables insecure TLS connections for the generated package.
|
|
|
|
Insecure bool
|
2021-02-17 21:25:56 +00:00
|
|
|
// SignIdentity is the codesigning identity to use (only macOS at this time)
|
|
|
|
SignIdentity string
|
2021-02-18 00:22:03 +00:00
|
|
|
// Notarize sets whether macOS packages should be Notarized.
|
|
|
|
Notarize bool
|
2021-02-25 20:38:21 +00:00
|
|
|
// FleetCertificate is a path to a server certificate to include in the package.
|
|
|
|
FleetCertificate string
|
2021-03-02 19:24:32 +00:00
|
|
|
// OrbitChannel is the update channel to use for Orbit.
|
|
|
|
OrbitChannel string
|
|
|
|
// OsqueryChannel is the update channel to use for Osquery.
|
|
|
|
OsqueryChannel string
|
2021-02-08 23:55:36 +00:00
|
|
|
}
|
2021-02-17 02:05:18 +00:00
|
|
|
|
|
|
|
func copyFile(srcPath, dstPath string, perm os.FileMode) error {
|
|
|
|
src, err := os.Open(srcPath)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "open src for copy")
|
|
|
|
}
|
|
|
|
defer src.Close()
|
|
|
|
|
|
|
|
if err := os.MkdirAll(filepath.Dir(dstPath), 0755); err != nil {
|
|
|
|
return errors.Wrap(err, "create dst dir for copy")
|
|
|
|
}
|
|
|
|
|
|
|
|
dst, err := os.OpenFile(dstPath, os.O_RDWR|os.O_CREATE, perm)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "open dst for copy")
|
|
|
|
}
|
|
|
|
defer dst.Close()
|
|
|
|
|
|
|
|
if _, err := io.Copy(dst, src); err != nil {
|
|
|
|
return errors.Wrap(err, "copy src to dst")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-02-25 20:38:21 +00:00
|
|
|
|
2021-03-02 19:24:32 +00:00
|
|
|
func initializeUpdates(updateOpt update.Options) error {
|
2021-02-25 20:38:21 +00:00
|
|
|
localStore, err := filestore.New(filepath.Join(updateOpt.RootDirectory, "tuf-metadata.json"))
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to create local metadata store")
|
|
|
|
}
|
|
|
|
updateOpt.LocalStore = localStore
|
|
|
|
|
|
|
|
updater, err := update.New(updateOpt)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to init updater")
|
|
|
|
}
|
|
|
|
if err := updater.UpdateMetadata(); err != nil {
|
|
|
|
return errors.Wrap(err, "failed to update metadata")
|
|
|
|
}
|
2021-03-02 19:24:32 +00:00
|
|
|
osquerydPath, err := updater.Get("osqueryd", updateOpt.OsqueryChannel)
|
2021-02-25 20:38:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get osqueryd")
|
|
|
|
}
|
|
|
|
log.Debug().Str("path", osquerydPath).Msg("got osqueryd")
|
|
|
|
|
2021-03-02 19:24:32 +00:00
|
|
|
orbitPath, err := updater.Get("orbit", updateOpt.OrbitChannel)
|
2021-02-25 20:38:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get orbit")
|
|
|
|
}
|
|
|
|
log.Debug().Str("path", orbitPath).Msg("got orbit")
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|