GNUmakefile.in 4.71 KB
Newer Older
1
#
2
# Copyright (c) 2005, 2006, 2007, 2010 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
22 23 24 25 26 27 28 29 30
#
# This is the Emulab specific makefile.
#

SRCDIR          = @srcdir@
TESTBED_SRCDIR  = @top_srcdir@
OBJDIR          = ../..
SUBDIR          = sensors/nfstrace

31 32
NFSTRACESUPPORT = @NFSTRACESUPPORT@

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
include $(OBJDIR)/Makeconf

all: nfstrace.proxy nfsdump2db nfsdump nfstrace.init

include $(TESTBED_SRCDIR)/GNUmakerules

#
# Install to the ops directory.
#
PREFIX=$(INSTALL_DIR)/opsdir
INSTALL_ETC=$(PREFIX)/etc
INSTALL_INITD=$(PREFIX)/etc/rc.d
INSTALL_SBIN=$(PREFIX)/sbin
INSTALL_MAN=$(PREFIX)/man

PW=/usr/sbin/pw
49 50
NFSTRACE_HOME=/var/nfstrace
NFSTRACE_DBDIR=/var/db/nfstrace
51

52 53 54
nfsdump:
	cd nfsdump2 && $(MAKE)
	cp nfsdump2/nfsdump2/nfsdump nfsdump
55

56
client client-install control-install:
57

58 59 60 61
$(NFSTRACE_HOME):
	sudo mkdir -m 0750 $(NFSTRACE_HOME)

add-nfstrace-user: $(NFSTRACE_HOME)
62
	@if ! id nfstrace > /dev/null 2>&1; then \
63
		sudo $(PW) useradd nfstrace -d $(NFSTRACE_HOME) \
64 65 66
			-s /sbin/nologin -u 50,200 \
			-c "NFS Tracing Daemon"; \
	fi
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
	@if ! id -Gn mysql | grep nfstrace > /dev/null 2>&1; then \
		sudo $(PW) usermod -n mysql -G "`id -Gn mysql` nfstrace"; \
	fi
	sudo chown nfstrace $(NFSTRACE_HOME)
	sudo chgrp wheel $(NFSTRACE_HOME)
	sudo chgrp nfstrace /dev/bpf0
	sudo chmod g+r /dev/bpf0

$(NFSTRACE_DBDIR):
	sudo mkdir -m 0750 -p $@
	sudo chown nfstrace $@
	sudo chgrp nfstrace $@

$(NFSTRACE_HOME)/dbpass:
	head -c 32 /dev/urandom | md5 -q | head -c 8 > $@
	sudo chown nfstrace $@
	sudo chgrp wheel $@
	sudo chmod o-r $@
	@if test ! -s $@; then \
		echo "error: generated empty password..."; \
		rm $@; \
		exit 1; \
89
	fi
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

$(NFSTRACE_HOME)/.my.cnf: $(NFSTRACE_HOME)/dbpass
	echo "[client]" > $@
	echo "user=nfstrace" >> $@
	echo "password=`cat $(NFSTRACE_HOME)/dbpass`" >> $@
	echo "[mysqldump]" >> $@
	echo "user=nfstrace" >> $@
	echo "password=`cat $(NFSTRACE_HOME)/dbpass`" >> $@
	sudo chown nfstrace $@
	sudo chgrp wheel $@
	sudo chmod o-r $@

# XXX Needs to be updated to properly create the DB and user.
create-db: $(NFSTRACE_HOME)/.my.cnf $(NFSTRACE_DBDIR)
	@if ! id mysql > /dev/null 2>&1; then \
		:; \
	elif sudo -u nfstrace -H mysqldump -d nfsdb > nfsdb-dump.sql; then \
		perl $(TESTBED_SRCDIR)/utils/schemadiff nfsdb-dump.sql \
			$(SRCDIR)/nfsdb-create.sql > nfsdb.diff; \
		if test -s nfsdb.diff; then \
			echo "error: nfsdb is out of sync"; \
			cat nfsdb.diff; \
			exit 1; \
		fi \
	else \
		echo "create database nfsdb" | sudo -u root mysql; \
		sudo -u nfstrace -H mysql nfsdb < $(SRCDIR)/nfsdb-create.sql; \
117
	fi
118 119 120 121 122 123

ifeq ($(NFSTRACESUPPORT),1)
fs-install: all add-nfstrace-user create-db
	-mkdir -p $(INSTALL_DIR)/sbin
	-mkdir -p $(INSTALL_DIR)/etc
	-mkdir -p $(INSTALL_DIR)/etc/rc.d
124 125 126 127
	$(INSTALL) -m 0755 nfsdump $(DESTDIR)$(INSTALL_SBINDIR)
	$(INSTALL) -m 0755 $(SRCDIR)/nfsdump2db $(DESTDIR)$(INSTALL_SBINDIR)
	$(INSTALL) -m 0755 $(SRCDIR)/nfstrace.proxy $(DESTDIR)$(INSTALL_SBINDIR)
	$(INSTALL) -m 0755 nfstrace.init $(INSTALL_DIR)/etc/rc.d/nfstrace
128 129 130 131 132 133 134 135
	-mkdir -p $(INSTALL_DIR)/man/man8
	$(INSTALL) -m 0644 $(SRCDIR)/nfstrace.proxy.8 \
		$(INSTALL_DIR)/man/man8/nfstrace.proxy.8
	$(INSTALL) -m 0644 $(SRCDIR)/nfsdump2db.8 \
		$(INSTALL_DIR)/man/man8/nfsdump2db.8
	-mkdir -p $(INSTALL_DIR)/man/man7
	$(INSTALL) -m 0644 $(SRCDIR)/nfstrace.7 \
		$(INSTALL_DIR)/man/man7/nfstrace.7
136 137 138 139 140

install: all
	$(INSTALL) -m 0755 nfsdump $(DESTDIR)$(INSTALL_SBIN)
	$(INSTALL) -m 0755 $(SRCDIR)/nfsdump2db $(DESTDIR)$(INSTALL_SBIN)
	$(INSTALL) -m 0755 $(SRCDIR)/nfstrace.proxy $(DESTDIR)$(INSTALL_SBIN)
141
	-mkdir -p $(DESTDIR)$(INSTALL_ETC)/rc.d
142
	$(INSTALL) -m 0755 nfstrace.init $(DESTDIR)$(INSTALL_ETC)/rc.d/nfstrace
143 144 145 146 147 148 149 150 151 152 153
	-mkdir -p $(INSTALL_DIR)/opsdir/man/man8
	$(INSTALL) -m 0644 $(SRCDIR)/nfstrace.proxy.8 \
		$(INSTALL_DIR)/opsdir/man/man8/nfstrace.proxy.8
	$(INSTALL) -m 0644 $(SRCDIR)/nfsdump2db.8 \
		$(INSTALL_DIR)/opsdir/man/man8/nfsdump2db.8
	-mkdir -p $(INSTALL_DIR)/opsdir/man/man7
	$(INSTALL) -m 0644 $(SRCDIR)/nfstrace.7 \
		$(INSTALL_DIR)/opsdir/man/man7/nfstrace.7
else
fs-install install:
endif
Leigh B. Stoller's avatar
Leigh B. Stoller committed
154

155
clean:
156
	cd nfsdump2 && $(MAKE) clean
157
	rm -f *.o core nfsdump nfstrace.init