Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows services and move to flag files #415

Merged
merged 21 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ vendor
build
bin
.DS_Store
test-cmds

## Below from https://github.com/github/gitignore/blob/master/Go.gitignore ##

Expand Down
2 changes: 1 addition & 1 deletion cmd/package-builder/package-builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func main() {
func defaultTargets() string {
switch runtime.GOOS {
case "windows":
return "windows-none-msi"
return "windows-service-msi"
case "linux":
return "linux-systemd-rpm,linux-systemd-deb"
case "darwin":
Expand Down
10 changes: 10 additions & 0 deletions docs/package-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,13 @@ As `ioutil.TempFile` respects the `TMPDIR` environmental variable, there is a si
``` shell
export TMPDIR=/tmp
```

#### Windows

Windows can be built without a service `windows-none-msi` or with a
service `windows-service-msi`.

Note that the windows package will only install as `ALLUSERS`. You may
need to use elevated privileges to install it. This will likely be
confusing. `msiexec.exe` will either silently fail, or be
inscrutable. But `start` will work.
23 changes: 13 additions & 10 deletions pkg/packagekit/internal/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions pkg/packagekit/internal/assets/main.wxs
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<?if $(var.Arch) = 386 ?>
<?define ProgFolder=ProgramFilesFolder ?>
<?else?>
<?define ProgFolder=ProgramFiles64Folder ?>
<?endif?>
<?if $(sys.BUILDARCH)="x86"?>
<?define Program_Files="ProgramFilesFolder"?>
<?elseif $(sys.BUILDARCH)="x64"?>
<?define Program_Files="ProgramFiles64Folder"?>
<?else?>
<?error Unsupported value of sys.BUILDARCH=$(sys.BUILDARCH)?>
<?endif?>

<Product
Id="*"
Name="Kolide {{.Opts.Name}} {{.Opts.Identifier}} $(var.Arch) {{.Opts.Version}}"
Id="{{.ProductCode}}"
Name="Kolide {{.Opts.Name}} {{.Opts.Identifier}} $(sys.BUILDARCH) {{.Opts.Version}}"
Language="1033"
Version="{{.Opts.Version}}"
Manufacturer="https://kolide.com"
UpgradeCode="{{.UpgradeCode}}" >

<Package
Id='*'
Id="*"
Keywords='Installer'
Description="Kolide {{.Opts.Name}} {{.Opts.Identifier}}"
Comments="Kolide {{.Opts.Name}} {{.Opts.Identifier}}"
InstallerVersion="300"
Compressed="yes"
InstallScope="perMachine"
InstallPrivileges="elevated"
Languages="1033" />

<!-- This holds the files generated by heat -->
Expand All @@ -36,7 +39,7 @@
It's up to the caller to decide which directories to use
-->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="$(var.ProgFolder)">
<Directory Id="$(var.Program_Files)">
<Directory Id="PROGDIR" Name="Kolide"/>
</Directory>
<Directory Id="CommonAppDataFolder">
Expand Down
1 change: 1 addition & 0 deletions pkg/packagekit/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type PackageOptions struct {
Scripts string // directory of packaging scripts (postinst, prerm, etc)
SigningKey string // key to sign packages with (platform specific behaviors)
Version string // package version
FlagFile string // Path to the flagfile for configuration
}
24 changes: 17 additions & 7 deletions pkg/packagekit/package_wix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package packagekit
import (
"bytes"
"context"
"fmt"
"io"
"runtime"
"strings"
Expand All @@ -17,7 +18,7 @@ import (

//go:generate go-bindata -nocompress -pkg internal -o internal/assets.go internal/assets/

func PackageWixMSI(ctx context.Context, w io.Writer, po *PackageOptions) error {
func PackageWixMSI(ctx context.Context, w io.Writer, po *PackageOptions, includeService bool) error {
ctx, span := trace.StartSpan(ctx, "packagekit.PackageWixMSI")
defer span.End()

Expand All @@ -30,8 +31,8 @@ func PackageWixMSI(ctx context.Context, w io.Writer, po *PackageOptions) error {
// little more debugable to do it with go's. This way, we can
// inspect the intermediate xml file.
//
// This might all be cleaner moved to a marshalled struct. For now,
// just sent the template the PackageOptions struct
// This might all be cleaner moved from a template to a marshalled
// struct. But enumerating the wix options looks very ugly
wixTemplateBytes, err := internal.Asset("internal/assets/main.wxs")
if err != nil {
return errors.Wrap(err, "getting go-bindata main.wxs")
Expand All @@ -51,7 +52,6 @@ func PackageWixMSI(ctx context.Context, w io.Writer, po *PackageOptions) error {
Opts: po,
UpgradeCode: generateMicrosoftProductCode("launcher" + po.Identifier),
ProductCode: generateMicrosoftProductCode("launcher"+po.Identifier, extraGuidIdentifiers...),
PackageCode: generateMicrosoftProductCode("launcher"+po.Identifier, extraGuidIdentifiers...),
}

wixTemplate, err := template.New("WixTemplate").Parse(string(wixTemplateBytes))
Expand All @@ -64,14 +64,24 @@ func PackageWixMSI(ctx context.Context, w io.Writer, po *PackageOptions) error {
return errors.Wrap(err, "executing WixTemplate")
}

wixTool, err := wix.New(po.Root, mainWxsContent.Bytes())
wixArgs := []wix.WixOpt{}

if includeService {
launcherService := wix.NewService("launcher.exe",
wix.ServiceName(fmt.Sprintf("KolideLauncher%sSvc", strings.Title(po.Identifier))),
wix.ServiceArgs([]string{"svc", "-config", po.FlagFile}),
wix.ServiceDescription(fmt.Sprintf("The Kolide Launcher (%s)", po.Identifier)),
)
wixArgs = append(wixArgs, wix.WithService(launcherService))
}

wixTool, err := wix.New(po.Root, mainWxsContent.Bytes(), wixArgs...)
if err != nil {
return errors.Wrap(err, "making wixTool")
}
defer wixTool.Cleanup()

// Run light to compile the msi (and copy the output into our file
// handle)
// Use wix to compile into an MSI
if err := wixTool.Package(ctx, w); err != nil {
return errors.Wrap(err, "running light")
}
Expand Down
Loading