2014-01-28 01:21:47 +04:00
# 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)
BUILDREV := $( BUILDREF) -$( BUILDDATE)
# Supported OSes: linux darwin freebsd windows
# Supported ARCHes: 386 amd64
2014-05-14 04:21:17 +04:00
OS := linux
2014-01-28 01:21:47 +04:00
ARCH := amd64
PREFIX := /usr/local/
DESTDIR := /
GPGMEDIR := src/mig/pgp/sign
BINDIR := bin/$( OS) /$( ARCH)
2014-02-05 22:30:19 +04:00
AGTCONF := conf/mig-agent-conf.go
2014-01-28 01:21:47 +04:00
2014-05-14 04:21:17 +04:00
GCC := gcc
2014-01-28 01:21:47 +04:00
CFLAGS :=
LDFLAGS :=
GOOPTS :=
2014-05-14 04:21:17 +04:00
GO := GOPATH = $( shell go env GOROOT) /bin:$( shell pwd ) GOOS = $( OS) GOARCH = $( ARCH) go
2014-02-05 22:30:19 +04:00
GOGETTER := GOPATH = $( shell pwd ) go get -u
2014-01-28 01:21:47 +04:00
GOLDFLAGS := -ldflags " -X main.version $( BUILDREV) "
GOCFLAGS :=
MKDIR := mkdir
INSTALL := install
2014-04-17 22:05:59 +04:00
2014-02-19 00:33:25 +04:00
all : mig -agent mig -scheduler mig -action -generator mig -action -verifier
2014-01-28 01:21:47 +04:00
2014-01-29 09:07:51 +04:00
mig-agent :
2014-04-25 20:53:41 +04:00
echo building mig-agent for $( OS) /$( ARCH)
2014-02-05 20:10:23 +04:00
if [ ! -r $( AGTCONF) ] ; then echo " $( AGTCONF) configuration file is missing " ; exit 1; fi
cp $( AGTCONF) src/mig/agent/configuration.go
2014-01-28 01:21:47 +04:00
$( MKDIR) -p $( BINDIR)
2014-04-18 21:38:51 +04:00
$( GO) build $( GOOPTS) -o $( BINDIR) /mig-agent-$( BUILDREV) $( GOLDFLAGS) mig/agent
2014-04-25 20:53:41 +04:00
[ -x $( BINDIR) /mig-agent-$( BUILDREV) ] && echo SUCCESS && exit 0
2014-04-25 21:26:08 +04:00
mig-agent-all : mig -agent -386 mig -agent -amd 64
mig-agent-386 :
2014-04-25 21:47:27 +04:00
make OS = linux ARCH = 386 mig-agent
make OS = darwin ARCH = 386 mig-agent
2014-04-25 21:26:08 +04:00
mig-agent-amd64 :
2014-04-25 21:47:27 +04:00
make OS = linux ARCH = amd64 mig-agent
make OS = darwin ARCH = amd64 mig-agent
2014-01-28 01:21:47 +04:00
2014-05-01 16:11:04 +04:00
mig-scheduler : gpgme
2014-01-28 01:21:47 +04:00
$( MKDIR) -p $( BINDIR)
2014-05-01 16:11:04 +04:00
ln -sf src/mig/pgp/sign/libmig_gpgme.a ./
2014-01-29 09:07:51 +04:00
$( GO) build $( GOOPTS) -o $( BINDIR) /mig-scheduler $( GOLDFLAGS) mig/scheduler
2014-01-28 01:21:47 +04:00
2014-02-11 21:06:20 +04:00
mig-api :
$( MKDIR) -p $( BINDIR)
$( GO) build $( GOOPTS) -o $( BINDIR) /mig-api $( GOLDFLAGS) mig/api
2014-01-29 19:38:36 +04:00
mig-action-generator : gpgme
2014-01-28 01:21:47 +04:00
$( MKDIR) -p $( BINDIR)
# XXX this could be nicer
2014-01-29 19:38:36 +04:00
ln -sf src/mig/pgp/sign/libmig_gpgme.a ./
2014-02-11 21:06:20 +04:00
$( GO) build $( GOOPTS) -o $( BINDIR) /mig-action-generator $( GOLDFLAGS) mig/clients/generator
2014-01-28 01:21:47 +04:00
2014-02-19 00:33:25 +04:00
mig-action-verifier : gpgme
$( MKDIR) -p $( BINDIR)
$( GO) build $( GOOPTS) -o $( BINDIR) /mig-action-verifier $( GOLDFLAGS) mig/clients/verifier
2014-04-12 00:53:53 +04:00
go_get_deps_into_system :
2014-04-13 00:38:48 +04:00
make GOGETTER = "go get -u" go_get_deps
2014-02-19 00:33:25 +04:00
2014-01-28 01:21:47 +04:00
go_get_deps :
$( GOGETTER) code.google.com/p/go.crypto/openpgp
$( GOGETTER) github.com/streadway/amqp
2014-05-14 04:15:32 +04:00
$( GOGETTER) github.com/lib/pq
2014-01-28 01:21:47 +04:00
$( GOGETTER) github.com/howeyc/fsnotify
$( GOGETTER) code.google.com/p/gcfg
2014-02-11 21:06:20 +04:00
$( GOGETTER) github.com/gorilla/mux
2014-02-17 17:56:40 +04:00
$( GOGETTER) github.com/jvehent/cljs
2014-04-20 22:11:21 +04:00
$( GOGETTER) bitbucket.org/kardianos/osext
2014-05-14 04:15:32 +04:00
$( GOGETTER) bitbucket.org/kardianos/service
2014-01-28 01:21:47 +04:00
2014-01-29 09:07:51 +04:00
install : gpgme mig -agent mig -scheduler
2014-01-31 05:03:49 +04:00
$( 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
2014-01-31 04:50:52 +04:00
$( MKDIR) -p $( DESTDIR) $( PREFIX) /var/cache/mig
2014-01-28 01:21:47 +04:00
2014-01-31 05:03:49 +04:00
rpm : rpm -agent rpm -scheduler rpm -utils
rpm-agent : mig -agent
# Bonus FPM options
# --rpm-digest sha512 --rpm-sign
rm -fr tmp
2014-04-18 21:38:51 +04:00
$( INSTALL) -D -m 0755 $( BINDIR) /mig-agent-$( BUILDREV) tmp/sbin/mig-agent-$( BUILDREV)
2014-01-31 05:03:49 +04:00
$( MKDIR) -p tmp/var/cache/mig
2014-04-17 22:05:59 +04:00
# Agent auto install startup scripts, so we just need to execute it once as priviliged user
echo -en " #!/bin/sh\nrm /sbin/mig-agent\nln -s /sbin/mig-agent- $( BUILDREV) /sbin/mig-agent\n/sbin/mig-agent " > tmp/agent_install.sh
2014-02-07 23:21:08 +04:00
chmod 0755 tmp/agent_install.sh
2014-01-31 05:03:49 +04:00
fpm -C tmp -n mig-agent --license GPL --vendor mozilla --description "Mozilla InvestiGator Agent" \
2014-02-07 23:21:08 +04:00
--url https://github.com/mozilla/mig --after-install tmp/agent_install.sh \
2014-01-31 05:03:49 +04:00
-s dir -t rpm .
2014-04-17 22:05:59 +04:00
deb-agent : mig -agent
# Bonus FPM options
# --rpm-digest sha512 --rpm-sign
rm -fr tmp
2014-04-18 21:38:51 +04:00
$( INSTALL) -D -m 0755 $( BINDIR) /mig-agent-$( BUILDREV) tmp/sbin/mig-agent-$( BUILDREV)
2014-04-17 22:05:59 +04:00
$( MKDIR) -p tmp/var/cache/mig
# Agent auto install startup scripts, so we just need to execute it once as priviliged user
echo -en " #!/bin/sh\nrm /sbin/mig-agent\nln -s /sbin/mig-agent- $( BUILDREV) /sbin/mig-agent\n/sbin/mig-agent " > tmp/agent_install.sh
chmod 0755 tmp/agent_install.sh
fpm -C tmp -n mig-agent --license GPL --vendor mozilla --description "Mozilla InvestiGator Agent" \
--url https://github.com/mozilla/mig --after-install tmp/agent_install.sh \
-s dir -t deb .
2014-01-31 05:03:49 +04:00
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" \
2014-02-03 20:13:28 +04:00
--url https://github.com/mozilla/mig \
2014-01-31 05:03:49 +04:00
-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" \
2014-02-03 20:13:28 +04:00
--url https://github.com/mozilla/mig \
2014-01-31 05:03:49 +04:00
-s dir -t rpm .
2014-02-05 19:42:27 +04:00
gpgme :
2014-01-28 01:21:47 +04:00
make -C $( GPGMEDIR)
2014-01-29 09:07:51 +04:00
tests : mig -agent
2014-02-07 18:14:30 +04:00
$( BINDIR) /mig-agent -m= filechecker '{"/etc/passwd":{"regex":{"this is an arbitrary string to describe this check":["^ulfrhasbeenhacked", "^rootkit.+/sbin/nologin"],"another arbitrary string":["iamaregex[0-9]"]}}}' > /dev/null
2014-01-31 04:43:55 +04:00
$( BINDIR) /mig-agent -m= filechecker -i= checks/policy_system_auditd_exec.json
2014-01-28 01:21:47 +04:00
clean :
make -C $( GPGMEDIR) clean
rm -f libmig_gpgme.a
rm -rf bin
2014-01-31 05:03:49 +04:00
rm -rf tmp
2014-02-11 02:50:49 +04:00
rm *.rpm
2014-04-19 03:01:14 +04:00
rm *.deb
2014-02-07 18:14:05 +04:00
find src/ -maxdepth 1 -mindepth 1 ! -name mig -exec rm -rf { } \;
2014-01-28 01:21:47 +04:00
clean-all : clean
rm -rf pkg
2014-04-25 21:26:08 +04:00
.PHONY : clean clean -all gpgme go_get_deps_into_system mig -agent -386 mig -agent -amd 64