Skip to content
This repository has been archived by the owner on Sep 14, 2019. It is now read-only.

Commit

Permalink
[medium] Windows MSI packaging of the agent
Browse files Browse the repository at this point in the history
  • Loading branch information
jvehent committed Dec 28, 2014
1 parent 176e49e commit e6ed8a4
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bin/*
*.cfg
conf/*
!conf/*.inc
!conf/mig-agent-installer.wxs
src/mig/agent/configuration.go
src/mig/*/available_modules.go
src/mig/*/*/available_modules.go
Expand Down
46 changes: 36 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

BUILDREF := $(shell git log --pretty=format:'%h' -n 1)
BUILDDATE := $(shell date +%Y%m%d)
BUILDENV := dev
BUILDREV := $(BUILDDATE)+$(BUILDREF).$(BUILDENV)
ifeq ($(OS),windows)
# on windows, the version is year.month.date
BUILDREV := $(shell date +%y).$(shell date +%m).$(shell date +%d)
BINSUFFIX := ".exe"
else
# on *nix, the version is yearmonthdate+lastcommit.env
BUILDREV := $(shell date +%Y%m%d)+$(shell git log --pretty=format:'%h' -n 1).$(BUILDENV)
BINSUFFIX := ""
endif

# Supported OSes: linux darwin windows
# Supported ARCHes: 386 amd64
OS := linux
OS := $(shell uname -s| tr '[:upper:]' '[:lower:]')
ARCH := amd64

ifeq ($(ARCH),amd64)
Expand All @@ -18,16 +24,13 @@ endif
ifeq ($(ARCH),386)
FPMARCH := i386
endif
ifeq ($(OS),windows)
BINSUFFIX := ".exe"
else
BINSUFFIX := ""
endif

PREFIX := /usr/local/
DESTDIR := /
BINDIR := bin/$(OS)/$(ARCH)
AGTCONF := conf/mig-agent-conf.go
AVAILMODS := conf/available_modules.go
MSICONF := mig-agent-installer.wxs

GCC := gcc
CFLAGS :=
Expand Down Expand Up @@ -111,10 +114,16 @@ go_get_deps:
ifeq ($(OS),windows)
$(GOGETTER) code.google.com/p/winsvc/eventlog
endif
$(GOGETTER) github.com/bobappleyard/readline
ifeq ($(OS),darwin)
$(GOGETTER) github.com/bobappleyard/readline
echo 'make sure that you have readline installed via {port,brew} install readline'
endif
ifeq ($(OS),linux)
$(GOGETTER) github.com/bobappleyard/readline
echo 'make sure that you have readline installed via:'
echo '* yum install readline-devel'
echo '* apt-get install libreadline-dev'
endif

install: mig-agent mig-scheduler
$(INSTALL) -D -m 0755 $(BINDIR)/mig-agent $(DESTDIR)$(PREFIX)/sbin/mig-agent
Expand Down Expand Up @@ -150,6 +159,9 @@ deb-agent: mig-agent
-s dir -t deb .

osxpkg-agent: mig-agent
ifneq ($(OS),darwin)
echo 'you must set OS=darwin on the make command line to compile an OSX package'
else
rm -fr tmp
mkdir 'tmp' 'tmp/sbin'
$(INSTALL) -m 0755 $(BINDIR)/mig-agent-$(BUILDREV) tmp/sbin/mig-agent-$(BUILDREV)
Expand All @@ -160,6 +172,7 @@ osxpkg-agent: mig-agent
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $(FPMARCH) -v $(BUILDREV) \
--after-install tmp/agent_install.sh \
-s dir -t osxpkg --osxpkg-identifier-prefix org.mozilla.mig .
endif

agent-install-script:
echo '#!/bin/sh' > tmp/agent_install.sh
Expand Down Expand Up @@ -187,6 +200,19 @@ agent-cron:
echo '*/10 * * * * root /sbin/mig-agent -q=pid 2>&1 1>/dev/null || /sbin/mig-agent' >> tmp/etc/cron.d/mig-agent
chmod 0644 tmp/etc/cron.d/mig-agent

msi-agent: mig-agent
ifneq ($(OS),windows)
echo 'you must set OS=windows on the make command line to compile a MSI package'
else
rm -fr tmp
mkdir 'tmp'
$(INSTALL) -m 0755 $(BINDIR)/mig-agent-$(BUILDREV).exe tmp/mig-agent-$(BUILDREV).exe
cp conf/$(MSICONF) tmp/
sed -i "s/REPLACE_WITH_MIG_AGENT_VERSION/$(BUILDREV)/" tmp/$(MSICONF)
wixl tmp/mig-agent-installer.wxs
cp tmp/mig-agent-installer.msi mig-agent-$(BUILDREV).msi
endif

rpm-scheduler: mig-scheduler
rm -rf tmp
$(INSTALL) -D -m 0755 $(BINDIR)/mig-scheduler tmp/usr/bin/mig-scheduler
Expand Down
62 changes: 62 additions & 0 deletions conf/mig-agent-installer.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version='1.0' encoding='windows-1252'?>
<?define ProductVersion = "REPLACE_WITH_MIG_AGENT_VERSION"?>
<?define ProductUpgradeCode = "00e305bd-5758-4c13-b3da-80cda1c5517e"?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>

<Product Name='Mozilla InvestiGator Agent'
Version='$(var.ProductVersion)'
Id='4a53b243-8405-4a1f-a85a-05cd21428206'
UpgradeCode='$(var.ProductUpgradeCode)'
Language='1033'
Manufacturer='Mozilla'>

<Package Comments='MIG Agent' InstallerVersion='100' Compressed='yes'/>

<Media Id='1' Cabinet='product.cab' EmbedCab='yes' />

<Property Id="ARPHELPLINK" Value="http://mig.mozilla.org"/>
<Property Id="ARPURLINFOABOUT" Value="http://mig.mozilla.org"/>
<Property Id="ARPNOREPAIR" Value="1"/>
<Property Id="ARPNOMODIFY" Value="1"/>

<Upgrade Id="$(var.ProductUpgradeCode)">
<UpgradeVersion Minimum="$(var.ProductVersion)"
OnlyDetect="yes"
Property="NEWERVERSIONDETECTED"/>
<UpgradeVersion Minimum="00000000-0"
Maximum="$(var.ProductVersion)"
IncludeMinimum="yes"
IncludeMaximum="no"
Property="OLDERVERSIONBEINGUPGRADED"/>
</Upgrade>
<Condition Message="A newer version of this software is already installed.">NOT NEWERVERSIONDETECTED</Condition>

<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='ProgramFiles64Folder'>
<Directory Id='INSTALLDIR' Name='mig'>
<Component Id='MainExecutable' Guid='9525c416-04b8-4bed-9567-ff6fb7dd4ea9'>
<File Name='mig-agent-$(var.ProductVersion).exe'
Id='25ac5e4f-3f70-4e21-9389-7e5fcd6fde9d'
DiskId='1'
Source='mig-agent-$(var.ProductVersion).exe'
KeyPath='yes'/>
</Component>
</Directory>
</Directory>
</Directory>

<Feature Id='Complete' Level='1'>
<ComponentRef Id='MainExecutable' />
</Feature>
<!--
<Binary Id="MIGAgent" SourceFile="mig-agent-$(var.ProductVersion).exe" />
<CustomAction Id='ExecMigAgent'
Execute='deferred'
BinaryKey="MIGAgent"
Return='ignore'/>
<InstallExecuteSequence>
<Custom Action='ExecMigAgent' Before="InstallFinalize"/>
</InstallExecuteSequence>
-->
</Product>
</Wix>
2 changes: 1 addition & 1 deletion src/mig/agent/env_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@ exit:
}

func getRunDir() string {
return `C:\Windows\`
return `C:\Program Files\mig\`
}
2 changes: 1 addition & 1 deletion src/mig/modules/agentdestroy/agentdestroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (r Runner) Run(Args []byte) string {
return r.buildResults()
}
case "windows":
targetExecutable = fmt.Sprintf("C:/Windows/mig-agent-%s.exe", r.Parameters.Version)
targetExecutable = fmt.Sprintf("C:\\Program Files\\mig\\mig-agent-%s.exe", r.Parameters.Version)
default:
r.Results.Errors = append(r.Results.Errors, fmt.Sprintf("'%s' isn't a supported OS", runtime.GOOS))
return r.buildResults()
Expand Down
4 changes: 2 additions & 2 deletions src/mig/modules/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ func moveBinary(binPath, version string) (linkloc string, err error) {
target = fmt.Sprintf("/sbin/mig-agent-%s", version)
linkloc = "/sbin/mig-agent"
case "windows":
target = fmt.Sprintf("C:/Windows/mig-agent-%s.exe", version)
linkloc = "C:/Windows/mig-agent.exe"
target = fmt.Sprintf("C:\\Program Files\\mig\\mig-agent-%s.exe", version)
linkloc = "C:\\Program Files\\mig\\mig-agent.exe"
default:
err = fmt.Errorf("'%s' isn't a supported OS", runtime.GOOS)
return
Expand Down

0 comments on commit e6ed8a4

Please sign in to comment.