forked from mozilla/mig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
303 lines (262 loc) · 12.9 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# This Source Code Form is subject to the terms of the Mozilla Public
# 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/.
BUILDENV := dev
BUILDREL := 0
ifeq ($(OS),windows)
# on windows, the version is year.month.date.release
BUILDREV := $(shell date +%y).$(shell date +%m).$(shell date +%d).$(BUILDREL)
BINSUFFIX := ".exe"
else
# on *nix, the version is yearmonthdate.release+lastcommit.env
BUILDREV := $(shell date +%Y%m%d)-$(BUILDREL).$(shell git log --pretty=format:'%h' -n 1).$(BUILDENV)
BINSUFFIX := ""
endif
# Supported OSes: linux darwin windows
# Supported ARCHes: 386 amd64
OS := $(shell uname -s| tr '[:upper:]' '[:lower:]')
ARCH := amd64
ifeq ($(ARCH),amd64)
FPMARCH := x86_64
endif
ifeq ($(ARCH),386)
FPMARCH := i386
endif
PREFIX := /usr/local/
DESTDIR := /
BINDIR := bin/$(OS)/$(ARCH)
AGTCONF := conf/mig-agent-conf.go.inc
MSICONF := mig-agent-installer.wxs
GCC := gcc
CFLAGS :=
LDFLAGS :=
GOOPTS :=
GO := GOOS=$(OS) GOARCH=$(ARCH) GO15VENDOREXPERIMENT=1 go
GOGETTER := GOPATH=$(shell pwd)/.tmpdeps go get -d
GOLDFLAGS := -ldflags "-X mig.ninja/mig.Version=$(BUILDREV)"
GOCFLAGS :=
MKDIR := mkdir
INSTALL := install
all: test mig-agent mig-scheduler mig-api mig-cmd mig-console mig-runner mig-action-generator mig-action-verifier worker-agent-intel worker-compliance-item
create-bindir:
$(MKDIR) -p $(BINDIR)
mig-agent: create-bindir
echo building mig-agent for $(OS)/$(ARCH)
if [ ! -r $(AGTCONF) ]; then echo "$(AGTCONF) configuration file does not exist" ; exit 1; fi
# test if the agent configuration variable contains something different than the default value
# and if so, replace the link to the default configuration with the provided configuration
if [ $(AGTCONF) != "conf/mig-agent-conf.go.inc" ]; then rm mig-agent/configuration.go; cp $(AGTCONF) mig-agent/configuration.go; fi
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-agent-$(BUILDREV)$(BINSUFFIX) $(GOLDFLAGS) mig.ninja/mig/mig-agent
ln -fs "$$(pwd)/$(BINDIR)/mig-agent-$(BUILDREV)$(BINSUFFIX)" "$$(pwd)/$(BINDIR)/mig-agent-latest"
[ -x "$(BINDIR)/mig-agent-$(BUILDREV)$(BINSUFFIX)" ] && echo SUCCESS && exit 0
mig-scheduler: create-bindir
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-scheduler $(GOLDFLAGS) mig.ninja/mig/mig-scheduler
mig-api: create-bindir
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-api $(GOLDFLAGS) mig.ninja/mig/mig-api
mig-runner: create-bindir
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-runner $(GOLDFLAGS) mig.ninja/mig/mig-runner
mig-action-generator: create-bindir
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-action-generator $(GOLDFLAGS) mig.ninja/mig/client/mig-action-generator
mig-action-verifier: create-bindir
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-action-verifier $(GOLDFLAGS) mig.ninja/mig/client/mig-action-verifier
mig-console: create-bindir
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-console $(GOLDFLAGS) mig.ninja/mig/client/mig-console
mig-cmd: create-bindir
$(GO) build $(GOOPTS) -o $(BINDIR)/mig $(GOLDFLAGS) mig.ninja/mig/client/mig
mig-agent-search: create-bindir
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-agent-search $(GOLDFLAGS) mig.ninja/mig/client/mig-agent-search
worker-agent-verif: create-bindir
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-worker-agent-verif $(GOLDFLAGS) mig.ninja/mig/workers/mig-worker-agent-verif
worker-agent-intel: create-bindir
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-worker-agent-intel $(GOLDFLAGS) mig.ninja/mig/workers/mig-worker-agent-intel
worker-compliance-item: create-bindir
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-worker-compliance-item $(GOLDFLAGS) mig.ninja/mig/workers/mig-worker-compliance-item
go_vendor_dependencies:
GOOS="linux" $(GOGETTER) github.com/bobappleyard/readline
GOOS="darwin" $(GOGETTER) github.com/bobappleyard/readline
GOOS="windows" $(GOGETTER) github.com/golang/sys/windows/svc/eventlog
$(GOGETTER) github.com/gorilla/mux
$(GOGETTER) github.com/jvehent/cljs
$(GOGETTER) github.com/jvehent/gozdef
$(GOGETTER) github.com/jvehent/service-go
$(GOGETTER) github.com/kardianos/osext
$(GOGETTER) github.com/lib/pq
$(GOGETTER) github.com/mozilla/masche/listlibs
$(GOGETTER) github.com/mozilla/masche/memsearch
$(GOGETTER) github.com/mozilla/masche/process
$(GOGETTER) github.com/mozilla/scribe/src/scribe
# go 1.5 vendoring and submodules don't work well, so comment this deps out
# https://github.com/oschwald/geoip2-golang/issues/13
#$(GOGETTER) github.com/oschwald/geoip2-golang
$(GOGETTER) github.com/streadway/amqp
$(GOGETTER) github.com/gorhill/cronexpr
$(GOGETTER) golang.org/x/crypto/openpgp
$(GOGETTER) golang.org/x/crypto/sha3
$(GOGETTER) golang.org/x/net/icmp
$(GOGETTER) golang.org/x/net/ipv4
$(GOGETTER) golang.org/x/net/ipv6
$(GOGETTER) gopkg.in/gcfg.v1
echo 'removing .git from vendored pkg and moving them to vendor'
find .tmpdeps/src -type d -name ".git" ! -name ".gitignore" -exec rm -rf {} \; || exit 0
cp -ar .tmpdeps/src/* vendor/
rm -rf .tmpdeps
rpm: rpm-agent rpm-scheduler
rpm-agent: mig-agent
# Bonus FPM options
# --rpm-digest sha512 --rpm-sign
rm -fr tmp
$(INSTALL) -D -m 0755 $(BINDIR)/mig-agent-$(BUILDREV) tmp/sbin/mig-agent-$(BUILDREV)
$(MKDIR) -p tmp/var/lib/mig
make agent-install-script
make agent-remove-script
fpm -C tmp -n mig-agent --license GPL --vendor mozilla --description "Mozilla InvestiGator Agent" \
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $(FPMARCH) -v $(BUILDREV) \
--after-remove tmp/agent_remove.sh --after-install tmp/agent_install.sh \
-s dir -t rpm .
deb-agent: mig-agent
rm -fr tmp
$(INSTALL) -D -m 0755 $(BINDIR)/mig-agent-$(BUILDREV) tmp/sbin/mig-agent-$(BUILDREV)
$(MKDIR) -p tmp/var/lib/mig
make agent-install-script
make agent-remove-script
fpm -C tmp -n mig-agent --license GPL --vendor mozilla --description "Mozilla InvestiGator Agent" \
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $(FPMARCH) -v $(BUILDREV) \
--after-remove tmp/agent_remove.sh --after-install tmp/agent_install.sh \
-s dir -t deb .
dmg-agent: mig-agent
ifneq ($(OS),darwin)
echo 'you must be on MacOS and set OS=darwin on the make command line to build an OSX package'
else
rm -fr tmp tmpdmg
mkdir 'tmp' 'tmp/sbin' 'tmpdmg'
$(INSTALL) -m 0755 $(BINDIR)/mig-agent-$(BUILDREV) tmp/sbin/mig-agent-$(BUILDREV)
$(MKDIR) -p 'tmp/Library/Preferences/mig/'
make agent-install-script
make agent-remove-script
fpm -C tmp -n mig-agent --license GPL --vendor mozilla --description "Mozilla InvestiGator 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 -p tmpdmg/mig-agent-$(BUILDREV)-$(FPMARCH).pkg .
hdiutil makehybrid -hfs -hfs-volume-name "Mozilla InvestiGator Agent" \
-o ./mig-agent-$(BUILDREV)-$(FPMARCH).dmg tmpdmg
endif
agent-install-script:
echo '#!/bin/sh' > tmp/agent_install.sh
echo 'chmod 500 /sbin/mig-agent-$(BUILDREV)' >> tmp/agent_install.sh
echo 'chown root:root /sbin/mig-agent-$(BUILDREV)' >> tmp/agent_install.sh
echo 'rm /sbin/mig-agent; ln -s /sbin/mig-agent-$(BUILDREV) /sbin/mig-agent'>> tmp/agent_install.sh
chmod 0755 tmp/agent_install.sh
agent-remove-script:
echo '#!/bin/sh' > tmp/agent_remove.sh
echo 'for f in "/etc/cron.d/mig-agent" "/etc/init/mig-agent.conf" "/etc/init.d/mig-agent" "/etc/systemd/system/mig-agent.service"; do' >> tmp/agent_remove.sh
echo ' [ -e "$$f" ] && rm -f "$$f"' >> tmp/agent_remove.sh
echo 'done' >> tmp/agent_remove.sh
echo 'echo mig-agent removed but not killed if running' >> tmp/agent_remove.sh
chmod 0755 tmp/agent_remove.sh
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
package-linux-clients: rpm-clients deb-clients
prepare-clients-packaging: mig-cmd mig-console mig-action-generator mig-action-verifier mig-agent-search
rm -fr tmp
mkdir 'tmp'
$(INSTALL) -D -m 0755 $(BINDIR)/mig tmp/usr/local/bin/mig
$(INSTALL) -D -m 0755 $(BINDIR)/mig-console tmp/usr/local/bin/mig-console
$(INSTALL) -D -m 0755 $(BINDIR)/mig-action-generator tmp/usr/local/bin/mig-action-generator
$(INSTALL) -D -m 0755 $(BINDIR)/mig-action-verifier tmp/usr/local/bin/mig-action-verifier
$(INSTALL) -D -m 0755 $(BINDIR)/mig-agent-search tmp/usr/local/bin/mig-agent-search
rpm-clients: prepare-clients-packaging
# --rpm-sign requires installing package `rpm-sign` and configuring this macros in ~/.rpmmacros
# %_signature gpg
# %_gpg_name Julien Vehent
fpm -C tmp -n mig-clients --license GPL --vendor mozilla --description "Mozilla InvestiGator Clients" \
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $(FPMARCH) -v $(BUILDREV) \
--rpm-digest sha512 --rpm-sign \
-s dir -t rpm .
deb-clients: prepare-clients-packaging
fpm -C tmp -n mig-clients --license GPL --vendor mozilla --description "Mozilla InvestiGator Clients" \
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $(FPMARCH) -v $(BUILDREV) \
-s dir -t deb .
# require dpkg-sig, it's a perl script, take it from any debian box and copy it in your PATH
dpkg-sig -k E60892BB9BD89A69F759A1A0A3D652173B763E8F --sign jvehent -m "Julien Vehent" mig-clients_$(BUILDREV)_$(ARCH).deb
dmg-clients: mig-cmd mig-console mig-action-generator
ifneq ($(OS),darwin)
echo 'you must be on MacOS and set OS=darwin on the make command line to build an OSX package'
else
rm -fr tmp tmpdmg
mkdir -p tmp/usr/local/bin tmpdmg
$(INSTALL) -m 0755 $(BINDIR)/mig tmp/usr/local/bin/mig
$(INSTALL) -m 0755 $(BINDIR)/mig-console tmp/usr/local/bin/mig-console
$(INSTALL) -m 0755 $(BINDIR)/mig-action-generator tmp/usr/local/bin/mig-action-generator
fpm -C tmp -n mig-clients --license GPL --vendor mozilla --description "Mozilla InvestiGator Clients" \
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $(FPMARCH) -v $(BUILDREV) \
-s dir -t osxpkg --osxpkg-identifier-prefix org.mozilla.mig -p tmpdmg/mig-clients-$(BUILDREV)-$(FPMARCH).pkg .
hdiutil makehybrid -hfs -hfs-volume-name "Mozilla InvestiGator Clients" \
-o ./mig-clients-$(BUILDREV)-$(FPMARCH).dmg tmpdmg
endif
deb-server: mig-scheduler mig-api mig-runner worker-agent-intel worker-compliance-item
rm -rf tmp
# add binaries
$(INSTALL) -D -m 0755 $(BINDIR)/mig-scheduler tmp/opt/mig/bin/mig-scheduler
$(INSTALL) -D -m 0755 $(BINDIR)/mig-api tmp/opt/mig/bin/mig-api
$(INSTALL) -D -m 0755 $(BINDIR)/mig-runner tmp/opt/mig/bin/mig-runner
$(INSTALL) -D -m 0755 $(BINDIR)/mig-worker-agent-intel tmp/opt/mig/bin/mig-worker-agent-intel
$(INSTALL) -D -m 0755 $(BINDIR)/mig-worker-compliance-item tmp/opt/mig/bin/mig-worker-compliance-item
$(INSTALL) -D -m 0755 tools/list_new_agents.sh tmp/opt/mig/bin/list_new_agents.sh
# add configuration templates
$(INSTALL) -D -m 0640 conf/scheduler.cfg.inc tmp/etc/mig/scheduler.cfg
$(INSTALL) -D -m 0640 conf/api.cfg.inc tmp/etc/mig/api.cfg
$(INSTALL) -D -m 0640 conf/agent-intel-worker.cfg.inc tmp/etc/mig/agent-intel-worker.cfg
$(INSTALL) -D -m 0640 conf/compliance-item-worker.cfg.inc tmp/etc/mig/compliance-item-worker.cfg
# add upstart configs
$(INSTALL) -D -m 0640 conf/upstart/mig-scheduler.conf tmp/etc/init/mig-scheduler.conf
$(INSTALL) -D -m 0640 conf/upstart/mig-api.conf tmp/etc/init/mig-api.conf
$(INSTALL) -D -m 0640 conf/upstart/mig-compliance-item-worker.conf tmp/etc/init/mig-compliance-item-worker.conf
$(INSTALL) -D -m 0640 conf/upstart/mig-agent-intel-worker.conf tmp/etc/init/mig-agent-intel-worker.conf
$(MKDIR) -p tmp/var/cache/mig
fpm -C tmp -n mig-server --license GPL --vendor mozilla --description "Mozilla InvestiGator Server" \
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $(FPMARCH) -v $(BUILDREV) -s dir -t deb .
doc:
make -C doc doc
test: test-modules
$(GO) test mig.ninja/mig/mig-agent/...
$(GO) test mig.ninja/mig/mig-scheduler/...
$(GO) test mig.ninja/mig/mig-api/...
$(GO) test mig.ninja/mig/mig-runner/...
$(GO) test mig.ninja/mig/client/...
$(GO) test mig.ninja/mig/database/...
$(GO) test mig.ninja/mig/workers/...
$(GO) test mig.ninja/mig
test-modules:
# test all modules
$(GO) test mig.ninja/mig/modules/...
clean-agent:
if [ -d bin/ ]; then \
find bin/ -name 'mig-agent*' -exec rm {} \;; \
fi
rm -rf packages
rm -rf tmp
vet:
$(GO) vet mig.ninja/mig/mig-agent/...
$(GO) vet mig.ninja/mig/mig-scheduler/...
$(GO) vet mig.ninja/mig/mig-api/...
$(GO) vet mig.ninja/mig/mig-runner/...
$(GO) vet mig.ninja/mig/client/...
$(GO) vet mig.ninja/mig/modules/...
$(GO) vet mig.ninja/mig/database/...
$(GO) vet mig.ninja/mig/workers/...
$(GO) vet mig.ninja/mig
clean: clean-agent
rm -rf bin
rm -rf tmp
rm -rf .builddir
.PHONY: clean clean-agent doc agent-install-script agent-remove-script