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/.
2014-06-12 01:19:52 +04:00
BUILDENV := dev
2014-12-28 21:40:10 +03:00
i f e q ( $( OS ) , w i n d o w s )
# on windows, the version is year.month.date
BUILDREV := $( shell date +%y) .$( shell date +%m) .$( shell date +%d)
BINSUFFIX := ".exe"
e l s e
# on *nix, the version is yearmonthdate+lastcommit.env
BUILDREV := $( shell date +%Y%m%d) +$( shell git log --pretty= format:'%h' -n 1) .$( BUILDENV)
BINSUFFIX := ""
e n d i f
2014-01-28 01:21:47 +04:00
2014-07-30 21:09:43 +04:00
# Supported OSes: linux darwin windows
2014-01-28 01:21:47 +04:00
# Supported ARCHes: 386 amd64
2014-12-28 21:40:10 +03:00
OS := $( shell uname -s| tr '[:upper:]' '[:lower:]' )
2014-01-28 01:21:47 +04:00
ARCH := amd64
2014-06-16 23:50:09 +04:00
i f e q ( $( ARCH ) , a m d 6 4 )
FPMARCH := x86_64
e n d i f
i f e q ( $( ARCH ) , 3 8 6 )
2014-08-21 17:10:59 +04:00
FPMARCH := i386
2014-06-16 23:50:09 +04:00
e n d i f
2014-12-28 21:40:10 +03:00
2014-01-28 01:21:47 +04:00
PREFIX := /usr/local/
DESTDIR := /
BINDIR := bin/$( OS) /$( ARCH)
2014-02-05 22:30:19 +04:00
AGTCONF := conf/mig-agent-conf.go
2014-11-24 20:50:50 +03:00
AVAILMODS := conf/available_modules.go
2014-12-28 21:40:10 +03:00
MSICONF := mig-agent-installer.wxs
2014-01-28 01:21:47 +04:00
2014-06-12 01:19:52 +04:00
GCC := gcc
2014-01-28 01:21:47 +04:00
CFLAGS :=
LDFLAGS :=
GOOPTS :=
2014-06-12 01:19:52 +04:00
GO := GOPATH = $( shell go env GOROOT) /bin:$( shell pwd ) GOOS = $( OS) GOARCH = $( ARCH) go
2014-07-30 21:09:43 +04:00
GOGETTER := GOPATH = $( shell pwd ) GOOS = $( OS) GOARCH = $( ARCH) 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-12-09 20:37:37 +03:00
all : mig -agent mig -scheduler mig -api mig -cmd mig -console 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-11-24 20:50:50 +03:00
if [ ! -r $( AVAILMODS) ] ; then echo " $( AGTCONF) configuration file is missing " ; exit 1; fi
cp $( AVAILMODS) src/mig/agent/available_modules.go
2014-01-28 01:21:47 +04:00
$( MKDIR) -p $( BINDIR)
2014-07-30 21:09:43 +04:00
$( GO) build $( GOOPTS) -o $( BINDIR) /mig-agent-$( BUILDREV) $( BINSUFFIX) $( GOLDFLAGS) mig/agent
2014-08-13 20:25:30 +04:00
ln -fs " $$ (pwd)/ $( BINDIR) /mig-agent- $( BUILDREV) $( BINSUFFIX) " " $$ (pwd)/ $( BINDIR) /mig-agent-latest "
2014-07-30 21:09:43 +04:00
[ -x " $( BINDIR) /mig-agent- $( BUILDREV) $( BINSUFFIX) " ] && echo SUCCESS && exit 0
2014-06-14 22:15:12 +04:00
mig-scheduler :
2014-01-28 01:21:47 +04:00
$( MKDIR) -p $( BINDIR)
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-06-14 22:15:12 +04:00
mig-action-generator :
2014-01-28 01:21:47 +04:00
$( MKDIR) -p $( BINDIR)
2014-11-03 21:35:50 +03:00
$( GO) build $( GOOPTS) -o $( BINDIR) /mig-action-generator $( GOLDFLAGS) mig/client/generator
2014-01-28 01:21:47 +04:00
2014-09-04 04:52:29 +04:00
filechecker-convert :
$( MKDIR) -p $( BINDIR)
$( GO) build $( GOOPTS) -o $( BINDIR) /filechecker-convertv1tov2 $( GOLDFLAGS) mig/modules/filechecker/convert
2014-06-14 22:15:12 +04:00
mig-action-verifier :
2014-02-19 00:33:25 +04:00
$( MKDIR) -p $( BINDIR)
2014-11-03 21:35:50 +03:00
$( GO) build $( GOOPTS) -o $( BINDIR) /mig-action-verifier $( GOLDFLAGS) mig/client/verifier
2014-02-19 00:33:25 +04:00
2014-06-18 07:39:07 +04:00
mig-console :
2014-11-24 20:50:50 +03:00
if [ ! -r $( AVAILMODS) ] ; then echo " $( AGTCONF) configuration file is missing " ; exit 1; fi
cp $( AVAILMODS) src/mig/client/console/available_modules.go
2014-06-18 07:39:07 +04:00
$( MKDIR) -p $( BINDIR)
2014-11-03 21:35:50 +03:00
$( GO) build $( GOOPTS) -o $( BINDIR) /mig-console $( GOLDFLAGS) mig/client/console
2014-06-18 07:39:07 +04:00
2014-11-07 17:38:18 +03:00
mig-cmd :
2014-11-24 20:50:50 +03:00
if [ ! -r $( AVAILMODS) ] ; then echo " $( AGTCONF) configuration file is missing " ; exit 1; fi
cp $( AVAILMODS) src/mig/client/cmd/available_modules.go
2014-11-07 17:38:18 +03:00
$( MKDIR) -p $( BINDIR)
2014-11-30 21:41:54 +03:00
$( GO) build $( GOOPTS) -o $( BINDIR) /mig-$( OS) $( ARCH) $( GOLDFLAGS) mig/client/cmd
ln -fs " $$ (pwd)/ $( BINDIR) /mig- $( OS) $( ARCH) " " $$ (pwd)/ $( BINDIR) /mig "
2014-11-07 17:38:18 +03:00
2014-11-08 00:20:05 +03:00
mig-agentsearch :
$( MKDIR) -p $( BINDIR)
$( GO) build $( GOOPTS) -o $( BINDIR) /mig-agentsearch $( GOLDFLAGS) mig/client/cmd/agentsearch
2015-01-02 22:13:18 +03:00
go_get_common_deps :
2014-01-28 01:21:47 +04:00
$( GOGETTER) code.google.com/p/go.crypto/openpgp
2015-01-02 22:13:18 +03:00
$( GOGETTER) code.google.com/p/gcfg
go_get_agent_deps : go_get_common_deps
2014-09-11 23:31:38 +04:00
$( GOGETTER) code.google.com/p/go.crypto/sha3
2014-01-28 01:21:47 +04:00
$( GOGETTER) github.com/streadway/amqp
2014-04-20 22:11:21 +04:00
$( GOGETTER) bitbucket.org/kardianos/osext
2014-12-22 05:45:31 +03:00
$( GOGETTER) github.com/jvehent/service-go
2014-08-22 17:52:50 +04:00
$( GOGETTER) github.com/ccding/go-stun/stun
2014-07-30 21:09:43 +04:00
i f e q ( $( OS ) , w i n d o w s )
$( GOGETTER) code.google.com/p/winsvc/eventlog
e n d i f
2015-01-02 22:13:18 +03:00
go_get_platform_deps : go_get_common_deps
$( GOGETTER) github.com/streadway/amqp
$( GOGETTER) github.com/lib/pq
$( GOGETTER) github.com/howeyc/fsnotify
$( GOGETTER) github.com/gorilla/mux
$( GOGETTER) github.com/jvehent/cljs
$( GOGETTER) camlistore.org/pkg/misc/gpgagent
$( GOGETTER) camlistore.org/pkg/misc/pinentry
go_get_client_deps : go_get_common_deps
2015-01-03 10:02:55 +03:00
$( GOGETTER) github.com/jvehent/cljs
2015-01-02 22:13:18 +03:00
$( GOGETTER) camlistore.org/pkg/misc/gpgagent
$( GOGETTER) camlistore.org/pkg/misc/pinentry
2014-09-19 18:41:03 +04:00
i f e q ( $( OS ) , d a r w i n )
2014-12-28 21:40:10 +03:00
$( GOGETTER) github.com/bobappleyard/readline
2014-09-11 23:31:38 +04:00
echo 'make sure that you have readline installed via {port,brew} install readline'
e n d i f
2014-12-28 21:40:10 +03:00
i f e q ( $( OS ) , l i n u x )
$( 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'
e n d i f
2014-01-28 01:21:47 +04:00
2015-01-02 22:13:18 +03:00
go_get_deps : go_get_common_deps go_get_agent_deps go_get_platform_deps go_get_client_deps
go_get_deps_into_system :
make GOGETTER = "go get -u" go_get_deps
2014-06-14 22:15:12 +04:00
install : 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-12-26 22:44:18 +03:00
rpm : rpm -agent rpm -scheduler
2014-01-31 05:03:49 +04:00
rpm-agent : mig -agent
# Bonus FPM options
# --rpm-digest sha512 --rpm-sign
rm -fr tmp
2014-12-26 22:49:42 +03:00
$( INSTALL) -D -m 0755 $( BINDIR) /mig-agent-$( BUILDREV) tmp/sbin/mig-agent-$( BUILDREV)
2014-12-29 21:22:55 +03:00
$( MKDIR) -p tmp/var/lib/mig
2014-07-31 01:08:48 +04:00
make agent-install-script
2014-12-26 22:44:18 +03:00
make agent-remove-script
2014-01-31 05:03:49 +04:00
fpm -C tmp -n mig-agent --license GPL --vendor mozilla --description "Mozilla InvestiGator Agent" \
2014-12-26 22:44:18 +03:00
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $( FPMARCH) -v $( BUILDREV) \
2014-12-28 02:33:07 +03:00
--after-remove tmp/agent_remove.sh --after-install tmp/agent_install.sh \
2014-12-26 22:44:18 +03:00
-s dir -t rpm .
2014-01-31 05:03:49 +04:00
2014-04-17 22:05:59 +04:00
deb-agent : mig -agent
rm -fr tmp
2014-12-26 22:44:18 +03:00
$( INSTALL) -D -m 0755 $( BINDIR) /mig-agent-$( BUILDREV) tmp/sbin/mig-agent-$( BUILDREV)
2014-12-29 21:22:55 +03:00
$( MKDIR) -p tmp/var/lib/mig
2014-07-31 01:08:48 +04:00
make agent-install-script
2014-12-26 22:44:18 +03:00
make agent-remove-script
2014-04-17 22:05:59 +04:00
fpm -C tmp -n mig-agent --license GPL --vendor mozilla --description "Mozilla InvestiGator Agent" \
2014-12-26 22:44:18 +03:00
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $( FPMARCH) -v $( BUILDREV) \
2014-12-28 02:33:07 +03:00
--after-remove tmp/agent_remove.sh --after-install tmp/agent_install.sh \
2014-12-26 22:44:18 +03:00
-s dir -t deb .
2014-04-17 22:05:59 +04:00
2014-12-29 22:06:08 +03:00
dmg-agent : mig -agent
2014-12-28 21:40:10 +03:00
i f n e q ( $( OS ) , d a r w i n )
2014-12-29 22:06:08 +03:00
echo 'you must be on MacOS and set OS=darwin on the make command line to build an OSX package'
2014-12-28 21:40:10 +03:00
e l s e
2014-06-20 02:02:21 +04:00
rm -fr tmp
2014-12-29 22:06:08 +03:00
mkdir 'tmp' 'tmp/sbin' 'tmpdmg'
2014-12-26 22:44:18 +03:00
$( INSTALL) -m 0755 $( BINDIR) /mig-agent-$( BUILDREV) tmp/sbin/mig-agent-$( BUILDREV)
2014-12-29 22:06:08 +03:00
$( MKDIR) -p 'tmp/Library/Preferences/mig/'
2014-07-31 01:08:48 +04:00
make agent-install-script
2014-12-26 22:44:18 +03:00
make agent-remove-script
2014-06-20 02:02:21 +04:00
fpm -C tmp -n mig-agent --license GPL --vendor mozilla --description "Mozilla InvestiGator Agent" \
2014-12-26 22:44:18 +03:00
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $( FPMARCH) -v $( BUILDREV) \
2014-12-26 23:36:25 +03:00
--after-install tmp/agent_install.sh \
2014-12-29 22:06:08 +03:00
-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
2014-12-28 21:40:10 +03:00
e n d i f
2014-06-20 02:02:21 +04:00
2014-07-31 01:08:48 +04:00
agent-install-script :
2014-12-28 01:12:53 +03:00
echo '#!/bin/sh' > tmp/agent_install.sh
2014-12-28 02:33:07 +03:00
echo '/sbin/mig-agent -q=shutdown; sleep 2' >> tmp/agent_remove.sh
echo 'pid=$$(/sbin/mig-agent -q=pid) && [ $$? -eq 0 ] && kill $$pid' >> tmp/agent_remove.sh
2014-12-28 01:12:53 +03:00
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
echo '/sbin/mig-agent-$(BUILDREV)' >> tmp/agent_install.sh
2014-07-31 01:08:48 +04:00
chmod 0755 tmp/agent_install.sh
2014-12-26 22:44:18 +03:00
agent-remove-script :
2014-12-28 02:33:07 +03:00
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 potentially running processes left untouched' >> tmp/agent_remove.sh
2014-12-26 22:44:18 +03:00
chmod 0755 tmp/agent_remove.sh
2014-08-04 17:24:00 +04:00
agent-cron :
mkdir -p tmp/etc/cron.d/
2014-12-26 22:44:18 +03:00
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 'MAILTO=""' >> tmp/etc/cron.d/mig-agent
2014-08-04 17:24:00 +04:00
echo '*/10 * * * * root /sbin/mig-agent -q=pid 2>&1 1>/dev/null || /sbin/mig-agent' >> tmp/etc/cron.d/mig-agent
2014-08-05 19:57:24 +04:00
chmod 0644 tmp/etc/cron.d/mig-agent
2014-08-04 17:24:00 +04:00
2014-12-28 21:40:10 +03:00
msi-agent : mig -agent
i f n e q ( $( OS ) , w i n d o w s )
echo 'you must set OS=windows on the make command line to compile a MSI package'
e l s e
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
e n d i f
2014-01-31 05:03:49 +04:00
rpm-scheduler : mig -scheduler
rm -rf tmp
2014-12-26 22:44:18 +03:00
$( INSTALL) -D -m 0755 $( BINDIR) /mig-scheduler tmp/usr/bin/mig-scheduler
$( INSTALL) -D -m 0640 conf/mig-scheduler.cfg.inc tmp/etc/mig/mig-scheduler.cfg
2014-01-31 05:03:49 +04:00
$( MKDIR) -p tmp/var/cache/mig
fpm -C tmp -n mig-scheduler --license GPL --vendor mozilla --description "Mozilla InvestiGator Scheduler" \
2014-12-26 22:44:18 +03:00
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $( FPMARCH) -v $( BUILDREV) -s dir -t rpm .
2014-01-31 05:03:49 +04:00
2014-12-26 22:44:18 +03:00
rpm-api : mig -api
2014-01-31 05:03:49 +04:00
rm -rf tmp
2014-12-26 22:44:18 +03:00
$( INSTALL) -D -m 0755 $( BINDIR) /mig-api tmp/usr/bin/mig-api
$( INSTALL) -D -m 0640 conf/mig-api.cfg.inc tmp/etc/mig/mig-api.cfg
2014-01-31 05:03:49 +04:00
$( MKDIR) -p tmp/var/cache/mig
2014-12-26 22:44:18 +03:00
fpm -C tmp -n mig-api --license GPL --vendor mozilla --description "Mozilla InvestiGator API" \
-m "Mozilla OpSec" --url http://mig.mozilla.org --architecture $( FPMARCH) -v $( BUILDREV) -s dir -t rpm .
2014-01-31 05:03:49 +04:00
2014-08-18 19:30:34 +04:00
test : mig -agent
2014-12-22 04:18:38 +03:00
$( BINDIR) /mig-agent-latest -m= file '{"searches": {"shouldmatch": {"names": ["^root"],"sizes": ["<10m"],"options": {"matchall": true},"paths": ["/etc/passwd"]},"shouldnotmatch": {"options": {"maxdepth": 1},"paths": ["/tmp"],"contents": ["should not match"]}}}'
2014-01-28 01:21:47 +04:00
2014-08-18 19:30:34 +04:00
clean-agent :
find bin/ -name mig-agent* -exec rm { } \;
rm -rf packages
rm -rf tmp
2014-08-28 22:30:48 +04:00
clean : clean -agent
rm -rf bin
rm -rf tmp
find src/ -maxdepth 1 -mindepth 1 ! -name mig -exec rm -rf { } \;
2014-09-11 07:32:25 +04:00
.PHONY : clean clean -all clean -agent doc go_get_deps_into_system mig -agent -386 mig -agent -amd 64 agent -install -script agent -cron