forked from mozilla/mig
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
200 lines (171 loc) · 7.11 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
# 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/.
BUILDREF := $(shell git log --pretty=format:'%h' -n 1)
BUILDDATE := $(shell date +%Y%m%d%H%M)
BUILDENV := dev
BUILDREV := $(BUILDDATE)+$(BUILDREF).$(BUILDENV)
# Supported OSes: linux darwin windows
# Supported ARCHes: 386 amd64
OS := linux
ARCH := amd64
ifeq ($(ARCH),amd64)
FPMARCH := x86_64
endif
ifeq ($(ARCH),386)
FPMARCH := i686
endif
ifeq ($(OS),windows)
BINSUFFIX := ".exe"
else
BINSUFFIX := ""
endif
PREFIX := /usr/local/
DESTDIR := /
GPGMEDIR := src/mig/pgp/sign
BINDIR := bin/$(OS)/$(ARCH)
AGTCONF := conf/mig-agent-conf.go
GCC := gcc
CFLAGS :=
LDFLAGS :=
GOOPTS :=
GO := GOPATH=$(shell go env GOROOT)/bin:$(shell pwd) GOOS=$(OS) GOARCH=$(ARCH) go
GOGETTER := GOPATH=$(shell pwd) GOOS=$(OS) GOARCH=$(ARCH) go get -u
GOLDFLAGS := -ldflags "-X main.version $(BUILDREV)"
GOCFLAGS :=
MKDIR := mkdir
INSTALL := install
all: mig-agent mig-scheduler mig-action-generator mig-action-verifier
mig-agent:
echo building mig-agent for $(OS)/$(ARCH)
if [ ! -r $(AGTCONF) ]; then echo "$(AGTCONF) configuration file is missing" ; exit 1; fi
cp $(AGTCONF) src/mig/agent/configuration.go
$(MKDIR) -p $(BINDIR)
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-agent-$(BUILDREV)$(BINSUFFIX) $(GOLDFLAGS) 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-agent-all: mig-agent-386 mig-agent-amd64
#
#mig-agent-386:
# make OS=linux ARCH=386 mig-agent
# make OS=darwin ARCH=386 mig-agent
# make OS=windows ARCH=386 mig-agent
#
#mig-agent-amd64:
# make OS=linux ARCH=amd64 mig-agent
# make OS=darwin ARCH=amd64 mig-agent
# make OS=windows ARCH=amd64 mig-agent
mig-scheduler:
$(MKDIR) -p $(BINDIR)
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-scheduler $(GOLDFLAGS) mig/scheduler
mig-api:
$(MKDIR) -p $(BINDIR)
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-api $(GOLDFLAGS) mig/api
mig-action-generator:
$(MKDIR) -p $(BINDIR)
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-action-generator $(GOLDFLAGS) mig/clients/generator
mig-action-verifier:
$(MKDIR) -p $(BINDIR)
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-action-verifier $(GOLDFLAGS) mig/clients/verifier
mig-console:
$(MKDIR) -p $(BINDIR)
$(GO) build $(GOOPTS) -o $(BINDIR)/mig-console $(GOLDFLAGS) mig/clients/console
go_get_deps_into_system:
make GOGETTER="go get -u" go_get_deps
go_get_deps:
$(GOGETTER) code.google.com/p/go.crypto/openpgp
$(GOGETTER) github.com/streadway/amqp
$(GOGETTER) github.com/lib/pq
$(GOGETTER) github.com/howeyc/fsnotify
$(GOGETTER) code.google.com/p/gcfg
$(GOGETTER) github.com/gorilla/mux
$(GOGETTER) github.com/jvehent/cljs
$(GOGETTER) bitbucket.org/kardianos/osext
$(GOGETTER) bitbucket.org/kardianos/service
$(GOGETTER) camlistore.org/pkg/misc/gpgagent
$(GOGETTER) camlistore.org/pkg/misc/pinentry
$(GOGETTER) github.com/bobappleyard/readline
ifeq ($(OS),windows)
$(GOGETTER) code.google.com/p/winsvc/eventlog
endif
install: mig-agent mig-scheduler
$(INSTALL) -D -m 0755 $(BINDIR)/mig-agent $(DESTDIR)$(PREFIX)/sbin/mig-agent
$(INSTALL) -D -m 0755 $(BINDIR)/mig-scheduler $(DESTDIR)$(PREFIX)/sbin/mig-scheduler
$(INSTALL) -D -m 0755 $(BINDIR)/mig_action-generator $(DESTDIR)$(PREFIX)/bin/mig_action-generator
$(INSTALL) -D -m 0640 mig.cfg $(DESTDIR)$(PREFIX)/etc/mig/mig.cfg
$(MKDIR) -p $(DESTDIR)$(PREFIX)/var/cache/mig
rpm: rpm-agent rpm-scheduler rpm-utils
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-$(BUILDENV)
$(MKDIR) -p tmp/var/cache/mig
make agent-install-script
#make agent-cron
fpm -C tmp -n mig-agent --license GPL --vendor mozilla --description "Mozilla InvestiGator Agent" \
-m "Mozilla OpSec" --url https://github.com/mozilla/mig --after-install tmp/agent_install.sh \
--architecture $(FPMARCH) -v $(BUILDREV) -s dir -t rpm .
deb-agent: mig-agent
rm -fr tmp
$(INSTALL) -D -m 0755 $(BINDIR)/mig-agent-$(BUILDREV) tmp/sbin/mig-agent-$(BUILDENV)
$(MKDIR) -p tmp/var/cache/mig
make agent-install-script
#make agent-cron
fpm -C tmp -n mig-agent --license GPL --vendor mozilla --description "Mozilla InvestiGator Agent" \
-m "Mozilla OpSec" --url https://github.com/mozilla/mig --after-install tmp/agent_install.sh \
--architecture $(FPMARCH) -v $(BUILDREV) -s dir -t deb .
osxpkg-agent: mig-agent
rm -fr tmp
mkdir 'tmp' 'tmp/sbin'
$(INSTALL) -m 0755 $(BINDIR)/mig-agent-$(BUILDREV) tmp/sbin/mig-agent-$(BUILDENV)
$(MKDIR) -p tmp/var/cache/mig
make agent-install-script
#make agent-cron
fpm -C tmp -n mig-agent --license GPL --vendor mozilla --description "Mozilla InvestiGator Agent" \
-m "Mozilla OpSec" --url https://github.com/mozilla/mig --after-install tmp/agent_install.sh \
--architecture $(FPMARCH) -v $(BUILDREV) -s dir -t osxpkg --osxpkg-identifier-prefix org.mozilla.mig .
agent-install-script:
echo '#!/bin/sh' > tmp/agent_install.sh
echo 'chmod 500 /sbin/mig-agent-$(BUILDENV)' >> tmp/agent_install.sh
echo 'chown root:root /sbin/mig-agent-$(BUILDENV)' >> tmp/agent_install.sh
echo 'rm /sbin/mig-agent; ln -s /sbin/mig-agent-$(BUILDENV) /sbin/mig-agent' >> tmp/agent_install.sh
echo '/sbin/mig-agent -q=pid 2>&1 1>/dev/null && kill $$(/sbin/mig-agent -q=pid)' >> tmp/agent_install.sh
echo '/sbin/mig-agent-$(BUILDENV)' >> tmp/agent_install.sh
chmod 0755 tmp/agent_install.sh
agent-cron:
mkdir -p tmp/etc/cron.d/
echo 'PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin"' > tmp/etc/cron.d/mig-agent
echo 'SHELL=/bin/bash' >> tmp/etc/cron.d/mig-agent
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
rpm-scheduler: mig-scheduler
rm -rf tmp
$(INSTALL) -D -m 0755 $(BINDIR)/mig-scheduler tmp/sbin/mig-scheduler
$(INSTALL) -D -m 0640 mig.cfg tmp/etc/mig/mig.cfg
$(MKDIR) -p tmp/var/cache/mig
fpm -C tmp -n mig-scheduler --license GPL --vendor mozilla --description "Mozilla InvestiGator Scheduler" \
-m "Mozilla OpSec" --url https://github.com/mozilla/mig \
-s dir -t rpm .
rpm-utils: mig-action-generator
rm -rf tmp
$(INSTALL) -D -m 0755 $(BINDIR)/mig-scheduler tmp/bin/mig-action-generator
$(MKDIR) -p tmp/var/cache/mig
fpm -C tmp -n mig-utils --license GPL --vendor mozilla --description "Mozilla InvestiGator Utilities" \
-m "Mozilla OpSec" --url https://github.com/mozilla/mig \
-s dir -t rpm .
test: mig-agent
$(BINDIR)/mig-agent-latest -m=filechecker '{"/etc/passwd":{"regex":{"this is an arbitrary string to describe this check":["^ulfrhasbeenhacked", "^rootkit.+/sbin/nologin"],"another arbitrary string":["iamaregex[0-9]"]}}}'
clean:
rm -rf bin
rm -rf tmp
rm *.rpm
rm *.deb
find src/ -maxdepth 1 -mindepth 1 ! -name mig -exec rm -rf {} \;
clean-all: clean
rm -rf packages
clean-agent:
find bin/ -name mig-agent* -exec rm {} \;
rm -rf packages
rm -rf tmp
.PHONY: clean clean-all clean-agent go_get_deps_into_system mig-agent-386 mig-agent-amd64 agent-install-script agent-cron